-
Notifications
You must be signed in to change notification settings - Fork 414
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
feat: add xcm benchmarks #1129
Merged
+2,104
−13
Merged
feat: add xcm benchmarks #1129
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4f45964
feat: add generic xcm benchmarks wrapper
ashutoshvarma 292d47f
feat: add fungible xcm benchmarks wrapper
ashutoshvarma 4d20c03
feat: add xcm benchmarks to shibuya
ashutoshvarma e050241
feat: add missing benchmark
ashutoshvarma 4cf8638
feat: use `WeightInfoBounds` in shibuya
ashutoshvarma 60c1e93
Merge branch 'master' into feat/xcm-benchmarks
ashutoshvarma 0a6acaa
fix: use max assets properly
ashutoshvarma 9d3ece7
feat: update weights from benchmarks
ashutoshvarma 3a8254a
feat: merge mocks
ashutoshvarma 8b0b9fe
feat: refactor code
ashutoshvarma 9399e5f
fix: make clippy happy
ashutoshvarma 4a84734
fix: buy execution benchmarks
ashutoshvarma 121a505
chore: remove file
ashutoshvarma d258dd8
fix: benchmakrs
ashutoshvarma ec7587f
feat: update weights from benchmarks
ashutoshvarma 69b84fa
feat: apply suggestions
ashutoshvarma 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
Next
Next commit
feat: add generic xcm benchmarks wrapper
commit 4f4596404c2cdd144cbd629585be35eb1bfc12fc
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
193 changes: 193 additions & 0 deletions
193
pallets/astar-xcm-benchmarks/src/generic/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,193 @@ | ||
// 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/>. | ||
|
||
use super::*; | ||
use frame_benchmarking::v2::*; | ||
// use frame_benchmarking::{benchmarks, BenchmarkError, BenchmarkResult}; | ||
use frame_support::dispatch::Weight; | ||
use pallet_xcm_benchmarks::{new_executor, XcmCallOf}; | ||
use sp_std::vec; | ||
use sp_std::vec::Vec; | ||
use xcm::latest::prelude::*; | ||
|
||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
/// We need re-write buy_execution benchmark becuase our runtime | ||
/// needs 1 additional DB read (XcAssetConfig) for fetching unit per sec | ||
/// for a fungible asset. The upstream benchmark use native assets thus | ||
/// won't accout for it. | ||
#[benchmark] | ||
fn buy_execution() -> Result<(), BenchmarkError> { | ||
let holding = T::worst_case_holding(0).into(); | ||
|
||
let mut executor = new_executor::<T>(Default::default()); | ||
executor.set_holding(holding); | ||
|
||
// A fungible asset | ||
let fee_asset = Concrete(MultiLocation::parent()); | ||
|
||
let instruction = Instruction::<XcmCallOf<T>>::BuyExecution { | ||
fees: (fee_asset, 100_000_000u128).into(), // should be something inside of holding | ||
weight_limit: WeightLimit::Unlimited, | ||
}; | ||
|
||
let xcm = Xcm(vec![instruction]); | ||
|
||
#[block] | ||
{ | ||
executor.bench_process(xcm)?; | ||
} | ||
// The completion of execution above is enough to validate this is completed. | ||
Ok(()) | ||
} | ||
|
||
/// Re-write as upstream one has hardcoded system pallet index as 1 whereas our runtimes | ||
/// uses index 10. | ||
#[benchmark] | ||
fn expect_pallet() -> Result<(), BenchmarkError> { | ||
let mut executor = new_executor::<T>(Default::default()); | ||
|
||
let instruction = Instruction::ExpectPallet { | ||
// used index 10 for our runtimes | ||
index: 10, | ||
name: b"System".to_vec(), | ||
module_name: b"frame_system".to_vec(), | ||
crate_major: 4, | ||
min_crate_minor: 0, | ||
}; | ||
let xcm = Xcm(vec![instruction]); | ||
|
||
#[block] | ||
{ | ||
executor.bench_process(xcm)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn exchange_asset() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
#[benchmark] | ||
fn export_message() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
#[benchmark] | ||
fn lock_asset() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
#[benchmark] | ||
fn unlock_asset() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
#[benchmark] | ||
fn note_unlockable() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
#[benchmark] | ||
fn request_unlock() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
#[benchmark] | ||
fn universal_origin() -> Result<(), BenchmarkError> { | ||
#[block] | ||
{} | ||
Err(BenchmarkError::Override(BenchmarkResult::from_weight( | ||
Weight::MAX, | ||
))) | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::generic::mock::new_test_ext(), | ||
crate::generic::mock::Test | ||
); | ||
} | ||
|
||
pub struct XcmGenericBenchmarks<T>(sp_std::marker::PhantomData<T>); | ||
// Benchmarks wrapper | ||
impl<T: Config> frame_benchmarking::Benchmarking for XcmGenericBenchmarks<T> { | ||
fn benchmarks(extra: bool) -> Vec<frame_benchmarking::BenchmarkMetadata> { | ||
// all the generic xcm benchmarks | ||
use pallet_xcm_benchmarks::generic::Pallet as PalletXcmGenericBench; | ||
PalletXcmGenericBench::<T>::benchmarks(extra) | ||
} | ||
fn run_benchmark( | ||
extrinsic: &[u8], | ||
c: &[(frame_benchmarking::BenchmarkParameter, u32)], | ||
whitelist: &[frame_benchmarking::TrackedStorageKey], | ||
verify: bool, | ||
internal_repeats: u32, | ||
) -> Result<Vec<frame_benchmarking::BenchmarkResult>, frame_benchmarking::BenchmarkError> { | ||
use pallet_xcm_benchmarks::generic::Pallet as PalletXcmGenericBench; | ||
|
||
use crate::generic::Pallet as AstarXcmGenericBench; | ||
if AstarXcmGenericBench::<T>::benchmarks(true) | ||
.iter() | ||
.any(|x| x.name == extrinsic) | ||
{ | ||
AstarXcmGenericBench::<T>::run_benchmark( | ||
extrinsic, | ||
c, | ||
whitelist, | ||
verify, | ||
internal_repeats, | ||
) | ||
} else { | ||
PalletXcmGenericBench::<T>::run_benchmark( | ||
extrinsic, | ||
c, | ||
whitelist, | ||
verify, | ||
internal_repeats, | ||
) | ||
} | ||
} | ||
} |
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,230 @@ | ||
// 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/>. | ||
|
||
//! A mock runtime for XCM benchmarking. | ||
use crate::{generic, mock::*, *}; | ||
use frame_benchmarking::BenchmarkError; | ||
use frame_support::{ | ||
parameter_types, | ||
traits::{Everything, OriginTrait}, | ||
}; | ||
use parity_scale_codec::Decode; | ||
use sp_core::H256; | ||
use sp_runtime::{ | ||
testing::Header, | ||
traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput}, | ||
BuildStorage, | ||
}; | ||
use xcm::latest::prelude::*; | ||
use xcm_builder::{ | ||
test_utils::{ | ||
Assets, TestAssetExchanger, TestAssetLocker, TestAssetTrap, TestSubscriptionService, | ||
TestUniversalAliases, | ||
}, | ||
AllowUnpaidExecutionFrom, | ||
}; | ||
use xcm_executor::traits::ConvertOrigin; | ||
|
||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>; | ||
type Block = frame_system::mocking::MockBlock<Test>; | ||
|
||
frame_support::construct_runtime!( | ||
pub enum Test where | ||
Block = Block, | ||
NodeBlock = Block, | ||
UncheckedExtrinsic = UncheckedExtrinsic, | ||
{ | ||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 10, | ||
PolkadotXcmBenchmarks: pallet_xcm_benchmarks::generic::{Pallet}, | ||
XcmGenericBenchmarks: generic::{Pallet}, | ||
} | ||
); | ||
|
||
parameter_types! { | ||
pub const BlockHashCount: u64 = 250; | ||
pub UniversalLocation: InteriorMultiLocation = Here; | ||
} | ||
|
||
impl frame_system::Config for Test { | ||
type BaseCallFilter = Everything; | ||
type BlockWeights = (); | ||
type BlockLength = (); | ||
type DbWeight = (); | ||
type RuntimeOrigin = RuntimeOrigin; | ||
type Index = u64; | ||
type BlockNumber = u64; | ||
type Hash = H256; | ||
type RuntimeCall = RuntimeCall; | ||
type Hashing = BlakeTwo256; | ||
type AccountId = u64; | ||
type Lookup = IdentityLookup<Self::AccountId>; | ||
type Header = Header; | ||
type RuntimeEvent = RuntimeEvent; | ||
type BlockHashCount = BlockHashCount; | ||
type Version = (); | ||
type PalletInfo = PalletInfo; | ||
type AccountData = pallet_balances::AccountData<u64>; | ||
type OnNewAccount = (); | ||
type OnKilledAccount = (); | ||
type SystemWeightInfo = (); | ||
type SS58Prefix = (); | ||
type OnSetCode = (); | ||
type MaxConsumers = frame_support::traits::ConstU32<16>; | ||
} | ||
|
||
/// The benchmarks in this pallet should never need an asset transactor to begin with. | ||
pub struct NoAssetTransactor; | ||
impl xcm_executor::traits::TransactAsset for NoAssetTransactor { | ||
fn deposit_asset(_: &MultiAsset, _: &MultiLocation, _: &XcmContext) -> Result<(), XcmError> { | ||
unreachable!(); | ||
} | ||
|
||
fn withdraw_asset( | ||
_: &MultiAsset, | ||
_: &MultiLocation, | ||
_: Option<&XcmContext>, | ||
) -> Result<Assets, XcmError> { | ||
unreachable!(); | ||
} | ||
} | ||
|
||
parameter_types! { | ||
pub const MaxInstructions: u32 = 100; | ||
pub const MaxAssetsIntoHolding: u32 = 64; | ||
} | ||
|
||
pub struct XcmConfig; | ||
impl xcm_executor::Config for XcmConfig { | ||
type RuntimeCall = RuntimeCall; | ||
type XcmSender = DevNull; | ||
type AssetTransactor = NoAssetTransactor; | ||
type OriginConverter = AlwaysSignedByDefault<RuntimeOrigin>; | ||
type IsReserve = AllAssetLocationsPass; | ||
type IsTeleporter = (); | ||
type UniversalLocation = UniversalLocation; | ||
type Barrier = AllowUnpaidExecutionFrom<Everything>; | ||
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>; | ||
type Trader = xcm_builder::FixedRateOfFungible<WeightPrice, ()>; | ||
type ResponseHandler = DevNull; | ||
type AssetTrap = TestAssetTrap; | ||
type AssetLocker = TestAssetLocker; | ||
type AssetExchanger = TestAssetExchanger; | ||
type AssetClaims = TestAssetTrap; | ||
type SubscriptionService = TestSubscriptionService; | ||
type PalletInstancesInfo = AllPalletsWithSystem; | ||
type MaxAssetsIntoHolding = MaxAssetsIntoHolding; | ||
type FeeManager = (); | ||
// No bridges yet... | ||
type MessageExporter = (); | ||
type UniversalAliases = TestUniversalAliases; | ||
type CallDispatcher = RuntimeCall; | ||
type SafeCallFilter = Everything; | ||
} | ||
|
||
impl pallet_xcm_benchmarks::Config for Test { | ||
type XcmConfig = XcmConfig; | ||
type AccountIdConverter = AccountIdConverter; | ||
fn valid_destination() -> Result<MultiLocation, BenchmarkError> { | ||
let valid_destination: MultiLocation = Junction::AccountId32 { | ||
network: None, | ||
id: [0u8; 32], | ||
} | ||
.into(); | ||
|
||
Ok(valid_destination) | ||
} | ||
fn worst_case_holding(_depositable_count: u32) -> MultiAssets { | ||
crate::mock::mock_worst_case_holding() | ||
} | ||
} | ||
|
||
impl pallet_xcm_benchmarks::generic::Config for Test { | ||
type RuntimeCall = RuntimeCall; | ||
|
||
fn worst_case_response() -> (u64, Response) { | ||
let assets: MultiAssets = (Concrete(Here.into()), 100).into(); | ||
(0, Response::Assets(assets)) | ||
} | ||
|
||
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> { | ||
Err(BenchmarkError::Skip) | ||
} | ||
|
||
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> { | ||
Err(BenchmarkError::Skip) | ||
} | ||
|
||
fn export_message_origin_and_destination( | ||
) -> Result<(MultiLocation, NetworkId, Junctions), BenchmarkError> { | ||
Err(BenchmarkError::Skip) | ||
} | ||
|
||
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> { | ||
Ok(( | ||
Default::default(), | ||
frame_system::Call::remark_with_event { remark: vec![] }.into(), | ||
)) | ||
} | ||
|
||
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> { | ||
Ok(Default::default()) | ||
} | ||
|
||
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> { | ||
let assets: MultiAssets = (Concrete(Here.into()), 100).into(); | ||
let ticket = MultiLocation { | ||
parents: 0, | ||
interior: X1(GeneralIndex(0)), | ||
}; | ||
Ok((Default::default(), ticket, assets)) | ||
} | ||
|
||
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> { | ||
Err(BenchmarkError::Skip) | ||
} | ||
} | ||
|
||
impl generic::Config for Test {} | ||
impl Config for Test {} | ||
|
||
pub fn new_test_ext() -> sp_io::TestExternalities { | ||
let t = GenesisConfig { | ||
..Default::default() | ||
} | ||
.build_storage() | ||
.unwrap(); | ||
t.into() | ||
} | ||
|
||
pub struct AlwaysSignedByDefault<Origin>(core::marker::PhantomData<Origin>); | ||
impl<Origin> ConvertOrigin<Origin> for AlwaysSignedByDefault<Origin> | ||
where | ||
Origin: OriginTrait, | ||
<Origin as OriginTrait>::AccountId: Decode, | ||
{ | ||
fn convert_origin( | ||
_origin: impl Into<MultiLocation>, | ||
_kind: OriginKind, | ||
) -> Result<Origin, MultiLocation> { | ||
Ok(Origin::signed( | ||
<Origin as OriginTrait>::AccountId::decode(&mut TrailingZeroInput::zeroes()) | ||
.expect("infinite length input; no invalid inputs for type; qed"), | ||
)) | ||
} | ||
} |
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,36 @@ | ||
// 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/>. | ||
|
||
pub use pallet::*; | ||
|
||
pub mod benchmarking; | ||
|
||
#[cfg(test)] | ||
pub mod mock; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
#[pallet::config] | ||
pub trait Config<I: 'static = ()>: | ||
frame_system::Config + crate::Config + pallet_xcm_benchmarks::generic::Config | ||
{ | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T, I = ()>(_); | ||
} |
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,32 @@ | ||
// 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/>. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
pub mod generic; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
pub mod fungible; | ||
|
||
#[cfg(test)] | ||
mod mock; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
/// A base trait for all individual pallets | ||
pub trait Config: frame_system::Config + pallet_xcm_benchmarks::Config {} |
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,92 @@ | ||
// 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/>. | ||
|
||
use frame_support::{dispatch::Weight, parameter_types, traits::ContainsPair}; | ||
use xcm::latest::prelude::*; | ||
|
||
// An xcm sender/receiver akin to > /dev/null | ||
pub struct DevNull; | ||
impl SendXcm for DevNull { | ||
type Ticket = (); | ||
|
||
fn validate( | ||
_destination: &mut Option<MultiLocation>, | ||
_message: &mut Option<opaque::Xcm>, | ||
) -> SendResult<Self::Ticket> { | ||
Ok(((), MultiAssets::new())) | ||
} | ||
|
||
fn deliver(_: Self::Ticket) -> Result<XcmHash, SendError> { | ||
Ok(XcmHash::default()) | ||
} | ||
} | ||
|
||
impl xcm_executor::traits::OnResponse for DevNull { | ||
fn expecting_response(_: &MultiLocation, _: u64, _: Option<&MultiLocation>) -> bool { | ||
false | ||
} | ||
fn on_response( | ||
_: &MultiLocation, | ||
_: u64, | ||
_: Option<&MultiLocation>, | ||
_: Response, | ||
_: Weight, | ||
_: &XcmContext, | ||
) -> Weight { | ||
Weight::zero() | ||
} | ||
} | ||
|
||
pub struct AccountIdConverter; | ||
impl xcm_executor::traits::Convert<MultiLocation, u64> for AccountIdConverter { | ||
fn convert(ml: MultiLocation) -> Result<u64, MultiLocation> { | ||
match ml { | ||
MultiLocation { | ||
parents: 0, | ||
interior: X1(Junction::AccountId32 { id, .. }), | ||
} => Ok(<u64 as parity_scale_codec::Decode>::decode(&mut &*id.to_vec()).unwrap()), | ||
_ => Err(ml), | ||
} | ||
} | ||
|
||
fn reverse(acc: u64) -> Result<MultiLocation, u64> { | ||
Err(acc) | ||
} | ||
} | ||
|
||
parameter_types! { | ||
pub Ancestry: MultiLocation = Junction::Parachain(101).into(); | ||
pub UnitWeightCost: u64 = 10; | ||
pub WeightPrice: (AssetId, u128, u128) = (Concrete(MultiLocation::parent()), 1_000_000, 1024); | ||
} | ||
|
||
pub struct AllAssetLocationsPass; | ||
impl ContainsPair<MultiAsset, MultiLocation> for AllAssetLocationsPass { | ||
fn contains(_: &MultiAsset, _: &MultiLocation) -> bool { | ||
true | ||
} | ||
} | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
pub fn mock_worst_case_holding() -> MultiAssets { | ||
let assets: Vec<MultiAsset> = vec![MultiAsset { | ||
id: Concrete(MultiLocation::parent()), | ||
fun: Fungible(u128::MAX), | ||
}]; | ||
assets.into() | ||
} |
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.
One general question about this approach - how viable is to reuse code from the official repo if we have to account for different actions for some calls?
This can change in the future, upstream, and it means we should be re-checking all of the benchmarks each time we do an uplift?
It would seem easier to just have all the benchmarks in our repo since that way we have full control over it. If I understood the current approach correctly, it's highly likely we miss something in the future.
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.
The upstream benchmarks are quite generic themselves, but not generic enough maybe because not many parachains are using them.
The benchmarks we had to re-write were only due the use of hardcoded native asset inside some benchmarks.
pallet_assets
).Other than that all benchmarks were configurable through the pallet's Config. As long as we we used same release upstream pallet (
XcmConfig
is not changed) it should be fine.For the hardcoded cases, we can make a upstream PR to make it more generic for other parachains to use as well.
I'm fine either ways, if we copy-paste all benchmarks then we need to keep them updated during uplift if there are major changes like
precompile-utils
and if we don't copy-paste then we still need to check them during upliftsThere 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.
Thanks for the explanation!
Let's keep it like this, as you suggested.
For the upstream PR, let's start with an issue first perhaps?