diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 2c3a618d1..4f553ed7a 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -73,7 +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; + use subtensor_macros::freeze_struct; #[cfg(not(feature = "std"))] use alloc::boxed::Box; @@ -1175,7 +1175,7 @@ pub mod pallet { StorageDoubleMap<_, Identity, u16, Blake2_128Concat, T::AccountId, AxonInfoOf, OptionQuery>; /// --- MAP ( netuid, hotkey ) --> certificate #[pallet::storage] - pub(super) type NeuronCertificates = StorageDoubleMap< + pub type NeuronCertificates = StorageDoubleMap< _, Identity, u16, diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index 469478dd2..e6c1a62d7 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -31,8 +31,8 @@ impl Pallet { /// * 'placeholder2' (u8): /// - Placeholder for further extra params. /// - /// * 'certificate' (Option>): - /// - Certificate for mutual Tls connection between neurons + /// * 'certificate' (Option>): + /// - Certificate for mutual Tls connection between neurons /// /// # Event: /// * AxonServed; @@ -253,7 +253,7 @@ impl Pallet { } pub fn has_neuron_certificate(netuid: u16, hotkey: &T::AccountId) -> bool { - return NeuronCertificates::::contains_key(netuid, hotkey); + NeuronCertificates::::contains_key(netuid, hotkey) } pub fn has_prometheus_info(netuid: u16, hotkey: &T::AccountId) -> bool { diff --git a/pallets/subtensor/tests/serving.rs b/pallets/subtensor/tests/serving.rs index a6a26a690..a0988fc02 100644 --- a/pallets/subtensor/tests/serving.rs +++ b/pallets/subtensor/tests/serving.rs @@ -129,8 +129,9 @@ fn test_serving_tls_ok() { placeholder2, certificate.clone() )); - let stored_certificate = SubtensorModule::get_neuron_certificate(netuid, uid); - assert_eq!(stored_certificate.unwrap().certificate, certificate); + let stored_certificate = + SubtensorModule::get_neuron_certificate(netuid, uid).expect("Certificate should exist"); + assert_eq!(stored_certificate.certificate, certificate); let new_certificate = "UPDATED_CERT".as_bytes().to_vec(); assert_ok!(SubtensorModule::serve_axon_tls( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -144,8 +145,9 @@ fn test_serving_tls_ok() { placeholder2, new_certificate.clone() )); - let stored_certificate = SubtensorModule::get_neuron_certificate(netuid, uid); - assert_eq!(stored_certificate.unwrap().certificate, new_certificate) + let stored_certificate = + SubtensorModule::get_neuron_certificate(netuid, uid).expect("Certificate should exist"); + assert_eq!(stored_certificate.certificate, new_certificate) }); } diff --git a/pallets/subtensor/tests/swap_hotkey.rs b/pallets/subtensor/tests/swap_hotkey.rs index bff738b86..845338be9 100644 --- a/pallets/subtensor/tests/swap_hotkey.rs +++ b/pallets/subtensor/tests/swap_hotkey.rs @@ -311,6 +311,40 @@ fn test_swap_axons() { }); } +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_certificates --exact --nocapture +#[test] +fn test_swap_certificates() { + new_test_ext(1).execute_with(|| { + let old_hotkey = U256::from(1); + let new_hotkey = U256::from(2); + let coldkey = U256::from(3); + let netuid = 0u16; + let certificate = NeuronCertificate { + certificate: vec![1, 2, 3], + }; + let mut weight = Weight::zero(); + + add_network(netuid, 0, 1); + IsNetworkMember::::insert(old_hotkey, netuid, true); + NeuronCertificates::::insert(netuid, old_hotkey, certificate.clone()); + + assert_ok!(SubtensorModule::perform_hotkey_swap( + &old_hotkey, + &new_hotkey, + &coldkey, + &mut weight + )); + + assert!(!NeuronCertificates::::contains_key( + netuid, old_hotkey + )); + assert_eq!( + NeuronCertificates::::get(netuid, new_hotkey), + Some(certificate) + ); + }); +} + // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_weight_commits --exact --nocapture #[test] fn test_swap_weight_commits() { diff --git a/pallets/subtensor/tests/uids.rs b/pallets/subtensor/tests/uids.rs index 82adc6b8a..743471b5d 100644 --- a/pallets/subtensor/tests/uids.rs +++ b/pallets/subtensor/tests/uids.rs @@ -3,6 +3,7 @@ use crate::mock::*; use frame_support::assert_ok; use frame_system::Config; +use pallet_subtensor::*; use sp_core::U256; mod mock; @@ -32,6 +33,9 @@ fn test_replace_neuron() { let new_hotkey_account_id = U256::from(2); let _new_colkey_account_id = U256::from(12345); + let certificate = NeuronCertificate { + certificate: vec![1, 2, 3], + }; //add network add_network(netuid, tempo, 0); @@ -51,6 +55,9 @@ fn test_replace_neuron() { let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id); assert_ok!(neuron_uid); + // Set a neuron certificate for it + NeuronCertificates::::insert(netuid, hotkey_account_id, certificate); + // Replace the neuron. SubtensorModule::replace_neuron( netuid, @@ -77,6 +84,10 @@ fn test_replace_neuron() { &new_hotkey_account_id )); assert_eq!(curr_hotkey.unwrap(), new_hotkey_account_id); + + // Check neuron certificate was reset + let certificate = SubtensorModule::get_neuron_certificate(netuid, neuron_uid.unwrap()); + assert_eq!(certificate, None); }); }