File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,13 @@ impl<T: Config> Pallet<T> {
9494
9595 // 5. Reset new neuron's values.
9696 Self :: clear_neuron ( netuid, uid_to_replace) ;
97+
98+ // 6. Replacement creates a new logical neuron at the reused UID, so the weights timing
99+ // state should start from this registration block.
100+ for mecid in 0 ..MechanismCountCurrent :: < T > :: get ( netuid) . into ( ) {
101+ let netuid_index = Self :: get_mechanism_storage_index ( netuid, mecid. into ( ) ) ;
102+ Self :: set_last_update_for_uid ( netuid_index, uid_to_replace, block_number) ;
103+ }
97104 }
98105
99106 /// Appends the uid to the network.
Original file line number Diff line number Diff line change @@ -190,6 +190,41 @@ fn test_bonds_cleared_on_replace() {
190190 } ) ;
191191}
192192
193+ #[ test]
194+ fn test_replace_neuron_resets_last_update ( ) {
195+ new_test_ext ( 1 ) . execute_with ( || {
196+ let registration_block: u64 = 0 ;
197+ let replacement_block: u64 = 123 ;
198+ let netuid = NetUid :: from ( 1 ) ;
199+ let tempo: u16 = 13 ;
200+ let hotkey_account_id = U256 :: from ( 1 ) ;
201+ let coldkey_account_id = U256 :: from ( 1234 ) ;
202+ let new_hotkey_account_id = U256 :: from ( 2 ) ;
203+
204+ System :: set_block_number ( registration_block) ;
205+ add_network ( netuid, tempo, 0 ) ;
206+ register_ok_neuron ( netuid, hotkey_account_id, coldkey_account_id, 0 ) ;
207+
208+ let neuron_uid =
209+ SubtensorModule :: get_uid_for_net_and_hotkey ( netuid, & hotkey_account_id) . unwrap ( ) ;
210+ let netuid_index = NetUidStorageIndex :: from ( netuid) ;
211+
212+ LastUpdate :: < Test > :: insert ( netuid_index, vec ! [ 7 ] ) ;
213+
214+ SubtensorModule :: replace_neuron (
215+ netuid,
216+ neuron_uid,
217+ & new_hotkey_account_id,
218+ replacement_block,
219+ ) ;
220+
221+ assert_eq ! (
222+ LastUpdate :: <Test >:: get( netuid_index) [ neuron_uid as usize ] ,
223+ replacement_block
224+ ) ;
225+ } ) ;
226+ }
227+
193228#[ test]
194229fn test_replace_neuron_multiple_subnets ( ) {
195230 new_test_ext ( 1 ) . execute_with ( || {
You can’t perform that action at this time.
0 commit comments