mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 00:47:55 +00:00
Add some important events to batch & staking to ensure ease of analysis (#9462)
* Add some important events to batch & staking to ensure ease of analysis * Update frame/staking/src/pallet/mod.rs Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com> * Update lib.rs * fix test Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -154,11 +154,13 @@ impl<T: Config> Pallet<T> {
|
||||
let validator_exposure_part = Perbill::from_rational(exposure.own, exposure.total);
|
||||
let validator_staking_payout = validator_exposure_part * validator_leftover_payout;
|
||||
|
||||
Self::deposit_event(Event::<T>::PayoutStarted(era, ledger.stash.clone()));
|
||||
|
||||
// We can now make total validator payout:
|
||||
if let Some(imbalance) =
|
||||
Self::make_payout(&ledger.stash, validator_staking_payout + validator_commission_payout)
|
||||
{
|
||||
Self::deposit_event(Event::<T>::Reward(ledger.stash, imbalance.peek()));
|
||||
Self::deposit_event(Event::<T>::Rewarded(ledger.stash, imbalance.peek()));
|
||||
}
|
||||
|
||||
// Track the number of payout ops to nominators. Note: `WeightInfo::payout_stakers_alive_staked`
|
||||
@@ -176,7 +178,8 @@ impl<T: Config> Pallet<T> {
|
||||
if let Some(imbalance) = Self::make_payout(&nominator.who, nominator_reward) {
|
||||
// Note: this logic does not count payouts for `RewardDestination::None`.
|
||||
nominator_payout_count += 1;
|
||||
Self::deposit_event(Event::<T>::Reward(nominator.who.clone(), imbalance.peek()));
|
||||
let e = Event::<T>::Rewarded(nominator.who.clone(), imbalance.peek());
|
||||
Self::deposit_event(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +357,7 @@ impl<T: Config> Pallet<T> {
|
||||
let issuance = T::Currency::total_issuance();
|
||||
let (validator_payout, rest) = T::EraPayout::era_payout(staked, issuance, era_duration);
|
||||
|
||||
Self::deposit_event(Event::<T>::EraPayout(active_era.index, validator_payout, rest));
|
||||
Self::deposit_event(Event::<T>::EraPaid(active_era.index, validator_payout, rest));
|
||||
|
||||
// Set ending era reward.
|
||||
<ErasValidatorReward<T>>::insert(&active_era.index, validator_payout);
|
||||
@@ -446,7 +449,7 @@ impl<T: Config> Pallet<T> {
|
||||
return None
|
||||
}
|
||||
|
||||
Self::deposit_event(Event::StakingElection);
|
||||
Self::deposit_event(Event::StakersElected);
|
||||
Some(Self::trigger_new_era(start_session_index, exposures))
|
||||
}
|
||||
|
||||
|
||||
@@ -525,17 +525,17 @@ pub mod pallet {
|
||||
/// The era payout has been set; the first balance is the validator-payout; the second is
|
||||
/// the remainder from the maximum amount of reward.
|
||||
/// \[era_index, validator_payout, remainder\]
|
||||
EraPayout(EraIndex, BalanceOf<T>, BalanceOf<T>),
|
||||
/// The staker has been rewarded by this amount. \[stash, amount\]
|
||||
Reward(T::AccountId, BalanceOf<T>),
|
||||
EraPaid(EraIndex, BalanceOf<T>, BalanceOf<T>),
|
||||
/// The nominator has been rewarded by this amount. \[stash, amount\]
|
||||
Rewarded(T::AccountId, BalanceOf<T>),
|
||||
/// One validator (and its nominators) has been slashed by the given amount.
|
||||
/// \[validator, amount\]
|
||||
Slash(T::AccountId, BalanceOf<T>),
|
||||
Slashed(T::AccountId, BalanceOf<T>),
|
||||
/// An old slashing report from a prior era was discarded because it could
|
||||
/// not be processed. \[session_index\]
|
||||
OldSlashingReportDiscarded(SessionIndex),
|
||||
/// A new set of stakers was elected.
|
||||
StakingElection,
|
||||
StakersElected,
|
||||
/// An account has bonded this amount. \[stash, amount\]
|
||||
///
|
||||
/// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably,
|
||||
@@ -553,6 +553,8 @@ pub mod pallet {
|
||||
/// An account has stopped participating as either a validator or nominator.
|
||||
/// \[stash\]
|
||||
Chilled(T::AccountId),
|
||||
/// The stakers' rewards are getting paid. \[era_index, validator_stash\]
|
||||
PayoutStarted(EraIndex, T::AccountId),
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
|
||||
@@ -584,7 +584,7 @@ pub fn do_slash<T: Config>(
|
||||
<Pallet<T>>::update_ledger(&controller, &ledger);
|
||||
|
||||
// trigger the event
|
||||
<Pallet<T>>::deposit_event(super::Event::<T>::Slash(stash.clone(), value));
|
||||
<Pallet<T>>::deposit_event(super::Event::<T>::Slashed(stash.clone(), value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ fn rewards_should_work() {
|
||||
);
|
||||
assert_eq!(
|
||||
*mock::staking_events().last().unwrap(),
|
||||
Event::EraPayout(0, total_payout_0, maximum_payout - total_payout_0)
|
||||
Event::EraPaid(0, total_payout_0, maximum_payout - total_payout_0)
|
||||
);
|
||||
mock::make_all_reward_payment(0);
|
||||
|
||||
@@ -295,7 +295,7 @@ fn rewards_should_work() {
|
||||
);
|
||||
assert_eq!(
|
||||
*mock::staking_events().last().unwrap(),
|
||||
Event::EraPayout(1, total_payout_1, maximum_payout - total_payout_1)
|
||||
Event::EraPaid(1, total_payout_1, maximum_payout - total_payout_1)
|
||||
);
|
||||
mock::make_all_reward_payment(1);
|
||||
|
||||
@@ -3942,7 +3942,7 @@ mod election_data_provider {
|
||||
run_to_block(20);
|
||||
assert_eq!(Staking::next_election_prediction(System::block_number()), 45);
|
||||
assert_eq!(staking_events().len(), 1);
|
||||
assert_eq!(*staking_events().last().unwrap(), Event::StakingElection);
|
||||
assert_eq!(*staking_events().last().unwrap(), Event::StakersElected);
|
||||
|
||||
for b in 21..45 {
|
||||
run_to_block(b);
|
||||
@@ -3953,7 +3953,7 @@ mod election_data_provider {
|
||||
run_to_block(45);
|
||||
assert_eq!(Staking::next_election_prediction(System::block_number()), 70);
|
||||
assert_eq!(staking_events().len(), 3);
|
||||
assert_eq!(*staking_events().last().unwrap(), Event::StakingElection);
|
||||
assert_eq!(*staking_events().last().unwrap(), Event::StakersElected);
|
||||
|
||||
Staking::force_no_eras(Origin::root()).unwrap();
|
||||
assert_eq!(Staking::next_election_prediction(System::block_number()), u64::MAX);
|
||||
@@ -3976,7 +3976,7 @@ mod election_data_provider {
|
||||
run_to_block(55);
|
||||
assert_eq!(Staking::next_election_prediction(System::block_number()), 55 + 25);
|
||||
assert_eq!(staking_events().len(), 6);
|
||||
assert_eq!(*staking_events().last().unwrap(), Event::StakingElection);
|
||||
assert_eq!(*staking_events().last().unwrap(), Event::StakersElected);
|
||||
// The new era has been planned, forcing is changed from `ForceNew` to `NotForcing`.
|
||||
assert_eq!(ForceEra::<Test>::get(), Forcing::NotForcing);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user