Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: take into account only active suspensions #5359

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
22 changes: 20 additions & 2 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ use pallet_cf_swapping::SwapLegInfo;
use pallet_cf_validator::SetSizeMaximisingAuctionResolver;
use pallet_transaction_payment::{ConstFeeMultiplier, Multiplier};
use scale_info::prelude::string::String;
use sp_std::collections::btree_map::BTreeMap;
use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};

pub use frame_support::{
debug, parameter_types,
Expand Down Expand Up @@ -2147,7 +2147,25 @@ 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 current_block = <frame_system::Pallet<Runtime>>::block_number();
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, elem)| {
if key == pallet_cf_threshold_signature::PalletOffence::FailedKeygen.into() {
return (key, suspended_for_keygen);
}
(key, elem.iter().filter_map(|(suspended_until, validator)| {
if *suspended_until > current_block {
return Some(validator);
}
None
}).collect::<BTreeSet<_>>().len() as u32)
}).collect()
dandanlen marked this conversation as resolved.
Show resolved Hide resolved
}
fn cf_epoch_state() -> EpochState {
let auction_params = Validator::auction_parameters();
Expand Down
Loading