diff --git a/substrate/frame/treasury/src/benchmarking.rs b/substrate/frame/treasury/src/benchmarking.rs index 0b9999e37fbea..ae079eb2a1acf 100644 --- a/substrate/frame/treasury/src/benchmarking.rs +++ b/substrate/frame/treasury/src/benchmarking.rs @@ -215,6 +215,8 @@ mod benchmarks { Ok(()) } + // This benchmark is short-circuited if `SpendOrigin` cannot provide + // a successful origin, in which case `spend` is un-callable and can use weight=0. #[benchmark] fn spend() -> Result<(), BenchmarkError> { let origin = @@ -248,9 +250,12 @@ mod benchmarks { Ok(()) } + // This benchmark is short-circuited if `SpendOrigin` cannot provide + // a successful origin, in which case there is no spend to payout. #[benchmark] fn payout() -> Result<(), BenchmarkError> { - let origin = T::SpendOrigin::try_successful_origin().map_err(|_| "No origin")?; + let origin = + T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let (asset_kind, amount, beneficiary, beneficiary_lookup) = create_spend_arguments::(SEED); T::BalanceConverter::ensure_successful(asset_kind.clone()); @@ -279,9 +284,12 @@ mod benchmarks { Ok(()) } + // This benchmark is short-circuited if `SpendOrigin` cannot provide + // a successful origin, in which case there is no spend to check. #[benchmark] fn check_status() -> Result<(), BenchmarkError> { - let origin = T::SpendOrigin::try_successful_origin().map_err(|_| "No origin")?; + let origin = + T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let (asset_kind, amount, beneficiary, beneficiary_lookup) = create_spend_arguments::(SEED); T::BalanceConverter::ensure_successful(asset_kind.clone()); @@ -311,9 +319,12 @@ mod benchmarks { Ok(()) } + // This benchmark is short-circuited if `SpendOrigin` cannot provide + // a successful origin, in which case there is no spend to void. #[benchmark] fn void_spend() -> Result<(), BenchmarkError> { - let origin = T::SpendOrigin::try_successful_origin().map_err(|_| "No origin")?; + let origin = + T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let (asset_kind, amount, _, beneficiary_lookup) = create_spend_arguments::(SEED); T::BalanceConverter::ensure_successful(asset_kind.clone()); Treasury::::spend( diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 5e429d3914bd0..8747d41ef4fb9 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -810,6 +810,7 @@ pub mod pallet { #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::payout())] pub fn payout(origin: OriginFor, index: SpendIndex) -> DispatchResult { + T::SpendOrigin::ensure_origin(origin.clone())?; ensure_signed(origin)?; let mut spend = Spends::::get(index).ok_or(Error::::InvalidIndex)?; let now = frame_system::Pallet::::block_number(); @@ -856,6 +857,7 @@ pub mod pallet { use PaymentState as State; use PaymentStatus as Status; + T::SpendOrigin::ensure_origin(origin.clone())?; ensure_signed(origin)?; let mut spend = Spends::::get(index).ok_or(Error::::InvalidIndex)?; let now = frame_system::Pallet::::block_number(); @@ -907,6 +909,7 @@ pub mod pallet { #[pallet::call_index(8)] #[pallet::weight(T::WeightInfo::void_spend())] pub fn void_spend(origin: OriginFor, index: SpendIndex) -> DispatchResult { + T::SpendOrigin::ensure_origin(origin.clone())?; T::RejectOrigin::ensure_origin(origin)?; let spend = Spends::::get(index).ok_or(Error::::InvalidIndex)?; ensure!(