Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
do not chill indirectly-slashed nominators (#4553)
Browse files Browse the repository at this point in the history
* do not chill indirectly-slashed nominators

* test nomination non-kick and vote ignoring behavior
  • Loading branch information
rphmeier authored and gavofyork committed Jan 7, 2020
1 parent 5420775 commit 9178b42
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frame/staking/src/slashing.rs
Expand Up @@ -392,9 +392,9 @@ fn slash_nominators<T: Trait>(
);

if target_span == Some(spans.span_index()) {
// Chill the nominator outright, ending the slashing span.
// End the span, but don't chill the nominator. its nomination
// on this validator will be ignored in the future.
spans.end_span(now);
<Module<T>>::chill_stash(stash);
}
}

Expand Down
40 changes: 39 additions & 1 deletion frame/staking/src/tests.rs
Expand Up @@ -2531,7 +2531,6 @@ fn remove_multi_deferred() {
&[Perbill::from_percent(10)],
);


on_offence_now(
&[
OffenceDetails {
Expand All @@ -2557,3 +2556,42 @@ fn version_initialized() {
assert_eq!(<Staking as Store>::StorageVersion::get(), crate::migration::CURRENT_VERSION);
});
}

#[test]
fn slash_kicks_validators_not_nominators() {
ExtBuilder::default().build().execute_with(|| {
start_era(1);

assert_eq!(Balances::free_balance(&11), 1000);

let exposure = Staking::stakers(&11);
assert_eq!(Balances::free_balance(&101), 2000);
let nominated_value = exposure.others.iter().find(|o| o.who == 101).unwrap().value;

on_offence_now(
&[
OffenceDetails {
offender: (11, exposure.clone()),
reporters: vec![],
},
],
&[Perbill::from_percent(10)],
);

assert_eq!(Balances::free_balance(&11), 900);
assert_eq!(Balances::free_balance(&101), 2000 - (nominated_value / 10));

// This is the best way to check that the validator was chilled; `get` will
// return default value.
for (stash, _) in <Staking as Store>::Validators::enumerate() {
assert!(stash != 11);
}

let nominations = <Staking as Store>::Nominators::get(&101).unwrap();

// and make sure that the vote will be ignored even if the validator
// re-registers.
let last_slash = <Staking as Store>::SlashingSpans::get(&11).unwrap().last_start();
assert!(nominations.submitted_in < last_slash);
});
}

0 comments on commit 9178b42

Please sign in to comment.