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

feat(mainnet): include xcm benchmarks #479

Conversation

al3mart
Copy link
Collaborator

@al3mart al3mart commented Feb 24, 2025

Needed for: #478

Adds benchmarks related to XCM in mainnet runtime.

  • pallet_xcm extrinsics benchmark
  • pallet_xcm_benchmarks::generic benchmark
  • pallet_xcm_benchmarks::fungible benchmark
  • Configure Weigher using WeightInfoBounds
  • Remove default weights from pallet_xcm and use benchmarks results.

Note that the benchmarks have been run locally, and they need to be re-run in the collator machines. A script will be provided in #478 such that we can do that easily.

@al3mart al3mart changed the title feat(benchmarks): xcm benchmarks feat(benchmarks): xcm benchmarks for mainnet runtime Feb 24, 2025
@al3mart al3mart changed the title feat(benchmarks): xcm benchmarks for mainnet runtime feat(mainnet): include xcm benchmarks Feb 24, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 5.66845% with 882 lines in your changes missing coverage. Please review.

Project coverage is 65.43%. Comparing base (fd64662) to head (f458b53).

Files with missing lines Patch % Lines
...t/src/weights/xcm/pallet_xcm_benchmarks_generic.rs 0.00% 265 Missing ⚠️
runtime/mainnet/src/weights/xcm/mod.rs 0.00% 221 Missing ⚠️
runtime/mainnet/src/weights/pallet_xcm.rs 0.00% 191 Missing ⚠️
runtime/mainnet/src/benchmarks.rs 0.00% 108 Missing ⚠️
.../src/weights/xcm/pallet_xcm_benchmarks_fungible.rs 0.00% 96 Missing ⚠️
runtime/mainnet/src/apis.rs 0.00% 1 Missing ⚠️
@@                           Coverage Diff                           @@
##           al3mart/feat-mainnet-all-benchmarks     #479      +/-   ##
=======================================================================
- Coverage                                68.43%   65.43%   -3.00%     
=======================================================================
  Files                                      113      120       +7     
  Lines                                    21344    22424    +1080     
  Branches                                 21344    22424    +1080     
=======================================================================
+ Hits                                     14606    14673      +67     
- Misses                                    6472     7485    +1013     
  Partials                                   266      266              
Files with missing lines Coverage Δ
runtime/mainnet/src/config/xcm.rs 100.00% <100.00%> (ø)
runtime/mainnet/src/lib.rs 66.23% <ø> (ø)
runtime/mainnet/src/apis.rs 0.00% <0.00%> (ø)
.../src/weights/xcm/pallet_xcm_benchmarks_fungible.rs 0.00% <0.00%> (ø)
runtime/mainnet/src/benchmarks.rs 0.00% <0.00%> (ø)
runtime/mainnet/src/weights/pallet_xcm.rs 0.00% <0.00%> (ø)
runtime/mainnet/src/weights/xcm/mod.rs 0.00% <0.00%> (ø)
...t/src/weights/xcm/pallet_xcm_benchmarks_generic.rs 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

@al3mart al3mart force-pushed the al3mart/feat-mainnet-all-benchmarks branch from ec2ffde to 1c65204 Compare February 24, 2025 23:01
@al3mart al3mart force-pushed the al3mart/feat-mainnet-xcm-benchmarks branch from a9e6d11 to 9b39ef8 Compare February 24, 2025 23:27
@al3mart al3mart marked this pull request as ready for review February 25, 2025 00:52
@al3mart al3mart requested a review from a team February 25, 2025 00:53
Comment on lines +30 to +33
// Magic number 2 has to do with the fact that we could have up to 2 times
// MaxAssetsIntoHolding in the worst-case scenario.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reason for this is:

// worst-case, holding.len becomes 2 * holding_limit.
// this guarantees that if holding.len() == holding_limit and you have more than
// holding_limit items (which has a best case outcome of holding.len() == holding_limit),
// then the operation is guaranteed to succeed.

source

Also, even though I've found this comment: paritytech/cumulus#2102 (comment)
The reason why this only is applied for NonFungible is not that apparent to me. It seems that it would apply to both cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Worth pinging a Cisco or someone about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clarified in: 0a50386

