Skip to content

feat(mainnet): include xcm benchmarks#479

Merged
al3mart merged 32 commits into
al3mart/feat-mainnet-all-benchmarksfrom
al3mart/feat-mainnet-xcm-benchmarks
Mar 4, 2025
Merged

feat(mainnet): include xcm benchmarks#479
al3mart merged 32 commits into
al3mart/feat-mainnet-all-benchmarksfrom
al3mart/feat-mainnet-xcm-benchmarks

Conversation

@al3mart

@al3mart al3mart commented Feb 24, 2025

Copy link
Copy Markdown
Member

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

codecov-commenter commented Feb 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ 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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 thread runtime/mainnet/src/weights/xcm/mod.rs
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
Member 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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@peterwht peterwht left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread runtime/mainnet/src/benchmarks.rs
// 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
Copy Markdown
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
Copy Markdown
Member 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 thread runtime/mainnet/src/weights/xcm/mod.rs
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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member 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.

Comment thread runtime/mainnet/src/benchmarks.rs Outdated

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

@peterwht peterwht left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

@Daanvdplas Daanvdplas left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread runtime/mainnet/src/apis.rs Outdated
Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs Outdated
Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs Outdated
Comment thread runtime/mainnet/src/weights/cumulus_pallet_xcmp_queue.rs Outdated
Comment thread runtime/mainnet/src/weights/pallet_message_queue.rs Outdated
Comment thread runtime/mainnet/src/weights/pallet_message_queue.rs Outdated
Comment thread runtime/mainnet/src/weights/xcm/pallet_xcm_benchmarks_generic.rs
Comment thread runtime/mainnet/src/benchmarks.rs Outdated
@al3mart

al3mart commented Feb 28, 2025

