XcmPaymentApi::query_weight_to_asset_fee simple common impl#8281
Conversation
|
CC @acatangiu |
acatangiu
left a comment
There was a problem hiding this comment.
I like the approach - using the Trader directly is the right way to go 👍
acatangiu
left a comment
There was a problem hiding this comment.
Looks good! cc @franciscoaguirre to also have a look, but I think you can go ahead with fully implementing the PR.
acatangiu
left a comment
There was a problem hiding this comment.
I tested the workaround locally using Westend Asset Hub. Is there a proper way to unit-test this?
Yes, I would add following tests:
- generic test here using native DOT/KSM that can be called for all runtimes in their local unit-tests (e.g. here)
- Asset Hub Westend unit test here that sets up a few pools then validates this call against a few assets (that have pools)
notes:
- there is already a helper function available for setting up pools in the tests
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Adrian Catangiu <adrian@parity.io>
some tests are failing |
| // We just created it, there's none. | ||
| assert_eq!(fee_in_usdt_fail, Err(XcmPaymentApiError::AssetNotFound)); | ||
|
|
||
| // USDT is sufficient asset, so it passes even if there is not enough liquidity yet. |
There was a problem hiding this comment.
Since #8376 was merged recently, sufficient assets can no longer directly buy weight and also have to go through liquidity pool to work.
There was a problem hiding this comment.
I'll revert this commit then. Merging master should fix the tests instead
|
also needs rebase and conflicts to resolve |
This reverts commit 3bcd52e.
5802306
# Description Add a common implementation for `XcmPaymentApi::query_weight_to_asset_fee` to `pallet-xcm`. This PR is a simple alternative to #8202 (which could still be useful for other reasons). It uses a workaround instead of a big refactoring. The workaround is: Computes the weight cost using the provided `WeightTrader`. This function is supposed to be used ONLY in `XcmPaymentApi::query_weight_to_asset_fee` Runtime API implementation, as it can introduce a massive change to the total issuance. The provided `WeightTrader` must be the same as the one used in the XcmExecutor to ensure uniformity in the weight cost calculation. NOTE: Currently this function uses a workaround that should be good enough for all practical uses: passes `u128::MAX / 2 == 2^127` of the specified asset to the `WeightTrader` as payment and computes the weight cost as the difference between this and the unspent amount. Some weight traders could add the provided payment to some account's balance. However, it should practically never result in overflow because even currencies with a lot of decimal digits (say 18) usually have the total issuance of billions (`x * 10^9`) or trillions (`x * 10^12`) at max, much less than `2^127 / 10^18 =~ 1.7 * 10^20` (170 billion billion). Thus, any account's balance most likely holds less than `2^127`, so adding `2^127` won't result in `u128` overflow. ## Integration The Runtime builders can use the `query_weight_to_asset_fee` provided by `pallet-xcm` in their XcmPaymentApi implementation. --------- Co-authored-by: Adrian Catangiu <adrian@parity.io>
This brings in `stable2506` Polkadot SDK, and integrates many new features. Integrated breaking changes to be verified by the original authors: - [x] ~paritytech/polkadot-sdk#8127 @kianenigma @Ank4n~ This will come in with AHM, and not before. - [x] paritytech/polkadot-sdk#7597 @gui1117 - [x] paritytech/polkadot-sdk#8254 @bkchr - [x] paritytech/polkadot-sdk#7592 @bkontur - [x] paritytech/polkadot-sdk#8382 @UtkarshBhardwaj007 - [x] paritytech/polkadot-sdk#8021 @serban300 - [x] paritytech/polkadot-sdk#8344 @serban300 - [x] paritytech/polkadot-sdk#8262 @athei - [x] paritytech/polkadot-sdk#8584 @athei - [x] paritytech/polkadot-sdk#8299 @skunert - [x] paritytech/polkadot-sdk#8652 @pgherveou - [x] paritytech/polkadot-sdk#8554 @pgherveou - [x] paritytech/polkadot-sdk#8281 @mrshiposha - [x] paritytech/polkadot-sdk#7730 @franciscoaguirre - [x] paritytech/polkadot-sdk#8599 @yrong @claravanstaden - [x] paritytech/polkadot-sdk#8531 @bkontur - [x] paritytech/polkadot-sdk#8409 @kianenigma - [x] paritytech/polkadot-sdk#9137 @franciscoaguirre - [x] paritytech/polkadot-sdk#7944 @bkontur - [x] paritytech/polkadot-sdk#8179 @bkontur - [x] paritytech/polkadot-sdk#8037 @yrong --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: claravanstaden <claravanstaden64@gmail.com> Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Alain Brenzikofer <alain@integritee.network> Co-authored-by: kianenigma <kian@parity.io> Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com> Co-authored-by: ron <yrong1997@gmail.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Overkillus <maciej.zyszkiewicz@parity.io>
# Description Add a common implementation for `XcmPaymentApi::query_weight_to_asset_fee` to `pallet-xcm`. This PR is a simple alternative to #8202 (which could still be useful for other reasons). It uses a workaround instead of a big refactoring. The workaround is: Computes the weight cost using the provided `WeightTrader`. This function is supposed to be used ONLY in `XcmPaymentApi::query_weight_to_asset_fee` Runtime API implementation, as it can introduce a massive change to the total issuance. The provided `WeightTrader` must be the same as the one used in the XcmExecutor to ensure uniformity in the weight cost calculation. NOTE: Currently this function uses a workaround that should be good enough for all practical uses: passes `u128::MAX / 2 == 2^127` of the specified asset to the `WeightTrader` as payment and computes the weight cost as the difference between this and the unspent amount. Some weight traders could add the provided payment to some account's balance. However, it should practically never result in overflow because even currencies with a lot of decimal digits (say 18) usually have the total issuance of billions (`x * 10^9`) or trillions (`x * 10^12`) at max, much less than `2^127 / 10^18 =~ 1.7 * 10^20` (170 billion billion). Thus, any account's balance most likely holds less than `2^127`, so adding `2^127` won't result in `u128` overflow. ## Integration The Runtime builders can use the `query_weight_to_asset_fee` provided by `pallet-xcm` in their XcmPaymentApi implementation. --------- Co-authored-by: Adrian Catangiu <adrian@parity.io>
Description
Add a common implementation for
XcmPaymentApi::query_weight_to_asset_feetopallet-xcm.This PR is a simple alternative to #8202 (which could still be useful for other reasons).
It uses a workaround instead of a big refactoring.
The workaround is:
Computes the weight cost using the provided
WeightTrader.This function is supposed to be used ONLY in
XcmPaymentApi::query_weight_to_asset_feeRuntime API implementation, as it can introduce a massive change to the total issuance.
The provided
WeightTradermust be the same as the one used in the XcmExecutor to ensureuniformity in the weight cost calculation.
NOTE: Currently this function uses a workaround that should be good enough for all practical
uses: passes
u128::MAX / 2 == 2^127of the specified asset to theWeightTraderaspayment and computes the weight cost as the difference between this and the unspent amount.
Some weight traders could add the provided payment to some account's balance. However,
it should practically never result in overflow because even currencies with a lot of decimal digits
(say 18) usually have the total issuance of billions (
x * 10^9) or trillions (x * 10^12) at max,much less than
2^127 / 10^18 =~ 1.7 * 10^20(170 billion billion). Thus, any account's balancemost likely holds less than
2^127, so adding2^127won't result inu128overflow.Integration
The Runtime builders can use the
query_weight_to_asset_feeprovided bypallet-xcmintheir XcmPaymentApi implementation.