mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
XCM: Limit the max number of assets weighable in MultiAssets (#6786)
* Limit the max number of assets weighable in MultiAssets * Apply suggestions from code review Co-authored-by: Gavin Wood <gavin@parity.io> * Add tests * cargo fmt * Include proof size weight in tests * Add comments --------- Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
@@ -51,7 +51,7 @@ trait WeighMultiAssets {
|
||||
}
|
||||
|
||||
// Westend only knows about one asset, the balances pallet.
|
||||
const MAX_ASSETS: u32 = 1;
|
||||
const MAX_ASSETS: u64 = 1;
|
||||
|
||||
impl WeighMultiAssets for MultiAssetFilter {
|
||||
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
|
||||
@@ -65,9 +65,12 @@ impl WeighMultiAssets for MultiAssetFilter {
|
||||
AssetTypes::Unknown => Weight::MAX,
|
||||
})
|
||||
.fold(Weight::zero(), |acc, x| acc.saturating_add(x)),
|
||||
// We don't support any NFTs on Westend, so these two variants will always match
|
||||
// only 1 kind of fungible asset.
|
||||
Self::Wild(AllOf { .. } | AllOfCounted { .. }) => balances_weight,
|
||||
Self::Wild(AllCounted(count)) => balances_weight.saturating_mul(*count as u64),
|
||||
Self::Wild(All) => balances_weight.saturating_mul(MAX_ASSETS as u64),
|
||||
Self::Wild(AllCounted(count)) =>
|
||||
balances_weight.saturating_mul(MAX_ASSETS.min(*count as u64)),
|
||||
Self::Wild(All) => balances_weight.saturating_mul(MAX_ASSETS),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,3 +282,11 @@ impl<RuntimeCall> XcmWeightInfo<RuntimeCall> for WestendXcmWeight<RuntimeCall> {
|
||||
XcmGeneric::<Runtime>::unpaid_execution()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_counted_has_a_sane_weight_upper_limit() {
|
||||
let assets = MultiAssetFilter::Wild(AllCounted(4294967295));
|
||||
let weight = Weight::from_parts(1000, 1000);
|
||||
|
||||
assert_eq!(assets.weigh_multi_assets(weight), weight * MAX_ASSETS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user