serarate max_age and max_lag

This commit is contained in:
Bryan Stitt 2023-01-17 15:52:31 -08:00
parent 9ba4c288c6
commit 9fe6365283
2 changed files with 14 additions and 4 deletions

@ -1,6 +1,6 @@
use anyhow::{anyhow, Context};
use chrono::{DateTime, Utc};
use ethers::types::{Block, TxHash, H256, U64};
use ethers::types::{Block, TxHash, H256};
use futures::{stream::FuturesUnordered, StreamExt};
use log::{debug, warn};
use serde::{Deserialize, Serialize};
@ -34,7 +34,12 @@ impl From<Block<TxHash>> for AbbreviatedBlock {
}
}
pub async fn main(rpc: String, others: Vec<String>, max_lag: i64) -> anyhow::Result<()> {
pub async fn main(
rpc: String,
others: Vec<String>,
max_age: i64,
max_lag: i64,
) -> anyhow::Result<()> {
let client = reqwest::Client::new();
let block_by_number_request = json!({
@ -118,7 +123,7 @@ pub async fn main(rpc: String, others: Vec<String>, max_lag: i64) -> anyhow::Res
.signed_duration_since(newest_other.max(&rpc_block).time)
.num_seconds();
match block_age.abs().cmp(&max_lag) {
match block_age.abs().cmp(&max_age) {
std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {}
std::cmp::Ordering::Greater => match duration_since.cmp(&0) {
std::cmp::Ordering::Equal => unimplemented!(),

@ -21,6 +21,10 @@ pub struct SentrydSubCommand {
/// the main (HTTP only) web3-proxy being checked.
web3_proxy: String,
#[argh(option)]
/// warning threshold for age of the best known head block
max_age: i64,
#[argh(option)]
/// warning threshold for seconds between the rpc and best other_rpc's head blocks
max_lag: i64,
@ -69,6 +73,7 @@ impl SentrydSubCommand {
// compare the main web3-proxy head block to all web3-proxies and rpcs
{
let max_age = self.max_age;
let max_lag = self.max_lag;
let rpc = self.web3_proxy.clone();
@ -77,7 +82,7 @@ impl SentrydSubCommand {
others.extend(self.other_rpc.clone());
let loop_f = a_loop(seconds, log::Level::Error, move || {
compare::main(rpc.clone(), others.clone(), max_lag)
compare::main(rpc.clone(), others.clone(), max_age, max_lag)
});
handles.push(tokio::spawn(loop_f));