From 97b4e9f800389ffb9ada32672e359d309ff62d2e Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 5 May 2022 21:38:15 +0000 Subject: [PATCH] allow connections to fail --- web3-proxy/src/connection.rs | 2 ++ web3-proxy/src/connections.rs | 9 ++++++--- web3-proxy/src/main.rs | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web3-proxy/src/connection.rs b/web3-proxy/src/connection.rs index 4b9e1b4f..28f211cf 100644 --- a/web3-proxy/src/connection.rs +++ b/web3-proxy/src/connection.rs @@ -95,6 +95,7 @@ impl Web3Connection { .interval(Duration::from_secs(1)) .into() } else if url_str.starts_with("ws") { + // TODO: wrapper automatically reconnect let provider = ethers::providers::Ws::connect(url_str.clone()).await?; // TODO: make sure this automatically reconnects @@ -142,6 +143,7 @@ impl Web3Connection { loop { // wait for the interval + // TODO: if error or rate limit, increase interval? interval.tick().await; let block_number = provider.get_block_number().await.map(|x| x.as_u64())?; diff --git a/web3-proxy/src/connections.rs b/web3-proxy/src/connections.rs index c16622d6..3ac2c8a4 100644 --- a/web3-proxy/src/connections.rs +++ b/web3-proxy/src/connections.rs @@ -69,11 +69,14 @@ impl Web3Connections { let num_connections = servers.len(); for server_config in servers.into_iter() { - let connection = server_config.try_build(clock, http_client.clone()).await?; - - connections.push(connection); + match server_config.try_build(clock, http_client.clone()).await { + Ok(connection) => connections.push(connection), + Err(e) => warn!("Unable to connect to a server! {}", e), + } } + // TODO: exit if no connections? + let connections = Arc::new(Self { inner: connections, synced_connections: ArcSwap::new(Arc::new(SyncedConnections::new(num_connections))), diff --git a/web3-proxy/src/main.rs b/web3-proxy/src/main.rs index 05738bac..728bc638 100644 --- a/web3-proxy/src/main.rs +++ b/web3-proxy/src/main.rs @@ -67,6 +67,7 @@ impl Web3ProxyApp { .user_agent(APP_USER_AGENT) .build()?; + // TODO: attach context to this error? let balanced_rpc_tiers = future::join_all(balanced_rpc_tiers.into_iter().map(|balanced_rpc_tier| { Web3Connections::try_new(balanced_rpc_tier, Some(http_client.clone()), &clock) @@ -75,6 +76,7 @@ impl Web3ProxyApp { .into_iter() .collect::>>>()?; + // TODO: attach context to this error? let private_rpcs = if private_rpcs.is_empty() { warn!("No private relays configured. Any transactions will be broadcast to the public mempool!"); // TODO: instead of None, set it to a list of all the rpcs from balanced_rpc_tiers. that way we broadcast very loudly