Skip to content

Commit

Permalink
xcm: add pallet benchmarks for fungible
Browse files Browse the repository at this point in the history
  • Loading branch information
hounsette committed Mar 9, 2023
1 parent b9ee54b commit fffd45f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions runtimes/eden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ std = [
"sp-transaction-pool/std",
"sp-version/std",
"sp-npos-elections/std",
"pallet-xcm-benchmarks/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
29 changes: 23 additions & 6 deletions runtimes/eden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn wasm_binary_unwrap() -> &'static [u8] {
}

use constants::RuntimeBlockWeights;
use frame_support::{construct_runtime, weights::Weight};
use frame_support::{construct_runtime, traits::Nothing, weights::Weight};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use primitives::{AccountId, Balance, BlockNumber, Hash, Index, Signature};
pub use primitives::{AuraId, ParaId};
Expand Down Expand Up @@ -339,8 +339,8 @@ sp_api::impl_runtime_apis! {
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use pallet_xcm_benchmarks::generic::Pallet as XcmBenchmarks;

use pallet_xcm_benchmarks::generic::Pallet as XcmGenericBenchmarks;
use pallet_xcm_benchmarks::fungible::Pallet as XcmFungibleBenchmarks;

// Trying to add benchmarks directly to the Session Pallet caused cyclic dependency
// issues. To get around that, we separated the Session benchmarks into its own crate,
Expand All @@ -364,7 +364,8 @@ sp_api::impl_runtime_apis! {
list_benchmark!(list, extra, pallet_collator_selection, CollatorSelection);
list_benchmark!(list, extra, pallet_contracts, Contracts);
list_benchmark!(list, extra, pallet_membership, TechnicalMembership);
list_benchmark!(list, extra, pallet_xcm_benchmarks::generic, XcmBenchmarks::<Runtime>);
list_benchmark!(list, extra, pallet_xcm_benchmarks::generic, XcmGenericBenchmarks::<Runtime>);
list_benchmark!(list, extra, pallet_xcm_benchmarks::fungible, XcmFungibleBenchmarks::<Runtime>);

let storage_info = AllPalletsWithSystem::storage_info();

Expand All @@ -386,7 +387,8 @@ sp_api::impl_runtime_apis! {

use xcm::latest::prelude::*;
use frame_benchmarking::BenchmarkError;
use pallet_xcm_benchmarks::generic::Pallet as XcmBenchmarks;
use pallet_xcm_benchmarks::generic::Pallet as XcmGenericBenchmarks;
use pallet_xcm_benchmarks::fungible::Pallet as XcmFungibleBenchmarks;
impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmConfig;
type AccountIdConverter = xcm_config::LocationToAccountId;
Expand Down Expand Up @@ -442,6 +444,20 @@ sp_api::impl_runtime_apis! {
}
}

impl pallet_xcm_benchmarks::fungible::Config for Runtime {

type TransactAsset= Balances;
type CheckedAccount = ();
type TrustedTeleporter = ();
type TrustedReserve = xcm_config::TrustedReserve;
fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(MultiLocation::here()),
fun: Fungible(u128::MAX),
}
}
}


let whitelist: Vec<TrackedStorageKey> = vec![];
let mut batches = Vec::<BenchmarkBatch>::new();
Expand All @@ -461,7 +477,8 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection);
add_benchmark!(params, batches, pallet_contracts, Contracts);
add_benchmark!(params, batches, pallet_membership, TechnicalMembership);
add_benchmark!(params, batches, pallet_xcm_benchmarks::generic, XcmBenchmarks::<Runtime>);
add_benchmark!(params, batches, pallet_xcm_benchmarks::generic, XcmGenericBenchmarks::<Runtime>);
add_benchmark!(params, batches, pallet_xcm_benchmarks::fungible, XcmFungibleBenchmarks::<Runtime>);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
7 changes: 6 additions & 1 deletion runtimes/eden/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ impl orml_xtokens::Config for Runtime {
type MultiLocationsFilter = Everything;
type ReserveProvider = RelativeReserveProvider;
}

parameter_types! {
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
MultiLocation::here(),
MultiAsset{ id: Concrete(Here.into()), fun: Fungible(100) }
));
}
#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit fffd45f

Please sign in to comment.