Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

XCM Benchmarks for Asset Transactor w/ Fungible Asset #3818

Merged
merged 31 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cdf3e86
benchmarks for fungibles
shawntabrizi Sep 9, 2021
7e4fd07
add benchmark to westend
shawntabrizi Sep 9, 2021
419702f
fix hex
shawntabrizi Sep 9, 2021
06c1a9d
clean up a bit
shawntabrizi Sep 9, 2021
70beba3
update code doc
shawntabrizi Sep 9, 2021
ce4705b
fix warnings
shawntabrizi Sep 9, 2021
99215ad
cargo run --quiet --release --features runtime-benchmarks -- benchmar…
Sep 9, 2021
26ece05
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 10, 2021
cdf2b9b
use skip
shawntabrizi Sep 10, 2021
9955fad
fix spelling
shawntabrizi Sep 10, 2021
f313d57
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 17, 2021
556dccf
Update Cargo.lock
shawntabrizi Sep 17, 2021
f491adf
add scale-info
shawntabrizi Sep 17, 2021
386d3a5
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 17, 2021
2381dcb
Update Cargo.lock
shawntabrizi Sep 17, 2021
dcdc5e8
update bench
shawntabrizi Sep 17, 2021
768e888
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 17, 2021
0515f70
weights compile
shawntabrizi Sep 21, 2021
cb752a9
update westend to use weights
shawntabrizi Sep 21, 2021
cfa4323
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 21, 2021
a73f703
fmt
shawntabrizi Sep 21, 2021
48dd6db
spelling fixes
shawntabrizi Sep 21, 2021
cb860e7
Delete pallet_xcm_benchmarks::fungible.rs
shawntabrizi Sep 21, 2021
532b61c
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 22, 2021
bddcb2b
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 22, 2021
11e5d7d
Apply suggestions from code review
shawntabrizi Sep 23, 2021
a7519b6
fix code review
shawntabrizi Sep 23, 2021
007e446
Merge branch 'master' into shawntabrizi-fungible-benchmarks
shawntabrizi Sep 27, 2021
161906f
update weight
shawntabrizi Sep 27, 2021
3f394c0
fix report_error
shawntabrizi Sep 27, 2021
7b47f5c
fix spell check
shawntabrizi Sep 27, 2021
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
41 changes: 41 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ members = [
"xcm/xcm-simulator",
"xcm/xcm-simulator/example",
"xcm/pallet-xcm",
"xcm/pallet-xcm-benchmarks",
"xcm/procedural",
"node/client",
"node/collation-generation",
Expand Down
2 changes: 1 addition & 1 deletion runtime/polkadot/src/weights/runtime_common_crowdloan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for runtime_common::crowdloan.
/// Weight functions for `runtime_common::crowdloan`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> runtime_common::crowdloan::WeightInfo for WeightInfo<T> {
// Storage: Crowdloan Funds (r:1 w:1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for runtime_common::paras_registrar.
/// Weight functions for `runtime_common::paras_registrar`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> runtime_common::paras_registrar::WeightInfo for WeightInfo<T> {
// Storage: Registrar NextFreeParaId (r:1 w:1)
Expand Down
4 changes: 3 additions & 1 deletion runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate"
pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-bags-list = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-democracy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Expand Down Expand Up @@ -69,7 +70,7 @@ pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "m
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false }
pallet-bags-list = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true }

frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
Expand Down Expand Up @@ -202,6 +203,7 @@ runtime-benchmarks = [
"frame-system-benchmarking",
"hex-literal",
"xcm-builder/runtime-benchmarks",
"pallet-xcm-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
]
Expand Down
68 changes: 58 additions & 10 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom,
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents,
CurrencyAdapter as XcmCurrencyAdapter, IsChildSystemParachain, IsConcrete, LocationInverter,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds,
};
use xcm_executor::XcmExecutor;

Expand Down Expand Up @@ -951,10 +951,6 @@ type LocalOriginConverter = (
ChildSystemParachainAsSuperuser<ParaId, Origin>,
);

parameter_types! {
pub const BaseXcmWeight: Weight = 1_000_000_000;
}

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
Expand All @@ -963,8 +959,9 @@ pub type XcmRouter = (
);

