From 8b5578b261aabcbf18fcc056ecabe38ac90cdea3 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 15 Jul 2022 23:59:34 +0000 Subject: [PATCH] better archive check this could still be better --- web3-proxy/src/connection.rs | 15 ++------------- web3-proxy/src/connections.rs | 36 +++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/web3-proxy/src/connection.rs b/web3-proxy/src/connection.rs index ec09fbbd..38d8b24c 100644 --- a/web3-proxy/src/connection.rs +++ b/web3-proxy/src/connection.rs @@ -623,15 +623,7 @@ impl Eq for Web3Connection {} impl Ord for Web3Connection { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - // TODO: what atomic ordering?! - let a = self.active_requests.load(atomic::Ordering::Acquire); - let b = other.active_requests.load(atomic::Ordering::Acquire); - - // TODO: how should we include the soft limit? floats are slower than integer math - let a = (a + 1) as f32 / self.soft_limit as f32; - let b = (b + 1) as f32 / other.soft_limit as f32; - - a.partial_cmp(&b).unwrap() + self.url.cmp(&other.url) } } @@ -641,11 +633,8 @@ impl PartialOrd for Web3Connection { } } -/// note that this is just comparing the active requests. two providers with different rpc urls are equal! impl PartialEq for Web3Connection { fn eq(&self, other: &Self) -> bool { - // TODO: what ordering?! - self.active_requests.load(atomic::Ordering::Acquire) - == other.active_requests.load(atomic::Ordering::Acquire) + self.url == other.url } } diff --git a/web3-proxy/src/connections.rs b/web3-proxy/src/connections.rs index 241de8b7..1dc87fc4 100644 --- a/web3-proxy/src/connections.rs +++ b/web3-proxy/src/connections.rs @@ -41,7 +41,10 @@ struct SyncedConnections { impl fmt::Debug for SyncedConnections { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: the default formatter takes forever to write. this is too quiet though - f.debug_struct("SyncedConnections").finish_non_exhaustive() + f.debug_struct("SyncedConnections") + .field("head_block_num", &self.head_block_num) + .field("head_block_hash", &self.head_block_hash) + .finish_non_exhaustive() } } @@ -201,7 +204,7 @@ impl Web3Connections { pending_tx_id: TxHash, ) -> Result, ProviderError> { // TODO: yearn devs have had better luck with batching these, but i think that's likely just adding a delay itself - // TODO: there is a race here sometimes the rpc isn't yet ready to serve the transaction (even though they told us about it!) + // TODO: there is a race here on geth. sometimes the rpc isn't yet ready to serve the transaction (even though they told us about it!) // TODO: maximum wait time let pending_transaction: Transaction = match rpc.try_request_handle().await { Ok(request_handle) => { @@ -222,7 +225,6 @@ impl Web3Connections { trace!(?pending_transaction, "pending"); - // TODO: do not unwrap. orphans might make this unsafe match &pending_transaction.block_hash { Some(_block_hash) => { // the transaction is already confirmed. no need to save in the pending_transactions map @@ -607,15 +609,25 @@ impl Web3Connections { ) -> Result> { let mut earliest_retry_after = None; - let mut synced_rpcs: Vec> = self - .synced_connections - .load() - .inner - .iter() - .filter(|x| !skip.contains(x)) - .filter(|x| if archive_needed { x.is_archive() } else { true }) - .cloned() - .collect(); + // filter the synced rpcs + let mut synced_rpcs: Vec> = if archive_needed { + // TODO: this includes ALL archive servers. but we only want them if they are on a somewhat recent block + // TODO: maybe instead of "archive_needed" bool it should be the minimum height. then even delayed servers might be fine. will need to track all heights then + self.inner + .iter() + .filter(|x| x.is_archive()) + .filter(|x| !skip.contains(x)) + .cloned() + .collect() + } else { + self.synced_connections + .load() + .inner + .iter() + .filter(|x| !skip.contains(x)) + .cloned() + .collect() + }; if synced_rpcs.is_empty() { return Err(None);