Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. .env
export CHAIN_ID
export RPC
cargo run
RUST_BACKTRACE=1 cargo run
12 changes: 11 additions & 1 deletion src/checks/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{fmt::Display, time::Duration};

use crate::shared::alert::Metadata;

Expand Down Expand Up @@ -43,6 +43,16 @@ impl CheckTrait for BlockCheck {
}
}

impl Display for BlockCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"BlockCheck(estimated_block_time: {}, block_time_deviation: {})",
self.estimated_block_time, self.block_time_deviation
)
}
}

impl BlockCheck {
pub fn new(config: &AppConfig) -> Self {
let config = config.get_config();
Expand Down
8 changes: 7 additions & 1 deletion src/checks/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};

use super::{AppConfig, CheckTrait};
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};

const FEE_CHECK_ID: &str = "fee_check";

Expand Down Expand Up @@ -82,3 +82,9 @@ impl CheckTrait for FeeCheck {
false
}
}

impl Display for FeeCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "FeeCheck with {} thresholds", self.thresholds.len())
}
}
12 changes: 12 additions & 0 deletions src/checks/gas.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use crate::shared::alert::Metadata;

use super::{AppConfig, CheckTrait};
Expand Down Expand Up @@ -49,6 +51,16 @@ impl CheckTrait for GasCheck {
}
}

impl Display for GasCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"GasCheck(gas_limit_threshold: {})",
self.gas_limit_threshold
)
}
}

impl GasCheck {
pub fn new(config: &AppConfig) -> Self {
let config = config.get_config();
Expand Down
15 changes: 14 additions & 1 deletion src/checks/halt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::{
fmt::Display,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use crate::shared::alert::{Alert, Metadata, Severity};

Expand Down Expand Up @@ -93,6 +96,16 @@ impl CheckTrait for HaltCheck {
}
}

impl Display for HaltCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"HaltCheck(estimated_block_time: {}, halt_threshold: {})",
self.estimated_block_time, self.halt_threshold
)
}
}

impl HaltCheck {
pub fn new(config: &AppConfig) -> Self {
let config = config.get_config();
Expand Down
7 changes: 7 additions & 0 deletions src/checks/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::str::FromStr;
use std::time::Duration;

Expand Down Expand Up @@ -140,6 +141,12 @@ impl CheckTrait for IbcCheck {
}
}

impl Display for IbcCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "IbcCheck with {} channels", self.channels.len())
}
}

impl IbcCheck {
pub fn new(config: &AppConfig) -> Self {
let channels = config
Expand Down
8 changes: 8 additions & 0 deletions src/checks/ibc_limit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::CheckTrait;

const LIMIT_IBC_CHECK_ID: &str = "ibc_limit_check";
Expand Down Expand Up @@ -44,3 +46,9 @@ impl CheckTrait for IbcLimitCheck {
false
}
}

impl Display for IbcLimitCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "IbcLimitCheck")
}
}
23 changes: 19 additions & 4 deletions src/checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ mod slashes;
mod transfer_limit;
mod tx;

use std::fmt::Display;

use async_trait::async_trait;
use halt::HaltCheck;

pub use crate::config::AppConfig;
pub use crate::state::State;
use crate::{
checks::{
block::BlockCheck, fees::FeeCheck, gas::GasCheck, ibc::IbcCheck, ibc_limit::IbcLimitCheck,
pos::PoSCheck, slashes::SlashCheck, transfer_limit::TransferLimitCheck, tx::TxCheck,
block::BlockCheck, fees::FeeCheck, gas::GasCheck, halt::HaltCheck, ibc::IbcCheck,
ibc_limit::IbcLimitCheck, pos::PoSCheck, slashes::SlashCheck,
transfer_limit::TransferLimitCheck, tx::TxCheck,
},
shared::alert::Alert,
};

#[async_trait]
pub trait CheckTrait: Send + Sync {
pub trait CheckTrait: Send + Sync + Display {
async fn check(&self, state: &State) -> Vec<Alert>;
fn is_continous(&self) -> bool;
}
Expand Down Expand Up @@ -69,4 +71,17 @@ impl CheckManager {
}
results
}

pub fn get_checks(&self) -> &Vec<Box<dyn CheckTrait>> {
&self.checks
}
}

impl Display for CheckManager {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for check in &self.checks {
write!(f, "{}", check)?;
}
write!(f, "CheckManager with {} checks", self.checks.len())
}
}
17 changes: 16 additions & 1 deletion src/checks/pos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{fmt::Display, time::Duration};

use super::{AppConfig, CheckTrait};

Expand Down Expand Up @@ -178,3 +178,18 @@ impl CheckTrait for PoSCheck {
false
}
}

impl Display for PoSCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"PoSCheck(mininimum_one_third_validators: {}, mininimum_two_third_validators: {}, bond_increase_threshold: {}, unbond_increase_threshold: {}, consensus_threshold: {}, threshold_missed_votes: {})",
self.mininimum_one_third_validators,
self.mininimum_two_third_validators,
self.bond_increase_threshold,
self.unbond_increase_threshold,
self.consensus_threshold,
self.threshold_missed_votes
)
}
}
8 changes: 8 additions & 0 deletions src/checks/slashes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use namada_sdk::tendermint::evidence;

use crate::{
Expand Down Expand Up @@ -89,3 +91,9 @@ impl CheckTrait for SlashCheck {
false
}
}

impl Display for SlashCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "SlashCheck")
}
}
12 changes: 11 additions & 1 deletion src/checks/transfer_limit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};

use namada_sdk::{ibc, token::Amount};

Expand Down Expand Up @@ -147,3 +147,13 @@ impl CheckTrait for TransferLimitCheck {
false
}
}

impl Display for TransferLimitCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"TransferLimitCheck with {} thresholds",
self.thresholds.len()
)
}
}
12 changes: 12 additions & 0 deletions src/checks/tx.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use super::{AppConfig, CheckTrait};

const TX_SECTIONS_CHECK_ID: &str = "tx_sections_check";
Expand Down Expand Up @@ -72,3 +74,13 @@ impl CheckTrait for TxCheck {
false
}
}

impl Display for TxCheck {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"TxCheck(threshold_sections: {}, threshold_batch: {})",
self.threshold_sections, self.threshold_batch
)
}
}
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ async fn main() -> anyhow::Result<()> {
let config = AppConfig::parse();
config.log.init();

tracing::info!(
"Namada monitoring version {}, commit {}",
env!("CARGO_PKG_VERSION"),
env!("VERGEN_GIT_SHA")
);

rlimit::increase_nofile_limit(10240).unwrap();
rlimit::increase_nofile_limit(u64::MAX).unwrap();

Expand Down
29 changes: 18 additions & 11 deletions src/shared/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ impl Manager {
.start_exporter()
.expect("Should be able to start metrics exporter");

(
Arc::new(RwLock::new(Self {
metrics_exporter,
checks,
alerts,
rpc,
state: State::default(),
})),
initial_block_height,
)
let manager = Self {
metrics_exporter,
checks,
alerts,
rpc,
state: State::default(),
};

for check in manager.checks.get_checks() {
tracing::info!("Loaded check: {}", check);
}

(Arc::new(RwLock::new(manager)), initial_block_height)
}

pub fn has_enough_blocks(&self) -> bool {
Expand All @@ -60,7 +63,11 @@ impl Manager {
block_height: u64,
tokens: Vec<(String, String)>,
) -> anyhow::Result<()> {
let last_epoch = self.state.last_block().block.epoch;
let last_epoch = if self.has_enough_blocks() {
self.state.last_block().block.epoch
} else {
0
};

let checksums = self.rpc.query_checksums_at_height(block_height).await?;
let epoch = self
Expand Down