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:
wigy
2021-11-17 15:11:02 +01:00
committed by GitHub
parent 186efbc2a5
commit 3f0f1aa6f7
8 changed files with 129 additions and 46 deletions
+5 -3
View File
@@ -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) {