Copy link
Copy Markdown
Member Author

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 thread runtime/mainnet/src/apis.rs
Comment on lines +108 to +116
let _ = <Balances as frame_support::traits::Currency<_>>::make_free_balance_be(
&ah_on_pop, balance,
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs Outdated
Comment thread runtime/mainnet/src/weights/pallet_xcm.rs
Comment thread runtime/mainnet/src/weights/pallet_xcm.rs
Comment thread runtime/mainnet/src/weights/xcm/pallet_xcm_benchmarks_generic.rs
@Daanvdplas

Copy link
Copy Markdown
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

@Daanvdplas Daanvdplas left a comment

Copy link
Copy Markdown
Collaborator

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 thread runtime/mainnet/src/benchmarks.rs Outdated
Comment on lines +127 to +128
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(ParaId::from(
AssetHubParaId::get(),

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/benchmarks.rs
Comment thread runtime/mainnet/src/config/xcm.rs
Comment thread runtime/mainnet/src/config/xcm.rs Outdated
Comment thread runtime/mainnet/src/weights/xcm/mod.rs Outdated
Comment thread runtime/mainnet/src/weights/xcm/pallet_xcm_benchmarks_generic.rs

@peterwht peterwht left a comment

Copy link
Copy Markdown
Collaborator

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

@Daanvdplas Daanvdplas left a comment

Copy link
Copy Markdown
Collaborator

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
@al3mart al3mart deleted the al3mart/feat-mainnet-xcm-benchmarks branch March 4, 2025 16:00
al3mart added a commit that referenced this pull request Mar 11, 2025
* feat(benchmark): add pallet_xcm extrinsic benchmarks

* refactor(benchmkars): amend xcm transfer_assets benchmark

fmt

* style(benchmarks): pretty comments.

* refactor(benchmarks): fund SA of AH on pop in reserve_transfer benchmark

* feat(mainnet): add generic & fungible xcm benchmarks

* refactor(benchmarks): don't define CheckAccount for pallet_xcm_benchmarks::fungible

* refactor(benchmarks): amend benchmarks for pallet_xcm_benchmarks::generic::unsubscribe_version

* feat(mainnet): configure xcm Weigher as WeightInfoBounds

* docs(xcm): missing doc

* refactor(weights): MAX_ASSETS is MaxAssetsIntoHolding

* refactor(mainnet): remove default weights from queue pallets

* docs(xcm): credit source for WeighAssets impl

* docs(xcm): reminders for updating benchmarks

* refactor(mainnet): DeliveryHelper considers delivery to parent

* docs(benchmarks): clarify xcm NonFungible AllOf weight comments

* refactor(api): reorg imports

* style(benchmark): refactor import syntax

* docs(bencmark): better docs for XcmBalances

* refactor(benchmark): define locations via xcm config definitions

* test(xcm): ensure xcm encoding size

* refactor(benchmark): improve worst_case_response

* chore(benchmark): update results for query_response bench

* style(benchmarks): remove RelayAsset

* docs(benchmarks): explain ExistentialDepositAsset

* docs(xcm): note worst_case_holding needs updating

* style(benchmark): better naming

* chore(benchmarks): update xcm benchmarks

visibility

* test(xcm): amend router_uses_ump_for_relay_and_xcmp_for_para

* test(xcm): amend router_uses_ump_for_relay_and_xcmp_for_para

* refactor(benchmarks): unnecessary ParaId::from

* refactor(xcm): unnecessary u64 cast

* test(xcm): msg_length factor is > 1 in price_for_parent_delivery~
al3mart added a commit that referenced this pull request Mar 11, 2025
* refactor(benchmakrs): benchmarks mod in its own file (#477)

refactor(benchmark): reorg files

* feat(benchmarks): add every pallet benchmark to mainnet without XCM

* refactor(benchmarks): rename Assets to TrustBackedAssets

* fix(motion): map to Weightless Error one origin check failure

* fix(monetary): Treausyr BenchmarkHelper to use correct ExistentialDeposit

* refactor(mainnet): remove default weights for assets

* refactor(mainnet): remove default weights for pallet_session

* refactor(mainnet): remove default weights from governance modules

* refactor(mainnet): remove default weights from monetary module

* refactor(mainnet): remove default weights from proxy

* refactor(mainnet): remove default weights from revive

* refactor(mainnet): remove default weights from system modules

* refactor(mainnet): remove default weights from utiliy

* feat(mainnet): introduce benchmarks-ci.sh

* refactor(mainnet): remove default weights for pallet_collator_selection

* style(collation): more correct comment.

* refactor(collation): amend candidates_disabled test

* docs(governance): provide docs for CouncilCollective

* docs(benchmakrs): allow missing docs

* chore(benchmarks): update weights results

* refactor(benchmark): rename TrustBackedAssets to Assets

* feat(mainnet): include xcm benchmarks (#479)

* feat(benchmark): add pallet_xcm extrinsic benchmarks

* refactor(benchmkars): amend xcm transfer_assets benchmark

fmt

* style(benchmarks): pretty comments.

* refactor(benchmarks): fund SA of AH on pop in reserve_transfer benchmark

* feat(mainnet): add generic & fungible xcm benchmarks

* refactor(benchmarks): don't define CheckAccount for pallet_xcm_benchmarks::fungible

* refactor(benchmarks): amend benchmarks for pallet_xcm_benchmarks::generic::unsubscribe_version

* feat(mainnet): configure xcm Weigher as WeightInfoBounds

* docs(xcm): missing doc

* refactor(weights): MAX_ASSETS is MaxAssetsIntoHolding

* refactor(mainnet): remove default weights from queue pallets

* docs(xcm): credit source for WeighAssets impl

* docs(xcm): reminders for updating benchmarks

* refactor(mainnet): DeliveryHelper considers delivery to parent

* docs(benchmarks): clarify xcm NonFungible AllOf weight comments

* refactor(api): reorg imports

* style(benchmark): refactor import syntax

* docs(bencmark): better docs for XcmBalances

* refactor(benchmark): define locations via xcm config definitions

* test(xcm): ensure xcm encoding size

* refactor(benchmark): improve worst_case_response

* chore(benchmark): update results for query_response bench

* style(benchmarks): remove RelayAsset

* docs(benchmarks): explain ExistentialDepositAsset

* docs(xcm): note worst_case_holding needs updating

* style(benchmark): better naming

* chore(benchmarks): update xcm benchmarks

visibility

* test(xcm): amend router_uses_ump_for_relay_and_xcmp_for_para

* test(xcm): amend router_uses_ump_for_relay_and_xcmp_for_para

* refactor(benchmarks): unnecessary ParaId::from

* refactor(xcm): unnecessary u64 cast

* test(xcm): msg_length factor is > 1 in price_for_parent_delivery~

* refactor(motion): improve pallet_motion benchmarking

* test(governance): amend simple_majority_is_never_origin

* refactor(weights): move weights into pop_runtime_common

* syle: fmt

* chore(benchmark): improve benchmarking script

* fix(ci): add and properly propagate pop-runtime-common try-runtime feat
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