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

[XCMv5] Better fee mechanism #5420

Merged
merged 54 commits into from
Oct 17, 2024
Merged

[XCMv5] Better fee mechanism #5420

merged 54 commits into from
Oct 17, 2024

Conversation

franciscoaguirre
Copy link
Contributor

@franciscoaguirre franciscoaguirre commented Aug 20, 2024

Implements RFC#105 which, at the time of this PR, has not been approved yet. Some aspects might be changed as a result of discussion.

TODO

  • Add new instruction and use it in conversion functions
  • Implement in xcm-executor
  • Setup for xcm-executor unit tests
  • Actual xcm-executor unit tests
    • Happy path
    • Unhappy path
  • Emulated tests
    • Asset hub westend
    • Asset hub rococo
  • Benchmarks
    • Dummy values
    • Actual benchmarks
  • PRDoc

@franciscoaguirre franciscoaguirre requested a review from a team as a code owner August 20, 2024 14:29
@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label Aug 20, 2024
@franciscoaguirre
Copy link
Contributor Author

bot bench polkadot-pallet --subcommand=xcm --runtime=westend --pallet=pallet_xcm_benchmarks::generic
bot bench polkadot-pallet --subcommand=xcm --runtime=rococo --pallet=pallet_xcm_benchmarks::generic

bot bench cumulus-assets --subcommand=xcm --runtime=asset-hub-westend --pallet=pallet_xcm_benchmarks::generic
bot bench cumulus-assets --subcommand=xcm --runtime=asset-hub-rococo --pallet=pallet_xcm_benchmarks::generic

bot bench cumulus-coretime --subcommand=xcm --runtime=coretime-westend --pallet=pallet_xcm_benchmarks::generic
bot bench cumulus-coretime --subcommand=xcm --runtime=coretime-rococo --pallet=pallet_xcm_benchmarks::generic

bot bench cumulus-bridge-hubs --subcommand=xcm --runtime=bridge-hub-rococo --pallet=pallet_xcm_benchmarks::generic
bot bench cumulus-bridge-hubs --subcommand=xcm --runtime=bridge-hub-westend --pallet=pallet_xcm_benchmarks::generic

bot bench cumulus-contracts --subcommand=xcm --pallet=pallet_xcm_benchmarks::generic

bot bench cumulus-people --subcommand=xcm --runtime=people-westend --pallet=pallet_xcm_benchmarks::generic
bot bench cumulus-people --subcommand=xcm --runtime=people-rococo --pallet=pallet_xcm_benchmarks::generic

command-bot added 8 commits August 27, 2024 10:53
…coco --target_dir=polkadot --pallet=pallet_xcm_benchmarks::generic
…stend --target_dir=polkadot --pallet=pallet_xcm_benchmarks::generic
…retime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_xcm_benchmarks::generic
…set-hub-rococo --runtime_dir=assets --target_dir=cumulus --pallet=pallet_xcm_benchmarks::generic
…set-hub-westend --runtime_dir=assets --target_dir=cumulus --pallet=pallet_xcm_benchmarks::generic
…retime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_xcm_benchmarks::generic
…idge-hub-rococo --runtime_dir=bridge-hubs --target_dir=cumulus --pallet=pallet_xcm_benchmarks::generic
…idge-hub-westend --runtime_dir=bridge-hubs --target_dir=cumulus --pallet=pallet_xcm_benchmarks::generic
@franciscoaguirre
Copy link
Contributor Author

bot fmt

@command-bot
Copy link

command-bot bot commented Oct 7, 2024

@franciscoaguirre https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7522122 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 21-9481da8a-95a0-43a6-a9ea-cf187608b520 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Oct 7, 2024

@franciscoaguirre Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7522122 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7522122/artifacts/download.

@franciscoaguirre
Copy link
Contributor Author

bot fmt

@command-bot
Copy link

command-bot bot commented Oct 7, 2024

@franciscoaguirre https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7522964 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 22-d5f8c9e1-786c-4c35-954f-97fb8b7585d4 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Oct 7, 2024

@franciscoaguirre Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7522964 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7522964/artifacts/download.

