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

fix: update benchmarks #790

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open

fix: update benchmarks #790

wants to merge 15 commits into from

Conversation

ntn-x2
Copy link
Member

@ntn-x2 ntn-x2 commented Nov 6, 2024

Part of https://github.com/KILTprotocol/ticket/issues/3650, built on top of #787.

What started as a simple fix for the web3name pallet benchmarks, turned out to be a bigger changeset due to a couple of bugs found in the Substrate code, which are mentioned in the self-review I gave myself below.

In a gist, what I did is:

  1. Update the benchmarking logic for the web3name pallet to delegate the name creation to a BenchmarkHelper type.
  2. Implement the trait above for both web3names (which uses the old implementation) and the dotnames
  3. Work around the Substrate bug for our pallets as well as the pallet_collective and pallet_membership pallets which we deploy multiple times
  4. Add the benchmarking of the pallet_membership deployments of the TipsMembership pallet

@ntn-x2 ntn-x2 self-assigned this Nov 6, 2024
// Implementation of `MembershipChanged` equivalent to using `()` but that
// returns `Some(AccountId::new([0; 32]))` in `get_prime()` only when
// benchmarking. TODO: Remove once we upgrade with a version containing the fix: https://github.com/paritytech/polkadot-sdk/pull/6439
pub struct MockMembershipChangedForBenchmarks;
Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't have benchmarks for the tips membership instance, and once I added that I found a bug in the pallet that happens when using () for the MembershipChanged implementation. The pallet will not require this anymore, but until we upgrade to a version with the fix, we need to provide an implementation that for benchmarks, always returns Some as the prime member. So that's why we need this type.


frame_support::parameter_types! {
pub const MaxBalance: crate::Balance = crate::Balance::max_value();
}

/// Workaround for a bug in the benchmarking code around instances.
/// Upstream fix PR: https://github.com/paritytech/polkadot-sdk/pull/6435
#[allow(unused_imports)]
Copy link
Member Author

Choose a reason for hiding this comment

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

See paritytech/polkadot-sdk#6435 for the issue and the fix.

[pallet_collective, Council]
[pallet_technical_committee_collective, TechnicalCommittee]
// pallet_membership instances
[pallet_membership, TipsMembership]
Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't run benchmarks for this instance at all before.

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

// TODO: Remove once the benchmarking stuff fully supports pallet instances.
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately this has to now be done by hand every time a weight file for a pallet instance is generated. We could use the pallets in the lib.rs and simply use super::* here, but I don't have a strong opinion about it.

@ntn-x2 ntn-x2 marked this pull request as ready for review November 11, 2024 13:54
@ntn-x2 ntn-x2 requested a review from Ad96el November 11, 2024 13:54
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.

2 participants