Skip to content

Commit 3bde188

Browse files
committed
pallet-bounties: defaults to some signed caller if RejectOrigin is unavailable
1 parent 1f6b1bb commit 3bde188

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

substrate/frame/bounties/src/benchmarking.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ benchmarks_instance_pallet! {
146146
);
147147
}
148148

149-
// Worst case when curator is inactive and any sender unassigns the curator,
149+
// Worst case when curator is inactive and any sender unassigns the curator,
150150
// or if `BountyUpdatePeriod` is large enough and `RejectOrigin` executes the call.
151151
unassign_curator {
152152
setup_pot_account::<T, I>();
@@ -156,13 +156,14 @@ benchmarks_instance_pallet! {
156156
let bounty_update_period = T::BountyUpdatePeriod::get();
157157
let inactivity_timeout = T::SpendPeriod::get().saturating_add(bounty_update_period);
158158
set_block_number::<T, I>(inactivity_timeout.saturating_add(2u32.into()));
159+
let caller: T::AccountId = whitelisted_caller();
160+
let signed_caller: T::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
159161

160162
// If `BountyUpdatePeriod` overflows the inactivity timeout the benchmark still executes the slash
161163
let origin = if Pallet::<T, I>::treasury_block_number() <= inactivity_timeout {
162-
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?
164+
T::RejectOrigin::try_successful_origin().unwrap_or_else(|_| signed_caller)
163165
} else {
164-
let caller: T::AccountId = whitelisted_caller();
165-
RawOrigin::Signed(caller.clone()).into()
166+
signed_caller
166167
};
167168
}: _<T::RuntimeOrigin>(origin, bounty_id)
168169

substrate/frame/child-bounties/src/benchmarking.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,19 @@ mod benchmarks {
277277
let bounty_update_period = T::BountyUpdatePeriod::get();
278278
let inactivity_timeout = T::SpendPeriod::get().saturating_add(bounty_update_period);
279279
set_block_number::<T>(inactivity_timeout.saturating_add(1u32.into()));
280+
let caller: T::AccountId = whitelisted_caller();
281+
let signed_caller: T::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
280282

281-
// If `BountyUpdatePeriod` overflows the inactivity timeout the benchmark still executes the slash
283+
// If `BountyUpdatePeriod` overflows the inactivity timeout the benchmark still
284+
// executes the slash
282285
let origin = if Pallet::<T>::treasury_block_number() <= inactivity_timeout {
283-
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?
286+
T::RejectOrigin::try_successful_origin().unwrap_or_else(|_| signed_caller)
284287
} else {
285-
let caller: T::AccountId = whitelisted_caller();
286-
RawOrigin::Signed(caller.clone()).into()
288+
signed_caller
287289
};
288290

289291
#[extrinsic_call]
290-
_(
291-
origin as T::RuntimeOrigin,
292-
bounty_setup.bounty_id,
293-
bounty_setup.child_bounty_id,
294-
);
292+
_(origin as T::RuntimeOrigin, bounty_setup.bounty_id, bounty_setup.child_bounty_id);
295293

296294
Ok(())
297295
}

0 commit comments

Comments
 (0)