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

Empty storage entries in conviction-voting pallet #7458

Open
muharem opened this issue Feb 5, 2025 · 3 comments
Open

Empty storage entries in conviction-voting pallet #7458

muharem opened this issue Feb 5, 2025 · 3 comments
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. C2-good-first-issue A task for a first time contributor to become familiar with the Polkadot-SDK.

Comments

@muharem
Copy link
Contributor

muharem commented Feb 5, 2025

Context

After inspecting the Polkadot storage snapshot from January 17, 2025, I found 20575 VotingFor records with zero capital (zero-balance votes, no delegations, no prior locks) and 8522 ClassLocksFor entries with zero-balance locks. These records likely serve no purpose and should not be stored.

Definition of zero record for VotingFor - https://github.com/muharem/polkadot-runtimes/blob/8f2deec8afa1384c56bd3795c6fa3e3e098b02f7/pallets/rc-migrator/src/conviction_voting.rs#L155
Definition of zero record for ClassLocksFor - https://github.com/muharem/polkadot-runtimes/blob/8f2deec8afa1384c56bd3795c6fa3e3e098b02f7/pallets/rc-migrator/src/conviction_voting.rs#L125

Note that a zero vote perhaps should still be possible if an account has delegations and to vote using only those delegations.

Task

Verify or refute the findings above. If the issue is present, prevent the creation of such records and implement a migration or a call to remove them from storage.

@muharem muharem changed the title Fix empty storage entries in conviction-voting pallet Empty storage entries in conviction-voting pallet Feb 5, 2025
@muharem muharem added C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. C2-good-first-issue A task for a first time contributor to become familiar with the Polkadot-SDK. labels Feb 5, 2025
@Nathy-bajo
Copy link

@muharem I'll look into this

@muharem
Copy link
Contributor Author

muharem commented Feb 6, 2025

@muharem I'll look into this

before implementing a fix, please do your own research. share here with your proposal to fix it. we review it together.

@Nathy-bajo
Copy link

@muharem The current implementation of the conviction voting pallet stores zero-balance records in the VotingFor and ClassLocksFor storage maps, which serve no purpose.

Proposed Solution
Prevent Creation of Zero-Balance Records: Modify the try_vote function to return an InsufficientFunds error if a vote has a zero balance. Similarly, update the extend_lock function to skip storing locks with a zero balance.
Migration to Clean Up Existing Zero-Balance Records: Create a new module (migrations.rs) to handle the cleanup of existing zero-balance records. Implement the OnRuntimeUpgrade trait to define the migration logic, which filters out entries with empty voting records or zero lock balances.
Optional: Add a Call to Remove Zero-Balance Records: Introduce a new extrinsic (remove_zero_balance_records) to allow users to remove their own zero-balance records.

I might be wrong. what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. C2-good-first-issue A task for a first time contributor to become familiar with the Polkadot-SDK.
Projects
None yet
Development

No branches or pull requests

2 participants