fix: Prevent and clean up zero-valued entries in Alpha storage maps during hotkey and coldkey swaps#2513
Conversation
|
@open-junius Could you please review this PR? Welcome to any feedbacks. |
|
change the target branch as devnet-ready, not main. |
8cd929a to
369a319
Compare
|
I changed target branch. Thanks! Ready to review |
|
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. |
|
@open-junius Thanks for your feedback! I updated all following your feedback. Could you please review again? |
|
please merge the latest devnet-ready, will fix the e2e test. |
|
@open-junius I merged the latest devnet-ready. Could you take a look once more? |
I would rather keep it with the migration. Please test it first on the mainnet clone, and use multi-block migration if needed. Let's see other opinions on this regard. |
I absolute agree with you. If possible, I want to keep migration in this PR, too. Now I am testing locally. After finishing, I will share result here. Thanks @evgeny-s |
|
Updated:
|
e7ec1f3 to
3fedc8b
Compare
ts-tests/suites/zombienet_staking/12-zero-alpha-prevention.test.ts
Outdated
Show resolved
Hide resolved
83a8392 to
2966490
Compare
|
@open-junius Thanks for your feedback. I removed e2e test. Please review again. |
|
@open-junius Could you tell me why |
You can ignore it. we need merge the main back to devnet-ready sometimes if there is any hotfix in main branch. |
|
|
I have updated the migration script more correctly: |
|
Tested on Finney mainnet clone via
No OOM or block timeout issues. |
|
@open-junius @evgeny-s I'd like you review once more ^^. It works well for me |
It is great, let me review it again. |
Thanks for collect the data, it is vaulable. |
…d multi-block migration to purge existing ones
f9d8183 to
59c82e4
Compare
…osure in migration.rs
|
@sam0x17 @open-junius Could you re-run CI testing? |
…into fix/remove-zero-alpha-entries
…into fix/remove-zero-alpha-entries
…vert out-of-scope LastRateLimitedBlock change
|
Additionally, I added Ready for review now. @open-junius @evgeny-s @sam0x17 |
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.