Skip to content

Commit 84faf83

Browse files
authored
added missed votes check (#63)
* added missed votes check * added missed votes check
1 parent 5d6fef2 commit 84faf83

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

config.toml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mininimum_two_third_validators = 4
1414
bond_increase_threshold = 0.1
1515
unbond_increase_threshold = 0.1
1616
consensus_threshold = 0.1
17+
threshold_missed_votes = 0.1
1718

1819
[tx]
1920
threshold_sections = 5

src/checks/pos.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const POS_TWO_THIRD_CHECK_ID: &str = "pos_one_third_check";
77
const POS_BONDS_CHECK_ID: &str = "pos_bonds_check";
88
const POS_UNBONDS_CHECK_ID: &str = "pos_unbonds_check";
99
const POS_CONSENSUS_CHECK_ID: &str = "pos_consensus_check";
10+
const POS_MISSED_VOTES_CHECK_ID: &str = "pos_missed_votes_check";
1011

1112
pub struct PoSCheck {
1213
mininimum_one_third_validators: u64,
1314
mininimum_two_third_validators: u64,
1415
bond_increase_threshold: f64,
1516
unbond_increase_threshold: f64,
1617
consensus_threshold: f64,
18+
threshold_missed_votes: f64,
1719
}
1820

1921
impl PoSCheck {
@@ -25,6 +27,7 @@ impl PoSCheck {
2527
bond_increase_threshold: config.pos.bond_increase_threshold,
2628
unbond_increase_threshold: config.pos.unbond_increase_threshold,
2729
consensus_threshold: config.pos.consensus_threshold,
30+
threshold_missed_votes: config.pos.threshold_missed_votes,
2831
}
2932
}
3033
}
@@ -140,6 +143,34 @@ impl CheckTrait for PoSCheck {
140143
});
141144
}
142145

146+
let total_validators = last_state.consensus_validators().len();
147+
let total_votes = last_state.block.block.last_commit.unwrap().signatures.len();
148+
149+
let missed_votes_percentage = if total_validators > 0 {
150+
1.0 - (total_votes as f64 / total_validators as f64)
151+
} else {
152+
0.0
153+
};
154+
155+
if missed_votes_percentage > self.threshold_missed_votes {
156+
alerts.push(crate::shared::alert::Alert {
157+
check_id: POS_MISSED_VOTES_CHECK_ID.to_string(),
158+
title: "High missed votes percentage".to_string(),
159+
description: format!(
160+
"Missed votes percentage is {:.2}% which is above the threshold of {:.2}%",
161+
missed_votes_percentage * 100.0,
162+
self.threshold_missed_votes * 100.0
163+
),
164+
metadata: crate::shared::alert::Metadata {
165+
block_height: Some(last_state.block.height as u32),
166+
tx_id: None,
167+
},
168+
severity: crate::shared::alert::Severity::Medium,
169+
trigger_after: None,
170+
continous: self.is_continous(),
171+
});
172+
}
173+
143174
alerts
144175
}
145176

src/shared/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct Pos {
3535
pub bond_increase_threshold: f64,
3636
pub unbond_increase_threshold: f64,
3737
pub consensus_threshold: f64,
38+
pub threshold_missed_votes: f64,
3839
}
3940

4041
#[derive(Debug, Clone, Deserialize)]

0 commit comments

Comments
 (0)