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

[Feature] Add XCM benchmark weights to Statemint and Statemine #1454

Merged
merged 66 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
999e8f7
[Feature] Add XCM benchmarark weights to Statemint and Statemine
ruseinov Jul 19, 2022
26457ca
add xcm-bench-template
ruseinov Jul 19, 2022
f07deed
add polkadot xcm bench pallet to statemint
ruseinov Jul 20, 2022
9a179aa
Sample benchmarking that compiles
ruseinov Jul 22, 2022
009a3c5
add benches to the module
ruseinov Jul 22, 2022
dc1b3ef
Remove batches assertion and whitelist ActiveConfig
ruseinov Jul 22, 2022
6e06b34
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Jul 22, 2022
c19763d
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Jul 22, 2022
4435ac6
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Jul 22, 2022
0fe8134
fix benchmarks
ruseinov Jul 22, 2022
c996d6e
fix get_multi_asset
ruseinov Jul 24, 2022
9845cdf
fmt and more bench fixes
ruseinov Jul 26, 2022
bfa6b5b
reformat
ruseinov Jul 26, 2022
0a8abce
move Xcm type definitions
ruseinov Jul 26, 2022
4086364
define types twice
ruseinov Jul 27, 2022
09b9f02
remove commented out lines
ruseinov Jul 27, 2022
4d28efa
define Xcm bench types globally
ruseinov Jul 27, 2022
bf182cc
test use
ruseinov Jul 27, 2022
af88575
fix semi
ruseinov Jul 27, 2022
84bd7c7
make sure the type definittion is properly documented
ruseinov Jul 28, 2022
1434df7
tweak TrustedTeleporter/Reserve
ruseinov Jul 28, 2022
b1e472c
use dots as asset
ruseinov Aug 7, 2022
7574607
Merge branch 'master' into ruseinov/feature/statemint-xcm-benchmarks
ruseinov Aug 15, 2022
063fabc
copy benchmarks over, fix the ci script
ruseinov Aug 16, 2022
0972d9d
remove extra asset
ruseinov Aug 16, 2022
19a991e
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Aug 16, 2022
dc64b57
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Aug 16, 2022
6c94d5c
benchmarks setup for statemint/e and westmint
ruseinov Aug 17, 2022
5dddc60
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Aug 17, 2022
3481ffa
".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmar…
Aug 17, 2022
3eeeea2
".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmar…
Aug 17, 2022
33e808e
remove a check
ruseinov Aug 17, 2022
2ff069f
".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmark…
Aug 17, 2022
2ebc26d
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Aug 17, 2022
bebc96b
".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmark…
Aug 17, 2022
08cc6e9
implement WeightInfoBounds for all the asset runtimes
ruseinov Aug 18, 2022
a2475db
Merge branch 'master' into ruseinov/feature/statemint-xcm-benchmarks
ruseinov Aug 18, 2022
b901025
update Cargo.lock
ruseinov Aug 18, 2022
2f8655b
Merge branch 'master' into ruseinov/feature/statemint-xcm-benchmarks
ruseinov Aug 22, 2022
aec4b36
fix Muharem's comments
ruseinov Aug 23, 2022
0a8a994
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Aug 24, 2022
de97475
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Aug 24, 2022
80faa1d
Update parachains/runtimes/assets/statemint/src/lib.rs
ruseinov Aug 24, 2022
5dabe9e
fix some review comments
ruseinov Aug 24, 2022
274a576
fix file headers
ruseinov Aug 24, 2022
c50d468
more fixes to licenses and such
ruseinov Aug 24, 2022
0fc3bf0
fix another inconsistency
ruseinov Aug 24, 2022
e6859c0
Extend weights template
ggwpez Aug 25, 2022
10b07ee
remove a placeholder
ruseinov Aug 25, 2022
d239b60
remove redundant overrides
ruseinov Aug 25, 2022
2161326
Merge branch 'master' of https://github.com/paritytech/cumulus into HEAD
Aug 25, 2022
3b869fe
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Aug 25, 2022
168f0b3
Update benchmarking.rs
ruseinov Aug 25, 2022
59ab737
remove redundant bench
ruseinov Aug 25, 2022
898b8bf
fix
ruseinov Aug 25, 2022
8cf49f1
".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmar…
Aug 25, 2022
3b4133f
Update pallets/xcm-benchmarks/src/fungible/mock.rs
ruseinov Aug 27, 2022
571ca78
remove TODO's
ruseinov Aug 27, 2022
5499ef2
remove local xcm-benchmark-pallet impl
ruseinov Aug 29, 2022
a09960e
disable CheckedAccount in benches
ruseinov Aug 29, 2022
247a9d9
Merge branch 'master' into ruseinov/feature/statemint-xcm-benchmarks
ruseinov Aug 30, 2022
49a3b1d
Merge branch 'master' into ruseinov/feature/statemint-xcm-benchmarks
ruseinov Aug 31, 2022
b8d6186
update template
ruseinov Aug 31, 2022
a12e37d
fix up imports
ruseinov Aug 31, 2022
1cb21e6
fix xcm
ruseinov Aug 31, 2022
0eab441
fix the template
ruseinov Aug 31, 2022
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions parachains/runtimes/assets/statemine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default-
pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false }
parachain-info = { path = "../../../pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../common", default-features = false }
pallet-xcm-benchmarks = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false, optional = true }


