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

Fix XCM Weights on Westend #4066

Merged
3 commits merged into from
Oct 12, 2021
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
18 changes: 18 additions & 0 deletions runtime/westend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,21 @@ fn call_size() {
If the limit is too strong, maybe consider increase the limit to 300.",
);
}

#[test]
fn sanity_check_teleport_assets_weight() {
// This test sanity checks that at least 50 teleports can exist in a block.
// Usually when XCM runs into an issue, it will return a weight of `Weight::MAX`,
// so this test will certainly ensure that this problem does not occur.
use frame_support::dispatch::GetDispatchInfo;
let weight = pallet_xcm::Call::<Runtime>::teleport_assets {
dest: Box::new(xcm::VersionedMultiLocation::V1(MultiLocation::here())),
beneficiary: Box::new(xcm::VersionedMultiLocation::V1(MultiLocation::here())),
assets: Box::new((Concrete(MultiLocation::here()), Fungible(200_000)).into()),
fee_asset_item: 0,
}
.get_dispatch_info()
.weight;

assert!(weight * 50 < BlockWeights::get().max_block);
}
6 changes: 4 additions & 2 deletions runtime/westend/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ trait WeighMultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
}

// TODO wild case
// Westend only knows about one asset, the balances pallet.
const MAX_ASSETS: u32 = 1;

impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
match self {
Expand All @@ -44,7 +46,7 @@ impl WeighMultiAssets for MultiAssetFilter {
AssetTypes::Unknown => Weight::MAX,
})
.fold(0, |acc, x| acc.saturating_add(x)),
_ => Weight::MAX,
Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(balances_weight),
}
}
}
Expand Down