From 14381c55c64af93955447b457d678cc568b4ff56 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 2 May 2022 20:40:16 +0000 Subject: [PATCH] less verbose logs --- src/connection.rs | 54 +++++++++++++++++++++++----------------------- src/connections.rs | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index debff9f9..44c1af23 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -82,12 +82,6 @@ pub struct Web3Connection { head_block_number: AtomicU64, } -impl Hash for Web3Connection { - fn hash(&self, state: &mut H) { - self.url.hash(state); - } -} - impl fmt::Debug for Web3Connection { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Web3Connection") @@ -96,6 +90,18 @@ impl fmt::Debug for Web3Connection { } } +impl fmt::Display for Web3Connection { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", &self.url) + } +} + +impl Hash for Web3Connection { + fn hash(&self, state: &mut H) { + self.url.hash(state); + } +} + impl Web3Connection { /// Connect to a web3 rpc and subscribe to new heads pub async fn try_new( @@ -160,7 +166,7 @@ impl Web3Connection { self: Arc, connections: Option>, ) -> anyhow::Result<()> { - info!("Watching new_heads on {:?}", self); + info!("Watching new_heads on {}", self); match &self.provider { Web3Provider::Http(provider) => { @@ -173,26 +179,20 @@ impl Web3Connection { // wait for 2 seconds interval.tick().await; - match ( - &connections, - provider.get_block_number().await.map(|x| x.as_u64()), - ) { - (None, Ok(block_number)) => { - // TODO: only store if this isn't already stored? - // TODO: also send something to the provider_tier so it can sort? - self.head_block_number - .store(block_number, atomic::Ordering::SeqCst); - } - (Some(connections), Ok(block_number)) => { - let old_block_number = self - .head_block_number - .swap(block_number, atomic::Ordering::SeqCst); + let block_number = provider.get_block_number().await.map(|x| x.as_u64())?; - if old_block_number != block_number { - connections.update_synced_rpcs(&self, block_number)?; - } + // TODO: only store if this isn't already stored? + // TODO: also send something to the provider_tier so it can sort? + let old_block_number = self + .head_block_number + .swap(block_number, atomic::Ordering::SeqCst); + + if old_block_number != block_number { + info!("new block on {}: {}", self, block_number); + + if let Some(connections) = &connections { + connections.update_synced_rpcs(&self, block_number)?; } - (_, Err(e)) => warn!("getBlockNumber failed: {}", e), } } } @@ -211,7 +211,7 @@ impl Web3Connection { .swap(block_number, atomic::Ordering::SeqCst); if old_block_number != block_number { - info!("new block on {:?}: {}", self, block_number); + info!("new block on {}: {}", self, block_number); if let Some(connections) = &connections { connections.update_synced_rpcs(&self, block_number)?; @@ -221,7 +221,7 @@ impl Web3Connection { } } - info!("Done watching new_heads"); + info!("Done watching new_heads on {}", self); Ok(()) } diff --git a/src/connections.rs b/src/connections.rs index ba617bce..91ca53ca 100644 --- a/src/connections.rs +++ b/src/connections.rs @@ -11,7 +11,7 @@ use std::cmp; use std::fmt; use std::sync::Arc; use tokio::sync::mpsc; -use tracing::{info, warn}; +use tracing::warn; use crate::connection::{JsonRpcForwardedResponse, Web3Connection};