diff --git a/pallets/subtensor/src/certificate.rs b/pallets/subtensor/src/certificate.rs new file mode 100644 index 000000000..f0f39845d --- /dev/null +++ b/pallets/subtensor/src/certificate.rs @@ -0,0 +1,4 @@ +use sp_std::vec::Vec; + +// TODO Certificate Encryption Pubkey +pub type Certificate = Vec; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index d0f301c88..54d1e7262 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1470,7 +1470,8 @@ pub mod pallet { ) } - // ---- Serves or updates axon /promethteus information for the neuron associated with the caller. If the caller is + // ---- Same as `serve_axon` but takes a certificate as an extra optional argument. + // Serves or updates axon /promethteus information for the neuron associated with the caller. If the caller is // already registered the metadata is updated. If the caller is not registered this call throws NotRegistered. // // # Args: diff --git a/pallets/subtensor/src/neuron_info.rs b/pallets/subtensor/src/neuron_info.rs index fc4f595b4..c13fca24e 100644 --- a/pallets/subtensor/src/neuron_info.rs +++ b/pallets/subtensor/src/neuron_info.rs @@ -79,14 +79,10 @@ impl Pallet { } fn get_neuron_subnet_exists(netuid: u16, uid: u16) -> Option> { - let _hotkey = Self::get_hotkey_for_net_and_uid(netuid, uid); - let hotkey; - if _hotkey.is_err() { - return None; - } else { - // No error, hotkey was registered - hotkey = _hotkey.expect("Hotkey should exist"); - } + let hotkey = match Self::get_hotkey_for_net_and_uid(netuid, uid) { + Ok(hotkey) => hotkey, // hotkey was registered + Err(_) => return None, + }; let axon_info = Self::get_axon_info(netuid, &hotkey.clone()); @@ -175,32 +171,23 @@ impl Pallet { return None; } - let _hotkey = Self::get_hotkey_for_net_and_uid(netuid, uid); - let hotkey; - if _hotkey.is_err() { - return None; - } else { - // No error, hotkey was registered - hotkey = _hotkey.expect("Hotkey should exist"); - } + let hotkey = match Self::get_hotkey_for_net_and_uid(netuid, uid) { + Ok(hotkey) => hotkey, // hotkey was registered + Err(_) => return None, + }; if Self::has_neuron_certificate(netuid, &hotkey) { - let certificate = NeuronCertificates::::get(netuid, hotkey).unwrap(); - Some(certificate) + NeuronCertificates::::get(netuid, hotkey) } else { None } } fn get_neuron_lite_subnet_exists(netuid: u16, uid: u16) -> Option> { - let _hotkey = Self::get_hotkey_for_net_and_uid(netuid, uid); - let hotkey; - if _hotkey.is_err() { - return None; - } else { - // No error, hotkey was registered - hotkey = _hotkey.expect("Hotkey should exist"); - } + let hotkey = match Self::get_hotkey_for_net_and_uid(netuid, uid) { + Ok(hotkey) => hotkey, // hotkey was registered + Err(_) => return None, + }; let axon_info = Self::get_axon_info(netuid, &hotkey.clone()); diff --git a/pallets/subtensor/src/serving.rs b/pallets/subtensor/src/serving.rs index f517e5379..c09d5f454 100644 --- a/pallets/subtensor/src/serving.rs +++ b/pallets/subtensor/src/serving.rs @@ -34,6 +34,9 @@ impl Pallet { // * 'placeholder2' (u8): // - Placeholder for further extra params. // + // * 'certificate' (Option>): + // - Certificate for mutual Tls connection between neurons + // // # Event: // * AxonServed; // - On successfully serving the axon info. diff --git a/pallets/subtensor/tests/serving.rs b/pallets/subtensor/tests/serving.rs index a036dc471..fcb4021ff 100644 --- a/pallets/subtensor/tests/serving.rs +++ b/pallets/subtensor/tests/serving.rs @@ -99,7 +99,7 @@ fn test_serving_ok() { fn test_serving_tls_ok() { new_test_ext().execute_with(|| { let hotkey_account_id = U256::from(1); - let uid: u16 = 0; + let uid: u16 = 0; let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 1c8f63e3e..6348e322b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1283,13 +1283,7 @@ impl_runtime_apis! { } fn get_delegate(delegate_account_vec: Vec) -> Vec { - let _result = SubtensorModule::get_delegate(delegate_account_vec); - if _result.is_some() { - let result = _result.expect("Could not get DelegateInfo"); - result.encode() - } else { - vec![] - } + SubtensorModule::get_delegate(delegate_account_vec).map(|r| r.encode()).unwrap_or(vec![]) } fn get_delegated(delegatee_account_vec: Vec) -> Vec { @@ -1305,13 +1299,7 @@ impl_runtime_apis! { } fn get_neuron_lite(netuid: u16, uid: u16) -> Vec { - let _result = SubtensorModule::get_neuron_lite(netuid, uid); - if _result.is_some() { - let result = _result.expect("Could not get NeuronInfoLite"); - result.encode() - } else { - vec![] - } + SubtensorModule::get_neuron_lite(netuid, uid).map(|r| r.encode()).unwrap_or(vec![]) } fn get_neurons(netuid: u16) -> Vec { @@ -1320,35 +1308,17 @@ impl_runtime_apis! { } fn get_neuron(netuid: u16, uid: u16) -> Vec { - let _result = SubtensorModule::get_neuron(netuid, uid); - if _result.is_some() { - let result = _result.expect("Could not get NeuronInfo"); - result.encode() - } else { - vec![] - } + SubtensorModule::get_neuron(netuid, uid).map(|r| r.encode()).unwrap_or(vec![]) } fn get_neuron_certificate(netuid: u16, uid: u16) -> Vec { - let _result = SubtensorModule::get_neuron_certificate(netuid, uid); - if _result.is_some() { - let result = _result.expect("Could not get Certificate"); - result.encode() - } else { - vec![] - } + SubtensorModule::get_neuron_certificate(netuid, uid).map(|r| r.encode()).unwrap_or(vec![]) } } impl subtensor_custom_rpc_runtime_api::SubnetInfoRuntimeApi for Runtime { fn get_subnet_info(netuid: u16) -> Vec { - let _result = SubtensorModule::get_subnet_info(netuid); - if _result.is_some() { - let result = _result.expect("Could not get SubnetInfo"); - result.encode() - } else { - vec![] - } + SubtensorModule::get_subnet_info(netuid).map(|r| r.encode()).unwrap_or(vec![]) } fn get_subnets_info() -> Vec { @@ -1357,13 +1327,7 @@ impl_runtime_apis! { } fn get_subnet_hyperparams(netuid: u16) -> Vec { - let _result = SubtensorModule::get_subnet_hyperparams(netuid); - if _result.is_some() { - let result = _result.expect("Could not get SubnetHyperparams"); - result.encode() - } else { - vec![] - } + SubtensorModule::get_subnet_hyperparams(netuid).map(|r| r.encode()).unwrap_or(vec![]) } }