Add storage leak detection test for subnet dissolution#2414
Open
ppolewicz wants to merge 1 commit intodevnet-readyfrom
Open
Add storage leak detection test for subnet dissolution#2414ppolewicz wants to merge 1 commit intodevnet-readyfrom
ppolewicz wants to merge 1 commit intodevnet-readyfrom
Conversation
Introduces test_dissolve_network_no_storage_leak which automatically detects per-subnet storage that is not cleaned up when a subnet is dissolved. The test: 1. Snapshots ALL raw storage keys before subnet creation 2. Creates a subnet, registers neurons, stakes, serves axon/prometheus, sets childkeys, sets weights, and runs 2 epochs 3. Dissolves the subnet via root 4. Snapshots ALL storage keys after dissolution 5. Diffs the snapshots, filtering to SubtensorModule and Swap pallets, excluding known global storage items This is future-proof: when a developer adds a new per-netuid StorageMap but forgets cleanup in remove_network, this test fails automatically with a clear error message naming the leaked storage item. Also fixes Swap::ScrapReservoirTao and Swap::ScrapReservoirAlpha not being cleaned up in do_clear_protocol_liquidity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49a4f02 to
4130b14
Compare
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.
Summary
test_dissolve_network_no_storage_leakwhich automatically detects per-subnet storage that is not cleaned up when a subnet is dissolvedSwap::ScrapReservoirTaoandSwap::ScrapReservoirAlphanot being cleaned up indo_clear_protocol_liquidity(caught by the new test)How the test works
sp_io::storage::next_key) before subnet creationSubtensorModuleorSwappallets (excluding a known global allowlist) is reported as a leakWhy this is useful
This test is future-proof: when a developer adds a new per-netuid
StorageMapbut forgets to clean it up inremove_network, this test fails automatically with a clear error message naming the leaked storage item — no need to update the test itself.Test plan
cargo test -p pallet-subtensor --lib— 998 tests passcargo clippy --workspace --all-features --all-targets— clean🤖 Generated with Claude Code