mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 13:48:00 +00:00
Migrate pallet-staking to pallet attribute macro (#9083)
* Migrate staking pallet to pallet attribute macro. * HistoryDepth default value. * Make all calls public. * Update frame/staking/src/lib.rs * remove externalities again * Update lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -50,12 +50,12 @@
|
||||
//! Based on research at <https://w3f-research.readthedocs.io/en/latest/polkadot/slashing/npos.html>
|
||||
|
||||
use super::{
|
||||
EraIndex, Config, Module, Store, BalanceOf, Exposure, Perbill, SessionInterface,
|
||||
EraIndex, Config, Pallet, Store, BalanceOf, Exposure, Perbill, SessionInterface,
|
||||
NegativeImbalanceOf, UnappliedSlash, Error,
|
||||
};
|
||||
use sp_runtime::{traits::{Zero, Saturating}, RuntimeDebug, DispatchResult};
|
||||
use frame_support::{
|
||||
StorageMap, StorageDoubleMap, ensure,
|
||||
ensure,
|
||||
traits::{Currency, OnUnbalanced, Imbalance},
|
||||
};
|
||||
use sp_std::vec::Vec;
|
||||
@@ -239,7 +239,7 @@ pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
|
||||
return None;
|
||||
}
|
||||
|
||||
let (prior_slash_p, _era_slash) = <Module<T> as Store>::ValidatorSlashInEra::get(
|
||||
let (prior_slash_p, _era_slash) = <Pallet<T> as Store>::ValidatorSlashInEra::get(
|
||||
&slash_era,
|
||||
stash,
|
||||
).unwrap_or((Perbill::zero(), Zero::zero()));
|
||||
@@ -247,7 +247,7 @@ pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
|
||||
// compare slash proportions rather than slash values to avoid issues due to rounding
|
||||
// error.
|
||||
if slash.deconstruct() > prior_slash_p.deconstruct() {
|
||||
<Module<T> as Store>::ValidatorSlashInEra::insert(
|
||||
<Pallet<T> as Store>::ValidatorSlashInEra::insert(
|
||||
&slash_era,
|
||||
stash,
|
||||
&(slash, own_slash),
|
||||
@@ -285,12 +285,12 @@ pub(crate) fn compute_slash<T: Config>(params: SlashParams<T>)
|
||||
// chill the validator - it misbehaved in the current span and should
|
||||
// not continue in the next election. also end the slashing span.
|
||||
spans.end_span(now);
|
||||
<Module<T>>::chill_stash(stash);
|
||||
<Pallet<T>>::chill_stash(stash);
|
||||
|
||||
// make sure to disable validator till the end of this session
|
||||
if T::SessionInterface::disable_validator(stash).unwrap_or(false) {
|
||||
// force a new era, to select a new validator set
|
||||
<Module<T>>::ensure_new_era()
|
||||
<Pallet<T>>::ensure_new_era()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,12 +325,12 @@ fn kick_out_if_recent<T: Config>(
|
||||
|
||||
if spans.era_span(params.slash_era).map(|s| s.index) == Some(spans.span_index()) {
|
||||
spans.end_span(params.now);
|
||||
<Module<T>>::chill_stash(params.stash);
|
||||
<Pallet<T>>::chill_stash(params.stash);
|
||||
|
||||
// make sure to disable validator till the end of this session
|
||||
if T::SessionInterface::disable_validator(params.stash).unwrap_or(false) {
|
||||
// force a new era, to select a new validator set
|
||||
<Module<T>>::ensure_new_era()
|
||||
<Pallet<T>>::ensure_new_era()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -367,14 +367,14 @@ fn slash_nominators<T: Config>(
|
||||
let own_slash_by_validator = slash * nominator.value;
|
||||
let own_slash_difference = own_slash_by_validator.saturating_sub(own_slash_prior);
|
||||
|
||||
let mut era_slash = <Module<T> as Store>::NominatorSlashInEra::get(
|
||||
let mut era_slash = <Pallet<T> as Store>::NominatorSlashInEra::get(
|
||||
&slash_era,
|
||||
stash,
|
||||
).unwrap_or_else(|| Zero::zero());
|
||||
|
||||
era_slash += own_slash_difference;
|
||||
|
||||
<Module<T> as Store>::NominatorSlashInEra::insert(
|
||||
<Pallet<T> as Store>::NominatorSlashInEra::insert(
|
||||
&slash_era,
|
||||
stash,
|
||||
&era_slash,
|
||||
@@ -437,9 +437,9 @@ fn fetch_spans<'a, T: Config + 'a>(
|
||||
slash_of: &'a mut BalanceOf<T>,
|
||||
reward_proportion: Perbill,
|
||||
) -> InspectingSpans<'a, T> {
|
||||
let spans = <Module<T> as Store>::SlashingSpans::get(stash).unwrap_or_else(|| {
|
||||
let spans = <Pallet<T> as Store>::SlashingSpans::get(stash).unwrap_or_else(|| {
|
||||
let spans = SlashingSpans::new(window_start);
|
||||
<Module<T> as Store>::SlashingSpans::insert(stash, &spans);
|
||||
<Pallet<T> as Store>::SlashingSpans::insert(stash, &spans);
|
||||
spans
|
||||
});
|
||||
|
||||
@@ -488,7 +488,7 @@ impl<'a, T: 'a + Config> InspectingSpans<'a, T> {
|
||||
) -> Option<SpanIndex> {
|
||||
let target_span = self.era_span(slash_era)?;
|
||||
let span_slash_key = (self.stash.clone(), target_span.index);
|
||||
let mut span_record = <Module<T> as Store>::SpanSlash::get(&span_slash_key);
|
||||
let mut span_record = <Pallet<T> as Store>::SpanSlash::get(&span_slash_key);
|
||||
let mut changed = false;
|
||||
|
||||
let reward = if span_record.slashed < slash {
|
||||
@@ -519,7 +519,7 @@ impl<'a, T: 'a + Config> InspectingSpans<'a, T> {
|
||||
|
||||
if changed {
|
||||
self.dirty = true;
|
||||
<Module<T> as Store>::SpanSlash::insert(&span_slash_key, &span_record);
|
||||
<Pallet<T> as Store>::SpanSlash::insert(&span_slash_key, &span_record);
|
||||
}
|
||||
|
||||
Some(target_span.index)
|
||||
@@ -533,18 +533,18 @@ impl<'a, T: 'a + Config> Drop for InspectingSpans<'a, T> {
|
||||
|
||||
if let Some((start, end)) = self.spans.prune(self.window_start) {
|
||||
for span_index in start..end {
|
||||
<Module<T> as Store>::SpanSlash::remove(&(self.stash.clone(), span_index));
|
||||
<Pallet<T> as Store>::SpanSlash::remove(&(self.stash.clone(), span_index));
|
||||
}
|
||||
}
|
||||
|
||||
<Module<T> as Store>::SlashingSpans::insert(self.stash, &self.spans);
|
||||
<Pallet<T> as Store>::SlashingSpans::insert(self.stash, &self.spans);
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear slashing metadata for an obsolete era.
|
||||
pub(crate) fn clear_era_metadata<T: Config>(obsolete_era: EraIndex) {
|
||||
<Module<T> as Store>::ValidatorSlashInEra::remove_prefix(&obsolete_era);
|
||||
<Module<T> as Store>::NominatorSlashInEra::remove_prefix(&obsolete_era);
|
||||
<Pallet<T> as Store>::ValidatorSlashInEra::remove_prefix(&obsolete_era);
|
||||
<Pallet<T> as Store>::NominatorSlashInEra::remove_prefix(&obsolete_era);
|
||||
}
|
||||
|
||||
/// Clear slashing metadata for a dead account.
|
||||
@@ -552,14 +552,14 @@ pub(crate) fn clear_stash_metadata<T: Config>(
|
||||
stash: &T::AccountId,
|
||||
num_slashing_spans: u32,
|
||||
) -> DispatchResult {
|
||||
let spans = match <Module<T> as Store>::SlashingSpans::get(stash) {
|
||||
let spans = match <Pallet<T> as Store>::SlashingSpans::get(stash) {
|
||||
None => return Ok(()),
|
||||
Some(s) => s,
|
||||
};
|
||||
|
||||
ensure!(num_slashing_spans as usize >= spans.iter().count(), Error::<T>::IncorrectSlashingSpans);
|
||||
|
||||
<Module<T> as Store>::SlashingSpans::remove(stash);
|
||||
<Pallet<T> as Store>::SlashingSpans::remove(stash);
|
||||
|
||||
// kill slashing-span metadata for account.
|
||||
//
|
||||
@@ -567,7 +567,7 @@ pub(crate) fn clear_stash_metadata<T: Config>(
|
||||
// in that case, they may re-bond, but it would count again as span 0. Further ancient
|
||||
// slashes would slash into this new bond, since metadata has now been cleared.
|
||||
for span in spans.iter() {
|
||||
<Module<T> as Store>::SpanSlash::remove(&(stash.clone(), span.index));
|
||||
<Pallet<T> as Store>::SpanSlash::remove(&(stash.clone(), span.index));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -582,12 +582,12 @@ pub fn do_slash<T: Config>(
|
||||
reward_payout: &mut BalanceOf<T>,
|
||||
slashed_imbalance: &mut NegativeImbalanceOf<T>,
|
||||
) {
|
||||
let controller = match <Module<T>>::bonded(stash) {
|
||||
let controller = match <Pallet<T>>::bonded(stash) {
|
||||
None => return, // defensive: should always exist.
|
||||
Some(c) => c,
|
||||
};
|
||||
|
||||
let mut ledger = match <Module<T>>::ledger(&controller) {
|
||||
let mut ledger = match <Pallet<T>>::ledger(&controller) {
|
||||
Some(ledger) => ledger,
|
||||
None => return, // nothing to do.
|
||||
};
|
||||
@@ -603,11 +603,11 @@ pub fn do_slash<T: Config>(
|
||||
*reward_payout = reward_payout.saturating_sub(missing);
|
||||
}
|
||||
|
||||
<Module<T>>::update_ledger(&controller, &ledger);
|
||||
<Pallet<T>>::update_ledger(&controller, &ledger);
|
||||
|
||||
// trigger the event
|
||||
<Module<T>>::deposit_event(
|
||||
super::RawEvent::Slash(stash.clone(), value)
|
||||
<Pallet<T>>::deposit_event(
|
||||
super::Event::<T>::Slash(stash.clone(), value)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user