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

Nits for collectives-westend XCM benchmarks setup #7215

Merged
merged 13 commits into from
Jan 24, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ sp-version = { workspace = true }

# Polkadot
pallet-xcm = { workspace = true }
pallet-xcm-benchmarks = { optional = true, workspace = true }
polkadot-parachain-primitives = { workspace = true }
polkadot-runtime-common = { workspace = true }
westend-runtime-constants = { workspace = true }
Expand Down Expand Up @@ -131,6 +132,7 @@ runtime-benchmarks = [
"pallet-transaction-payment/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand Down Expand Up @@ -222,6 +224,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-utility/std",
"pallet-xcm-benchmarks?/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
Expand Down
122 changes: 119 additions & 3 deletions cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ mod benches {
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_alliance, Alliance]
[pallet_collective, AllianceMotion]
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_preimage, Preimage]
[pallet_scheduler, Scheduler]
[pallet_referenda, FellowshipReferenda]
Expand All @@ -816,6 +815,11 @@ mod benches {
[pallet_treasury, FellowshipTreasury]
[pallet_asset_rate, AssetRate]
[cumulus_pallet_weight_reclaim, WeightReclaim]
// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
[pallet_xcm_benchmarks::fungible, XcmBalances]
[pallet_xcm_benchmarks::generic, XcmGeneric]
);
}

Expand Down Expand Up @@ -1065,6 +1069,12 @@ impl_runtime_apis! {
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;

// 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 Down Expand Up @@ -1093,10 +1103,11 @@ impl_runtime_apis! {

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

parameter_types! {
pub ExistentialDepositAsset: Option<Asset> = Some((
xcm_config::WndLocation::get(),
WndLocation::get(),
ExistentialDeposit::get()
).into());
}
Expand Down Expand Up @@ -1149,14 +1160,119 @@ impl_runtime_apis! {
}
}

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = xcm_config::XcmConfig;
type AccountIdConverter = xcm_config::LocationToAccountId;
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
xcm_config::XcmConfig,
ExistentialDepositAsset,
xcm_config::PriceForParentDelivery,
>;
fn valid_destination() -> Result<Location, BenchmarkError> {
Ok(WndLocation::get())
}
fn worst_case_holding(_depositable_count: u32) -> Assets {
// just concrete assets according to relay chain.
let assets: Vec<Asset> = vec![
Asset {
id: AssetId(WndLocation::get()),
fun: Fungible(1_000_000 * UNITS),
}
];
assets.into()
}
}

parameter_types! {
pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
WndLocation::get(),
Asset { fun: Fungible(UNITS), id: AssetId(WndLocation::get()) },
));
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
pub const TrustedReserve: Option<(Location, Asset)> = None;
}

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

type CheckedAccount = CheckedAccount;
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;

fn get_asset() -> Asset {
Asset {
id: AssetId(WndLocation::get()),
fun: Fungible(UNITS),
}
}
}

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

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

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

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

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

fn subscribe_origin() -> Result<Location, BenchmarkError> {
Ok(WndLocation::get())
}

fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
let origin = WndLocation::get();
let assets: Assets = (AssetId(WndLocation::get()), 1_000 * UNITS).into();
let ticket = Location { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}

fn fee_asset() -> Result<Asset, BenchmarkError> {
Ok(Asset {
id: AssetId(WndLocation::get()),
fun: Fungible(1_000_000 * UNITS),
})
}

fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
Err(BenchmarkError::Skip)
}

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

fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
// Any location can alias to an internal location.
// Here parachain 1000 aliases to an internal account.
let origin = Location::new(1, [Parachain(1000)]);
let target = Location::new(1, [Parachain(1000), AccountId32 { id: [128u8; 32], network: None }]);
Ok((origin, target))
}
}

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

use frame_support::traits::WhitelistedStorageKeys;
let whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
add_benchmarks!(params, batches);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
}
Expand Down
Loading
Loading