Fix orphaned storage cleanup on subnet deregistration#2578
Open
eureka0928 wants to merge 2 commits intoopentensor:devnet-readyfrom
Open
Fix orphaned storage cleanup on subnet deregistration#2578eureka0928 wants to merge 2 commits intoopentensor:devnet-readyfrom
eureka0928 wants to merge 2 commits intoopentensor:devnet-readyfrom
Conversation
Clean up AllowancesStorage, RootAlphaDividendsPerSubnet, and 12 additional storage items that were not being removed during subnet deregistration in remove_network.
plind-junior
reviewed
Apr 9, 2026
| /// | ||
| /// Because `netuid` is embedded in the second key `(spender, netuid)`, we must iterate | ||
| /// all entries and filter. Called during subnet deregistration. | ||
| pub fn purge_allowances_for_netuid(netuid: u16) { |
Author
There was a problem hiding this comment.
Thanks for the context! Yes, the concern about unbounded iteration was raised in #2478. In practice though, remove_network already does the same iterate-and-filter pattern for several other DMAPs where netuid is not the first key (ChildkeyTake, ChildKeys, ParentKeys, LastHotkeyEmissionOnNetuid, TransactionKeyLastBlock, StakingOperationRateLimiter), so this is consistent with the existing approach.
The number of allowance entries per netuid should also be small in practice since each requires an explicit approve call from an EVM user.
open-junius
reviewed
Apr 9, 2026
| #[test] | ||
| fn test_dissolve_network_clears_orphaned_storage() { | ||
| new_test_ext(0).execute_with(|| { | ||
| let cold = U256::from(1); |
Contributor
There was a problem hiding this comment.
can you add the check AllowancesStorage is removed after subnet de-reg
Adds a test verifying that AllowancesStorage entries for a given netuid are fully removed by purge_allowances_for_netuid, while entries for other netuids remain intact.
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
Clean up
AllowancesStorage,RootAlphaDividendsPerSubnet, and 12 additional storage items that were not being removed during subnet deregistration inremove_network.AllowancesStorage (EVM staking precompile) uses netuid embedded in the second key
(spender, netuid), so it cannot useclear_prefix. A newPrecompileCleanupInterfacetrait (following the existingCommitmentsInterfacepattern) 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)
Type of Change
Breaking Change
N/A — this only adds cleanup of storage that was previously leaked on subnet deregistration.
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyAdditional Notes
The
PrecompileCleanupInterfacetrait follows the same pattern as the existingCommitmentsInterface— a trait defined inpallet-subtensor, implemented in the precompiles crate, and wired through the runtimeConfig. This avoids a circular dependency since precompiles depends onpallet-subtensor, not the reverse.