Skip to content

Commit

Permalink
fix: take into account only active suspensions (#5359)
Browse files Browse the repository at this point in the history
* keep into account only active suspensions

* filter out duplicates and properly count keygen suspensions

* addressed comments

---------

Co-authored-by: dandanlen <3168260+dandanlen@users.noreply.github.com>
  • Loading branch information
marcellorigotti and dandanlen committed Nov 6, 2024
1 parent 38d072e commit 7bbe120
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion state-chain/pallets/cf-validator/src/rotation_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sp_std::collections::btree_set::BTreeSet;
pub struct RotationState<Id, Amount> {
primary_candidates: Vec<Id>,
secondary_candidates: Vec<Id>,
banned: BTreeSet<Id>,
pub banned: BTreeSet<Id>,
pub bond: Amount,
pub new_epoch_index: EpochIndex,
}
Expand Down
14 changes: 13 additions & 1 deletion state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,19 @@ impl_runtime_apis! {
}

fn cf_suspended_validators() -> Vec<(Offence, u32)> {
pallet_cf_reputation::Suspensions::<Runtime>::iter().map(|(key, elem)| (key, elem.len() as u32)).collect()
let suspended_for_keygen = match pallet_cf_validator::Pallet::<Runtime>::current_rotation_phase() {
pallet_cf_validator::RotationPhase::KeygensInProgress(rotation_state) |
pallet_cf_validator::RotationPhase::KeyHandoversInProgress(rotation_state) |
pallet_cf_validator::RotationPhase::ActivatingKeys(rotation_state) |
pallet_cf_validator::RotationPhase::NewKeysActivated(rotation_state) => { rotation_state.banned.len() as u32 },
_ => {0u32}
};
pallet_cf_reputation::Suspensions::<Runtime>::iter().map(|(key, _)| {
if key == pallet_cf_threshold_signature::PalletOffence::FailedKeygen.into() {
return (key, suspended_for_keygen);
}
(key, pallet_cf_reputation::Pallet::<Runtime>::validators_suspended_for(&[key]).len() as u32)
}).collect()
}
fn cf_epoch_state() -> EpochState {
let auction_params = Validator::auction_parameters();
Expand Down

0 comments on commit 7bbe120

Please sign in to comment.