Skip to content

Commit

Permalink
clear neuron
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Aug 31, 2024
1 parent 51df2e4 commit 1b7402d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub mod pallet {
use sp_runtime::traits::{Dispatchable, TrailingZeroInput};
use sp_std::vec;
use sp_std::vec::Vec;
use subtensor_macros::freeze_struct;

#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
Expand Down Expand Up @@ -132,6 +133,7 @@ pub mod pallet {
/// Struct for NeuronCertificate.
pub type NeuronCertificateOf = NeuronCertificate;
/// Data structure for NeuronCertificate information.
#[freeze_struct("e6193a76002d491")]
#[derive(Decode, Encode, Default, TypeInfo, PartialEq, Eq, Clone, Debug)]
pub struct NeuronCertificate {
/// The neuron certificate.
Expand Down
3 changes: 3 additions & 0 deletions pallets/subtensor/src/subnets/uids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ impl<T: Config> Pallet<T> {
Uids::<T>::insert(netuid, new_hotkey.clone(), uid_to_replace); // Make uid - hotkey association.
BlockAtRegistration::<T>::insert(netuid, uid_to_replace, block_number); // Fill block at registration.
IsNetworkMember::<T>::insert(new_hotkey.clone(), netuid, true); // Fill network is member.

// 4. Clear neuron certificates
NeuronCertificates::<T>::remove(netuid, old_hotkey.clone());
}

/// Appends the uid to the network.
Expand Down
12 changes: 12 additions & 0 deletions pallets/subtensor/src/swap/swap_hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ impl<T: Config> Pallet<T> {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
}
}

// 9.7. Swap neuron TLS certificates.
// NeuronCertificates( netuid, hotkey ) -> Vec<u8> -- the neuron certificate for the hotkey.
if is_network_member {
if let Ok(old_neuron_certificates) =
NeuronCertificates::<T>::try_get(netuid, old_hotkey)
{
NeuronCertificates::<T>::remove(netuid, old_hotkey);
NeuronCertificates::<T>::insert(netuid, new_hotkey, old_neuron_certificates);
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
}
}
}

// 10. Swap Stake.
Expand Down

0 comments on commit 1b7402d

Please sign in to comment.