Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[Fix] Weight calculations for Wild -> affects teleports #1639

Merged
merged 8 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions parachains/runtimes/assets/statemine/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
}

const MAX_ASSETS: u32 = 100;
const MAX_ASSETS: u32 = 1;
muharem marked this conversation as resolved.
Show resolved Hide resolved
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::Definite(assets) => weight.saturating_mul(assets.len() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
Expand All @@ -46,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter {

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
7 changes: 3 additions & 4 deletions parachains/runtimes/assets/statemint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
}

const 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::Definite(assets) => weight.saturating_mul(assets.len() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
Expand All @@ -46,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter {

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
7 changes: 3 additions & 4 deletions parachains/runtimes/assets/westmint/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
}

const 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::Definite(assets) => weight.saturating_mul(assets.len() as u64),
Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64),
};
weight.ref_time()
Expand All @@ -46,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter {

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