Fix orphaned storage cleanup on subnet deregistration#2578
Fix orphaned storage cleanup on subnet deregistration#2578eureka0928 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.
| /// | ||
| /// 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) { |
There was a problem hiding this comment.
This approach is already mentioned at #2478
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.
| #[test] | ||
| fn test_dissolve_network_clears_orphaned_storage() { | ||
| new_test_ext(0).execute_with(|| { | ||
| let cold = U256::from(1); |
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.
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.