Skip to content

Introduce netuid generation for storage cleaning#2592

Open
evgeny-s wants to merge 3 commits intodevnet-readyfrom
generation-flag-subnet
Open

Introduce netuid generation for storage cleaning#2592
evgeny-s wants to merge 3 commits intodevnet-readyfrom
generation-flag-subnet

Conversation

@evgeny-s
Copy link
Copy Markdown
Collaborator

Description

Iterating an unbounded StorageDoubleMap is unsafe, so instead of clearing state, we make stale state unreachable.

Design

  • New storage pallet_subtensor::NetuidGeneration: Map<NetUid, u64>, bumped on every do_register_network.
  • AllowancesStorage secondary key changes from (spender, netuid) to (spender, netuid, generation).
  • approve, allowance, increaseAllowance, decreaseAllowance, and transferStakeFrom read the current generation from pallet_subtensor and mix it into the key.
  • After a netuid is deregistered and re-registered, the generation differs, so entries written under the previous lifetime land at an unreachable key, and all reads through the precompile default to 0 (ValueQuery).
  • No iteration, no cleanup hook, no block-time risk.

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

@evgeny-s evgeny-s changed the title introduce netuid generation for storage cleaning Introduce netuid generation for storage cleaning Apr 15, 2026
@evgeny-s evgeny-s added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Apr 15, 2026
@open-junius
Copy link
Copy Markdown
Contributor

Thanks for the solution, I am wondering if we really need it. After we get next generation netuid, the data related old generation is not useful and never can be updated by any transaction. We can remove them all. And I don't think there will be much data for this map in the real production env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants