Skip to content

Commit 131a044

Browse files
authored
minors (#64)
* minors * minors * minors
1 parent 84faf83 commit 131a044

File tree

14 files changed

+150
-21
lines changed

14 files changed

+150
-21
lines changed

run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
. .env
22
export CHAIN_ID
33
export RPC
4-
cargo run
4+
RUST_BACKTRACE=1 cargo run

src/checks/block.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::time::Duration;
1+
use std::{fmt::Display, time::Duration};
22

33
use crate::shared::alert::Metadata;
44

@@ -43,6 +43,16 @@ impl CheckTrait for BlockCheck {
4343
}
4444
}
4545

46+
impl Display for BlockCheck {
47+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48+
write!(
49+
f,
50+
"BlockCheck(estimated_block_time: {}, block_time_deviation: {})",
51+
self.estimated_block_time, self.block_time_deviation
52+
)
53+
}
54+
}
55+
4656
impl BlockCheck {
4757
pub fn new(config: &AppConfig) -> Self {
4858
let config = config.get_config();

src/checks/fees.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
};
66

77
use super::{AppConfig, CheckTrait};
8-
use std::collections::HashMap;
8+
use std::{collections::HashMap, fmt::Display};
99

1010
const FEE_CHECK_ID: &str = "fee_check";
1111

@@ -82,3 +82,9 @@ impl CheckTrait for FeeCheck {
8282
false
8383
}
8484
}
85+
86+
impl Display for FeeCheck {
87+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88+
write!(f, "FeeCheck with {} thresholds", self.thresholds.len())
89+
}
90+
}

src/checks/gas.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::Display;
2+
13
use crate::shared::alert::Metadata;
24

35
use super::{AppConfig, CheckTrait};
@@ -49,6 +51,16 @@ impl CheckTrait for GasCheck {
4951
}
5052
}
5153

54+
impl Display for GasCheck {
55+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56+
write!(
57+
f,
58+
"GasCheck(gas_limit_threshold: {})",
59+
self.gas_limit_threshold
60+
)
61+
}
62+
}
63+
5264
impl GasCheck {
5365
pub fn new(config: &AppConfig) -> Self {
5466
let config = config.get_config();

src/checks/halt.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
1+
use std::{
2+
fmt::Display,
3+
time::{Duration, SystemTime, UNIX_EPOCH},
4+
};
25

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

@@ -93,6 +96,16 @@ impl CheckTrait for HaltCheck {
9396
}
9497
}
9598

99+
impl Display for HaltCheck {
100+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
101+
write!(
102+
f,
103+
"HaltCheck(estimated_block_time: {}, halt_threshold: {})",
104+
self.estimated_block_time, self.halt_threshold
105+
)
106+
}
107+
}
108+
96109
impl HaltCheck {
97110
pub fn new(config: &AppConfig) -> Self {
98111
let config = config.get_config();

src/checks/ibc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Display;
12
use std::str::FromStr;
23
use std::time::Duration;
34

@@ -140,6 +141,12 @@ impl CheckTrait for IbcCheck {
140141
}
141142
}
142143

144+
impl Display for IbcCheck {
145+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
146+
write!(f, "IbcCheck with {} channels", self.channels.len())
147+
}
148+
}
149+
143150
impl IbcCheck {
144151
pub fn new(config: &AppConfig) -> Self {
145152
let channels = config

src/checks/ibc_limit.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::Display;
2+
13
use super::CheckTrait;
24

35
const LIMIT_IBC_CHECK_ID: &str = "ibc_limit_check";
@@ -44,3 +46,9 @@ impl CheckTrait for IbcLimitCheck {
4446
false
4547
}
4648
}
49+
50+
impl Display for IbcLimitCheck {
51+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52+
write!(f, "IbcLimitCheck")
53+
}
54+
}

src/checks/mod.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ mod slashes;
99
mod transfer_limit;
1010
mod tx;
1111

12+
use std::fmt::Display;
13+
1214
use async_trait::async_trait;
13-
use halt::HaltCheck;
1415

1516
pub use crate::config::AppConfig;
1617
pub use crate::state::State;
1718
use crate::{
1819
checks::{
19-
block::BlockCheck, fees::FeeCheck, gas::GasCheck, ibc::IbcCheck, ibc_limit::IbcLimitCheck,
20-
pos::PoSCheck, slashes::SlashCheck, transfer_limit::TransferLimitCheck, tx::TxCheck,
20+
block::BlockCheck, fees::FeeCheck, gas::GasCheck, halt::HaltCheck, ibc::IbcCheck,
21+
ibc_limit::IbcLimitCheck, pos::PoSCheck, slashes::SlashCheck,
22+
transfer_limit::TransferLimitCheck, tx::TxCheck,
2123
},
2224
shared::alert::Alert,
2325
};
2426

2527
#[async_trait]
26-
pub trait CheckTrait: Send + Sync {
28+
pub trait CheckTrait: Send + Sync + Display {
2729
async fn check(&self, state: &State) -> Vec<Alert>;
2830
fn is_continous(&self) -> bool;
2931
}
@@ -69,4 +71,17 @@ impl CheckManager {
6971
}
7072
results
7173
}
74+
75+
pub fn get_checks(&self) -> &Vec<Box<dyn CheckTrait>> {
76+
&self.checks
77+
}
78+
}
79+
80+
impl Display for CheckManager {
81+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82+
for check in &self.checks {
83+
write!(f, "{}", check)?;
84+
}
85+
write!(f, "CheckManager with {} checks", self.checks.len())
86+
}
7287
}

src/checks/pos.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::time::Duration;
1+
use std::{fmt::Display, time::Duration};
22

33
use super::{AppConfig, CheckTrait};
44

@@ -178,3 +178,18 @@ impl CheckTrait for PoSCheck {
178178
false
179179
}
180180
}
181+
182+
impl Display for PoSCheck {
183+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
184+
write!(
185+
f,
186+
"PoSCheck(mininimum_one_third_validators: {}, mininimum_two_third_validators: {}, bond_increase_threshold: {}, unbond_increase_threshold: {}, consensus_threshold: {}, threshold_missed_votes: {})",
187+
self.mininimum_one_third_validators,
188+
self.mininimum_two_third_validators,
189+
self.bond_increase_threshold,
190+
self.unbond_increase_threshold,
191+
self.consensus_threshold,
192+
self.threshold_missed_votes
193+
)
194+
}
195+
}

src/checks/slashes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::Display;
2+
13
use namada_sdk::tendermint::evidence;
24

35
use crate::{
@@ -89,3 +91,9 @@ impl CheckTrait for SlashCheck {
8991
false
9092
}
9193
}
94+
95+
impl Display for SlashCheck {
96+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97+
write!(f, "SlashCheck")
98+
}
99+
}

0 commit comments

Comments
 (0)