less verbose logs
This commit is contained in:
parent
b47482298c
commit
14381c55c6
@ -82,12 +82,6 @@ pub struct Web3Connection {
|
|||||||
head_block_number: AtomicU64,
|
head_block_number: AtomicU64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hash for Web3Connection {
|
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
||||||
self.url.hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Web3Connection {
|
impl fmt::Debug for Web3Connection {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("Web3Connection")
|
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<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.url.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Web3Connection {
|
impl Web3Connection {
|
||||||
/// Connect to a web3 rpc and subscribe to new heads
|
/// Connect to a web3 rpc and subscribe to new heads
|
||||||
pub async fn try_new(
|
pub async fn try_new(
|
||||||
@ -160,7 +166,7 @@ impl Web3Connection {
|
|||||||
self: Arc<Self>,
|
self: Arc<Self>,
|
||||||
connections: Option<Arc<Web3Connections>>,
|
connections: Option<Arc<Web3Connections>>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
info!("Watching new_heads on {:?}", self);
|
info!("Watching new_heads on {}", self);
|
||||||
|
|
||||||
match &self.provider {
|
match &self.provider {
|
||||||
Web3Provider::Http(provider) => {
|
Web3Provider::Http(provider) => {
|
||||||
@ -173,27 +179,21 @@ impl Web3Connection {
|
|||||||
// wait for 2 seconds
|
// wait for 2 seconds
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
|
||||||
match (
|
let block_number = provider.get_block_number().await.map(|x| x.as_u64())?;
|
||||||
&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: only store if this isn't already stored?
|
||||||
// TODO: also send something to the provider_tier so it can sort?
|
// 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
|
let old_block_number = self
|
||||||
.head_block_number
|
.head_block_number
|
||||||
.swap(block_number, atomic::Ordering::SeqCst);
|
.swap(block_number, atomic::Ordering::SeqCst);
|
||||||
|
|
||||||
if old_block_number != block_number {
|
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)?;
|
connections.update_synced_rpcs(&self, block_number)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(_, Err(e)) => warn!("getBlockNumber failed: {}", e),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Web3Provider::Ws(provider) => {
|
Web3Provider::Ws(provider) => {
|
||||||
@ -211,7 +211,7 @@ impl Web3Connection {
|
|||||||
.swap(block_number, atomic::Ordering::SeqCst);
|
.swap(block_number, atomic::Ordering::SeqCst);
|
||||||
|
|
||||||
if old_block_number != block_number {
|
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 {
|
if let Some(connections) = &connections {
|
||||||
connections.update_synced_rpcs(&self, block_number)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use std::cmp;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tracing::{info, warn};
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::connection::{JsonRpcForwardedResponse, Web3Connection};
|
use crate::connection::{JsonRpcForwardedResponse, Web3Connection};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user