Skip to content

Improve pallet-xcm-precompile docs (assets ordering)#58

Merged
RomarQ merged 2 commits into
mainfrom
agustin-improve-xcm-precompile-docs
Oct 29, 2025
Merged

Improve pallet-xcm-precompile docs (assets ordering)#58
RomarQ merged 2 commits into
mainfrom
agustin-improve-xcm-precompile-docs

Conversation

@Agusrodri

Copy link
Copy Markdown
Contributor

What does it do?

Adds an extra line of description to the functions present in pallet-xcm-precompile's interface.

Basically, if we send assets that are not sorted and we specify a fee index, it may happen that the incorrect asset is used to pay for fees. This is because internally, we need to perform some conversions with the Assets struct, which automatically sorts the assets being converted.

The purpose of the new extra line of docs is to inform (and prevent) users about this behavior.

@gonzamontiel gonzamontiel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see this as a necessary patch but I would soon add a function to automatically sort the assets.
Also, the type of sort that the users need to use is implicit. While it might be obvious, I would take the opportunity to be more precise (and maybe add an example).

@stiiifff

Copy link
Copy Markdown

I would specify that the order matters, and as you mention, that the fee index relates to the asset array.

@Agusrodri

Copy link
Copy Markdown
Contributor Author

As discussed internally, we will add some examples for the assets ordering, and will work on a future PR containing the helper function to automatically sort the assets.

@RomarQ

RomarQ commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

Adding some context to this issue, the explanation below is copied from: paritytech/polkadot-sdk#2388 (comment)

MultiAssets object internally sorts the list of assets (I'm not sure where this requirement to be sorted comes from, maybe required for encoding/decoding?).

So my guess is you're doing something like:

let assets: MultiAssets = vec![TEER, ROC].into();    // <-- this works
let fee_idx = 1;                                     // ok

let assets: MultiAssets = vec![ROC, TEER].into();    // <-- still works, but `fee_idx` should still be `1` because of sorting :(
let fee_idx = 0; // <-- reading this looks like it's pointing to ROC, but because of the sorting done by `.into()`, TEER is actually idx 0 and ROC is idx 1

(local assets will always go first because of parents=0 vs ROC which has parents=1)

and I know... this is annoying and bad API design - we could change extrinsic to take actual fee asset instead of index, but would be a breaking change..

Also here is an example helper function I used in tests to get the right index for transfers.

@RomarQ RomarQ merged commit 0779a15 into main Oct 29, 2025
@RomarQ RomarQ deleted the agustin-improve-xcm-precompile-docs branch October 29, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants