From 5a567ebeeab12978b05ead14ef0a4c8a71d1310d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 3 Jan 2023 11:54:24 -0800 Subject: [PATCH] try a new way to check block data limit if no longer syncing but limit is 0 --- web3_proxy/src/rpcs/connection.rs | 21 ++++++++++++++++++++- web3_proxy/src/rpcs/connections.rs | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index 1b0225f0..6a299133 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -62,6 +62,7 @@ impl ProviderState { pub struct Web3Connection { pub name: String, pub display_name: Option, + pub db_conn: Option, /// TODO: can we get this from the provider? do we even need it? pub(super) url: String, /// Some connections use an http_client. we keep a clone for reconnecting @@ -137,6 +138,7 @@ impl Web3Connection { let new_connection = Self { name, + db_conn: db_conn.clone(), display_name, http_client, url: url_str, @@ -272,6 +274,10 @@ impl Web3Connection { } if let Some(limit) = limit { + if limit == 0 { + warn!("{} is unable to serve requests", self); + } + self.block_data_limit .store(limit, atomic::Ordering::Release); } @@ -283,7 +289,7 @@ impl Web3Connection { /// TODO: this might be too simple. different nodes can prune differently. its possible we will have a block range pub fn block_data_limit(&self) -> U64 { - self.block_data_limit.load(atomic::Ordering::Relaxed).into() + self.block_data_limit.load(atomic::Ordering::Acquire).into() } pub fn syncing(&self) -> bool { @@ -536,6 +542,16 @@ impl Web3Connection { let _ = head_block.insert(new_head_block.clone().into()); } + if self.block_data_limit() == U64::zero() && !self.syncing() { + let authorization = Arc::new(Authorization::internal(self.db_conn.clone())?); + if let Err(err) = self.check_block_data_limit(&authorization).await { + warn!( + "failed checking block limit after {} finished syncing. {:?}", + self, err + ); + } + } + Some(new_head_block) } Err(err) => { @@ -1194,6 +1210,7 @@ mod tests { let x = Web3Connection { name: "name".to_string(), + db_conn: None, display_name: None, url: "ws://example.com".to_string(), http_client: None, @@ -1240,6 +1257,7 @@ mod tests { // TODO: this is getting long. have a `impl Default` let x = Web3Connection { name: "name".to_string(), + db_conn: None, display_name: None, url: "ws://example.com".to_string(), http_client: None, @@ -1290,6 +1308,7 @@ mod tests { let x = Web3Connection { name: "name".to_string(), + db_conn: None, display_name: None, url: "ws://example.com".to_string(), http_client: None, diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index d2c15d1f..1bc25844 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -931,6 +931,7 @@ mod tests { let head_rpc = Web3Connection { name: "synced".to_string(), + db_conn: None, display_name: None, url: "ws://example.com/synced".to_string(), http_client: None, @@ -949,6 +950,7 @@ mod tests { let lagged_rpc = Web3Connection { name: "lagged".to_string(), + db_conn: None, display_name: None, url: "ws://example.com/lagged".to_string(), http_client: None, @@ -1151,6 +1153,7 @@ mod tests { let pruned_rpc = Web3Connection { name: "pruned".to_string(), + db_conn: None, display_name: None, url: "ws://example.com/pruned".to_string(), http_client: None, @@ -1169,6 +1172,7 @@ mod tests { let archive_rpc = Web3Connection { name: "archive".to_string(), + db_conn: None, display_name: None, url: "ws://example.com/archive".to_string(), http_client: None,