serarate max_age and max_lag
This commit is contained in:
parent
9ba4c288c6
commit
9fe6365283
@ -1,6 +1,6 @@
|
|||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use ethers::types::{Block, TxHash, H256, U64};
|
use ethers::types::{Block, TxHash, H256};
|
||||||
use futures::{stream::FuturesUnordered, StreamExt};
|
use futures::{stream::FuturesUnordered, StreamExt};
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use serde::{Deserialize, Serialize};
|
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 client = reqwest::Client::new();
|
||||||
|
|
||||||
let block_by_number_request = json!({
|
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)
|
.signed_duration_since(newest_other.max(&rpc_block).time)
|
||||||
.num_seconds();
|
.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::Less | std::cmp::Ordering::Equal => {}
|
||||||
std::cmp::Ordering::Greater => match duration_since.cmp(&0) {
|
std::cmp::Ordering::Greater => match duration_since.cmp(&0) {
|
||||||
std::cmp::Ordering::Equal => unimplemented!(),
|
std::cmp::Ordering::Equal => unimplemented!(),
|
||||||
|
@ -21,6 +21,10 @@ pub struct SentrydSubCommand {
|
|||||||
/// the main (HTTP only) web3-proxy being checked.
|
/// the main (HTTP only) web3-proxy being checked.
|
||||||
web3_proxy: String,
|
web3_proxy: String,
|
||||||
|
|
||||||
|
#[argh(option)]
|
||||||
|
/// warning threshold for age of the best known head block
|
||||||
|
max_age: i64,
|
||||||
|
|
||||||
#[argh(option)]
|
#[argh(option)]
|
||||||
/// warning threshold for seconds between the rpc and best other_rpc's head blocks
|
/// warning threshold for seconds between the rpc and best other_rpc's head blocks
|
||||||
max_lag: i64,
|
max_lag: i64,
|
||||||
@ -69,6 +73,7 @@ impl SentrydSubCommand {
|
|||||||
|
|
||||||
// compare the main web3-proxy head block to all web3-proxies and rpcs
|
// 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 max_lag = self.max_lag;
|
||||||
let rpc = self.web3_proxy.clone();
|
let rpc = self.web3_proxy.clone();
|
||||||
|
|
||||||
@ -77,7 +82,7 @@ impl SentrydSubCommand {
|
|||||||
others.extend(self.other_rpc.clone());
|
others.extend(self.other_rpc.clone());
|
||||||
|
|
||||||
let loop_f = a_loop(seconds, log::Level::Error, move || {
|
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));
|
handles.push(tokio::spawn(loop_f));
|
||||||
|
Loading…
Reference in New Issue
Block a user