Skip to content

Commit b0590ec

Browse files
committed
renumber UIDs during trim
1 parent 3e00e41 commit b0590ec

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pallets/subtensor/src/macros/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,7 @@ mod errors {
256256
CannotAffordLockCost,
257257
/// exceeded the rate limit for associating an EVM key.
258258
EvmKeyAssociateRateLimitExceeded,
259+
/// The UID map for the subnet could not be cleared
260+
UidMapCouldNotBeCleared,
259261
}
260262
}

pallets/subtensor/src/subnets/uids.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,21 @@ impl<T: Config> Pallet<T> {
352352
}
353353
}
354354

355+
// Clear the UID map for the subnet
356+
let clear_result = Uids::<T>::clear_prefix(netuid, u32::MAX, None);
357+
// Shouldn't happen, but possible.
358+
ensure!(
359+
clear_result.maybe_cursor.is_none(),
360+
Error::<T>::UidMapCouldNotBeCleared
361+
);
362+
363+
// Insert the new UIDs
364+
for (old_uid, new_uid) in &old_to_new_uid {
365+
// Get the hotkey using Keys map and new UID.
366+
let hotkey = Keys::<T>::get(netuid, *new_uid as u16);
367+
Uids::<T>::insert(netuid, hotkey, *new_uid as u16);
368+
}
369+
355370
// Update the subnet's uid count to reflect the new maximum
356371
SubnetworkN::<T>::insert(netuid, max_n);
357372
}

0 commit comments

Comments
 (0)