mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Offence implementations can disable offenders independently from slashing (#10201)
* Offence implementations can disable offenders independently from slashing * Fix build on CI * Run cargo fmt * Fixes based on review comments * Make parameter naming consistent * Fix migration and some English * Fix migration - again * cargo fmt * Cover 2 new cases with a test
This commit is contained in:
@@ -33,7 +33,7 @@ use sp_runtime::{
|
||||
testing::{Header, TestXt, UintAuthorityId},
|
||||
traits::{IdentityLookup, Zero},
|
||||
};
|
||||
use sp_staking::offence::{OffenceDetails, OnOffenceHandler};
|
||||
use sp_staking::offence::{DisableStrategy, OffenceDetails, OnOffenceHandler};
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub const INIT_TIMESTAMP: u64 = 30_000;
|
||||
@@ -765,11 +765,12 @@ pub(crate) fn on_offence_in_era(
|
||||
>],
|
||||
slash_fraction: &[Perbill],
|
||||
era: EraIndex,
|
||||
disable_strategy: DisableStrategy,
|
||||
) {
|
||||
let bonded_eras = crate::BondedEras::<Test>::get();
|
||||
for &(bonded_era, start_session) in bonded_eras.iter() {
|
||||
if bonded_era == era {
|
||||
let _ = Staking::on_offence(offenders, slash_fraction, start_session);
|
||||
let _ = Staking::on_offence(offenders, slash_fraction, start_session, disable_strategy);
|
||||
return
|
||||
} else if bonded_era > era {
|
||||
break
|
||||
@@ -781,6 +782,7 @@ pub(crate) fn on_offence_in_era(
|
||||
offenders,
|
||||
slash_fraction,
|
||||
Staking::eras_start_session_index(era).unwrap(),
|
||||
disable_strategy,
|
||||
);
|
||||
} else {
|
||||
panic!("cannot slash in era {}", era);
|
||||
@@ -795,7 +797,7 @@ pub(crate) fn on_offence_now(
|
||||
slash_fraction: &[Perbill],
|
||||
) {
|
||||
let now = Staking::active_era().unwrap().index;
|
||||
on_offence_in_era(offenders, slash_fraction, now)
|
||||
on_offence_in_era(offenders, slash_fraction, now, DisableStrategy::WhenSlashed)
|
||||
}
|
||||
|
||||
pub(crate) fn add_slash(who: &AccountId) {
|
||||
|
||||
Reference in New Issue
Block a user