Skip to content

[pallet-conviction-voting] Prevent and remove empty storage entries#7631

Open
Nathy-bajo wants to merge 17 commits into
paritytech:masterfrom
Nathy-bajo:pallet-conviction-voting
Open

[pallet-conviction-voting] Prevent and remove empty storage entries#7631
Nathy-bajo wants to merge 17 commits into
paritytech:masterfrom
Nathy-bajo:pallet-conviction-voting

Conversation

@Nathy-bajo

@Nathy-bajo Nathy-bajo commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

resolves #7458

The conviction-voting pallet was creating and retaining 29,000+ empty storage entries (VotingFor and ClassLocksFor with zero votes, delegations, and locks) which this PR fixes by implementing automatic cleanup after vote/delegation operations, a one-time migration to remove existing empty entries, and a new permissionless extrinsic for manual cleanup—all without breaking changes.

Polkadot address: 121HJWZtD13GJQPD82oEj3gSeHqsRYm1mFgRALu4L96kfPD1

@Nathy-bajo
Nathy-bajo requested a review from a team as a code owner February 19, 2025 16:16
@Nathy-bajo
Nathy-bajo marked this pull request as draft February 19, 2025 16:17
@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

Please review @muharem

Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/migrations.rs Outdated
Comment thread substrate/frame/conviction-voting/src/migrations.rs Outdated
Comment thread substrate/frame/conviction-voting/src/migrations.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
@Nathy-bajo
Nathy-bajo force-pushed the pallet-conviction-voting branch from 224df7d to 8908678 Compare January 19, 2026 07:43
@Nathy-bajo
Nathy-bajo marked this pull request as ready for review January 19, 2026 07:44
@Nathy-bajo
Nathy-bajo requested review from ggwpez and muharem January 19, 2026 07:44
@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

Please review @ggwpez @muharem
Apologies for the delay!

@Nathy-bajo Nathy-bajo changed the title [pallet-conviction-voting] prevent creation of zero-balance records #7458 [pallet-conviction-voting] Prevent and remove empty storage entries Jan 19, 2026
Comment thread substrate/frame/conviction-voting/src/migrations.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated

@muharem muharem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we still let zero balance vote? I do not see the restriction on this regard

@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

do we still let zero balance vote? I do not see the restriction on this regard

I have updated it

@Nathy-bajo
Nathy-bajo requested a review from muharem March 19, 2026 12:35
@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

/cmd prdoc --audience runtime_dev --bump minor

@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

Ready for review @muharem @ggwpez

@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

/cmd label T1-FRAME

@paritytech-cmd-bot-polkadot-sdk paritytech-cmd-bot-polkadot-sdk Bot added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Apr 20, 2026
Comment thread substrate/frame/conviction-voting/src/lib.rs
Comment thread substrate/frame/conviction-voting/src/lib.rs
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs
Comment thread prdoc/pr_7631.prdoc Outdated
Comment thread substrate/frame/conviction-voting/Cargo.toml Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/tests.rs
@Nathy-bajo
Nathy-bajo force-pushed the pallet-conviction-voting branch from 36c1909 to 033a2d2 Compare July 1, 2026 15:58
@Nathy-bajo

Copy link
Copy Markdown
Contributor Author

@muharem All reviews addressed, please take a look!

@Nathy-bajo
Nathy-bajo requested a review from muharem July 1, 2026 17:03
Comment thread substrate/frame/conviction-voting/src/benchmarking.rs
@muharem
muharem requested a review from dhirajs0 July 14, 2026 15:05
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread polkadot/runtime/westend/src/weights/pallet_conviction_voting.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
Comment thread substrate/frame/conviction-voting/src/lib.rs Outdated
}
});

ensure!(voting_cleaned || locks_cleaned, Error::<T, I>::NotVoter);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On a no-op cleanup this returns NotVoter, but the caller isn't expected to be a voter and the target may simply have nothing stale. Overloading NotVoter makes error handling ambiguous. Consider a dedicated variant, e.g. add NothingToClean and use it here:

ensure!(voting_cleaned || locks_cleaned, Error::<T, I>::NothingToClean);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, added NothingToClean and used it for the no-op case.

@dhirajs0

Copy link
Copy Markdown
Contributor

/cmd bench --pallet pallet_conviction_voting

@github-actions

Copy link
Copy Markdown
Contributor

Command "bench --pallet pallet_conviction_voting" has started 🚀 See logs here

@github-actions

Copy link
Copy Markdown
Contributor

Command "bench --pallet pallet_conviction_voting" has finished ✅ See logs here

Details

Subweight results:
File Extrinsic Old New Change [%]
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_conviction_voting.rs remove_other_vote 260.52us 282.11us +8.29
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_conviction_voting.rs vote_new 4.94ms 5.30ms +7.14
substrate/frame/staking-async/runtimes/rc/src/weights/pallet_conviction_voting.rs cleanup_empty_storage 517.20us Added
substrate/frame/staking-async/runtimes/parachain/src/weights/pallet_conviction_voting.rs cleanup_empty_storage 517.20us Added
substrate/frame/conviction-voting/src/weights.rs cleanup_empty_storage 517.20us Added
polkadot/runtime/rococo/src/weights/pallet_conviction_voting.rs cleanup_empty_storage 517.20us Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_conviction_voting.rs cleanup_empty_storage 293.59us Added
Command output:

❌ Failed benchmarks of runtimes/pallets:
-- dev: ['pallet_conviction_voting']
✅ Successful benchmarks of runtimes/pallets:
-- asset-hub-westend: ['pallet_conviction_voting']

@Nathy-bajo
Nathy-bajo requested a review from dhirajs0 July 19, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty storage entries in conviction-voting pallet

6 participants