From 9fe63652839d99e4736e637d166eaa473c91262a Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 17 Jan 2023 15:52:31 -0800 Subject: [PATCH] serarate max_age and max_lag --- web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs | 11 ++++++++--- web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs b/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs index 50fcea7a..ada4681e 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/sentryd/compare.rs @@ -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> for AbbreviatedBlock { } } -pub async fn main(rpc: String, others: Vec, max_lag: i64) -> anyhow::Result<()> { +pub async fn main( + rpc: String, + others: Vec, + 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, 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!(), diff --git a/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs b/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs index 22b6aab1..51d0df7a 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs @@ -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));