subtensor icon indicating copy to clipboard operation
subtensor copied to clipboard

Fix orphaned storage cleanup on subnet deregistration

Open fury0928 opened this issue 7 months ago • 0 comments

Description

Clean up AllowancesStorage, RootAlphaDividendsPerSubnet, and 12 additional storage items that were not being removed during subnet deregistration in remove_network.

AllowancesStorage (EVM staking precompile) uses netuid embedded in the second key (spender, netuid), so it cannot use clear_prefix. A new PrecompileCleanupInterface trait (following the existing CommitmentsInterface pattern) is added to handle this cross-crate cleanup.

RootAlphaDividendsPerSubnet and VotingPower have netuid as the first key and are cleaned via clear_prefix.

11 additional simple StorageMaps were also missing removal: MinAllowedUids, MaxWeightsLimit, AdjustmentAlpha, AdjustmentInterval, MinNonImmuneUids, RootProp, RecycleOrBurn, RootClaimableThreshold, VotingPowerTrackingEnabled, VotingPowerDisableAtBlock, VotingPowerEmaAlpha.

Related Issue(s)

  • Closes #2573

Type of Change

  • [x] 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

N/A — this only adds cleanup of storage that was previously leaked on subnet deregistration.

Checklist

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

Additional Notes

The PrecompileCleanupInterface trait follows the same pattern as the existing CommitmentsInterface — a trait defined in pallet-subtensor, implemented in the precompiles crate, and wired through the runtime Config. This avoids a circular dependency since precompiles depends on pallet-subtensor, not the reverse.

fury0928 avatar Apr 09 '26 01:04 fury0928