Comment on lines +1415 to +1417
PayFees { .. } => {
return Err(());
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are more new instructions coming, do we want to make this generic or case-by-case e.g.: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/src/v2/mod.rs#L1182

Suggested change
PayFees { .. } => {
return Err(());
},
i => {
log::warn!(target: "xcm::v5tov4", "`{i:?}` not supported by v4");
return Err(());
},

Comment on lines +270 to +292
let maybe_builder_attr = variant.attrs.iter().find(|attr| match attr.meta {
Meta::List(ref list) => list.path.is_ident("builder"),
_ => false,
});
let builder_attr = match maybe_builder_attr {
Some(builder) => builder.clone(),
None => return Ok(None), /* It's not going to be an instruction that pays fees */
};
let Meta::List(ref list) = builder_attr.meta else { unreachable!("We checked before") };
let inner_ident: Ident = syn::parse2(list.tokens.clone()).map_err(|_| {
Error::new_spanned(
&builder_attr,
"Expected `builder(loads_holding)` or `builder(pays_fees)`",
)
})?;
let ident_to_match: Ident = syn::parse_quote!(pays_fees);
if inner_ident == ident_to_match {
Ok(Some(variant))
} else {
Ok(None) // Must have been `loads_holding` instead.
}
})
.collect::<Result<Vec<_>>>()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be deduplicated. Parsing pay_fees_variants and load_holding_variants uses exactly the same code, differing only in: syn::parse_quote!(pays_fees); vs syn::parse_quote!(loads_holding).
So it should be possible to extract it to some helper function:

let load_holding_variants =  parse_variants(data_enum, syn::parse_quote!(loads_holding));
let pay_fees_variants =  parse_variants(data_enum, syn::parse_quote!(pays_fees));

_ =>
return Err(Error::new_spanned(
variant,
"Both BuyExecution and PayFees have named fields",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not fully convinced that this builder(pay_fees) assumes specific instructions like BuyExecution or PayFees and their structure. Why do we assume that these instructions can't have unnamed fields?

I suggest extracting the entire block of code that parses let load_holding_methods = load_holding_variants, and doing the following:

  • Turn it into a helper function parse_variant_methods (or better name).
  • It can nicely parse both named and unnamed fields
  • Add a parameter that specifies the result type (that is the only difference here), such as LoadedHolding or AnythingGoes.

This way, we could have a single helper function, like parse_variant_methods, which will make generate_builder_impl simpler and more deduplicated:

fn generate_builder_impl(..) {
    // We first require an instruction that load the holding register
    let load_holding_methods =  parse_variant_methods(data_enum, syn::parse_quote!(loads_holding), LoadedHolding);
...
    // Some operations are allowed after the holding register is loaded
    let allowed_after_load_holding_methods: ...
...
    // Then we require fees to be paid
    let pay_fees_methods =  parse_variant_methods(data_enum, syn::parse_quote!(pays_fees), AnythingGoes);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@franciscoaguirre please do this in a followup PR, let's merge this one so we can work on top of the new fees mechanism

…st` (#6092)

Relates to: #5420

This PR includes some cleanup, as every time we upgrade XCM, we will
need to rewrite all instances of `V5` to `V6`.

---------

Co-authored-by: command-bot <>
@acatangiu acatangiu merged commit d1425bb into xcm-v5 Oct 17, 2024
195 of 218 checks passed
@acatangiu acatangiu deleted the xcm-pay-fees branch October 17, 2024 12:35
This was referenced Oct 17, 2024
@acatangiu acatangiu restored the xcm-pay-fees branch October 17, 2024 12:45
@acatangiu acatangiu deleted the xcm-pay-fees branch October 17, 2024 12:48
github-merge-queue bot pushed a commit that referenced this pull request Nov 6, 2024
# Context

This PR aims to introduce XCMv5, for now it's in progress and will be
updated over time.
This branch will serve as a milestone branch for merging in all features
we want to add to XCM, roughly outlined
[here](polkadot-fellows/xcm-format#60).
More features could be added.

## TODO
- [x] Migrate foreign assets from v3 to v4
- [x] Setup v5 skeleton
- [x] Remove XCMv2
- [x] #5390
- [x] #5585
- [x] #5420
- [x] #5876
- [x] #5971
- [x] #6148
- [x] #6228

Fixes #3434 
Fixes #4190
Fixes #5209
Fixes #5241
Fixes #4284

---------

Signed-off-by: Adrian Catangiu <[email protected]>
Co-authored-by: Adrian Catangiu <[email protected]>
Co-authored-by: Andrii <[email protected]>
Co-authored-by: Branislav Kontur <[email protected]>
Co-authored-by: Joseph Zhao <[email protected]>
Co-authored-by: Nazar Mokrynskyi <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Shawn Tabrizi <[email protected]>
Co-authored-by: command-bot <>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Serban Iorga <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T6-XCM This PR/Issue is related to XCM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants