From f736aeb027c838d9114a04f1ca3741233d27dc4d Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 4 Dec 2022 17:25:23 -0800 Subject: [PATCH] move config safty checks earlier --- web3_proxy/src/app/mod.rs | 21 +++++++++++++++++++++ web3_proxy/src/rpcs/connection.rs | 1 + web3_proxy/src/rpcs/connections.rs | 11 ----------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 35b8ec21..2751cca2 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -284,6 +284,27 @@ impl Web3ProxyApp { }; let balanced_rpcs = top_config.balanced_rpcs; + + // safety check on balanced_rpcs + if balanced_rpcs.len() < top_config.app.min_synced_rpcs { + return Err(anyhow::anyhow!( + "Only {}/{} rpcs! Add more balanced_rpcs or reduce min_synced_rpcs.", + balanced_rpcs.len(), + top_config.app.min_synced_rpcs + )); + } + + // safety check on sum soft limit + let sum_soft_limit = balanced_rpcs.values().fold(0, |acc, x| acc + x.soft_limit); + + if sum_soft_limit < top_config.app.min_sum_soft_limit { + return Err(anyhow::anyhow!( + "Only {}/{} soft limit! Add more balanced_rpcs, increase soft limits, or reduce min_sum_soft_limit.", + sum_soft_limit, + top_config.app.min_sum_soft_limit + )); + } + let private_rpcs = top_config.private_rpcs.unwrap_or_default(); // these are safe to cancel diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index e37100c6..6dd8e628 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -959,6 +959,7 @@ impl Serialize for Web3Connection { &self.frontend_requests.load(atomic::Ordering::Relaxed), )?; + // TODO: rename to head_block (need to work with the frontend team) let head_block_id = &*self.head_block.read(); state.serialize_field("head_block_id", head_block_id)?; diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index d5492920..832d5b2a 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -173,17 +173,6 @@ impl Web3Connections { } } - // TODO: now this errors for private rpcs when we disable all! - if connections.len() < min_head_rpcs { - return Err(anyhow::anyhow!( - "Only {}/{} connections! Add more connections or reduce min_head_rpcs.", - connections.len(), - min_head_rpcs - )); - } - - // TODO: safety check on sum soft limit - let synced_connections = SyncedConnections::default(); // TODO: max_capacity and time_to_idle from config