This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
[Fix] Weight calculations for Wild -> affects teleports #1639
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ebdb90
[Fix] Weight calculations for Wild -> affects teleports
ruseinov 77d33b1
introduce a separate asset limit for teleports
ruseinov 4901fe3
fix deposit
ruseinov 81ea3be
reshuffle abstractions
ruseinov 9efa822
fix imports
ruseinov 9258f4e
little refactoring
ruseinov 2d60b9f
Update parachains/common/src/xcm_config.rs
ruseinov 4b1583a
add comments
ruseinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,32 +21,49 @@ use crate::Runtime; | |
| use frame_support::weights::Weight; | ||
| use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; | ||
| use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; | ||
| use sp_std::prelude::*; | ||
| use xcm::{ | ||
| latest::{prelude::*, Weight as XCMWeight}, | ||
| DoubleEncoded, | ||
| }; | ||
|
|
||
| fn weigh_multi_assets_generic( | ||
| filter: &MultiAssetFilter, | ||
| weight: Weight, | ||
| max_assets: u32, | ||
| ) -> XCMWeight { | ||
| let weight = match filter { | ||
| MultiAssetFilter::Definite(assets) => weight.saturating_mul(assets.len() as u64), | ||
| MultiAssetFilter::Wild(_) => weight.saturating_mul(max_assets as u64), | ||
| }; | ||
| weight.ref_time() | ||
| } | ||
|
|
||
| trait WeighMultiAssets { | ||
| fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight; | ||
| } | ||
|
|
||
| const MAX_ASSETS: u32 = 100; | ||
| trait WeighMultiAssetsReserve { | ||
| fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight; | ||
| } | ||
|
|
||
| const RESERVE_MAX_ASSETS: u32 = 100; | ||
| const MAX_ASSETS: u32 = 1; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we say that this is now TELEPORT_MAX_ASSETS ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, because it also does deposits! I will add a comment instead
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks incorrect: both |
||
|
|
||
| impl WeighMultiAssets for MultiAssetFilter { | ||
| fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { | ||
| let weight = match self { | ||
| Self::Definite(assets) => | ||
| weight.saturating_mul(assets.inner().into_iter().count() as u64), | ||
| Self::Wild(_) => weight.saturating_mul(MAX_ASSETS as u64), | ||
| }; | ||
| weight.ref_time() | ||
| weigh_multi_assets_generic(self, weight, MAX_ASSETS) | ||
| } | ||
| } | ||
|
|
||
| impl WeighMultiAssetsReserve for MultiAssetFilter { | ||
| fn weigh_multi_assets_reserve(&self, weight: Weight) -> XCMWeight { | ||
| weigh_multi_assets_generic(self, weight, RESERVE_MAX_ASSETS) | ||
| } | ||
| } | ||
|
|
||
| impl WeighMultiAssets for MultiAssets { | ||
| fn weigh_multi_assets(&self, weight: Weight) -> XCMWeight { | ||
| weight.saturating_mul(self.inner().into_iter().count() as u64).ref_time() | ||
| weight.saturating_mul(self.len() as u64).ref_time() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -125,7 +142,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> { | |
| _dest: &MultiLocation, | ||
| _xcm: &Xcm<()>, | ||
| ) -> XCMWeight { | ||
| assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset()) | ||
| assets.weigh_multi_assets_reserve(XcmFungibleWeight::<Runtime>::deposit_reserve_asset()) | ||
| } | ||
| fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> XCMWeight { | ||
| Weight::MAX.ref_time() | ||
|
|
@@ -135,7 +152,7 @@ impl<Call> XcmWeightInfo<Call> for StatemineXcmWeight<Call> { | |
| _reserve: &MultiLocation, | ||
| _xcm: &Xcm<()>, | ||
| ) -> XCMWeight { | ||
| assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw()) | ||
| assets.weigh_multi_assets_reserve(XcmGeneric::<Runtime>::initiate_reserve_withdraw()) | ||
| } | ||
| fn initiate_teleport( | ||
| assets: &MultiAssetFilter, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.