better logs and only allow being 1 block behind

This commit is contained in:
Bryan Stitt 2022-04-27 05:51:22 +00:00
parent 570d11a987
commit 2feb5d213c
4 changed files with 20 additions and 11 deletions

@ -121,12 +121,10 @@ impl BlockWatcher {
// TODO: include time since last update?
info!(
"{:?} = {} Ts: {:?}, block number: {}, age: {}s {}",
"{:?} = {}, {}, {} sec, {}",
new_block.hash.unwrap(),
rpc,
// TODO: human readable time?
new_block.timestamp,
new_block.number.unwrap(),
rpc,
now - new_block.timestamp.as_u64() as i64,
label_slow_heads
);

@ -345,10 +345,16 @@ async fn main() {
vec![("ws://10.11.12.16:8545", 0), ("ws://10.11.12.16:8946", 0)],
// paid nodes
// TODO: add paid nodes (with rate limits)
// free nodes
// TODO: add rate limits
vec![
("https://main-rpc.linkpool.io", 0),
// chainstack.com archive
(
"wss://ws-nd-373-761-850.p2pify.com/106d73af4cebc487df5ba92f1ad8dee7",
0,
),
],
// free nodes
vec![
// ("https://main-rpc.linkpool.io", 0), // linkpool is slow
("https://rpc.ankr.com/eth", 0),
],
],

@ -1,6 +1,6 @@
///! Communicate with a web3 providers
use derive_more::From;
use ethers::prelude::Middleware;
use ethers::prelude::{BlockNumber, Middleware};
use futures::StreamExt;
use std::time::Duration;
use std::{cmp::Ordering, sync::Arc};
@ -40,16 +40,21 @@ impl Web3Provider {
// TODO: automatically reconnect
match &self {
Web3Provider::Http(_provider) => {
Web3Provider::Http(provider) => {
// TODO: there is a "watch_blocks" function, but a lot of public nodes do not support the necessary rpc endpoints
// TODO: how often?
// TODO: maybe it would be better to have one interval for all of these, but this works for now
let mut interval = interval(Duration::from_secs(2));
loop {
// wait for 2 seconds
interval.tick().await;
unimplemented!("todo: send block number")
match provider.get_block(BlockNumber::Latest).await {
Ok(Some(block)) => block_watcher_sender.send((url.clone(), block)).unwrap(),
Ok(None) => warn!("no black at {}", url),
Err(e) => warn!("getBlock at {} failed: {}", url, e),
}
}
}
Web3Provider::Ws(provider) => {

@ -155,7 +155,7 @@ impl Web3ProviderTier {
for selected_rpc in self.rpcs.read().await.iter() {
// check that the server is synced
if !block_watcher
.is_synced(selected_rpc.clone(), 3)
.is_synced(selected_rpc.clone(), 1)
.await
.expect("checking is_synced failed")
{