Comment on lines +108 to +116
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
&ah_on_pop, balance,
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Funding AH sovereign account on pop because the benchmark tries to withdraw from destination as a way to verify the benchmark.

I believe that makes sense for reserve transfers happening within the reserve itself. Not quite that for our case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@peterwht peterwht left a comment

Choose a reason for hiding this comment

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

Very clean PR, almost ready to approve.

// Measured: `0`
// Estimated: `0`
// Minimum execution time: 18_446_744_073_709_551_000 picoseconds.
Weight::from_parts(18_446_744_073_709_551_000, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For future reviewers: this value is so large because we don't support teleporting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks!

Indeed, max weight is applied for unsupported actions.

Comment on lines +30 to +33
// Magic number 2 has to do with the fact that we could have up to 2 times
// MaxAssetsIntoHolding in the worst-case scenario.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Worth pinging a Cisco or someone about?

// Measured: `111`
// Estimated: `1596`
// Minimum execution time: 291_401_000 picoseconds.
Weight::from_parts(291_401_000, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be, I've did these benchmarks in my laptop :)
Recreating weights in our collators will give us a better point to compare.


impl pallet_xcm::benchmarking::Config for Runtime {
type DeliveryHelper = (
polkadot_runtime_common::xcm_sender::ToParachainDeliveryHelper<
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will be better with it 👍 375e9d1

AssetHubParaId::get(),
));
// Pop can only reserve transfer DOT.
// This test needs to be adapted as the features grow.
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you please add a comment on one of the XCM config unit tests?

Basically that way we have this flow:

  1. we change XCM to support other asset transfers
  2. We now have a failing unit test
  3. We fix unit test and see comment that says: "update set_up_complex_asset_transfer ..."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

The worst_case_holding is also one that must be included in this cycle? Perhaps we should create a doc that we can circle back to? Just an idea not saying it as a requirement

@al3mart al3mart requested a review from peterwht February 26, 2025 14:21
Copy link
Collaborator

@peterwht peterwht left a comment

Choose a reason for hiding this comment

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

Great job. Approving!

@peterwht
Copy link
Collaborator

do we need cumulus_pallet_weight_reclaim : https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs#L1486?

@Daanvdplas Daanvdplas self-requested a review February 27, 2025 21:58
Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

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

Nice job!!!

I must say that I didn't expect this complex review and have to finish it tomorrow. Will need some more reference material to give a proper review. Already left some comments you can take a look at.

@al3mart
Copy link
Collaborator Author

al3mart commented Feb 28, 2025

do we need cumulus_pallet_weight_reclaim : https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs#L1486?

Once we move from using cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime> to using the pallet we need to include it in our benchmarks. The pallet didn't ship benchmarks yet for 2412, so I'd suggest to tackle this in a different PR.

Here the PR where it was introduced.

Have created an issue to track this: #480

Comment on lines +108 to +116
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
&ah_on_pop, balance,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Daanvdplas
Copy link
Collaborator

Don't forget to rebase before next review :)

@al3mart al3mart force-pushed the al3mart/feat-mainnet-xcm-benchmarks branch from 7a74982 to 95d1187 Compare February 28, 2025 15:40
@al3mart al3mart force-pushed the al3mart/feat-mainnet-xcm-benchmarks branch from 95d1187 to f6f8af0 Compare February 28, 2025 15:41
Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

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

A few last comments

Comment on lines 127 to 128
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(ParaId::from(
AssetHubParaId::get(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(ParaId::from(
AssetHubParaId::get(),
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
AssetHubParaId::get(),

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@peterwht peterwht left a comment

Choose a reason for hiding this comment

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

Approving again.

  • The code to generate the benchmarks are solid
  • The outputted weight files discrepancies make sense to me as well due to hardware, number of steps, and different XCM configs. So, until we run on production collators this will be sufficient.

@al3mart al3mart requested a review from Daanvdplas March 4, 2025 11:16
Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

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

Well done on this PR, very big and complex undertaking and you helped me understand everything very well!

@al3mart al3mart merged commit 0c41112 into al3mart/feat-mainnet-all-benchmarks Mar 4, 2025
15 checks passed
@al3mart al3mart deleted the al3mart/feat-mainnet-xcm-benchmarks branch March 4, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants