fix: clean up orphaned storage on subnet deregistration#2579
Open
plind-dm wants to merge 4 commits intoopentensor:devnet-readyfrom
Open
fix: clean up orphaned storage on subnet deregistration#2579plind-dm wants to merge 4 commits intoopentensor:devnet-readyfrom
plind-dm wants to merge 4 commits intoopentensor:devnet-readyfrom
Conversation
f2cbbd4 to
a4261ae
Compare
5f14e48 to
462b882
Compare
RootAlphaDividendsPerSubnet is not cleaned up when a subnet is dissolved. Since netuids are recycled (subnet.rs:178-186), stale root dividend entries from the old subnet persist and become visible to the new subnet, potentially affecting run_coinbase dividend calculations. Add clear_prefix for RootAlphaDividendsPerSubnet alongside the existing AlphaDividendsPerSubnet cleanup in remove_network. Closes opentensor#1867
462b882 to
7074c43
Compare
Contributor
|
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. |
Add PrecompileCleanupInterface trait to allow the pallet to invoke cross-crate storage cleanup when a subnet is removed. The precompiles crate iterates and removes all AllowancesStorage entries matching the dissolved netuid, preventing stale EVM approvals from carrying over when the netuid is recycled.
7074c43 to
0010253
Compare
Add PrecompileCleanupInterface no-op to all test mocks (chain-extensions, eco-tests, admin-utils, transaction-fee). Clean up additional orphaned storage items on subnet deregistration: MinAllowedUids, MaxWeightsLimit, AdjustmentAlpha, AdjustmentInterval, MinNonImmuneUids, RootProp, RecycleOrBurn, RootClaimableThreshold, VotingPower, VotingPowerTrackingEnabled, VotingPowerDisableAtBlock, VotingPowerEmaAlpha. Move PrecompileCleanup struct into the precompiles crate for cleaner wiring.
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
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:
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.RootAlphaDividendsPerSubnet,VotingPower,RootClaimed): cleared viaclear_prefixsince netuid is the first key.MinAllowedUids,MaxWeightsLimit,AdjustmentAlpha,AdjustmentInterval,MinNonImmuneUids,RootProp,RecycleOrBurn,RootClaimableThreshold,VotingPowerTrackingEnabled,VotingPowerDisableAtBlock,VotingPowerEmaAlpha.Related Issue(s)
Type of Change
Breaking Change
N/A — only adds cleanup that was previously missing. No behavioral change for live subnets.
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyAdditional Notes
Subnet deregistration is infrequent, so iterating
AllowancesStorageto filter by netuid is acceptable. The simple map removals are single-key deletes with negligible cost.