Skip to content

Commit 930ba5c

Browse files
committed
handle AssociatedEvmAddress in trim
1 parent 0ac67c9 commit 930ba5c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pallets/admin-utils/src/tests/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,28 @@ fn test_trim_to_max_allowed_uids() {
24922492
BlockAtRegistration::<Test>::set(netuid, 6, now);
24932493
BlockAtRegistration::<Test>::set(netuid, 11, now);
24942494

2495+
// Set some evm addresses
2496+
AssociatedEvmAddress::<Test>::insert(
2497+
netuid,
2498+
6,
2499+
(sp_core::H160::from_slice(b"0x12345678901234567890"), now),
2500+
);
2501+
AssociatedEvmAddress::<Test>::insert(
2502+
netuid,
2503+
11,
2504+
(sp_core::H160::from_slice(b"0xA2345678901234567890"), now),
2505+
);
2506+
AssociatedEvmAddress::<Test>::insert(
2507+
netuid,
2508+
7,
2509+
(sp_core::H160::from_slice(b"0xB2345678901234567890"), now),
2510+
);
2511+
AssociatedEvmAddress::<Test>::insert(
2512+
netuid,
2513+
14,
2514+
(sp_core::H160::from_slice(b"0xC2345678901234567890"), now),
2515+
);
2516+
24952517
// And some temporally immune uids
24962518
Keys::<Test>::insert(netuid, 7, sn_owner_hotkey1);
24972519
Uids::<Test>::insert(netuid, sn_owner_hotkey1, 7);
@@ -2574,6 +2596,7 @@ fn test_trim_to_max_allowed_uids() {
25742596
for uid in new_max_n..max_n {
25752597
assert!(!Keys::<Test>::contains_key(netuid, uid));
25762598
assert!(!BlockAtRegistration::<Test>::contains_key(netuid, uid));
2599+
assert!(!AssociatedEvmAddress::<Test>::contains_key(netuid, uid));
25772600
for mecid in 0..mechanism_count.into() {
25782601
let netuid_index =
25792602
SubtensorModule::get_mechanism_storage_index(netuid, MechId::from(mecid));
@@ -2631,6 +2654,7 @@ fn test_trim_to_max_allowed_uids() {
26312654
// Actual number of neurons on the network updated after trimming
26322655
assert_eq!(SubnetworkN::<Test>::get(netuid), new_max_n);
26332656

2657+
// Uids match enumeration order
26342658
for i in 0..new_max_n.into() {
26352659
let hotkey = Keys::<Test>::get(netuid, i);
26362660
let uid = Uids::<Test>::get(netuid, hotkey);

pallets/subtensor/src/subnets/uids.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ impl<T: Config> Pallet<T> {
209209
#[allow(unknown_lints)]
210210
Keys::<T>::remove(netuid, neuron_uid);
211211
BlockAtRegistration::<T>::remove(netuid, neuron_uid);
212+
AssociatedEvmAddress::<T>::remove(netuid, neuron_uid);
212213
for mecid in 0..mechanisms_count {
213214
let netuid_index = Self::get_mechanism_storage_index(netuid, mecid.into());
214215
Weights::<T>::remove(netuid_index, neuron_uid);
@@ -315,6 +316,7 @@ impl<T: Config> Pallet<T> {
315316

316317
// Swap uid specific storage items to new compressed positions
317318
Keys::<T>::swap(netuid, old_neuron_uid, netuid, new_neuron_uid);
319+
AssociatedEvmAddress::<T>::swap(netuid, old_neuron_uid, netuid, new_neuron_uid);
318320
BlockAtRegistration::<T>::swap(netuid, old_neuron_uid, netuid, new_neuron_uid);
319321

320322
for mecid in 0..mechanisms_count {

0 commit comments

Comments
 (0)