fix: clean up orphaned storage on subnet deregistration
Description
When a subnet is dissolved, its netuid gets recycled for future registrations. Several storage items were not being cleared during remove_network, which means a newly registered subnet could inherit stale state from the previous occupant of that netuid.
This PR ensures all per-subnet storage is properly cleaned up on deregistration:
- EVM allowances:
AllowancesStorageembeds netuid in its second key(spender, netuid), so it can't be cleared withclear_prefix. We introduce aPrecompileCleanupInterfacetrait (mirroring the existingCommitmentsInterfacepattern) to let the pallet invoke cleanup across the crate boundary without creating a circular dependency. - Double maps (
RootAlphaDividendsPerSubnet,VotingPower,RootClaimed): cleared viaclear_prefixsince netuid is the first key. - Simple maps that were previously missed:
MinAllowedUids,MaxWeightsLimit,AdjustmentAlpha,AdjustmentInterval,MinNonImmuneUids,RootProp,RecycleOrBurn,RootClaimableThreshold,VotingPowerTrackingEnabled,VotingPowerDisableAtBlock,VotingPowerEmaAlpha.
Related Issue(s)
- Closes #1867
- 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 — only adds cleanup that was previously missing. No behavioral change for live subnets.
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.shto 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
Subnet deregistration is infrequent, so iterating AllowancesStorage to filter by netuid is acceptable. The simple map removals are single-key deletes with negligible cost.
pls fix the fmt in CI. and the generation make the solution complicated. subnet deregistration and registration not happens frequently. we can just remove the storage after subnet is deregistered.
The PR#2592 is merged. please pull devnet-ready and fix the conflict.
please fix the CI
merge conflicts
In general, the PR looks good to me. For these gc code, I am not sure if we really need it. It can identify some unneeded data like LastColdkeyHotkeyStakeBlock, but some operation need to scan a lot of data. It is risky to consume too much weights.