mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 04:41:03 +00:00
e3c97e4860
# Description ## Summary Previously, the `pallet_xcm::do_reserve_transfer_assets` and `pallet_xcm::do_teleport_assets` functions relied on weight estimation for remote chain execution, which was based on guesswork derived from the local chain. This approach led to complications for runtimes that did not provide or support specific [XCM configurations](https://github.com/paritytech/polkadot-sdk/blob/7cbe0c76ef8fd2aabf9f07de0156941ce3ed44b0/polkadot/xcm/xcm-executor/src/config.rs#L43-L47) for `IsReserve` or `IsTeleporter`. Consequently, such runtimes had to resort to implementing hard-coded weights for XCM instructions like `reserve_asset_deposited` or `receive_teleported_asset` to support extrinsics such as `pallet_xcm::reserve_transfer_assets` and `pallet_xcm::teleport_assets`, which depended on remote weight estimation. The issue of remote weight estimation was addressed and resolved by [Pull Request #1645](https://github.com/paritytech/polkadot-sdk/pull/1645), which removed the need for remote weight estimation. ## Solution As a continuation of this improvement, the current PR proposes further cleanup by removing unnecessary hard-coded values and rectifying benchmark results with `Weight::MAX` that previously used `T::BlockWeights::get().max_block` as an override for unsupported XCM instructions like `ReserveAssetDeposited` and `ReceiveTeleportedAsset`. ## Questions - [x] Can we remove now also `Hardcoded till the XCM pallet is fixed` for `deposit_asset`? E.g. for AssetHubKusama [here](https://github.com/paritytech/polkadot-sdk/blob/7cbe0c76ef8fd2aabf9f07de0156941ce3ed44b0/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/weights/xcm/mod.rs#L129-L134) - [x] Are comments like [this](https://github.com/paritytech/polkadot-sdk/blob/7cbe0c76ef8fd2aabf9f07de0156941ce3ed44b0/polkadot/runtime/kusama/src/weights/xcm/mod.rs#L94) `// Kusama doesn't support ReserveAssetDeposited, so this benchmark has a default weight` still relevant? Shouldnt be removed/changed? ## TODO - [x] `bench bot` regenerate xcm weights for all runtimes - [x] remove hard-coded stuff from system parachain weight files - [ ] when merged, open `polkadot-fellow/runtimes` PR ## References Fixes #1132 Closes #1132 Old polkadot repo [PR](https://github.com/paritytech/polkadot/pull/7546) --------- Co-authored-by: command-bot <>
246 lines
8.0 KiB
Rust
246 lines
8.0 KiB
Rust
// Copyright (C) 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::{xcm_config::MaxAssetsIntoHolding, Runtime};
|
|
use frame_support::weights::Weight;
|
|
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
|
|
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
|
|
use sp_std::prelude::*;
|
|
use xcm::{latest::prelude::*, DoubleEncoded};
|
|
|
|
trait WeighMultiAssets {
|
|
fn weigh_multi_assets(&self, weight: Weight) -> Weight;
|
|
}
|
|
|
|
const MAX_ASSETS: u64 = 100;
|
|
|
|
impl WeighMultiAssets for MultiAssetFilter {
|
|
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
|
match self {
|
|
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
|
|
Self::Wild(asset) => match asset {
|
|
All => weight.saturating_mul(MAX_ASSETS),
|
|
AllOf { fun, .. } => match fun {
|
|
WildFungibility::Fungible => weight,
|
|
// Magic number 2 has to do with the fact that we could have up to 2 times
|
|
// MaxAssetsIntoHolding in the worst-case scenario.
|
|
WildFungibility::NonFungible =>
|
|
weight.saturating_mul((MaxAssetsIntoHolding::get() * 2) as u64),
|
|
},
|
|
AllCounted(count) => weight.saturating_mul(MAX_ASSETS.min(*count as u64)),
|
|
AllOfCounted { count, .. } => weight.saturating_mul(MAX_ASSETS.min(*count as u64)),
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WeighMultiAssets for MultiAssets {
|
|
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
|
weight.saturating_mul(self.inner().iter().count() as u64)
|
|
}
|
|
}
|
|
|
|
pub struct BridgeHubPolkadotXcmWeight<Call>(core::marker::PhantomData<Call>);
|
|
impl<Call> XcmWeightInfo<Call> for BridgeHubPolkadotXcmWeight<Call> {
|
|
fn withdraw_asset(assets: &MultiAssets) -> Weight {
|
|
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
|
}
|
|
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
|
|
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
|
}
|
|
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: &Weight,
|
|
_querier: &Option<MultiLocation>,
|
|
) -> 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: &Weight,
|
|
_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_response_info: &QueryResponseInfo) -> Weight {
|
|
XcmGeneric::<Runtime>::report_error()
|
|
}
|
|
|
|
fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> Weight {
|
|
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
|
}
|
|
fn deposit_reserve_asset(
|
|
assets: &MultiAssetFilter,
|
|
_dest: &MultiLocation,
|
|
_xcm: &Xcm<()>,
|
|
) -> Weight {
|
|
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
|
}
|
|
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn initiate_reserve_withdraw(
|
|
assets: &MultiAssetFilter,
|
|
_reserve: &MultiLocation,
|
|
_xcm: &Xcm<()>,
|
|
) -> Weight {
|
|
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
|
}
|
|
fn initiate_teleport(
|
|
assets: &MultiAssetFilter,
|
|
_dest: &MultiLocation,
|
|
_xcm: &Xcm<()>,
|
|
) -> Weight {
|
|
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
|
}
|
|
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
|
|
XcmGeneric::<Runtime>::report_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: &Weight) -> Weight {
|
|
XcmGeneric::<Runtime>::subscribe_version()
|
|
}
|
|
fn unsubscribe_version() -> Weight {
|
|
XcmGeneric::<Runtime>::unsubscribe_version()
|
|
}
|
|
fn burn_asset(assets: &MultiAssets) -> Weight {
|
|
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
|
|
}
|
|
fn expect_asset(assets: &MultiAssets) -> Weight {
|
|
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
|
|
}
|
|
fn expect_origin(_origin: &Option<MultiLocation>) -> Weight {
|
|
XcmGeneric::<Runtime>::expect_origin()
|
|
}
|
|
fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
|
|
XcmGeneric::<Runtime>::expect_error()
|
|
}
|
|
fn expect_transact_status(_transact_status: &MaybeErrorCode) -> Weight {
|
|
XcmGeneric::<Runtime>::expect_transact_status()
|
|
}
|
|
fn query_pallet(_module_name: &Vec<u8>, _response_info: &QueryResponseInfo) -> Weight {
|
|
XcmGeneric::<Runtime>::query_pallet()
|
|
}
|
|
fn expect_pallet(
|
|
_index: &u32,
|
|
_name: &Vec<u8>,
|
|
_module_name: &Vec<u8>,
|
|
_crate_major: &u32,
|
|
_min_crate_minor: &u32,
|
|
) -> Weight {
|
|
XcmGeneric::<Runtime>::expect_pallet()
|
|
}
|
|
fn report_transact_status(_response_info: &QueryResponseInfo) -> Weight {
|
|
XcmGeneric::<Runtime>::report_transact_status()
|
|
}
|
|
fn clear_transact_status() -> Weight {
|
|
XcmGeneric::<Runtime>::clear_transact_status()
|
|
}
|
|
fn universal_origin(_: &Junction) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
fn set_fees_mode(_: &bool) -> Weight {
|
|
XcmGeneric::<Runtime>::set_fees_mode()
|
|
}
|
|
fn set_topic(_topic: &[u8; 32]) -> Weight {
|
|
XcmGeneric::<Runtime>::set_topic()
|
|
}
|
|
fn clear_topic() -> Weight {
|
|
XcmGeneric::<Runtime>::clear_topic()
|
|
}
|
|
fn alias_origin(_: &MultiLocation) -> Weight {
|
|
// XCM Executor does not currently support alias origin operations
|
|
Weight::MAX
|
|
}
|
|
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> Weight {
|
|
XcmGeneric::<Runtime>::unpaid_execution()
|
|
}
|
|
}
|