@@ -40,7 +40,7 @@ use sp_staking::{
4040 offence:: { DisableStrategy , OffenceDetails , OnOffenceHandler } ,
4141 EraIndex , SessionIndex , Stake , StakingInterface ,
4242} ;
43- use sp_std:: { collections :: btree_map :: BTreeMap , prelude:: * } ;
43+ use sp_std:: prelude:: * ;
4444
4545use crate :: {
4646 log, slashing, weights:: WeightInfo , ActiveEraInfo , BalanceOf , EraPayout , Exposure , ExposureOf ,
@@ -351,6 +351,7 @@ impl<T: Config> Pallet<T> {
351351 }
352352 }
353353
354+ /// Start a new era. It does:
354355 ///
355356 /// * Increment `active_era.index`,
356357 /// * reset `active_era.start`,
@@ -704,11 +705,6 @@ impl<T: Config> Pallet<T> {
704705 /// `maybe_max_len` can imposes a cap on the number of voters returned;
705706 ///
706707 /// This function is self-weighing as [`DispatchClass::Mandatory`].
707- ///
708- /// ### Slashing
709- ///
710- /// All votes that have been submitted before the last non-zero slash of the corresponding
711- /// target are *auto-chilled*, but still count towards the limit imposed by `maybe_max_len`.
712708 pub fn get_npos_voters ( maybe_max_len : Option < usize > ) -> Vec < VoterOf < Self > > {
713709 let max_allowed_len = {
714710 let all_voter_count = T :: VoterList :: count ( ) as usize ;
@@ -719,7 +715,6 @@ impl<T: Config> Pallet<T> {
719715
720716 // cache a few things.
721717 let weight_of = Self :: weight_of_fn ( ) ;
722- let slashing_spans = <SlashingSpans < T > >:: iter ( ) . collect :: < BTreeMap < _ , _ > > ( ) ;
723718
724719 let mut voters_seen = 0u32 ;
725720 let mut validators_taken = 0u32 ;
@@ -737,18 +732,12 @@ impl<T: Config> Pallet<T> {
737732 None => break ,
738733 } ;
739734
740- if let Some ( Nominations { submitted_in, mut targets, suppressed : _ } ) =
741- <Nominators < T > >:: get ( & voter)
742- {
743- // if this voter is a nominator:
744- targets. retain ( |stash| {
745- slashing_spans
746- . get ( stash)
747- . map_or ( true , |spans| submitted_in >= spans. last_nonzero_slash ( ) )
748- } ) ;
749- if !targets. len ( ) . is_zero ( ) {
735+ if let Some ( Nominations { targets, .. } ) = <Nominators < T > >:: get ( & voter) {
736+ if !targets. is_empty ( ) {
750737 all_voters. push ( ( voter. clone ( ) , weight_of ( & voter) , targets) ) ;
751738 nominators_taken. saturating_inc ( ) ;
739+ } else {
740+ // Technically should never happen, but not much we can do about it.
752741 }
753742 } else if Validators :: < T > :: contains_key ( & voter) {
754743 // if this voter is a validator:
@@ -771,18 +760,14 @@ impl<T: Config> Pallet<T> {
771760 warn,
772761 "DEFENSIVE: invalid item in `VoterList`: {:?}, this nominator probably has too many nominations now" ,
773762 voter
774- )
763+ ) ;
775764 }
776765 }
777766
778767 // all_voters should have not re-allocated.
779768 debug_assert ! ( all_voters. capacity( ) == max_allowed_len) ;
780769
781- Self :: register_weight ( T :: WeightInfo :: get_npos_voters (
782- validators_taken,
783- nominators_taken,
784- slashing_spans. len ( ) as u32 ,
785- ) ) ;
770+ Self :: register_weight ( T :: WeightInfo :: get_npos_voters ( validators_taken, nominators_taken) ) ;
786771
787772 log ! (
788773 info,
@@ -1285,6 +1270,12 @@ where
12851270 disable_strategy,
12861271 } ) ;
12871272
1273+ Self :: deposit_event ( Event :: < T > :: SlashReported {
1274+ validator : stash. clone ( ) ,
1275+ fraction : * slash_fraction,
1276+ slash_era,
1277+ } ) ;
1278+
12881279 if let Some ( mut unapplied) = unapplied {
12891280 let nominators_len = unapplied. others . len ( ) as u64 ;
12901281 let reporters_len = details. reporters . len ( ) as u64 ;
0 commit comments