Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the max number of assets weighable in XCM #2215

Merged
merged 4 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions pallets/moonbeam-xcm-benchmarks/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod moonbeam_xcm_benchmarks_fungible;
mod moonbeam_xcm_benchmarks_generic;

use crate::weights::moonbeam_xcm_benchmarks_generic::WeightInfo;
use core::cmp::min;
use frame_support::weights::Weight;
use moonbeam_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight;
use moonbeam_xcm_benchmarks_generic::SubstrateWeight as XcmGeneric;
Expand All @@ -26,8 +27,7 @@ use xcm::{
latest::{prelude::*, Weight as XCMWeight},
DoubleEncoded,
};

const MAX_ASSETS: u32 = 100;
use xcm_primitives::MAX_ASSETS;

trait WeighMultiAssets {
fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight;
Expand All @@ -43,9 +43,10 @@ impl WeighMultiAssetsFilter for MultiAssetFilter {
Self::Definite(assets) => {
weight.saturating_mul(assets.inner().into_iter().count() as u64)
}
Self::Wild(AllOf { .. } | AllOfCounted { .. }) => weight,
Self::Wild(AllCounted(count)) => weight.saturating_mul(*count as u64),
Self::Wild(All) => weight.saturating_mul(MAX_ASSETS as u64),
Self::Wild(AllCounted(count) | AllOfCounted { count, .. }) => {
weight.saturating_mul(min(MAX_ASSETS, *count) as u64)
}
Self::Wild(All | AllOf { .. }) => weight.saturating_mul(MAX_ASSETS as u64),
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions primitives/xcm/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2019-2022 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

pub const MAX_ASSETS: u32 = 64;
3 changes: 3 additions & 0 deletions primitives/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub use asset_id_conversions::*;
mod barriers;
pub use barriers::*;

mod constants;
pub use constants::*;

mod fee_handlers;
pub use fee_handlers::*;

Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl frame_support::traits::Contains<RuntimeCall> for SafeCallFilter {
}

parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS;
}

pub struct XcmExecutorConfig;
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbeam/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl frame_support::traits::Contains<RuntimeCall> for SafeCallFilter {
}

parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS;
}

pub struct XcmExecutorConfig;
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonriver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl frame_support::traits::Contains<RuntimeCall> for SafeCallFilter {
}

parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS;
}

pub struct XcmExecutorConfig;
Expand Down