Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-bounties: Fix benchmarks for 0 ED #7013

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions prdoc/pr_7013.prdoc
Original file line number Diff line number Diff line change
@@ -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
24 changes: 15 additions & 9 deletions substrate/frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -37,6 +35,16 @@ fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T, I>) {
<T as pallet_treasury::Config<I>>::BlockNumberProvider::set_block_number(n);
}

fn minimum_balance<T: Config<I>, I: 'static>() -> BalanceOf<T, I> {
let minimum_balance = T::Currency::minimum_balance();

if minimum_balance.is_zero() {
1u32.into()
} else {
minimum_balance
}
}

// Create bounties that are approved for use in `on_initialize`.
fn create_approved_bounties<T: Config<I>, I: 'static>(n: u32) -> Result<(), BenchmarkError> {
for i in 0..n {
Expand All @@ -62,12 +70,10 @@ fn setup_bounty<T: Config<I>, 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::<T, I>());
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::<T, I>());
let reason = vec![0; d as usize];
(caller, curator, fee, value, reason)
}
Expand All @@ -91,7 +97,7 @@ fn create_bounty<T: Config<I>, I: 'static>(

fn setup_pot_account<T: Config<I>, I: 'static>() {
let pot_account = Bounties::<T, I>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
let value = minimum_balance::<T, I>().saturating_mul(1_000_000_000u32.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
}

Expand Down
1 change: 1 addition & 0 deletions substrate/frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod migrations;
mod tests;
Expand Down
Loading