Remove implicit approval chilling upon slash. (#12420)

* don't read slashing spans when taking election snapshot

* update cargo.toml

* bring back remote test

* fix merge stuff

* fix npos-voters function sig

* remove as much redundant diff as you can

* Update frame/staking/src/pallet/mod.rs

Co-authored-by: Andronik <write@reusable.software>

* fix

* Update frame/staking/src/pallet/impls.rs

* update lock

* fix all tests

* review comments

* fmt

* fix offence bench

* clippy

* ".git/.scripts/bench-bot.sh" pallet dev pallet_staking

Co-authored-by: Andronik <write@reusable.software>
Co-authored-by: Ankan <ankan.anurag@gmail.com>
Co-authored-by: command-bot <>
This commit is contained in:
Kian Paimani
2022-12-12 17:05:13 +00:00
committed by GitHub
parent af46f85e0c
commit 0b29691688
9 changed files with 526 additions and 546 deletions
+14 -23
View File
@@ -40,7 +40,7 @@ use sp_staking::{
offence::{DisableStrategy, OffenceDetails, OnOffenceHandler},
EraIndex, SessionIndex, Stake, StakingInterface,
};
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use sp_std::prelude::*;
use crate::{
log, slashing, weights::WeightInfo, ActiveEraInfo, BalanceOf, EraPayout, Exposure, ExposureOf,
@@ -351,6 +351,7 @@ impl<T: Config> Pallet<T> {
}
}
/// Start a new era. It does:
///
/// * Increment `active_era.index`,
/// * reset `active_era.start`,
@@ -704,11 +705,6 @@ impl<T: Config> Pallet<T> {
/// `maybe_max_len` can imposes a cap on the number of voters returned;
///
/// This function is self-weighing as [`DispatchClass::Mandatory`].
///
/// ### Slashing
///
/// All votes that have been submitted before the last non-zero slash of the corresponding
/// target are *auto-chilled*, but still count towards the limit imposed by `maybe_max_len`.
pub fn get_npos_voters(maybe_max_len: Option<usize>) -> Vec<VoterOf<Self>> {
let max_allowed_len = {
let all_voter_count = T::VoterList::count() as usize;
@@ -719,7 +715,6 @@ impl<T: Config> Pallet<T> {
// cache a few things.
let weight_of = Self::weight_of_fn();
let slashing_spans = <SlashingSpans<T>>::iter().collect::<BTreeMap<_, _>>();
let mut voters_seen = 0u32;
let mut validators_taken = 0u32;
@@ -737,18 +732,12 @@ impl<T: Config> Pallet<T> {
None => break,
};
if let Some(Nominations { submitted_in, mut targets, suppressed: _ }) =
<Nominators<T>>::get(&voter)
{
// if this voter is a nominator:
targets.retain(|stash| {
slashing_spans
.get(stash)
.map_or(true, |spans| submitted_in >= spans.last_nonzero_slash())
});
if !targets.len().is_zero() {
if let Some(Nominations { targets, .. }) = <Nominators<T>>::get(&voter) {
if !targets.is_empty() {
all_voters.push((voter.clone(), weight_of(&voter), targets));
nominators_taken.saturating_inc();
} else {
// Technically should never happen, but not much we can do about it.
}
} else if Validators::<T>::contains_key(&voter) {
// if this voter is a validator:
@@ -771,18 +760,14 @@ impl<T: Config> Pallet<T> {
warn,
"DEFENSIVE: invalid item in `VoterList`: {:?}, this nominator probably has too many nominations now",
voter
)
);
}
}
// all_voters should have not re-allocated.
debug_assert!(all_voters.capacity() == max_allowed_len);
Self::register_weight(T::WeightInfo::get_npos_voters(
validators_taken,
nominators_taken,
slashing_spans.len() as u32,
));
Self::register_weight(T::WeightInfo::get_npos_voters(validators_taken, nominators_taken));
log!(
info,
@@ -1285,6 +1270,12 @@ where
disable_strategy,
});
Self::deposit_event(Event::<T>::SlashReported {
validator: stash.clone(),
fraction: *slash_fraction,
slash_era,
});
if let Some(mut unapplied) = unapplied {
let nominators_len = unapplied.others.len() as u64;
let reporters_len = details.reporters.len() as u64;