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

Fix DepositReserveAsset fees payment #3340

Merged
merged 13 commits into from
Feb 23, 2024
Merged

Conversation

NachoPal
Copy link
Contributor

The fee should be calculated with the reanchored asset, otherwise it could lead to a failure where the set aside fee ends up not being enough.

@acatangiu

@NachoPal NachoPal requested a review from a team as a code owner February 15, 2024 15:24
@NachoPal NachoPal added R0-silent Changes should not be mentioned in any release notes T6-XCM This PR/Issue is related to XCM. labels Feb 15, 2024
Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test?

@NachoPal
Copy link
Contributor Author

Test?

What test would you like to see? It failing without the changes?

You can go to #3339 , undo the xcm-executor changes and run:

cargo test -p  asset-hub-rococo-integration-tests reserve_transfer_native_asset_from_para_to_system_para

It will fail due to the reason explained in this PR.

In any case, upon examining the code, it seems that the failure is potentially expected because the beforehand calculated fee is based on non-reanchored assets, while the actual calculation is performed for the reanchored assets

@liamaharon
Copy link
Contributor

cargo test -p asset-hub-rococo-integration-tests reserve_transfer_native_asset_from_para_to_system_para passed for me on latest master.

I see there is a test for it in a different branch, but it is preferred I think (helps with review and ensures no regression can occur) to bundle the test with the fix when merging to master.

polkadot/xcm/xcm-executor/src/lib.rs Outdated Show resolved Hide resolved
@acatangiu
Copy link
Contributor

I agree you should add a test for this in this branch/PR, #3339 is more controversial.

Also for a regression test of this particular fix, instead of relying on a full xcm-emulator e2e test, you could add a (simpler) executor unit-test here.

@NachoPal
Copy link
Contributor Author

@liamaharon @acatangiu I added a regression test. I'll merge the PR unless you request further changes.

@NachoPal NachoPal requested a review from a team as a code owner February 20, 2024 13:25
@acatangiu acatangiu added this pull request to the merge queue Feb 20, 2024
acatangiu pushed a commit that referenced this pull request Feb 20, 2024
Backport of #3340

Includes #3404 to fix
compilation

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 20, 2024
@acatangiu acatangiu added this pull request to the merge queue Feb 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 21, 2024
@NachoPal NachoPal added this pull request to the merge queue Feb 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 21, 2024
/// Regression test for `DepostiReserveAsset` changes in
/// <https://github.com/paritytech/polkadot-sdk/pull/3340>
#[test]
fn deposit_reserve_asset_works_for_any_xcm_sender() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new test is failing in CI following merge from master

Copy link
Contributor Author

@NachoPal NachoPal Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous PriceForMessageDelivery was flaky returning different prices.

Primarily, it was designed to return the same price for identical messages. However, reanchored messages weren't actually the same.

  • First price calculation is done for a message with the full asset amount in ReserveAssetDeposited
  • Actual price calculation during send() is done for a message where transport_fee has been deducted from the initial asset amount.

It does not explain by itself why the test was flaky. The reason for this flakiness is that the appended SetTopic(id) is calculated using the previous block as entropy. This is why any change in the runtime led to changes in the final message which might or might not generate enough transport fees to be paid.

All of this made me realise that the current method of setting aside the transport_fee for DepositReserveAsset will never be infallible for any possible PriceForMessageDelivery implementation. There is a circular dependency where it is impossible to know the actual DepositReserveAsset amount that will finally be included in the message from which the transport_fee is calculated. @acatangiu @franciscoaguirre

I followed a different approach to fix the test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand a bit on the transport cost variance?

The actual amount (scalar value) of the asset within the message changes/impacts the message weight? I.e. An instruction containing asset: 2 DOT is more expensive than same instruction with asset: 3 DOT? Did I understand that correctly?
Or is it an issue with SetTopic(id) whose transport cost is not correctly calculated during execution of ReserveAssetDeposited? Looking at the code I'm missing where this cost changes between when we calculate and when it is charged..

Copy link
Contributor Author

@NachoPal NachoPal Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An instruction containing asset: 2 DOT is more expensive than same instruction with asset: 3 DOT? Did I understand that correctly?

Not for our PriceForMessageDelivery implementation, because it only depends on the message size, that is why it was failing when the asset was not reanchored.

I am just saying that potentially, a third party could make use of the xcm-executor with a different PriceForMessageDelivery implementation, and we can not guarantee that the set aside transport_fee approach for DepositReserveAsset will be infalible. It is just something to be aware of in case the design can be improved, not a big deal, not even probable to ever happen, and something that shouldn't block this PR.

Copy link
Contributor Author

@NachoPal NachoPal Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll proceed to merge it if the new test looks ok to you.

@NachoPal NachoPal added this pull request to the merge queue Feb 23, 2024
Merged via the queue into master with commit 11b5354 Feb 23, 2024
132 of 133 checks passed
@NachoPal NachoPal deleted the nacho/fix-deposit-reserve-asset branch February 23, 2024 12:17
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/improve-xcm-development-and-release-process/6497/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T6-XCM This PR/Issue is related to XCM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants