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 56 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
34 changes: 31 additions & 3 deletions Cargo.lock

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

48 changes: 48 additions & 0 deletions pallets/xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[package]
name = "pallet-xcm-benchmarks"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
version = "0.9.27"
ruseinov marked this conversation as resolved.
Show resolved Hide resolved
ruseinov marked this conversation as resolved.
Show resolved Hide resolved
description = "A pallet to benchmark XCM interactions."
homepage = "https://substrate.io"
license = "Gpl3_0"
readme = "README.md"
repository = "https://github.com/paritytech/cumulus/"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" }
xcm-executor = {git = "https://github.com/paritytech/polkadot" , branch = "master", default-features = false, features = ["runtime-benchmarks"] }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate" , branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master", default-features = false, features = ["runtime-benchmarks"] }
Copy link
Member

Choose a reason for hiding this comment

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

I guess we can clean up the feature stuff later, since enabling this feature per default can cause it to be enabled unintentionally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please elaborate

Copy link
Contributor

Choose a reason for hiding this comment

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

Meaning the normal way to enable it is by creating a new feature called runtime-benchmarks, and under the feature, we'd also enable all other crates that have a runtime-benchmarks feature.

log = "0.4.17"

[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate" , branch = "master" }
pallet-assets = { git = "https://github.com/paritytech/substrate" , branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate" , branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate" , branch = "master" }
sp-tracing = { git = "https://github.com/paritytech/substrate" , branch = "master" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot" , branch = "master" }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot" , branch = "master" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot" , branch = "master" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std"
]
1 change: 1 addition & 0 deletions pallets/xcm-benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
License: Gpl3_0
234 changes: 234 additions & 0 deletions pallets/xcm-benchmarks/src/fungible/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
// 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/>.

use super::*;
use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf};
use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError};
use frame_support::{
pallet_prelude::Get,
traits::fungible::{Inspect, Mutate},
};
use sp_runtime::traits::{Bounded, Zero};
use sp_std::{prelude::*, vec};
use xcm::latest::prelude::*;
use xcm_executor::traits::{Convert, TransactAsset};

benchmarks_instance_pallet! {
where_clause { where
<
<
T::TransactAsset
as
Inspect<T::AccountId>
>::Balance
as
TryInto<u128>
>::Error: sp_std::fmt::Debug,
}

withdraw_asset {
let (sender_account, sender_location) = account_and_location::<T>(1);
let worst_case_holding = T::worst_case_holding();
let asset = T::get_multi_asset();

<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location).unwrap();
// check the assets of origin.
assert!(!T::TransactAsset::balance(&sender_account).is_zero());

let mut executor = new_executor::<T>(sender_location);
executor.holding = worst_case_holding.into();
let instruction = Instruction::<XcmCallOf<T>>::WithdrawAsset(vec![asset.clone()].into());
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
// check one of the assets of origin.
assert!(T::TransactAsset::balance(&sender_account).is_zero());
assert!(executor.holding.ensure_contains(&vec![asset].into()).is_ok());
}

transfer_asset {
let (sender_account, sender_location) = account_and_location::<T>(1);
let asset = T::get_multi_asset();
let assets: MultiAssets = vec![ asset.clone() ].into();
// this xcm doesn't use holding

let dest_location = T::valid_destination()?;
let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();

<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location).unwrap();
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(sender_location);
let instruction = Instruction::TransferAsset { assets, beneficiary: dest_location };
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
assert!(T::TransactAsset::balance(&sender_account).is_zero());
assert!(!T::TransactAsset::balance(&dest_account).is_zero());
}

transfer_reserve_asset {
let (sender_account, sender_location) = account_and_location::<T>(1);
let dest_location = T::valid_destination()?;
let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();

let asset = T::get_multi_asset();
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location).unwrap();
let assets: MultiAssets = vec![ asset ].into();
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(sender_location);
let instruction = Instruction::TransferReserveAsset {
assets,
dest: dest_location,
xcm: Xcm::new()
};
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
assert!(T::TransactAsset::balance(&sender_account).is_zero());
assert!(!T::TransactAsset::balance(&dest_account).is_zero());
// TODO: Check sender queue is not empty. #4426
}

reserve_asset_deposited {
let (trusted_reserve, transferable_reserve_asset) = T::TrustedReserve::get()
.ok_or(BenchmarkError::Skip)?;

let assets: MultiAssets = vec![ transferable_reserve_asset ].into();

let mut executor = new_executor::<T>(trusted_reserve);
let instruction = Instruction::ReserveAssetDeposited(assets.clone());
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
assert!(executor.holding.ensure_contains(&assets).is_ok());
}

receive_teleported_asset {
// If there is no trusted teleporter, then we skip this benchmark.
let (trusted_teleporter, teleportable_asset) = T::TrustedTeleporter::get()
.ok_or(BenchmarkError::Skip)?;

if let Some(checked_account) = T::CheckedAccount::get() {
T::TransactAsset::mint_into(
&checked_account,
<
T::TransactAsset
as
Inspect<T::AccountId>
>::Balance::max_value() / 2u32.into(),
)?;
}

let assets: MultiAssets = vec![ teleportable_asset ].into();

let mut executor = new_executor::<T>(trusted_teleporter);
let instruction = Instruction::ReceiveTeleportedAsset(assets.clone());
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
assert!(executor.holding.ensure_contains(&assets).is_ok());
}

deposit_asset {
let asset = T::get_multi_asset();
let mut holding = T::worst_case_holding();

// Add our asset to the holding.
holding.push(asset.clone());

// our dest must have no balance initially.
let dest_location = T::valid_destination()?;
let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding.into();
let instruction = Instruction::<XcmCallOf<T>>::DepositAsset {
assets: asset.into(),
max_assets: 1,
beneficiary: dest_location,
};
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
// dest should have received some asset.
assert!(!T::TransactAsset::balance(&dest_account).is_zero())
}

deposit_reserve_asset {
let asset = T::get_multi_asset();
let mut holding = T::worst_case_holding();

// Add our asset to the holding.
holding.push(asset.clone());

// our dest must have no balance initially.
let dest_location = T::valid_destination()?;
let dest_account = T::AccountIdConverter::convert(dest_location.clone()).unwrap();
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding.into();
let instruction = Instruction::<XcmCallOf<T>>::DepositReserveAsset {
assets: asset.into(),
max_assets: 1,
dest: dest_location,
xcm: Xcm::new(),
};
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
// dest should have received some asset.
assert!(!T::TransactAsset::balance(&dest_account).is_zero())
}

initiate_teleport {
let asset = T::get_multi_asset();
let mut holding = T::worst_case_holding();

// Add our asset to the holding.
holding.push(asset.clone());

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding.into();
let instruction = Instruction::<XcmCallOf<T>>::InitiateTeleport {
assets: asset.into(),
dest: T::valid_destination()?,
xcm: Xcm::new(),
};
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
// we're good as long as there's no error, checking account is bypassed when operating on
// native assets aka Dot
}

impl_benchmark_test_suite!(
Pallet,
crate::fungible::mock::new_test_ext(),
crate::fungible::mock::Test
);
}
Loading