Skip to content

Commit 4130b14

Browse files
ppolewiczclaude
andcommitted
Add storage leak detection test for subnet dissolution
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>
1 parent 77b60d4 commit 4130b14

3 files changed

Lines changed: 430 additions & 0 deletions

File tree

pallets/subtensor/src/coinbase/root.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,17 @@ impl<T: Config> Pallet<T> {
363363
StakeWeight::<T>::remove(netuid);
364364
LoadedEmission::<T>::remove(netuid);
365365

366+
// --- 18b. Root prop.
367+
RootProp::<T>::remove(netuid);
368+
RootClaimableThreshold::<T>::remove(netuid);
369+
366370
// --- 19. DMAPs where netuid is the FIRST key: clear by prefix.
367371
let _ = BlockAtRegistration::<T>::clear_prefix(netuid, u32::MAX, None);
368372
let _ = Axons::<T>::clear_prefix(netuid, u32::MAX, None);
369373
let _ = NeuronCertificates::<T>::clear_prefix(netuid, u32::MAX, None);
370374
let _ = Prometheus::<T>::clear_prefix(netuid, u32::MAX, None);
371375
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
376+
let _ = RootAlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
372377
let _ = PendingChildKeys::<T>::clear_prefix(netuid, u32::MAX, None);
373378
let _ = AssociatedEvmAddress::<T>::clear_prefix(netuid, u32::MAX, None);
374379

0 commit comments

Comments
 (0)