Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
39 changes: 28 additions & 11 deletions parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,49 @@ use crate::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::*, Weight as XCMWeight},
DoubleEncoded,
};

fn weigh_multi_assets_generic(
filter: &MultiAssetFilter,
weight: Weight,
max_assets: u32,
) -> XCMWeight {
let weight = match filter {
MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64),
MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64),
};
weight.ref_time()
}

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

const MAX_ASSETS: u32 = 100;
trait WeighMultiAssetsReserve {
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight;
}

const RESERVE_MAX_ASSETS: u32 = 100;
const MAX_ASSETS: u32 = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we say that this is now TELEPORT_MAX_ASSETS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, because it also does deposits! I will add a comment instead

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks incorrect: both DepositAsset and InitiateTeleport uses this value, and if they ever use Wild(All) as their MultiAssetFilter, the weights given here will be incorrect, as it assumes that the code only interacts with a maximum of 1 asset.


impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
let weight = match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
weigh_multi_assets_generic(self, weight, MAX_ASSETS)
}
}

impl WeighMultiAssetsReserve for MultiAssetFilter {
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight {
weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS)
}
}

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
weight.saturating_mul(self.len() as u64).ref_time()
}
}

Expand Down Expand Up @@ -125,7 +142,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight {
Weight::MAX.ref_time()
Expand All @@ -135,7 +152,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
_reserve: &MultiLocation,
_xcm: &Xcm<()>,
) -> XCMWeight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
Expand Down
39 changes: 28 additions & 11 deletions parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,49 @@ use crate::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::*, Weight as XCMWeight},
DoubleEncoded,
};

fn weigh_multi_assets_generic(
filter: &MultiAssetFilter,
weight: Weight,
max_assets: u32,
) -> XCMWeight {
let weight = match filter {
MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64),
MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64),
};
weight.ref_time()
}

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

const MAX_ASSETS: u32 = 100;
trait WeighMultiAssetsReserve {
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight;
}

const RESERVE_MAX_ASSETS: u32 = 100;
const MAX_ASSETS: u32 = 1;

impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
let weight = match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
weigh_multi_assets_generic(self, weight, MAX_ASSETS)
}
}

impl WeighMultiAssetsReserve for MultiAssetFilter {
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight {
weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS)
}
}

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
weight.saturating_mul(self.len() as u64).ref_time()
}
}

Expand Down Expand Up @@ -125,7 +142,7 @@ impl<Call> XcmWeightInfo<Call> for StatemintXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight {
Weight::MAX.ref_time()
Expand All @@ -135,7 +152,7 @@ impl<Call> XcmWeightInfo<Call> for StatemintXcmWeight<Call> {
_reserve: &MultiLocation,
_xcm: &Xcm<()>,
) -> XCMWeight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
Expand Down
39 changes: 28 additions & 11 deletions parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,49 @@ use crate::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::*, Weight as XCMWeight},
DoubleEncoded,
};

fn weigh_multi_assets_generic(
filter: &MultiAssetFilter,
weight: Weight,
max_assets: u32,
) -> XCMWeight {
let weight = match filter {
MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64),
MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64),
};
weight.ref_time()
}

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

const MAX_ASSETS: u32 = 100;
trait WeighMultiAssetsReserve {
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight;
}

const RESERVE_MAX_ASSETS: u32 = 100;
const MAX_ASSETS: u32 = 1;

impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
let weight = match self {
Self::Definite(assets) =>
weight.saturating_mul(assets.inner().into_iter().count() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
weigh_multi_assets_generic(self, weight, MAX_ASSETS)
}
}

impl WeighMultiAssetsReserve for MultiAssetFilter {
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight {
weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS)
}
}

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
weight.saturating_mul(self.len() as u64).ref_time()
}
}

Expand Down Expand Up @@ -125,7 +142,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> XCMWeight {
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight {
Weight::MAX.ref_time()
Expand All @@ -135,7 +152,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
_reserve: &MultiLocation,
_xcm: &Xcm<()>,
) -> XCMWeight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
Expand Down