parameter_types! {
pub const Westmint: MultiLocation = Parachain(1000).into();
pub const WestendForWestmint: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Parachain(1000).into());
(Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }), Westmint::get());
pub const MaxInstructions: u32 = 100;
}
pub type TrustedTeleporters = (xcm_builder::Case<WestendForWestmint>,);
Expand All @@ -989,7 +986,7 @@ impl xcm_executor::Config for XcmConfig {
type IsTeleporter = TrustedTeleporters;
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Weigher = WeightInfoBounds<weights::xcm::WestendXcmWeight<Call>, Call, MaxInstructions>;
type Trader = UsingComponents<WeightToFee, WndLocation, AccountId, Balances, ToAuthor<Runtime>>;
type ResponseHandler = XcmPallet;
type AssetTrap = XcmPallet;
Expand All @@ -1015,7 +1012,7 @@ impl pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
type Weigher = WeightInfoBounds<weights::xcm::WestendXcmWeight<Call>, Call, MaxInstructions>;
type LocationInverter = LocationInverter<Ancestry>;
type Origin = Origin;
type Call = Call;
Expand Down Expand Up @@ -1468,6 +1465,8 @@ sp_api::impl_runtime_apis! {
use pallet_offences_benchmarking::Pallet as OffencesBench;
use frame_system_benchmarking::Pallet as SystemBench;

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

let mut list = Vec::<BenchmarkList>::new();

// Polkadot
Expand All @@ -1479,6 +1478,7 @@ sp_api::impl_runtime_apis! {
list_benchmark!(list, extra, runtime_common::slots, Slots);
list_benchmark!(list, extra, runtime_parachains::configuration, Configuration);
list_benchmark!(list, extra, runtime_parachains::paras, Paras);

// Substrate
list_benchmark!(list, extra, pallet_bags_list, BagsList);
list_benchmark!(list, extra, pallet_balances, Balances);
Expand All @@ -1497,6 +1497,10 @@ sp_api::impl_runtime_apis! {
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_vesting, Vesting);

// XCM Benchmarks
// NOTE: Make sure you point to the individual modules below.
list_benchmark!(list, extra, pallet_xcm_benchmarks::fungible, XcmBalances);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
Expand All @@ -1519,6 +1523,39 @@ sp_api::impl_runtime_apis! {
impl pallet_offences_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}

use xcm::latest::MultiAsset;

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = XcmConfig;
type AccountIdConverter = LocationConverter;
fn valid_destination() -> Result<MultiLocation, sp_runtime::DispatchError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DQ: Why does this return a result?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may need to be some setup required to make a destination valid, for example calling some dispatchables which sets up UMP/DMP settings, or gives a chain funds or anything. Also there may be no valid destination for a chain which doesnt communicate to anyone.

Ok(Westmint::get())
}
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Westmint::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(WndLocation::get()) },
));
}

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

type CheckedAccount = CheckAccount;
type TrustedTeleporter = TrustedTeleporter;

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

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

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
Expand All @@ -1532,6 +1569,12 @@ sp_api::impl_runtime_apis! {
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
// Treasury Account
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(),
// Dmp DownwardMessageQueueHeads
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

justification for whitelisting these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can assume XCM will be used once every block, and these storage items will be updated pretty much once every block. No need to double count them everywhere.

hex_literal::hex!("63f78c98723ddc9073523ef3beefda0c4d7fefc408aac59dbfe80a72ac8e3ce5").to_vec().into(),
// Dmp DownwardMessageQueues
hex_literal::hex!("63f78c98723ddc9073523ef3beefda0ca95dac46c07a40d91506e7637ec4ba57").to_vec().into(),
// Configuration ActiveConfig
hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(),
];

let mut batches = Vec::<BenchmarkBatch>::new();
Expand All @@ -1546,6 +1589,7 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, runtime_common::slots, Slots);
add_benchmark!(params, batches, runtime_parachains::configuration, Configuration);
add_benchmark!(params, batches, runtime_parachains::paras, Paras);

// Substrate
add_benchmark!(params, batches, pallet_bags_list, BagsList);
add_benchmark!(params, batches, pallet_balances, Balances);
Expand All @@ -1564,6 +1608,10 @@ sp_api::impl_runtime_apis! {
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_vesting, Vesting);

// XCM Benchmarks
// NOTE: Make sure you point to the individual modules below.
apopiak marked this conversation as resolved.
Show resolved Hide resolved
add_benchmark!(params, batches, pallet_xcm_benchmarks::fungible, XcmBalances);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
Expand Down
1 change: 1 addition & 0 deletions runtime/westend/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ pub mod runtime_common_paras_registrar;
pub mod runtime_common_slots;
pub mod runtime_parachains_configuration;
pub mod runtime_parachains_paras;
pub mod xcm;
Loading