mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
remove OnStakerSlash replace with OnStakingEvents (#14527)
* remove 'OnStakerSlash', replace with 'OnStakingEvents' * fix other features in pallets * small fixes * fix docs * fix docs * fix docs * Update primitives/staking/src/lib.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> --------- Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
This commit is contained in:
@@ -26,13 +26,13 @@ use frame_election_provider_support::SortedListProvider;
|
||||
use frame_support::{
|
||||
dispatch::UnfilteredDispatchable,
|
||||
pallet_prelude::*,
|
||||
traits::{Currency, CurrencyToVote, Get, Imbalance},
|
||||
traits::{Currency, Get, Imbalance},
|
||||
};
|
||||
use sp_runtime::{
|
||||
traits::{Bounded, One, StaticLookup, TrailingZeroInput, Zero},
|
||||
Perbill, Percent,
|
||||
};
|
||||
use sp_staking::SessionIndex;
|
||||
use sp_staking::{currency_to_vote::CurrencyToVote, SessionIndex};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
pub use frame_benchmarking::v1::{
|
||||
|
||||
@@ -314,7 +314,7 @@ use sp_runtime::{
|
||||
pub use sp_staking::StakerStatus;
|
||||
use sp_staking::{
|
||||
offence::{Offence, OffenceError, ReportOffence},
|
||||
EraIndex, SessionIndex,
|
||||
EraIndex, OnStakingUpdate, SessionIndex,
|
||||
};
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||
pub use weights::WeightInfo;
|
||||
@@ -549,7 +549,7 @@ impl<T: Config> StakingLedger<T> {
|
||||
///
|
||||
/// `slash_era` is the era in which the slash (which is being enacted now) actually happened.
|
||||
///
|
||||
/// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash was
|
||||
/// This calls `Config::OnStakingUpdate::on_slash` with information as to how the slash was
|
||||
/// applied.
|
||||
pub fn slash(
|
||||
&mut self,
|
||||
@@ -562,7 +562,6 @@ impl<T: Config> StakingLedger<T> {
|
||||
}
|
||||
|
||||
use sp_runtime::PerThing as _;
|
||||
use sp_staking::OnStakerSlash as _;
|
||||
let mut remaining_slash = slash_amount;
|
||||
let pre_slash_total = self.total;
|
||||
|
||||
@@ -667,7 +666,7 @@ impl<T: Config> StakingLedger<T> {
|
||||
// clean unlocking chunks that are set to zero.
|
||||
self.unlocking.retain(|c| !c.value.is_zero());
|
||||
|
||||
T::OnStakerSlash::on_slash(&self.stash, self.active, &slashed_unlocking);
|
||||
T::EventListeners::on_slash(&self.stash, self.active, &slashed_unlocking);
|
||||
pre_slash_total.saturating_sub(self.total)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +236,6 @@ parameter_types! {
|
||||
pub static HistoryDepth: u32 = 80;
|
||||
pub static MaxUnlockingChunks: u32 = 32;
|
||||
pub static RewardOnUnbalanceWasCalled: bool = false;
|
||||
pub static LedgerSlashPerEra: (BalanceOf<Test>, BTreeMap<EraIndex, BalanceOf<Test>>) = (Zero::zero(), BTreeMap::new());
|
||||
pub static MaxWinners: u32 = 100;
|
||||
}
|
||||
|
||||
@@ -268,8 +267,14 @@ impl OnUnbalanced<PositiveImbalanceOf<Test>> for MockReward {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OnStakerSlashMock<T: Config>(core::marker::PhantomData<T>);
|
||||
impl<T: Config> sp_staking::OnStakerSlash<AccountId, Balance> for OnStakerSlashMock<T> {
|
||||
parameter_types! {
|
||||
pub static LedgerSlashPerEra:
|
||||
(BalanceOf<Test>, BTreeMap<EraIndex, BalanceOf<Test>>) =
|
||||
(Zero::zero(), BTreeMap::new());
|
||||
}
|
||||
|
||||
pub struct EventListenerMock;
|
||||
impl OnStakingUpdate<AccountId, Balance> for EventListenerMock {
|
||||
fn on_slash(
|
||||
_pool_account: &AccountId,
|
||||
slashed_bonded: Balance,
|
||||
@@ -284,7 +289,7 @@ impl crate::pallet::pallet::Config for Test {
|
||||
type Currency = Balances;
|
||||
type CurrencyBalance = <Self as pallet_balances::Config>::Balance;
|
||||
type UnixTime = Timestamp;
|
||||
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
|
||||
type CurrencyToVote = ();
|
||||
type RewardRemainder = RewardRemainderMock;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Slash = ();
|
||||
@@ -305,7 +310,7 @@ impl crate::pallet::pallet::Config for Test {
|
||||
type TargetList = UseValidatorsMap<Self>;
|
||||
type MaxUnlockingChunks = MaxUnlockingChunks;
|
||||
type HistoryDepth = HistoryDepth;
|
||||
type OnStakerSlash = OnStakerSlashMock<Test>;
|
||||
type EventListeners = EventListenerMock;
|
||||
type BenchmarkingConfig = TestBenchmarkingConfig;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ use frame_support::{
|
||||
dispatch::WithPostDispatchInfo,
|
||||
pallet_prelude::*,
|
||||
traits::{
|
||||
Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get,
|
||||
Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons,
|
||||
Currency, Defensive, DefensiveResult, EstimateNextNewSession, Get, Imbalance,
|
||||
LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons,
|
||||
},
|
||||
weights::Weight,
|
||||
};
|
||||
@@ -38,6 +38,7 @@ use sp_runtime::{
|
||||
Perbill,
|
||||
};
|
||||
use sp_staking::{
|
||||
currency_to_vote::CurrencyToVote,
|
||||
offence::{DisableStrategy, OffenceDetails, OnOffenceHandler},
|
||||
EraIndex, SessionIndex, Stake, StakingInterface,
|
||||
};
|
||||
@@ -1568,10 +1569,10 @@ impl<T: Config> SortedListProvider<T::AccountId> for UseNominatorsAndValidatorsM
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: in this entire impl block, the assumption is that `who` is a stash account.
|
||||
impl<T: Config> StakingInterface for Pallet<T> {
|
||||
type AccountId = T::AccountId;
|
||||
type Balance = BalanceOf<T>;
|
||||
type CurrencyToVote = T::CurrencyToVote;
|
||||
|
||||
fn minimum_nominator_bond() -> Self::Balance {
|
||||
MinNominatorBond::<T>::get()
|
||||
|
||||
@@ -24,7 +24,7 @@ use frame_support::{
|
||||
dispatch::Codec,
|
||||
pallet_prelude::*,
|
||||
traits::{
|
||||
Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin,
|
||||
Currency, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin,
|
||||
EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, TryCollect,
|
||||
UnixTime,
|
||||
},
|
||||
@@ -113,7 +113,7 @@ pub mod pallet {
|
||||
/// in 128.
|
||||
/// Consequently, the backward convert is used convert the u128s from sp-elections back to a
|
||||
/// [`BalanceOf`].
|
||||
type CurrencyToVote: CurrencyToVote<BalanceOf<Self>>;
|
||||
type CurrencyToVote: sp_staking::currency_to_vote::CurrencyToVote<BalanceOf<Self>>;
|
||||
|
||||
/// Something that provides the election functionality.
|
||||
type ElectionProvider: ElectionProvider<
|
||||
@@ -261,9 +261,11 @@ pub mod pallet {
|
||||
#[pallet::constant]
|
||||
type MaxUnlockingChunks: Get<u32>;
|
||||
|
||||
/// A hook called when any staker is slashed. Mostly likely this can be a no-op unless
|
||||
/// other pallets exist that are affected by slashing per-staker.
|
||||
type OnStakerSlash: sp_staking::OnStakerSlash<Self::AccountId, BalanceOf<Self>>;
|
||||
/// Something that listens to staking updates and performs actions based on the data it
|
||||
/// receives.
|
||||
///
|
||||
/// WARNING: this only reports slashing events for the time being.
|
||||
type EventListeners: sp_staking::OnStakingUpdate<Self::AccountId, BalanceOf<Self>>;
|
||||
|
||||
/// Some parameters of the benchmarking.
|
||||
type BenchmarkingConfig: BenchmarkingConfig;
|
||||
|
||||
Reference in New Issue
Block a user