From e87c2863ba8c7c02f93586292b83a78e516772d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 30 Dec 2024 11:34:31 +0100 Subject: [PATCH 1/3] BACKPORT-CONFLICT --- prdoc/pr_7013.prdoc | 7 +++++ substrate/frame/bounties/src/benchmarking.rs | 31 ++++++++++++++------ substrate/frame/bounties/src/lib.rs | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 prdoc/pr_7013.prdoc diff --git a/prdoc/pr_7013.prdoc b/prdoc/pr_7013.prdoc new file mode 100644 index 000000000000..138fa7f23102 --- /dev/null +++ b/prdoc/pr_7013.prdoc @@ -0,0 +1,7 @@ +title: 'pallet-bounties: Fix benchmarks for 0 ED' +doc: +- audience: Runtime Dev + description: 'Closes: https://github.com/paritytech/polkadot-sdk/issues/7009' +crates: +- name: pallet-bounties + bump: patch diff --git a/substrate/frame/bounties/src/benchmarking.rs b/substrate/frame/bounties/src/benchmarking.rs index de93ba5c4ce7..41c9be4c281e 100644 --- a/substrate/frame/bounties/src/benchmarking.rs +++ b/substrate/frame/bounties/src/benchmarking.rs @@ -15,9 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! bounties pallet benchmarking. - -#![cfg(feature = "runtime-benchmarks")] +//! Bounties pallet benchmarking. use super::*; @@ -33,6 +31,23 @@ use pallet_treasury::Pallet as Treasury; const SEED: u32 = 0; +<<<<<<< HEAD +======= +fn set_block_number, I: 'static>(n: BlockNumberFor) { + >::BlockNumberProvider::set_block_number(n); +} + +fn minimum_balance, I: 'static>() -> BalanceOf { + let minimum_balance = T::Currency::minimum_balance(); + + if minimum_balance.is_zero() { + 1u32.into() + } else { + minimum_balance + } +} + +>>>>>>> 997db8e (pallet-bounties: Fix benchmarks for 0 ED (#7013)) // Create bounties that are approved for use in `on_initialize`. fn create_approved_bounties, I: 'static>(n: u32) -> Result<(), BenchmarkError> { for i in 0..n { @@ -58,12 +73,10 @@ fn setup_bounty, I: 'static>( let fee = value / 2u32.into(); let deposit = T::BountyDepositBase::get() + T::DataDepositPerByte::get() * T::MaximumReasonLength::get().into(); - let _ = T::Currency::make_free_balance_be(&caller, deposit + T::Currency::minimum_balance()); + let _ = T::Currency::make_free_balance_be(&caller, deposit + minimum_balance::()); let curator = account("curator", u, SEED); - let _ = T::Currency::make_free_balance_be( - &curator, - fee / 2u32.into() + T::Currency::minimum_balance(), - ); + let _ = + T::Currency::make_free_balance_be(&curator, fee / 2u32.into() + minimum_balance::()); let reason = vec![0; d as usize]; (caller, curator, fee, value, reason) } @@ -86,7 +99,7 @@ fn create_bounty, I: 'static>( fn setup_pot_account, I: 'static>() { let pot_account = Bounties::::account_id(); - let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into()); + let value = minimum_balance::().saturating_mul(1_000_000_000u32.into()); let _ = T::Currency::make_free_balance_be(&pot_account, value); } diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index 7b89a6e3e76f..f392f457772d 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -82,6 +82,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "runtime-benchmarks")] mod benchmarking; pub mod migrations; mod tests; From 05b1c75631444c56c2de994cd2227c98bcfae6f3 Mon Sep 17 00:00:00 2001 From: EgorPopelyaev Date: Thu, 9 Jan 2025 15:24:52 +0100 Subject: [PATCH 2/3] Delete conflict marks --- substrate/frame/bounties/src/benchmarking.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/substrate/frame/bounties/src/benchmarking.rs b/substrate/frame/bounties/src/benchmarking.rs index 41c9be4c281e..5781475a7654 100644 --- a/substrate/frame/bounties/src/benchmarking.rs +++ b/substrate/frame/bounties/src/benchmarking.rs @@ -31,8 +31,6 @@ use pallet_treasury::Pallet as Treasury; const SEED: u32 = 0; -<<<<<<< HEAD -======= fn set_block_number, I: 'static>(n: BlockNumberFor) { >::BlockNumberProvider::set_block_number(n); } @@ -47,7 +45,6 @@ fn minimum_balance, I: 'static>() -> BalanceOf { } } ->>>>>>> 997db8e (pallet-bounties: Fix benchmarks for 0 ED (#7013)) // Create bounties that are approved for use in `on_initialize`. fn create_approved_bounties, I: 'static>(n: u32) -> Result<(), BenchmarkError> { for i in 0..n { From 7aa357b1c487c6990a702ccb02a1b874756499fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 9 Jan 2025 16:37:40 +0100 Subject: [PATCH 3/3] Update substrate/frame/bounties/src/benchmarking.rs --- substrate/frame/bounties/src/benchmarking.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/substrate/frame/bounties/src/benchmarking.rs b/substrate/frame/bounties/src/benchmarking.rs index 5781475a7654..250bf53999ad 100644 --- a/substrate/frame/bounties/src/benchmarking.rs +++ b/substrate/frame/bounties/src/benchmarking.rs @@ -31,10 +31,6 @@ use pallet_treasury::Pallet as Treasury; const SEED: u32 = 0; -fn set_block_number, I: 'static>(n: BlockNumberFor) { - >::BlockNumberProvider::set_block_number(n); -} - fn minimum_balance, I: 'static>() -> BalanceOf { let minimum_balance = T::Currency::minimum_balance();