@@ -7,13 +7,15 @@ const POS_TWO_THIRD_CHECK_ID: &str = "pos_one_third_check";
77const POS_BONDS_CHECK_ID : & str = "pos_bonds_check" ;
88const POS_UNBONDS_CHECK_ID : & str = "pos_unbonds_check" ;
99const POS_CONSENSUS_CHECK_ID : & str = "pos_consensus_check" ;
10+ const POS_MISSED_VOTES_CHECK_ID : & str = "pos_missed_votes_check" ;
1011
1112pub 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
1921impl 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
0 commit comments