From 206d339d450840ba2ffff3c53cd0b0498f6a970d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 2 Jan 2023 10:34:16 -0800 Subject: [PATCH] all_backend_connections skips syncing servers --- TODO.md | 1 + web3_proxy/src/app/mod.rs | 2 +- web3_proxy/src/rpcs/connection.rs | 7 +++++++ web3_proxy/src/rpcs/connections.rs | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index bd0c65ff..b2957393 100644 --- a/TODO.md +++ b/TODO.md @@ -292,6 +292,7 @@ These are not yet ordered. There might be duplicates. We might not actually need - ERROR http_request:request:try_send_all_upstream_servers: web3_proxy::rpcs::request: bad response! err=JsonRpcClientError(JsonRpcError(JsonRpcError { code: -32000, message: "INTERNAL_ERROR: existing tx with same hash", data: None })) method=eth_sendRawTransaction rpc=local_erigon_alpha_archive id=01GF4HV03Y4ZNKQV8DW5NDQ5CG method=POST authorized_request=User(Some(SqlxMySqlPoolConnection), AuthorizedKey { ip: 10.11.12.15, origin: None, user_key_id: 4, log_revert_chance: 0.0000 }) self=Web3Connections { conns: {"local_erigon_alpha_archive_ws": Web3Connection { name: "local_erigon_alpha_archive_ws", blocks: "all", .. }, "local_geth_ws": Web3Connection { name: "local_geth_ws", blocks: 64, .. }, "local_erigon_alpha_archive": Web3Connection { name: "local_erigon_alpha_archive", blocks: "all", .. }}, .. } authorized_request=Some(User(Some(SqlxMySqlPoolConnection), AuthorizedKey { ip: 10.11.12.15, origin: None, user_key_id: 4, log_revert_chance: 0.0000 })) request=JsonRpcRequest { id: RawValue(39), method: "eth_sendRawTransaction", .. } request_metadata=Some(RequestMetadata { datetime: 2022-10-11T22:14:57.406829095Z, period_seconds: 60, request_bytes: 633, backend_requests: 0, no_servers: 0, error_response: false, response_bytes: 0, response_millis: 0 }) block_needed=None - [x] serde collect unknown fields in config instead of crash - [x] upgrade user tier by address +- [x] all_backend_connections skips syncing servers - [-] fix multiple origin and referer checks - [-] let users choose a % to log (or maybe x/second). someone like curve logging all reverts will be a BIG database very quickly - this must be opt-in or spawned since it will slow things down and will make their calls less private diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 6edd1ac7..6bc9e623 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1158,7 +1158,7 @@ impl Web3ProxyApp { if let Ok(tx) = Transaction::decode(&rlp) { let tx_hash = json!(tx.hash()); - debug!("tx_hash: {:#?}", tx_hash); + trace!("tx_hash: {:#?}", tx_hash); let tx_hash = to_raw_value(&tx_hash).unwrap(); diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index 48d338ed..5f197201 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -286,6 +286,13 @@ impl Web3Connection { self.block_data_limit.load(atomic::Ordering::Relaxed).into() } + pub fn syncing(&self) -> bool { + match self.head_block.read().clone() { + None => true, + Some(x) => x.syncing(), + } + } + pub fn has_block_data(&self, needed_block_num: &U64) -> bool { let head_block_num = match self.head_block.read().clone() { None => return false, diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index 9fac1150..53dc6e36 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -572,6 +572,9 @@ impl Web3Connections { if !connection.has_block_data(block_needed) { continue; } + } else if connection.syncing() { + continue; + } } // check rate limits and increment our connection counter