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

Lowering XCM weights and fees #3692

Open
2 tasks
bkontur opened this issue Mar 14, 2024 · 5 comments
Open
2 tasks

Lowering XCM weights and fees #3692

bkontur opened this issue Mar 14, 2024 · 5 comments
Assignees
Labels
T6-XCM This PR/Issue is related to XCM.

Comments

@bkontur
Copy link
Contributor

bkontur commented Mar 14, 2024

Summary

The dedicated XCM-relevant benchmarks (pallet_xcm, pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::generic) can utilize a SendXcm implementation at the end, which typically employs the WrapVersion implementation, often sourced from pallet_xcm. This also impacts all other extrinsics and benchmarks that utilize SendXcm + WrapVersion.

The pallet_xcm's WrapVersion implementation adds unnecessary overhead to the weights - 2 reads and 1 write:

        /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1)
	/// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
	/// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0)
	/// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)

This overhead arises from checking the compatible XCM version for the destination. If no supported version is stored, we utilize SafeXcmVersion and store the VersionDiscoveryQueue key/value for later version discovery.
This process occurs only the first time when the destination is not added to the SupportedVersion in pallet_xcm.

The idea here is that this overhead should not be borne by the end user, but rather should be part of establishing the communication channel (e.g., opening HRMP).

Proposed solution part 1 - reducing XCM weights

Implemented by: #3664

We utilize xcm_builder::EnsureDelivery and DeliveryHelper features for XCM benchmarking, as demonstrated here and here. These features ensure successful delivery for extrinsic benchmarks with the underlying SendXcm implementation.

A good example is benchmarking for AssetHubRococo, where it is essential to ensure that we can deliver to the Parent and/or to the sibling parachains. The DeliveryHelper ensures that the sender account has enough assets for delivery fees and/or opens HRMP channels.

Therefore, the straightforward solution here is to extend this DeliveryHelper by one more step, which will insert the desired XCM version into the pallet_xcm::SupportedVersion to eliminate the mentioned overhead.

Note: These EnsureDelivery features can also be directly reused for other benchmarks when needed.

Proposed solution part 2 - initiate VersionDiscoveryQueue when HRMP is accepted

Implemented by: #3696

Currently, XcmExecutor does not support the implementation for HrmpNewChannelOpenRequest / HrmpChannelAccepted / HrmpChannelClosing XCM instructions, as indicated here.

The idea here is that when a parachain receives HrmpChannelAccepted, it will add a key/value pair to the VersionDiscoveryQueue, which will automatically initiate the "XCM version negotiation" mechanism. To achieve this, we need to add a proper callback handler to the XcmExecutor's configuration.

Example:

// + tuple impl
pub trait HandleHrmpChannelNotification {
    fn on_accepted(recipient: u32);
    fn on_closing(recipient: u32);
    fn on_open_request(recipient: u32);
}

/// XcmExecutor setup
impl xcm_executor::Config for XcmConfig {
     type HrmpChannelNotificationHandler = PolkadotXcm // <- pallet_xcm::Pallet<T>
}


/// Implemenatation for `pallet_xcm`.
impl HandleHrmpChannelNotification for pallet_xcm::Pallet<T> {
   ...
}

TODO/questions

  • design proper trait - one trait with function per notification or one trait per notification?
  • do we need XCM rfc for that?
@bkontur bkontur added the T6-XCM This PR/Issue is related to XCM. label Mar 14, 2024
@bkontur
Copy link
Contributor Author

bkontur commented Mar 14, 2024

@franciscoaguirre I would greatly appreciate your assistance and opinion on part 2, at the very least :)

@acatangiu
Copy link
Contributor

Before starting on part 2, please sync up with participants of polkadot-fellows/RFCs#82 (comment) discussion, to make sure we don't duplicate work.

@franciscoaguirre
Copy link
Contributor

I think 2 is the best solution. I wanted to add callbacks for those instructions already, so that any parachain can do whatever they want when they open a channel to another chain. For example they could register a derivative of their token on the other chain.
It feels like killing two birds with one stone

@franciscoaguirre
Copy link
Contributor

I heard the same about Polimec, let's work with them to make sure it gets upstreamed

@bkontur
Copy link
Contributor Author

bkontur commented Apr 12, 2024

Second part is fixed here: #4025.

First part is low prio and very nice to have, but it is better recommended to fix extrinsic:

  • read actual benchmarked weight for extrinsic (AEW)
  • reduce AEW about VersionDiscover weight when we don't hit version discovery scenario
  • return reduced AEW from extrinsic, that way user will pay less

@bkontur bkontur removed the status in Parity Roadmap Apr 12, 2024
@bkontur bkontur moved this to Backlog in Parity Roadmap Apr 12, 2024
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
Status: Backlog
Development

No branches or pull requests

3 participants