fix: Prevent and clean up zero-valued entries in Alpha storage maps during hotkey and coldkey swaps#2513
Open
bittoby wants to merge 4 commits intoopentensor:devnet-readyfrom
Open
Conversation
Author
|
@open-junius Could you please review this PR? Welcome to any feedbacks. |
Contributor
|
change the target branch as devnet-ready, not main. |
8cd929a to
369a319
Compare
…ion to purge existing ones
Author
|
I changed target branch. Thanks! Ready to review |
open-junius
reviewed
Mar 19, 2026
open-junius
reviewed
Mar 19, 2026
open-junius
reviewed
Mar 19, 2026
open-junius
reviewed
Mar 19, 2026
open-junius
reviewed
Mar 19, 2026
open-junius
reviewed
Mar 19, 2026
open-junius
reviewed
Mar 19, 2026
Contributor
|
please check https://github.com/opentensor/subtensor/pull/2509/changes, which also prevent some zero value insert. Could you include these storage into the PR. |
Author
|
@open-junius Thanks for your feedback! I updated all following your feedback. Could you please review again? |
Contributor
|
please merge the latest devnet-ready, will fix the e2e test. |
…into fix/remove-zero-alpha-entries
Author
|
@open-junius I merged the latest devnet-ready. Could you take a look once more? |
9 tasks
Author
|
@open-junius All e2e tests passed. thank you. The benchmark testing issue is not relate to my change. |
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.
Description
Prevent and clean up zero-valued entries in Alpha storage maps during hotkey and coldkey swaps.
Coldkey and hotkey swap logic was inserting zero-valued entries into
Alpha,TotalHotkeyShares,TotalHotkeyAlphaLastEpoch, andAlphaDividendsPerSubnetwithout checking if the value was zero first. These entries persist indefinitely and bloat storage - a single coldkey swap could produce ~18k zero entries, and roughly 52% of Alpha entries on-chain are zero-valued.This PR adds zero-guards to all insertion points in
swap_coldkey.rsandswap_hotkey.rs, and includes a one-time migration to purge existing zero entries from the four affected storage maps.Related Issue(s)
Type of Change
Breaking Change
No breaking changes.
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyAdditional Notes
The migration collects the full
Alphamap into memory before removing zero entries. This is intentional - mutating a Substrate storage map while iterating over it is unsafe. The other three maps are smaller and iterated directly. All four maps useHasMigrationRunto ensure idempotency.