diff --git a/web3_proxy/src/rpcs/blockchain.rs b/web3_proxy/src/rpcs/blockchain.rs index 3159dfe2..613f1300 100644 --- a/web3_proxy/src/rpcs/blockchain.rs +++ b/web3_proxy/src/rpcs/blockchain.rs @@ -69,7 +69,7 @@ impl SavedBlock { } /// When the block was received, this node was still syncing - pub fn was_syncing(&self) -> bool { + pub fn syncing(&self) -> bool { // TODO: margin should come from a global config self.lag > 60 } @@ -85,7 +85,7 @@ impl Display for SavedBlock { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{} ({})", self.number(), self.hash())?; - if self.was_syncing() { + if self.syncing() { write!(f, " (behind by {} seconds)", self.lag)?; } @@ -307,7 +307,7 @@ impl Web3Connections { // we don't know if its on the heaviest chain yet self.save_block(&rpc_head_block.block, false).await?; - if rpc_head_block.was_syncing() { + if rpc_head_block.syncing() { if connection_heads.remove(&rpc.name).is_some() { warn!("{} is behind by {} seconds", &rpc.name, rpc_head_block.lag); }; @@ -590,7 +590,7 @@ impl Web3Connections { } Ordering::Greater => { debug!( - "new {}/{}/{} con head={} rpc_head={} rpc={}", + "new {}/{}/{} con_head={} rpc_head={} rpc={}", num_consensus_rpcs, num_connection_heads, total_conns, diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index 29cb80c9..0e7ee884 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -277,7 +277,15 @@ impl Web3Connection { pub fn has_block_data(&self, needed_block_num: &U64) -> bool { let head_block_num = match self.head_block.read().clone() { None => return false, - Some(x) => x.number(), + Some(x) => { + if x.syncing() { + // skip syncing nodes. even though they might be able to serve a query, + // latency will be poor and + return false; + } + + x.number() + } }; // this rpc doesn't have that block yet. still syncing