From 0732a13c122637d2e8d506b5d486139e7490a804 Mon Sep 17 00:00:00 2001 From: Adam Reif Date: Wed, 12 Apr 2023 23:20:25 -0500 Subject: [PATCH] Charge 0-asset XCM instructions as if they were 1-asset (#1071) Signed-off-by: Adam Reif --- runtime/calamari/src/weights/xcm/mod.rs | 5 +++-- runtime/dolphin/src/weights/xcm/mod.rs | 5 +++-- runtime/manta/src/weights/xcm/mod.rs | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/runtime/calamari/src/weights/xcm/mod.rs b/runtime/calamari/src/weights/xcm/mod.rs index ef0b43a7d..2cacb6ae9 100644 --- a/runtime/calamari/src/weights/xcm/mod.rs +++ b/runtime/calamari/src/weights/xcm/mod.rs @@ -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), } @@ -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) } } diff --git a/runtime/dolphin/src/weights/xcm/mod.rs b/runtime/dolphin/src/weights/xcm/mod.rs index b3034917e..4e1ebdb17 100644 --- a/runtime/dolphin/src/weights/xcm/mod.rs +++ b/runtime/dolphin/src/weights/xcm/mod.rs @@ -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), } @@ -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) } } diff --git a/runtime/manta/src/weights/xcm/mod.rs b/runtime/manta/src/weights/xcm/mod.rs index 617b92324..9d64cf87d 100644 --- a/runtime/manta/src/weights/xcm/mod.rs +++ b/runtime/manta/src/weights/xcm/mod.rs @@ -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), } @@ -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) } }