Skip to content

Commit

Permalink
Measured XCM weights and benchmarking for collectives-polkadot (#547)
Browse files Browse the repository at this point in the history
Closes: paritytech/polkadot-sdk#2904
Closes: #446
Continuation: paritytech/polkadot-sdk#6820

The `collectives-polkadot` uses `FixedWeightBounds`. This PR introduces
a properly measured XCM benchmarking setup and updates the weights with
fresh data.


## TODO
- [x] check if we use somewhere some hard-coded weights for `Transact`
that goes to the `collectives-polkadot`

---------

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Muharem <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2025
1 parent 5099ad4 commit 3c520e3
Show file tree
Hide file tree
Showing 16 changed files with 1,035 additions and 142 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix missing Encointer democracy pallet hook needed for enactment ([polkadot-fellows/runtimes/pull/508](https://github.com/polkadot-fellows/runtimes/pull/508))
- Improve benchmark configuration: fix storage whitelist in benchmarks ([polkadot-fellows/runtimes/pull/525](https://github.com/polkadot-fellows/runtimes/pull/525))
- Unstake the last remaining corrupt ledger ([polkadot-fellows/runtimes/pull/538](https://github.com/polkadot-fellows/runtimes/pull/538))

### Fixed

- Disallow `add_sub` and `set_subs` from `NonTransfer` proxy type in people chain runtimes ([polkadot-fellows/runtimes#518](https://github.com/polkadot-fellows/runtimes/pull/518))

### Added
Expand All @@ -30,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Kusama Treasury: remove funding to the Kappa Sigma Mu Society and disable burn ([polkadot-fellows/runtimes#507](https://github.com/polkadot-fellows/runtimes/pull/507))
- Kusama Treasury: allow burn parameters to be set via OpenGov ([polkadot-fellows/runtimes#511](https://github.com/polkadot-fellows/runtimes/pull/511))
- Remove Snowbridge create agent and channel extrinsics. ([polkadot-fellows/runtimes#506](https://github.com/polkadot-fellows/runtimes/pull/506))
- Update the XCM `Weigher` from `FixedWeightBounds` to `WeightInfoBounds` with benchmarked weights for Polkadot Collectives ([polkadot-fellows/runtimes#547](https://github.com/polkadot-fellows/runtimes/pull/547))
- Increase max PoV size to 10Mib on Kusama ([polkadot-fellows/runtimes#553](https://github.com/polkadot-fellows/runtimes/pull/553))

#### From [#490](https://github.com/polkadot-fellows/runtimes/pull/490)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

30 changes: 15 additions & 15 deletions relay/kusama/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ impl From<&Asset> for AssetTypes {
}

trait WeighAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
fn weigh_assets(&self, balances_weight: Weight) -> Weight;
}

// Kusama only knows about one asset, the balances pallet.
const MAX_ASSETS: u64 = 1;

impl WeighAssets for AssetFilter {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
fn weigh_assets(&self, balances_weight: Weight) -> Weight {
match self {
Self::Definite(assets) => assets
.inner()
Expand All @@ -72,7 +72,7 @@ impl WeighAssets for AssetFilter {
}

impl WeighAssets for Assets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
fn weigh_assets(&self, balances_weight: Weight) -> Weight {
self.inner()
.iter()
.map(<AssetTypes as From<&Asset>>::from)
Expand All @@ -87,13 +87,13 @@ impl WeighAssets for Assets {
pub struct KusamaXcmWeight<RuntimeCall>(core::marker::PhantomData<RuntimeCall>);
impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
fn withdraw_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
}
fn reserve_asset_deposited(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
}
fn receive_teleported_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(
_query_id: &u64,
Expand All @@ -104,10 +104,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
XcmGeneric::<Runtime>::query_response()
}
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_kind: &OriginKind,
Expand Down Expand Up @@ -143,10 +143,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
}

fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
// Kusama does not currently support exchange asset operations
Expand All @@ -157,10 +157,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
_reserve: &Location,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down Expand Up @@ -193,10 +193,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for KusamaXcmWeight<RuntimeCall> {
XcmGeneric::<Runtime>::unsubscribe_version()
}
fn burn_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
}
fn expect_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
}
fn expect_origin(_origin: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::expect_origin()
Expand Down Expand Up @@ -272,5 +272,5 @@ fn all_counted_has_a_sane_weight_upper_limit() {
let assets = AssetFilter::Wild(AllCounted(4294967295));
let weight = Weight::from_parts(1000, 1000);

assert_eq!(assets.weigh_multi_assets(weight), weight * MAX_ASSETS);
assert_eq!(assets.weigh_assets(weight), weight * MAX_ASSETS);
}
30 changes: 15 additions & 15 deletions relay/polkadot/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ impl From<&Asset> for AssetTypes {
}

trait WeighAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
fn weigh_assets(&self, balances_weight: Weight) -> Weight;
}

// Polkadot only knows about one asset, the balances pallet.
const MAX_ASSETS: u64 = 1;

impl WeighAssets for AssetFilter {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
fn weigh_assets(&self, balances_weight: Weight) -> Weight {
match self {
Self::Definite(assets) => assets
.inner()
Expand All @@ -72,7 +72,7 @@ impl WeighAssets for AssetFilter {
}

impl WeighAssets for Assets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
fn weigh_assets(&self, balances_weight: Weight) -> Weight {
self.inner()
.iter()
.map(<AssetTypes as From<&Asset>>::from)
Expand All @@ -87,13 +87,13 @@ impl WeighAssets for Assets {
pub struct PolkadotXcmWeight<RuntimeCall>(core::marker::PhantomData<RuntimeCall>);
impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for PolkadotXcmWeight<RuntimeCall> {
fn withdraw_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
}
fn reserve_asset_deposited(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
}
fn receive_teleported_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(
_query_id: &u64,
Expand All @@ -104,10 +104,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for PolkadotXcmWeight<RuntimeCall>
XcmGeneric::<Runtime>::query_response()
}
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_kind: &OriginKind,
Expand Down Expand Up @@ -143,10 +143,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for PolkadotXcmWeight<RuntimeCall>
}

fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
// Polkadot does not currently support exchange asset operations
Expand All @@ -157,10 +157,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for PolkadotXcmWeight<RuntimeCall>
_reserve: &Location,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
assets.weigh_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down Expand Up @@ -193,10 +193,10 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for PolkadotXcmWeight<RuntimeCall>
XcmGeneric::<Runtime>::unsubscribe_version()
}
fn burn_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
}
fn expect_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
}
fn expect_origin(_origin: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::expect_origin()
Expand Down Expand Up @@ -272,5 +272,5 @@ fn all_counted_has_a_sane_weight_upper_limit() {
let assets = AssetFilter::Wild(AllCounted(4294967295));
let weight = Weight::from_parts(1000, 1000);

assert_eq!(assets.weigh_multi_assets(weight), weight * MAX_ASSETS);
assert_eq!(assets.weigh_assets(weight), weight * MAX_ASSETS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ use sp_std::prelude::*;
use xcm::{latest::prelude::*, DoubleEncoded};

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

const MAX_ASSETS: u64 = 100;

impl WeighAssets for AssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
fn weigh_assets(&self, weight: Weight) -> Weight {
match self {
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
Self::Wild(asset) => match asset {
Expand All @@ -50,21 +50,21 @@ impl WeighAssets for AssetFilter {
}

impl WeighAssets for Assets {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
fn weigh_assets(&self, weight: Weight) -> Weight {
weight.saturating_mul(self.inner().iter().count() as u64)
}
}

pub struct AssetHubKusamaXcmWeight<Call>(core::marker::PhantomData<Call>);
impl<Call> XcmWeightInfo<Call> for AssetHubKusamaXcmWeight<Call> {
fn withdraw_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
}
fn reserve_asset_deposited(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
}
fn receive_teleported_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(
_query_id: &u64,
Expand All @@ -75,10 +75,10 @@ impl<Call> XcmWeightInfo<Call> for AssetHubKusamaXcmWeight<Call> {
XcmGeneric::<Runtime>::query_response()
}
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_type: &OriginKind,
Expand Down Expand Up @@ -114,10 +114,10 @@ impl<Call> XcmWeightInfo<Call> for AssetHubKusamaXcmWeight<Call> {
}

fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
Weight::MAX
Expand All @@ -127,10 +127,10 @@ impl<Call> XcmWeightInfo<Call> for AssetHubKusamaXcmWeight<Call> {
_reserve: &Location,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
}
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
XcmGeneric::<Runtime>::report_holding()
Expand Down Expand Up @@ -163,10 +163,10 @@ impl<Call> XcmWeightInfo<Call> for AssetHubKusamaXcmWeight<Call> {
XcmGeneric::<Runtime>::unsubscribe_version()
}
fn burn_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
}
fn expect_asset(assets: &Assets) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
}
fn expect_origin(_origin: &Option<Location>) -> Weight {
XcmGeneric::<Runtime>::expect_origin()
Expand Down
Loading

0 comments on commit 3c520e3

Please sign in to comment.