Skip to content

Commit

Permalink
fix(pallet-communities-manager): limit to u16 / benchmark to 1,1024
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed May 8, 2024
1 parent 9aff757 commit 1bb052e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pallets/communities-manager/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use frame_benchmarking::v2::*;

use frame_support::traits::fungible::Mutate;
use frame_system::RawOrigin;
use sp_runtime::SaturatedConversion;

type RuntimeEventFor<T> = <T as Config>::RuntimeEvent;

Expand Down Expand Up @@ -58,7 +59,7 @@ mod benchmarks {
}

#[benchmark]
fn create_memberships() -> Result<(), BenchmarkError> {
fn create_memberships(q: Linear<1, 1024>) -> Result<(), BenchmarkError> {
// setup code
T::CreateCollection::create_collection_with_id(
T::MembershipsManagerCollectionId::get(),
Expand All @@ -74,7 +75,7 @@ mod benchmarks {
#[extrinsic_call]
_(
RawOrigin::Root,
u16::MAX.into(),
q.saturated_into(),
100u32.into(),
300_000_000_000u128.into(),
);
Expand All @@ -83,7 +84,7 @@ mod benchmarks {
assert_has_event::<T>(
Event::<T>::MembershipsCreated {
starting_at: 100u32.into(),
amount: u16::MAX.into(),
amount: q.saturated_into(),
}
.into(),
);
Expand Down
5 changes: 3 additions & 2 deletions pallets/communities-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ pub mod pallet {
Ok(())
}

#[pallet::weight(<T as Config>::WeightInfo::create_memberships(*amount))]
#[pallet::call_index(1)]
pub fn create_memberships(
origin: OriginFor<T>,
#[pallet::compact] amount: u32,
#[pallet::compact] starting_at: <T as Config>::MembershipId,
amount: u16,
starting_at: <T as Config>::MembershipId,
#[pallet::compact] price: NativeBalanceOf<T>,
) -> DispatchResult {
T::CreateMembershipsOrigin::ensure_origin(origin)?;
Expand Down
6 changes: 3 additions & 3 deletions pallets/communities-manager/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::marker::PhantomData;
/// Weight functions needed for pallet_communities.
pub trait WeightInfo {
fn register() -> Weight;
fn create_memberships() -> Weight;
fn create_memberships(q: u16, ) -> Weight;
}

/// Weights for pallet_communities using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().writes(14))
}

fn create_memberships() -> Weight {
fn create_memberships(_: u16, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `278`
// Estimated: `132561`
Expand Down Expand Up @@ -105,7 +105,7 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().writes(14))
}

fn create_memberships() -> Weight {
fn create_memberships(_: u16, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `278`
// Estimated: `132561`
Expand Down
2 changes: 1 addition & 1 deletion runtime/kreivo/src/weights/pallet_communities_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<T: frame_system::Config> pallet_communities_manager::WeightInfo for WeightI
.saturating_add(T::DbWeight::get().writes(14))
}

fn create_memberships() -> Weight {
fn create_memberships(_: u16, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `278`
// Estimated: `132561`
Expand Down

0 comments on commit 1bb052e

Please sign in to comment.