Referenda benchmarks#2626
Merged
Merged
Conversation
shamil-gadelshin
approved these changes
Apr 30, 2026
Collaborator
|
Cargo clippy failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Referenda & multi-collective: split hook traits and add benchmarks
Summary
Adds proper benchmarks to
pallet-referendaandpallet-multi-collective,and reshapes the cross-pallet hook surface (poll hooks, members hook) so
each notification carries its own weight bound. Both pallets' extrinsics
are now weighted from real benchmarks instead of
dev_mode's zerodefaults.
Motivation
Both
pallet-referendaandpallet-multi-collectivewere running withdev_modeenabled, silently zero-weighting every extrinsic. Several oftheir extrinsics fan out into hooks living in other pallets (the voting
backend, the vote-cleanup hook), so even benchmarking each pallet's own
logic isn't enough — the static charge needs to include each hook's
worst case too. To weight them honestly we needed the hook traits to
publish their weight, and we needed real benchmarks for the extrinsics
themselves.
Changes
pallet-referendaPollHooksinto per-event traits(
OnPollCreated,OnPollCompleted); foldedon_tally_updatedintoPollssince it shares the same provider type.weight()so callers cancharge the right static budget upfront.
dev_mode, added aWeightInfotrait, and benchmarkedsubmit,kill,advance_referendum, andon_tally_updated.advance_referendumis benchmarked on the worst-case branch(approve-with-
Review, which fires both hooks); other branches arebounded conservatively from above.
pallet-multi-collectiveMembersstorage is now kept sorted byAccountId. Every write path(
add_member,remove_member,swap_member,set_members) usesbinary_searchplustry_insert/remove, andset_membersdiffsagainst the previous set via
ChangeMembers::compute_members_diff_sorted. The sorted invariantbounds the per-call cost so the extrinsics are actually benchmarkable.
reset_members→set_membersandSetMembersOrigin→SetOrigin; the call takes the full member list and overwrites, so"set" is what it actually does.
force_rotatenow returnsDispatchResultand pays the staticworst-case instead of refunding via
OnNewTerm's returned weight.WeightInfotrait, benchmarked every extrinsic, and wiredweights as
WeightInfo::*().saturating_add(T::OnMembersChanged::weight()).Cross-pallet hook traits
OnMembersChangedfrompallet-multi-collectiveintosubtensor-runtime-common::traits, alongsidePolls,OnPollCreated, andOnPollCompleted.weight(). The runtime'sGovernanceVoteCleanup(theOnMembersChangedimpl that wipessigned-voting state for outgoing members) bounds itself by
MaxMembers × MaxQueued × (per-poll storage cost + on_tally_updated_weight).Runtime wiring
BenchmarkHelperconfig fields on both pallets, wired against theexisting governance tracks and the
Proposers/Economiccollectives so the per-pallet benchmarks have a non-rotatable
collective to fill freely and a rotatable one for
force_rotate.