Skip to content

Commit

Permalink
Charge 0-asset XCM instructions as if they were 1-asset (#1071)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Reif <[email protected]>
  • Loading branch information
Adam Reif authored Apr 13, 2023
1 parent c348344 commit 0732a13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions runtime/calamari/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
match self {
Self::Definite(assets) => {
(assets.inner().iter().count() as Weight).saturating_mul(weight)
// NOTE: We charge fees for at least 1 asset even if 0 were requested to punish spam
(assets.inner().iter().count().max(1) as Weight).saturating_mul(weight)
}
Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight),
}
Expand All @@ -44,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter {

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
(self.inner().iter().count() as Weight).saturating_mul(weight)
(self.inner().iter().count().max(1) as Weight).saturating_mul(weight)
}
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/dolphin/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
match self {
Self::Definite(assets) => {
(assets.inner().iter().count() as Weight).saturating_mul(weight)
// NOTE: We charge fees for at least 1 asset even if 0 were requested to punish spam
(assets.inner().iter().count().max(1) as Weight).saturating_mul(weight)
}
Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight),
}
Expand All @@ -44,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter {

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
(self.inner().iter().count() as Weight).saturating_mul(weight)
(self.inner().iter().count().max(1) as Weight).saturating_mul(weight)
}
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/manta/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
match self {
Self::Definite(assets) => {
(assets.inner().iter().count() as Weight).saturating_mul(weight)
// NOTE: We charge fees for at least 1 asset even if 0 were requested to punish spam
(assets.inner().iter().count().max(1) as Weight).saturating_mul(weight)
}
Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(weight),
}
Expand All @@ -44,7 +45,7 @@ impl WeighMultiAssets for MultiAssetFilter {

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
(self.inner().iter().count() as Weight).saturating_mul(weight)
(self.inner().iter().count().max(1) as Weight).saturating_mul(weight)
}
}

Expand Down

0 comments on commit 0732a13

Please sign in to comment.