Skip to content

Commit 96219d9

Browse files
committed
fix: benchmarks
1 parent 09af643 commit 96219d9

File tree

4 files changed

+325
-101
lines changed

4 files changed

+325
-101
lines changed

pallets/collator-selection/src/benchmarking.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@ benchmarks! {
270270
assert_last_event::<T>(Event::CandidateAdded(caller, bond / 2u32.into()).into());
271271
}
272272

273+
reject_application {
274+
<CandidacyBond<T>>::put(T::Currency::minimum_balance());
275+
276+
let origin = T::GovernanceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
277+
let caller: T::AccountId = whitelisted_caller();
278+
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 2u32.into();
279+
T::Currency::make_free_balance_be(&caller, bond);
280+
281+
<session::Pallet<T>>::set_keys(
282+
RawOrigin::Signed(caller.clone()).into(),
283+
keys::<T>(1),
284+
Vec::new()
285+
).unwrap();
286+
287+
<CollatorSelection<T>>::apply_for_candidacy(
288+
RawOrigin::Signed(caller.clone()).into(),
289+
).unwrap();
290+
291+
}: {
292+
assert_ok!(<CollatorSelection<T>>::reject_application(origin, caller.clone()));
293+
}
294+
verify {
295+
assert_last_event::<T>(Event::CandidacyApplicationRejected(caller).into());
296+
}
297+
273298
// worse case is the last candidate kicking.
274299
kick_candidate {
275300
let c in (T::MinCandidates::get() + 1) .. T::MaxCandidates::get();

pallets/collator-selection/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ pub mod pallet {
422422
///
423423
/// This call is not available to `Invulnerable` collators.
424424
#[pallet::call_index(3)]
425-
#[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCandidates::get()))]
425+
#[pallet::weight(T::WeightInfo::register_as_candidate())]
426426
pub fn register_as_candidate(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
427427
let _who = ensure_signed(origin)?;
428428
// Always fail with permission error to enforce new workflow
@@ -536,7 +536,7 @@ pub mod pallet {
536536
///
537537
/// This call is not available to `Invulnerable` collators or exisiting candidates.
538538
#[pallet::call_index(9)]
539-
#[pallet::weight(T::WeightInfo::remove_invulnerable(T::MaxInvulnerables::get()))]
539+
#[pallet::weight(T::WeightInfo::apply_for_candidacy())]
540540
pub fn apply_for_candidacy(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
541541
let who = ensure_signed(origin)?;
542542

@@ -603,7 +603,7 @@ pub mod pallet {
603603
/// This will remove the application from pending status and immediately add the account
604604
/// to the candidates list, making them eligible for collator selection.
605605
#[pallet::call_index(11)]
606-
#[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCandidates::get()))]
606+
#[pallet::weight(T::WeightInfo::approve_application(T::MaxCandidates::get()))]
607607
pub fn approve_application(
608608
origin: OriginFor<T>,
609609
who: T::AccountId,
@@ -638,15 +638,15 @@ pub mod pallet {
638638
});
639639

640640
Self::deposit_event(Event::CandidateAdded(who, deposit));
641-
Ok(Some(T::WeightInfo::register_as_candidate(current_count as u32)).into())
641+
Ok(Some(T::WeightInfo::approve_application(current_count as u32)).into())
642642
}
643643

644644
/// Reject a pending candidacy application and unreserve the bond.
645645
///
646646
/// This will remove the application from pending status and unreserve the
647647
/// applicant's bond, effectively denying their candidacy request.
648648
#[pallet::call_index(12)]
649-
#[pallet::weight(T::WeightInfo::withdraw_bond())]
649+
#[pallet::weight(T::WeightInfo::reject_application())]
650650
pub fn reject_application(
651651
origin: OriginFor<T>,
652652
who: T::AccountId,
@@ -672,7 +672,7 @@ pub mod pallet {
672672
/// This call will fail if removing the candidate would bring the total
673673
/// number of candidates below the minimum threshold.
674674
#[pallet::call_index(13)]
675-
#[pallet::weight(T::WeightInfo::remove_invulnerable(T::MaxInvulnerables::get()))]
675+
#[pallet::weight(T::WeightInfo::kick_candidate(T::MaxInvulnerables::get()))]
676676
pub fn kick_candidate(
677677
origin: OriginFor<T>,
678678
who: T::AccountId,
@@ -686,7 +686,7 @@ pub mod pallet {
686686
Self::slash_non_candidate(&who);
687687

688688
Self::deposit_event(Event::CandidateKickedByCouncil(who));
689-
Ok(Some(T::WeightInfo::leave_intent(current_count as u32)).into())
689+
Ok(Some(T::WeightInfo::kick_candidate(current_count as u32)).into())
690690
}
691691
}
692692

0 commit comments

Comments
 (0)