[dev-dependencies]
Expand Down Expand Up @@ -101,6 +102,7 @@ runtime-benchmarks = [
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"pallet-xcm-benchmarks",
]
try-runtime = [
"frame-executive/try-runtime",
Expand Down
105 changes: 103 additions & 2 deletions parachains/runtimes/assets/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ mod benches {
[pallet_timestamp, Timestamp]
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// 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 @@ -789,6 +793,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 @@ -799,14 +809,104 @@ impl_runtime_apis! {
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, BenchmarkError,
TrackedStorageKey};

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::KsmLocation;
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(KsmLocation::get())
}
fn worst_case_holding() -> MultiAssets {
// A mix of fungible, non-fungible, and concrete assets.
const HOLDING_FUNGIBLES: u32 = 100;
const HOLDING_NON_FUNGIBLES: u32 = 100;
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(KsmLocation::get()),
fun: Fungible(1_000_000 * UNITS),
});
assets.into()
}
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
KsmLocation::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI you can not define these and do type TrustedReserve = () etc.

pub const CheckedAccount: Option<AccountId> = None;

}

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

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

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

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

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

fn transact_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(KsmLocation::get())
}

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

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

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 All @@ -818,13 +918,14 @@ impl_runtime_apis! {
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
// System Events
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
//TODO: use from relay_well_known_keys::ACTIVE_CONFIG
hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(),
];

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
1 change: 1 addition & 0 deletions parachains/runtimes/assets/statemine/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod pallet_uniques;
pub mod pallet_utility;
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
179 changes: 179 additions & 0 deletions parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// Copyright 2022 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use frame_support::weights::Weight;
use sp_std::prelude::*;
use xcm::{latest::prelude::*, DoubleEncoded};

use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;

trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> Weight;
}

const MAX_ASSETS: u32 = 100;

impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
match self {
Self::Definite(assets) =>
(assets.inner().into_iter().count() as Weight).saturating_mul(weight),
Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight),
}
}
}

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
(self.inner().into_iter().count() as Weight).saturating_mul(weight)
}
}

pub struct StatemineXcmWeight<Call>(core::marker::PhantomData<Call>);
impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
fn withdraw_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
}
// Currently there is no trusted reserve
fn reserve_asset_deposited(_assets: &MultiAssets) -> Weight {
unimplemented!()
}
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight {
XcmGeneric::<Runtime>::query_response()
}
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(
assets: &MultiAssets,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_type: &OriginKind,
_require_weight_at_most: &u64,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
_sender: &u32,
_max_message_size: &u32,
_max_capacity: &u32,
) -> Weight {
// XCM Executor does not currently support HRMP channel operations
Weight::MAX
}
fn hrmp_channel_accepted(_recipient: &u32) -> Weight {
// XCM Executor does not currently support HRMP channel operations
Weight::MAX
}
fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight {
// XCM Executor does not currently support HRMP channel operations
Weight::MAX
}
fn clear_origin() -> Weight {
XcmGeneric::<Runtime>::clear_origin()
}
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
XcmGeneric::<Runtime>::descend_origin()
}
fn report_error(
_query_id: &QueryId,
_dest: &MultiLocation,
_max_response_weight: &u64,
) -> Weight {
XcmGeneric::<Runtime>::report_error()
}

fn deposit_asset(
assets: &MultiAssetFilter,
_max_assets: &u32,
_dest: &MultiLocation,
) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(
assets: &MultiAssetFilter,
_max_assets: &u32,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight {
Weight::MAX // todo fix
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor

Choose a reason for hiding this comment

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

resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, this is resolved, this stays as it was as it's not defined, so will have weight::MAX. @joepetrowski does this seem reasonable?

Copy link
Contributor

Choose a reason for hiding this comment

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

}
fn initiate_reserve_withdraw(
assets: &MultiAssetFilter,
_reserve: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn query_holding(
_query_id: &u64,
_dest: &MultiLocation,
_assets: &MultiAssetFilter,
_max_response_weight: &u64,
) -> Weight {
XcmGeneric::<Runtime>::query_holding()
}
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
XcmGeneric::<Runtime>::buy_execution()
}
fn refund_surplus() -> Weight {
XcmGeneric::<Runtime>::refund_surplus()
}
fn set_error_handler(_xcm: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::set_error_handler()
}
fn set_appendix(_xcm: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::set_appendix()
}
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
}
fn trap(_code: &u64) -> Weight {
XcmGeneric::<Runtime>::trap()
}
fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight {
XcmGeneric::<Runtime>::subscribe_version()
}
fn unsubscribe_version() -> Weight {
XcmGeneric::<Runtime>::unsubscribe_version()
}
}
Loading