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
1 change: 1 addition & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mininimum_two_third_validators = 4
bond_increase_threshold = 0.1
unbond_increase_threshold = 0.1
consensus_threshold = 0.1
threshold_missed_votes = 0.1

[tx]
threshold_sections = 5
Expand Down
31 changes: 31 additions & 0 deletions src/checks/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const POS_TWO_THIRD_CHECK_ID: &str = "pos_one_third_check";
const POS_BONDS_CHECK_ID: &str = "pos_bonds_check";
const POS_UNBONDS_CHECK_ID: &str = "pos_unbonds_check";
const POS_CONSENSUS_CHECK_ID: &str = "pos_consensus_check";
const POS_MISSED_VOTES_CHECK_ID: &str = "pos_missed_votes_check";

pub struct PoSCheck {
mininimum_one_third_validators: u64,
mininimum_two_third_validators: u64,
bond_increase_threshold: f64,
unbond_increase_threshold: f64,
consensus_threshold: f64,
threshold_missed_votes: f64,
}

impl PoSCheck {
Expand All @@ -25,6 +27,7 @@ impl PoSCheck {
bond_increase_threshold: config.pos.bond_increase_threshold,
unbond_increase_threshold: config.pos.unbond_increase_threshold,
consensus_threshold: config.pos.consensus_threshold,
threshold_missed_votes: config.pos.threshold_missed_votes,
}
}
}
Expand Down Expand Up @@ -140,6 +143,34 @@ impl CheckTrait for PoSCheck {
});
}

let total_validators = last_state.consensus_validators().len();
let total_votes = last_state.block.block.last_commit.unwrap().signatures.len();

let missed_votes_percentage = if total_validators > 0 {
1.0 - (total_votes as f64 / total_validators as f64)
} else {
0.0
};

if missed_votes_percentage > self.threshold_missed_votes {
alerts.push(crate::shared::alert::Alert {
check_id: POS_MISSED_VOTES_CHECK_ID.to_string(),
title: "High missed votes percentage".to_string(),
description: format!(
"Missed votes percentage is {:.2}% which is above the threshold of {:.2}%",
missed_votes_percentage * 100.0,
self.threshold_missed_votes * 100.0
),
metadata: crate::shared::alert::Metadata {
block_height: Some(last_state.block.height as u32),
tx_id: None,
},
severity: crate::shared::alert::Severity::Medium,
trigger_after: None,
continous: self.is_continous(),
});
}

alerts
}

Expand Down
1 change: 1 addition & 0 deletions src/shared/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Pos {
pub bond_increase_threshold: f64,
pub unbond_increase_threshold: f64,
pub consensus_threshold: f64,
pub threshold_missed_votes: f64,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down