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

do not chill indirectly-slashed nominators #4553

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions frame/staking/src/slashing.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});
}