mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 18:31:05 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -517,7 +517,7 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn slashing_spans)]
|
||||
#[pallet::unbounded]
|
||||
pub(crate) type SlashingSpans<T: Config> =
|
||||
pub type SlashingSpans<T: Config> =
|
||||
StorageMap<_, Twox64Concat, T::AccountId, slashing::SlashingSpans>;
|
||||
|
||||
/// Records information about the maximum slash of a stash within a slashing span,
|
||||
@@ -671,8 +671,11 @@ pub mod pallet {
|
||||
EraPaid { era_index: EraIndex, validator_payout: BalanceOf<T>, remainder: BalanceOf<T> },
|
||||
/// The nominator has been rewarded by this amount.
|
||||
Rewarded { stash: T::AccountId, amount: BalanceOf<T> },
|
||||
/// One staker (and potentially its nominators) has been slashed by the given amount.
|
||||
/// A staker (validator or nominator) has been slashed by the given amount.
|
||||
Slashed { staker: T::AccountId, amount: BalanceOf<T> },
|
||||
/// A slash for the given validator, for the given percentage of their stake, at the given
|
||||
/// era as been reported.
|
||||
SlashReported { validator: T::AccountId, fraction: Perbill, slash_era: EraIndex },
|
||||
/// An old slashing report from a prior era was discarded because it could
|
||||
/// not be processed.
|
||||
OldSlashingReportDiscarded { session_index: SessionIndex },
|
||||
|
||||
Reference in New Issue
Block a user