Revert "[Fix] Weight calculations for Wild -> affects teleports (#1639)" (#1640)

This reverts commit 14115c82de.
This commit is contained in:
joe petrowski
2022-09-19 22:18:14 +02:00
committed by GitHub
parent 14115c82de
commit 822c4d7962
4 changed files with 33 additions and 68 deletions
-14
View File
@@ -119,17 +119,3 @@ impl<Location: Get<MultiLocation>> FilterAssetLocation for ConcreteNativeAssetFr
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get()) matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
} }
} }
/// A generic function to use for MultiAssetFilter implementations, currently used to differentiate
/// between reserve operations and the rest of them.
pub fn weigh_multi_assets_generic(
filter: &MultiAssetFilter,
weight: Weight,
max_assets: u32,
) -> XCMWeight {
let multiplier = match filter {
MultiAssetFilter::Definite(assets) => assets.len() as u64,
MultiAssetFilter::Wild(_) => max_assets as u64,
};
weight.saturating_mul(multiplier).ref_time()
}
@@ -21,7 +21,7 @@ use crate::Runtime;
use frame_support::weights::Weight; use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use parachains_common::xcm_config::weigh_multi_assets_generic; use sp_std::prelude::*;
use xcm::{ use xcm::{
latest::{prelude::*, Weight as XCMWeight}, latest::{prelude::*, Weight as XCMWeight},
DoubleEncoded, DoubleEncoded,
@@ -31,29 +31,22 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
} }
trait WeighMultiAssetsReserve { const MAX_ASSETS: u32 = 100;
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight;
}
const RESERVE_MAX_ASSETS: u32 = 100;
/// For teleports and deposits
const MAX_ASSETS: u32 = 1;
impl WeighMultiAssets for MultiAssetFilter { impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weigh_multi_assets_generic(self, weight, MAX_ASSETS) 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),
impl WeighMultiAssetsReserve for MultiAssetFilter { };
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { weight.ref_time()
weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS)
} }
} }
impl WeighMultiAssets for MultiAssets { impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.len() as u64).ref_time() weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
} }
} }
@@ -132,7 +125,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
_dest: &MultiLocation, _dest: &MultiLocation,
_xcm: &Xcm<()>, _xcm: &Xcm<()>,
) -> XCMWeight { ) -> XCMWeight {
assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset()) assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
} }
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight {
Weight::MAX.ref_time() Weight::MAX.ref_time()
@@ -142,7 +135,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> {
_reserve: &MultiLocation, _reserve: &MultiLocation,
_xcm: &Xcm<()>, _xcm: &Xcm<()>,
) -> XCMWeight { ) -> XCMWeight {
assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw()) assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
} }
fn initiate_teleport( fn initiate_teleport(
assets: &MultiAssetFilter, assets: &MultiAssetFilter,
@@ -21,7 +21,7 @@ use crate::Runtime;
use frame_support::weights::Weight; use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use parachains_common::xcm_config::weigh_multi_assets_generic; use sp_std::prelude::*;
use xcm::{ use xcm::{
latest::{prelude::*, Weight as XCMWeight}, latest::{prelude::*, Weight as XCMWeight},
DoubleEncoded, DoubleEncoded,
@@ -31,29 +31,22 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
} }
trait WeighMultiAssetsReserve { const MAX_ASSETS: u32 = 100;
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight;
}
const RESERVE_MAX_ASSETS: u32 = 100;
/// For teleports and deposits
const MAX_ASSETS: u32 = 1;
impl WeighMultiAssets for MultiAssetFilter { impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weigh_multi_assets_generic(self, weight, MAX_ASSETS) 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),
impl WeighMultiAssetsReserve for MultiAssetFilter { };
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { weight.ref_time()
weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS)
} }
} }
impl WeighMultiAssets for MultiAssets { impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.len() as u64).ref_time() weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
} }
} }
@@ -132,7 +125,7 @@ impl<Call> XcmWeightInfo<Call> for StatemintXcmWeight<Call> {
_dest: &MultiLocation, _dest: &MultiLocation,
_xcm: &Xcm<()>, _xcm: &Xcm<()>,
) -> XCMWeight { ) -> XCMWeight {
assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset()) assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
} }
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight {
Weight::MAX.ref_time() Weight::MAX.ref_time()
@@ -142,7 +135,7 @@ impl<Call> XcmWeightInfo<Call> for StatemintXcmWeight<Call> {
_reserve: &MultiLocation, _reserve: &MultiLocation,
_xcm: &Xcm<()>, _xcm: &Xcm<()>,
) -> XCMWeight { ) -> XCMWeight {
assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw()) assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
} }
fn initiate_teleport( fn initiate_teleport(
assets: &MultiAssetFilter, assets: &MultiAssetFilter,
@@ -21,7 +21,7 @@ use crate::Runtime;
use frame_support::weights::Weight; use frame_support::weights::Weight;
use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
use parachains_common::xcm_config::weigh_multi_assets_generic; use sp_std::prelude::*;
use xcm::{ use xcm::{
latest::{prelude::*, Weight as XCMWeight}, latest::{prelude::*, Weight as XCMWeight},
DoubleEncoded, DoubleEncoded,
@@ -31,29 +31,22 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
} }
trait WeighMultiAssetsReserve { const MAX_ASSETS: u32 = 100;
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight;
}
const RESERVE_MAX_ASSETS: u32 = 100;
/// For teleports and deposits
const MAX_ASSETS: u32 = 1;
impl WeighMultiAssets for MultiAssetFilter { impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weigh_multi_assets_generic(self, weight, MAX_ASSETS) 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),
impl WeighMultiAssetsReserve for MultiAssetFilter { };
fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { weight.ref_time()
weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS)
} }
} }
impl WeighMultiAssets for MultiAssets { impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight {
weight.saturating_mul(self.len() as u64).ref_time() weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time()
} }
} }
@@ -132,7 +125,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
_dest: &MultiLocation, _dest: &MultiLocation,
_xcm: &Xcm<()>, _xcm: &Xcm<()>,
) -> XCMWeight { ) -> XCMWeight {
assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset()) assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
} }
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight {
Weight::MAX.ref_time() Weight::MAX.ref_time()
@@ -142,7 +135,7 @@ impl<Call> XcmWeightInfo<Call> for WestmintXcmWeight<Call> {
_reserve: &MultiLocation, _reserve: &MultiLocation,
_xcm: &Xcm<()>, _xcm: &Xcm<()>,
) -> XCMWeight { ) -> XCMWeight {
assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw()) assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
} }
fn initiate_teleport( fn initiate_teleport(
assets: &MultiAssetFilter, assets: &MultiAssetFilter,