-
Notifications
You must be signed in to change notification settings - Fork 361
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
Benchmarking xcm instructions Weight #1012
Closed
Closed
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d0cb1ff
add constants
gitofdeepanshu 52b47f6
setup for generic instructions benchmarks
gitofdeepanshu b1050db
fmt
gitofdeepanshu ec64063
taplo
gitofdeepanshu 0cfbbd5
header fix
gitofdeepanshu 78b5a2b
warnings fix
gitofdeepanshu e350c4f
add astar-xcm-benchmarks
gitofdeepanshu ea71a94
license update
gitofdeepanshu ad2c526
.toml fix
gitofdeepanshu abce24d
merge master
gitofdeepanshu 5039bf7
temporary fix
gitofdeepanshu a2515be
add support for fungible benchmarks
gitofdeepanshu 94da10a
change to weightinfobounds
gitofdeepanshu 1e2a8c4
add comments
gitofdeepanshu 106bb2e
clippy and license fix
gitofdeepanshu 7f929d1
Merge branch 'master' into feat/weightinfobounds-xcm
gitofdeepanshu bbcff0b
clean up
gitofdeepanshu ac8d97e
unitweight fix
gitofdeepanshu a4e2bd9
mock config fix
gitofdeepanshu 1ee6bc4
add correct weight
gitofdeepanshu f4fcec2
comments edit
gitofdeepanshu 2908a26
change benchmark to V2
gitofdeepanshu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[package] | ||
name = "astar-xcm-benchmarks" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
[dependencies] | ||
log = { workspace = true } | ||
serde = { workspace = true, optional = true } | ||
|
||
# Substrate | ||
frame-support = { workspace = true, default-features = false } | ||
frame-system = { workspace = true } | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
# Polkadot / XCM | ||
astar-primitives = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
xcm = { workspace = true } | ||
xcm-builder = { workspace = true } | ||
xcm-executor = { workspace = true } | ||
|
||
# Benchmarks | ||
frame-benchmarking = { workspace = true } | ||
|
||
[dev-dependencies] | ||
pallet-assets = { workspace = true } | ||
pallet-balances = { workspace = true } | ||
pallet-xcm = { workspace = true } | ||
paste = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-tracing = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"parity-scale-codec/std", | ||
"sp-std/std", | ||
"xcm-builder/std", | ||
"xcm-executor/std", | ||
"xcm/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-core/std", | ||
"astar-primitives/std", | ||
"scale-info/std", | ||
"astar-primitives/std", | ||
"pallet-balances/std", | ||
"pallet-assets/std", | ||
] | ||
|
||
runtime-benchmarks = [ | ||
"xcm-builder/runtime-benchmarks", | ||
"xcm-executor/runtime-benchmarks", | ||
"pallet-xcm/runtime-benchmarks", | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"astar-primitives/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
|
||
try-runtime = ["frame-support/try-runtime"] |
249 changes: 249 additions & 0 deletions
249
pallets/astar-xcm-benchmarks/src/fungible/assets/benchmarking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
// This file is part of Astar. | ||
|
||
// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// Astar 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. | ||
|
||
// Astar 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 Astar. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
use super::*; | ||
use crate::{account_and_location, new_executor, AssetTransactorOf, XcmCallOf}; | ||
use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult}; | ||
use frame_support::traits::fungible::Inspect; | ||
use sp_runtime::traits::Zero; | ||
use sp_std::{prelude::*, vec}; | ||
use xcm::latest::{prelude::*, Weight}; | ||
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, | ||
|
||
< T::TransactAsset | ||
as | ||
Inspect<T::AccountId> | ||
>::Balance : Into<u128> | ||
|
||
} | ||
|
||
withdraw_asset { | ||
let (sender_account, sender_location) = account_and_location::<T>(1); | ||
let worst_case_holding = T::worst_case_holding(0); | ||
let asset = T::get_multi_asset(); | ||
|
||
<AssetTransactorOf<T>>::deposit_asset( | ||
&asset, | ||
&sender_location, | ||
&XcmContext { | ||
origin: Some(sender_location.clone()), | ||
message_hash: [0; 32], | ||
topic: None, | ||
}, | ||
).unwrap(); | ||
// check the assets of origin. | ||
assert!(!T::TransactAsset::balance(&sender_account).is_zero()); | ||
|
||
let mut executor = new_executor::<T>(sender_location); | ||
executor.set_holding(worst_case_holding.into()); | ||
let instruction = Instruction::<XcmCallOf<T>>::WithdrawAsset(vec![asset.clone()].into()); | ||
let xcm = Xcm(vec![instruction]); | ||
}: { | ||
executor.bench_process(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 mut 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, | ||
&XcmContext { | ||
origin: Some(sender_location.clone()), | ||
message_hash: [0; 32], | ||
topic: None, | ||
}, | ||
).unwrap(); | ||
assert!(T::TransactAsset::balance(&dest_account).is_zero()); | ||
|
||
// reducing some assets for Existential deposit | ||
if let Fungible(x) = asset.fun { | ||
asset.fun = Fungible(x/10) | ||
}; | ||
|
||
let assets: MultiAssets = vec![ asset.clone() ].into(); | ||
log::trace!( | ||
target: "xcm::process", | ||
"assets is {:?}",assets.clone()); | ||
|
||
<AssetTransactorOf<T>>::transfer_asset( | ||
&asset, | ||
&sender_location, | ||
&dest_location, | ||
&XcmContext { | ||
origin: Some(sender_location.clone()), | ||
message_hash: [0; 32], | ||
topic: None, | ||
}, | ||
).unwrap(); | ||
let mut executor = new_executor::<T>(sender_location); | ||
let instruction = Instruction::TransferAsset { assets, beneficiary: dest_location }; | ||
let xcm = Xcm(vec![instruction]); | ||
log::trace!( | ||
target: "xcm::process", | ||
"destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); | ||
assert!(!T::TransactAsset::balance(&dest_account).is_zero()); | ||
let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); | ||
}: { | ||
executor.bench_process(xcm)?; | ||
} verify { | ||
log::trace!( | ||
target: "xcm::process", | ||
"destination balance is {:?}, sender balance is {:?}",T::TransactAsset::balance(&dest_account),T::TransactAsset::balance(&sender_account)); | ||
assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); | ||
} | ||
|
||
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 mut asset = T::get_multi_asset(); | ||
<AssetTransactorOf<T>>::deposit_asset( | ||
&asset, | ||
&sender_location, | ||
&XcmContext { | ||
origin: Some(sender_location.clone()), | ||
message_hash: [0; 32], | ||
topic: None, | ||
}, | ||
).unwrap(); | ||
|
||
assert!(T::TransactAsset::balance(&dest_account).is_zero()); | ||
|
||
if let Fungible(x) = asset.fun { | ||
asset.fun = Fungible(x/10) | ||
}; | ||
|
||
<AssetTransactorOf<T>>::transfer_asset( | ||
&asset, | ||
&sender_location, | ||
&dest_location, | ||
&XcmContext { | ||
origin: Some(sender_location.clone()), | ||
message_hash: [0; 32], | ||
topic: None, | ||
}, | ||
).unwrap(); | ||
let assets: MultiAssets = vec![ asset ].into(); | ||
let mut executor = new_executor::<T>(sender_location); | ||
let instruction = Instruction::TransferReserveAsset { | ||
assets, | ||
dest: dest_location, | ||
xcm: Xcm::new() | ||
}; | ||
let xcm = Xcm(vec![instruction]); | ||
assert!(!T::TransactAsset::balance(&dest_account).is_zero()); | ||
let previous_balance: u128 = T::TransactAsset::balance(&dest_account).into(); | ||
}: { | ||
executor.bench_process(xcm)?; | ||
} verify { | ||
assert!(T::TransactAsset::balance(&dest_account).into() == 2 * previous_balance); | ||
} | ||
|
||
receive_teleported_asset { | ||
} : { | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; | ||
} | ||
|
||
deposit_asset { | ||
let asset = T::get_multi_asset(); | ||
let mut holding = T::worst_case_holding(1); | ||
|
||
// 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.set_holding(holding.into()); | ||
let instruction = Instruction::<XcmCallOf<T>>::DepositAsset { | ||
assets: asset.into(), | ||
beneficiary: dest_location, | ||
}; | ||
let xcm = Xcm(vec![instruction]); | ||
}: { | ||
executor.bench_process(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(1); | ||
|
||
// 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.set_holding(holding.into()); | ||
let instruction = Instruction::<XcmCallOf<T>>::DepositReserveAsset { | ||
assets: asset.into(), | ||
dest: dest_location, | ||
xcm: Xcm::new(), | ||
}; | ||
let xcm = Xcm(vec![instruction]); | ||
}: { | ||
executor.bench_process(xcm)?; | ||
} verify { | ||
// dest should have received some asset. | ||
assert!(!T::TransactAsset::balance(&dest_account).is_zero()) | ||
} | ||
|
||
initiate_teleport { | ||
}: { | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?; | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::fungible::mock::new_test_ext(), | ||
crate::fungible::mock::Test | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use old
v1
benchmarks if newv2
has been available for many months?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to v2.