Skip to content

Commit 1b7402d

Browse files
clear neuron
1 parent 51df2e4 commit 1b7402d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pallets/subtensor/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub mod pallet {
7373
use sp_runtime::traits::{Dispatchable, TrailingZeroInput};
7474
use sp_std::vec;
7575
use sp_std::vec::Vec;
76+
use subtensor_macros::freeze_struct;
7677

7778
#[cfg(not(feature = "std"))]
7879
use alloc::boxed::Box;
@@ -132,6 +133,7 @@ pub mod pallet {
132133
/// Struct for NeuronCertificate.
133134
pub type NeuronCertificateOf = NeuronCertificate;
134135
/// Data structure for NeuronCertificate information.
136+
#[freeze_struct("e6193a76002d491")]
135137
#[derive(Decode, Encode, Default, TypeInfo, PartialEq, Eq, Clone, Debug)]
136138
pub struct NeuronCertificate {
137139
/// The neuron certificate.

pallets/subtensor/src/subnets/uids.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ impl<T: Config> Pallet<T> {
4545
Uids::<T>::insert(netuid, new_hotkey.clone(), uid_to_replace); // Make uid - hotkey association.
4646
BlockAtRegistration::<T>::insert(netuid, uid_to_replace, block_number); // Fill block at registration.
4747
IsNetworkMember::<T>::insert(new_hotkey.clone(), netuid, true); // Fill network is member.
48+
49+
// 4. Clear neuron certificates
50+
NeuronCertificates::<T>::remove(netuid, old_hotkey.clone());
4851
}
4952

5053
/// Appends the uid to the network.

pallets/subtensor/src/swap/swap_hotkey.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ impl<T: Config> Pallet<T> {
276276
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
277277
}
278278
}
279+
280+
// 9.7. Swap neuron TLS certificates.
281+
// NeuronCertificates( netuid, hotkey ) -> Vec<u8> -- the neuron certificate for the hotkey.
282+
if is_network_member {
283+
if let Ok(old_neuron_certificates) =
284+
NeuronCertificates::<T>::try_get(netuid, old_hotkey)
285+
{
286+
NeuronCertificates::<T>::remove(netuid, old_hotkey);
287+
NeuronCertificates::<T>::insert(netuid, new_hotkey, old_neuron_certificates);
288+
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
289+
}
290+
}
279291
}
280292

281293
// 10. Swap Stake.

0 commit comments

Comments
 (0)