Skip to content

Commit

Permalink
Add XCM benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Jul 11, 2023
1 parent 1df5667 commit 9928a77
Show file tree
Hide file tree
Showing 10 changed files with 15,316 additions and 53 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion runtime/kreivo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", defa
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.43" }
pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", default-features = false, optional = true, branch = "release-v0.9.43" }

# Cumulus
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.43", default-features = false }
Expand Down Expand Up @@ -172,7 +173,8 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"assets-common/runtime-benchmarks"
"assets-common/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
]

try-runtime = [
Expand Down
117 changes: 116 additions & 1 deletion runtime/kreivo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ mod benches {
[pallet_assets, Assets]
[pallet_proxy, Proxy]
[pallet_asset_registry, AssetRegistry]
// XCM
// NOTE: Make sure you point to the individual modules below.
[pallet_xcm_benchmarks::fungible, XcmBalances]
[pallet_xcm_benchmarks::generic, XcmGeneric]
);
}

Expand Down Expand Up @@ -824,6 +828,12 @@ impl_runtime_apis! {
use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;

// This is defined once again in dispatch_benchmark, because list_benchmarks!
// and add_benchmarks! are macros exported by define_benchmarks! macros and those types
// are referenced in that call.
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 All @@ -834,14 +844,119 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, BenchmarkError};

use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}

use xcm::latest::prelude::*;
use xcm_config::RelayLocation;
use pallet_xcm_benchmarks::asset_instance_from;

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmConfig;
type AccountIdConverter = xcm_config::LocationToAccountId;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(RelayLocation::get())
}
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
// A mix of fungible, non-fungible, and concrete assets.
let holding_non_fungibles = xcm_config::MaxAssetsIntoHolding::get() / 2 - depositable_count;
let holding_fungibles = holding_non_fungibles.saturating_sub(1);
let fungibles_amount: u128 = 100;
let mut assets = (0..holding_fungibles)
.map(|i| {
MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
fun: Fungible(fungibles_amount * i as u128),
}
.into()
})
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
.chain((0..holding_non_fungibles).map(|i| MultiAsset {
id: Concrete(GeneralIndex(i as u128).into()),
fun: NonFungible(asset_instance_from(i)),
}))
.collect::<Vec<_>>();

assets.push(MultiAsset{
id: Concrete(RelayLocation::get()),
fun: Fungible(1_000_000 * UNITS),
});
assets.into()
}
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
RelayLocation::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(RelayLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;

}

impl pallet_xcm_benchmarks::fungible::Config for Runtime {
type TransactAsset = Balances;

type CheckedAccount = CheckedAccount;
type TrustedTeleporter = TrustedTeleporter;

fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(RelayLocation::get()),
fun: Fungible(1 * UNITS),
}
}
}

impl pallet_xcm_benchmarks::generic::Config for Runtime {
type RuntimeCall = RuntimeCall;

fn worst_case_response() -> (u64, Response) {
(0u64, Response::Version(Default::default()))
}

fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
Err(BenchmarkError::Skip)
}

fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
Err(BenchmarkError::Skip)
}

fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
Ok((RelayLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
}

fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(RelayLocation::get())
}

fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let origin = RelayLocation::get();
let assets: MultiAssets = (Concrete(RelayLocation::get()), 1_000 * UNITS).into();
let ticket = MultiLocation { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}

fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
Err(BenchmarkError::Skip)
}

fn export_message_origin_and_destination(
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
Err(BenchmarkError::Skip)
}
}

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

use frame_support::traits::WhitelistedStorageKeys;
let whitelist = AllPalletsWithSystem::whitelisted_storage_keys();

Expand Down
1 change: 1 addition & 0 deletions runtime/kreivo/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod pallet_assets;
pub mod pallet_proxy;
pub mod paritydb_weights;
pub mod rocksdb_weights;
pub mod xcm;

pub use block_weights::constants::BlockExecutionWeight;
pub use extrinsic_weights::constants::ExtrinsicBaseWeight;
Expand Down
Loading

0 comments on commit 9928a77

Please sign in to comment.