diff --git a/substrate/frame/staking/src/slashing.rs b/substrate/frame/staking/src/slashing.rs index 1263198d86..6d591603fd 100644 --- a/substrate/frame/staking/src/slashing.rs +++ b/substrate/frame/staking/src/slashing.rs @@ -392,9 +392,9 @@ fn slash_nominators( ); 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); - >::chill_stash(stash); } } diff --git a/substrate/frame/staking/src/tests.rs b/substrate/frame/staking/src/tests.rs index e550a90c4e..1ab43910c7 100644 --- a/substrate/frame/staking/src/tests.rs +++ b/substrate/frame/staking/src/tests.rs @@ -2531,7 +2531,6 @@ fn remove_multi_deferred() { &[Perbill::from_percent(10)], ); - on_offence_now( &[ OffenceDetails { @@ -2557,3 +2556,42 @@ fn version_initialized() { assert_eq!(::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 ::Validators::enumerate() { + assert!(stash != 11); + } + + let nominations = ::Nominators::get(&101).unwrap(); + + // and make sure that the vote will be ignored even if the validator + // re-registers. + let last_slash = ::SlashingSpans::get(&11).unwrap().last_start(); + assert!(nominations.submitted_in < last_slash); + }); +}