Skip to content

Conversation

@ppolewicz
Copy link
Collaborator

Summary

  • Adds test_dissolve_network_no_storage_leak which automatically detects per-subnet storage that is not cleaned up when a subnet is dissolved
  • Fixes Swap::ScrapReservoirTao and Swap::ScrapReservoirAlpha not being cleaned up in do_clear_protocol_liquidity (caught by the new test)

How the test works

  1. Snapshots all raw storage keys (via sp_io::storage::next_key) before subnet creation
  2. Creates a subnet and exercises it fully: registers neurons, stakes, serves axon/prometheus, sets childkeys, sets weights, runs 2 epochs (for vpermit/bonds/dividends)
  3. Dissolves the subnet via root
  4. Snapshots all storage keys after dissolution
  5. Any key present in "after" but not in "before" that belongs to SubtensorModule or Swap pallets (excluding a known global allowlist) is reported as a leak

Why this is useful

This test is future-proof: when a developer adds a new per-netuid StorageMap but forgets to clean it up in remove_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 pass
  • cargo clippy --workspace --all-features --all-targets — clean

🤖 Generated with Claude Code

@ppolewicz ppolewicz changed the base branch from taoflow2 to devnet-ready February 10, 2026 20:34
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant