Skip to content

Commit

Permalink
Fix benchmarking for vesting
Browse files Browse the repository at this point in the history
Signed-off-by: Dengjianping <[email protected]>
  • Loading branch information
Dengjianping committed Apr 16, 2024
1 parent 52cbf8e commit dda1d90
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
26 changes: 25 additions & 1 deletion pallets/asset-manager/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_call
use frame_support::traits::Get;
use frame_system::{EventRecord, RawOrigin};
use manta_primitives::{
assets::{AssetConfig, AssetRegistryMetadata, FungibleLedger, TestingDefault, UnitsPerSecond},
assets::{
AssetConfig, AssetRegistryMetadata, AssetStorageMetadata, FungibleLedger, TestingDefault,
UnitsPerSecond,
},
types::Balance,
};
use sp_std::vec;
Expand All @@ -34,6 +37,27 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
assert_eq!(event, &system_event);
}

pub fn register_asset_helper<T: Config>(location: MultiLocation, i: u32) {
let metadata = AssetRegistryMetadata::<Balance> {
metadata: AssetStorageMetadata {
name: format!("{}-name", i).into(),
symbol: format!("{}-symbol", i).into(),
decimals: 12,
is_frozen: false,
},
min_balance: 1,
is_sufficient: true,
};
Pallet::<T>::register_asset(RawOrigin::Root.into(), location.into(), metadata)
.expect("Filed to register asset");
Pallet::<T>::set_units_per_second(
RawOrigin::Root.into(),
<T as Config>::AssetId::from(i),
i.into(),
)
.expect("Filed to set ups");
}

benchmarks! {
where_clause { where T::Location: From<MultiLocation>, <T as Config>::AssetId: From<u32> }

Expand Down
2 changes: 1 addition & 1 deletion pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod benchmarking;
pub mod weights;

#[cfg(test)]
Expand Down
20 changes: 19 additions & 1 deletion runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ parameter_types! {
pub const NativeTokenExistentialDeposit: u128 = 10 * cKMA; // 0.1 KMA
}

// It's for fixing benchmarking pallet-treasury, 100 will be deposited into an
// account in the pallet_treasury::payout, so we have to set a smaller ED.
#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub const BenchmarksNativeTokenExistentialDeposit: u128 = 10;
Expand Down Expand Up @@ -931,11 +933,19 @@ parameter_types! {
pub const MinVestedTransfer: Balance = KMA;
}

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub const BenchmarksMinVestedTransfer: Balance = 10;
}

impl calamari_vesting::Config for Runtime {
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type Timestamp = Timestamp;
#[cfg(not(feature = "runtime-benchmarks"))]
type MinVestedTransfer = MinVestedTransfer;
#[cfg(feature = "runtime-benchmarks")]
type MinVestedTransfer = BenchmarksMinVestedTransfer;
type MaxScheduleLength = ConstU32<6>;
type WeightInfo = weights::calamari_vesting::SubstrateWeight<Runtime>;
}
Expand Down Expand Up @@ -1152,7 +1162,9 @@ mod benches {
// always get this error(Unimplemented) while benchmarking pallet_xcm_benchmarks::fungible::initiate_teleport
// so this time we will use statemint's fungible weights
// and actually we don't support teleport now
// [pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
// [pallet_xcm_benchmarks::fungible, XcmBalances]
[pallet_xcm_benchmarks::generic, XcmGeneric]
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
[pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::<Runtime>]
// Nimbus pallets
[pallet_author_inherent, AuthorInherent]
Expand Down Expand Up @@ -1508,6 +1520,9 @@ impl_runtime_apis! {
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
use frame_system_benchmarking::Pallet as SystemBench;

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;

let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);

Expand Down Expand Up @@ -1656,6 +1671,9 @@ impl_runtime_apis! {
}
}

type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::<Runtime>;
type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::<Runtime>;

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/manta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ mod benches {
[cumulus_pallet_xcmp_queue, XcmpQueue]
// always get this error(Unimplemented) while benchmarking pallet_xcm_benchmarks::fungible::initiate_teleport
// so this time we will use statemint's fungible weights
[pallet_xcm_benchmarks::fungible, XcmBalances]
// [pallet_xcm_benchmarks::fungible, XcmBalances]
[pallet_xcm_benchmarks::generic, XcmGeneric]
[pallet_session, SessionBench::<Runtime>]
// Manta pallets
Expand Down

0 comments on commit dda1d90

Please sign in to comment.