Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 3478e0f

Browse files
gavofyorkemostovshawntabrizi
authored
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 <[email protected]> * Update lib.rs * fix test Co-authored-by: Zeke Mostov <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]>
1 parent 9f7ce37 commit 3478e0f

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

frame/contracts/src/exec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,11 @@ mod tests {
25062506
event: MetaEvent::System(frame_system::Event::Remarked(BOB, remark_hash)),
25072507
topics: vec![],
25082508
},
2509+
EventRecord {
2510+
phase: Phase::Initialization,
2511+
event: MetaEvent::Utility(pallet_utility::Event::ItemCompleted),
2512+
topics: vec![],
2513+
},
25092514
EventRecord {
25102515
phase: Phase::Initialization,
25112516
event: MetaEvent::Utility(pallet_utility::Event::BatchInterrupted(

frame/offences/benchmarking/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ benchmarks! {
289289
let slash_amount = slash_fraction * bond_amount;
290290
let reward_amount = slash_amount * (1 + n) / 2;
291291
let slash = |id| core::iter::once(
292-
<T as StakingConfig>::Event::from(StakingEvent::<T>::Slash(id, BalanceOf::<T>::from(slash_amount)))
292+
<T as StakingConfig>::Event::from(StakingEvent::<T>::Slashed(id, BalanceOf::<T>::from(slash_amount)))
293293
);
294294
let chill = |id| core::iter::once(
295295
<T as StakingConfig>::Event::from(StakingEvent::<T>::Chilled(id))

frame/staking/src/pallet/impls.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ impl<T: Config> Pallet<T> {
154154
let validator_exposure_part = Perbill::from_rational(exposure.own, exposure.total);
155155
let validator_staking_payout = validator_exposure_part * validator_leftover_payout;
156156

157+
Self::deposit_event(Event::<T>::PayoutStarted(era, ledger.stash.clone()));
158+
157159
// We can now make total validator payout:
158160
if let Some(imbalance) =
159161
Self::make_payout(&ledger.stash, validator_staking_payout + validator_commission_payout)
160162
{
161-
Self::deposit_event(Event::<T>::Reward(ledger.stash, imbalance.peek()));
163+
Self::deposit_event(Event::<T>::Rewarded(ledger.stash, imbalance.peek()));
162164
}
163165

164166
// Track the number of payout ops to nominators. Note: `WeightInfo::payout_stakers_alive_staked`
@@ -176,7 +178,8 @@ impl<T: Config> Pallet<T> {
176178
if let Some(imbalance) = Self::make_payout(&nominator.who, nominator_reward) {
177179
// Note: this logic does not count payouts for `RewardDestination::None`.
178180
nominator_payout_count += 1;
179-
Self::deposit_event(Event::<T>::Reward(nominator.who.clone(), imbalance.peek()));
181+
let e = Event::<T>::Rewarded(nominator.who.clone(), imbalance.peek());
182+
Self::deposit_event(e);
180183
}
181184
}
182185

@@ -354,7 +357,7 @@ impl<T: Config> Pallet<T> {
354357
let issuance = T::Currency::total_issuance();
355358
let (validator_payout, rest) = T::EraPayout::era_payout(staked, issuance, era_duration);
356359

357-
Self::deposit_event(Event::<T>::EraPayout(active_era.index, validator_payout, rest));
360+
Self::deposit_event(Event::<T>::EraPaid(active_era.index, validator_payout, rest));
358361

359362
// Set ending era reward.
360363
<ErasValidatorReward<T>>::insert(&active_era.index, validator_payout);
@@ -446,7 +449,7 @@ impl<T: Config> Pallet<T> {
446449
return None
447450
}
448451

449-
Self::deposit_event(Event::StakingElection);
452+
Self::deposit_event(Event::StakersElected);
450453
Some(Self::trigger_new_era(start_session_index, exposures))
451454
}
452455

frame/staking/src/pallet/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,17 @@ pub mod pallet {
525525
/// The era payout has been set; the first balance is the validator-payout; the second is
526526
/// the remainder from the maximum amount of reward.
527527
/// \[era_index, validator_payout, remainder\]
528-
EraPayout(EraIndex, BalanceOf<T>, BalanceOf<T>),
529-
/// The staker has been rewarded by this amount. \[stash, amount\]
530-
Reward(T::AccountId, BalanceOf<T>),
528+
EraPaid(EraIndex, BalanceOf<T>, BalanceOf<T>),
529+
/// The nominator has been rewarded by this amount. \[stash, amount\]
530+
Rewarded(T::AccountId, BalanceOf<T>),
531531
/// One validator (and its nominators) has been slashed by the given amount.
532532
/// \[validator, amount\]
533-
Slash(T::AccountId, BalanceOf<T>),
533+
Slashed(T::AccountId, BalanceOf<T>),
534534
/// An old slashing report from a prior era was discarded because it could
535535
/// not be processed. \[session_index\]
536536
OldSlashingReportDiscarded(SessionIndex),
537537
/// A new set of stakers was elected.
538-
StakingElection,
538+
StakersElected,
539539
/// An account has bonded this amount. \[stash, amount\]
540540
///
541541
/// NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably,
@@ -553,6 +553,8 @@ pub mod pallet {
553553
/// An account has stopped participating as either a validator or nominator.
554554
/// \[stash\]
555555
Chilled(T::AccountId),
556+
/// The stakers' rewards are getting paid. \[era_index, validator_stash\]
557+
PayoutStarted(EraIndex, T::AccountId),
556558
}
557559

558560
#[pallet::error]

frame/staking/src/slashing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ pub fn do_slash<T: Config>(
584584
<Pallet<T>>::update_ledger(&controller, &ledger);
585585

586586
// trigger the event
587-
<Pallet<T>>::deposit_event(super::Event::<T>::Slash(stash.clone(), value));
587+
<Pallet<T>>::deposit_event(super::Event::<T>::Slashed(stash.clone(), value));
588588
}
589589
}
590590

frame/staking/src/tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ fn rewards_should_work() {
257257
);
258258
assert_eq!(
259259
*mock::staking_events().last().unwrap(),
260-
Event::EraPayout(0, total_payout_0, maximum_payout - total_payout_0)
260+
Event::EraPaid(0, total_payout_0, maximum_payout - total_payout_0)
261261
);
262262
mock::make_all_reward_payment(0);
263263

@@ -295,7 +295,7 @@ fn rewards_should_work() {
295295
);
296296
assert_eq!(
297297
*mock::staking_events().last().unwrap(),
298-
Event::EraPayout(1, total_payout_1, maximum_payout - total_payout_1)
298+
Event::EraPaid(1, total_payout_1, maximum_payout - total_payout_1)
299299
);
300300
mock::make_all_reward_payment(1);
301301

@@ -3942,7 +3942,7 @@ mod election_data_provider {
39423942
run_to_block(20);
39433943
assert_eq!(Staking::next_election_prediction(System::block_number()), 45);
39443944
assert_eq!(staking_events().len(), 1);
3945-
assert_eq!(*staking_events().last().unwrap(), Event::StakingElection);
3945+
assert_eq!(*staking_events().last().unwrap(), Event::StakersElected);
39463946

39473947
for b in 21..45 {
39483948
run_to_block(b);
@@ -3953,7 +3953,7 @@ mod election_data_provider {
39533953
run_to_block(45);
39543954
assert_eq!(Staking::next_election_prediction(System::block_number()), 70);
39553955
assert_eq!(staking_events().len(), 3);
3956-
assert_eq!(*staking_events().last().unwrap(), Event::StakingElection);
3956+
assert_eq!(*staking_events().last().unwrap(), Event::StakersElected);
39573957

39583958
Staking::force_no_eras(Origin::root()).unwrap();
39593959
assert_eq!(Staking::next_election_prediction(System::block_number()), u64::MAX);
@@ -3976,7 +3976,7 @@ mod election_data_provider {
39763976
run_to_block(55);
39773977
assert_eq!(Staking::next_election_prediction(System::block_number()), 55 + 25);
39783978
assert_eq!(staking_events().len(), 6);
3979-
assert_eq!(*staking_events().last().unwrap(), Event::StakingElection);
3979+
assert_eq!(*staking_events().last().unwrap(), Event::StakersElected);
39803980
// The new era has been planned, forcing is changed from `ForceNew` to `NotForcing`.
39813981
assert_eq!(ForceEra::<Test>::get(), Forcing::NotForcing);
39823982
})

frame/utility/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ pub mod pallet {
108108
BatchInterrupted(u32, DispatchError),
109109
/// Batch of dispatches completed fully with no error.
110110
BatchCompleted,
111+
/// A single item within a Batch of dispatches has completed with no error.
112+
ItemCompleted,
111113
}
112114

113115
#[pallet::call]
@@ -173,6 +175,7 @@ pub mod pallet {
173175
// Return the actual used weight + base_weight of this call.
174176
return Ok(Some(base_weight + weight).into())
175177
}
178+
Self::deposit_event(Event::ItemCompleted);
176179
}
177180
Self::deposit_event(Event::BatchCompleted);
178181
let base_weight = T::WeightInfo::batch(calls_len as u32);
@@ -289,6 +292,7 @@ pub mod pallet {
289292
err.post_info = Some(base_weight + weight).into();
290293
err
291294
})?;
295+
Self::deposit_event(Event::ItemCompleted);
292296
}
293297
Self::deposit_event(Event::BatchCompleted);
294298
let base_weight = T::WeightInfo::batch_all(calls_len as u32);

0 commit comments

Comments
 (0)