From f4ec03632056334b0e1e4f1da4d6ed638ebfac77 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 12:00:40 -0400 Subject: [PATCH 1/8] add types for delegate info --- Cargo.lock | 2 + Cargo.toml | 3 +- pallets/subtensor/rpc/Cargo.toml | 1 + pallets/subtensor/rpc/src/lib.rs | 48 +++++++++++++++---- pallets/subtensor/runtime-api/Cargo.toml | 1 + pallets/subtensor/runtime-api/src/lib.rs | 11 +++-- .../subtensor/src/rpc_info/delegate_info.rs | 33 +++++++------ runtime/src/lib.rs | 27 +++++------ 8 files changed, 81 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1536c2b52..638d9c1ad7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9883,6 +9883,7 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", + "sp-core", "sp-rpc", "sp-runtime", "subtensor-custom-rpc-runtime-api", @@ -9894,6 +9895,7 @@ version = "0.0.2" dependencies = [ "frame-support", "pallet-subtensor", + "parity-scale-codec", "serde", "sp-api", ] diff --git a/Cargo.toml b/Cargo.toml index e2af5f69fc..c423d29246 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,6 @@ manual_inspect = "allow" [workspace.dependencies] cargo-husky = { version = "1", default-features = false } clap = "4.5.4" -codec = { version = "3.2.2", default-features = false } enumflags2 = "0.7.9" futures = "0.3.30" hex = { version = "0.4", default-features = false } @@ -80,6 +79,8 @@ walkdir = "2" subtensor-macros = { path = "support/macros" } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false } + frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.16.0-rc1", default-features = false } frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.16.0-rc1" } frame-executive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "v1.16.0-rc1", default-features = false } diff --git a/pallets/subtensor/rpc/Cargo.toml b/pallets/subtensor/rpc/Cargo.toml index 861c313d8f..d49ef15237 100644 --- a/pallets/subtensor/rpc/Cargo.toml +++ b/pallets/subtensor/rpc/Cargo.toml @@ -21,6 +21,7 @@ serde = { workspace = true, features = ["derive"] } # Substrate packages sp-api = { workspace = true } sp-blockchain = { workspace = true } +sp-core = { workspace = true } sp-rpc = { workspace = true } sp-runtime = { workspace = true } diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 2445a5edaa..dbae614b0f 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -1,12 +1,14 @@ //! RPC interface for the custom Subtensor rpc methods +use codec::{Decode, Encode}; use jsonrpsee::{ core::RpcResult, proc_macros::rpc, types::{error::ErrorObject, ErrorObjectOwned}, }; use sp_blockchain::HeaderBackend; -use sp_runtime::traits::Block as BlockT; +use sp_core::hexdisplay::AsBytesRef; +use sp_runtime::{traits::Block as BlockT, AccountId32}; use std::sync::Arc; use sp_api::ProvideRuntimeApi; @@ -108,9 +110,12 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_delegates(at).map_err(|e| { - Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into() - }) + match api.get_delegates(at) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into()) + } + Ok(result) => Ok(result.encode()), + } } fn get_delegate( @@ -121,9 +126,20 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_delegate(at, delegate_account_vec).map_err(|e| { - Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into() - }) + let delegate_account = match AccountId32::decode(&mut delegate_account_vec.as_bytes_ref()) { + Err(e) => { + return Err( + Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into(), + ) + } + Ok(delegate_account) => delegate_account, + }; + match api.get_delegate(at, delegate_account) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into()) + } + Ok(result) => Ok(result.encode()), + } } fn get_delegated( @@ -134,9 +150,21 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_delegated(at, delegatee_account_vec).map_err(|e| { - Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into() - }) + let delegatee_account = match AccountId32::decode(&mut delegatee_account_vec.as_bytes_ref()) + { + Err(e) => { + return Err( + Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into(), + ) + } + Ok(delegatee_account) => delegatee_account, + }; + match api.get_delegated(at, delegatee_account) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get delegates info: {:?}", e)).into()) + } + Ok(result) => Ok(result.encode()), + } } fn get_neurons_lite( diff --git a/pallets/subtensor/runtime-api/Cargo.toml b/pallets/subtensor/runtime-api/Cargo.toml index ef3e04947d..8705e5ba78 100644 --- a/pallets/subtensor/runtime-api/Cargo.toml +++ b/pallets/subtensor/runtime-api/Cargo.toml @@ -13,6 +13,7 @@ workspace = true [dependencies] sp-api = { workspace = true } +codec = { workspace = true } frame-support = { workspace = true } serde = { workspace = true, features = ["derive"] } diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index ca43384b87..987504efea 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -1,14 +1,19 @@ #![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; use alloc::vec::Vec; +use codec::Compact; +use frame_support::sp_runtime::AccountId32; +use pallet_subtensor::rpc_info::{ + delegate_info::DelegateInfo +}; // Here we declare the runtime API. It is implemented it the `impl` block in // src/neuron_info.rs, src/subnet_info.rs, and src/delegate_info.rs sp_api::decl_runtime_apis! { pub trait DelegateInfoRuntimeApi { - fn get_delegates() -> Vec; - fn get_delegate( delegate_account_vec: Vec ) -> Vec; - fn get_delegated( delegatee_account_vec: Vec ) -> Vec; + fn get_delegates() -> Vec>; + fn get_delegate( delegate_account: AccountId32 ) -> Option>; + fn get_delegated( delegatee_account: AccountId32 ) -> Vec<(DelegateInfo, Compact)>; } pub trait NeuronInfoRuntimeApi { diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index a41b6e17e7..a46e1de969 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -2,18 +2,19 @@ use super::*; use frame_support::pallet_prelude::{Decode, Encode}; use frame_support::storage::IterableStorageMap; use frame_support::IterableStorageDoubleMap; +use sp_runtime::AccountId32; use substrate_fixed::types::U64F64; extern crate alloc; use codec::Compact; use sp_core::hexdisplay::AsBytesRef; -#[freeze_struct("5752e4c650a83e0d")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct DelegateInfo { - delegate_ss58: T::AccountId, +#[freeze_struct("66105c2cfec0608d")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] +pub struct DelegateInfo { + delegate_ss58: AccountId, take: Compact, - nominators: Vec<(T::AccountId, Compact)>, // map of nominator_ss58 to stake amount - owner_ss58: T::AccountId, + nominators: Vec<(AccountId, Compact)>, // map of nominator_ss58 to stake amount + owner_ss58: AccountId, registrations: Vec>, // Vec of netuid this delegate is registered on validator_permits: Vec>, // Vec of netuid this delegate has validator permit on return_per_1000: Compact, // Delegators current daily return per 1000 TAO staked minus take fee @@ -21,7 +22,7 @@ pub struct DelegateInfo { } impl Pallet { - fn get_delegate_by_existing_account(delegate: AccountIdOf) -> DelegateInfo { + fn get_delegate_by_existing_account(delegate: AccountIdOf) -> DelegateInfo { let mut nominators = Vec::<(T::AccountId, Compact)>::new(); for (nominator, stake) in @@ -82,10 +83,8 @@ impl Pallet { } } - pub fn get_delegate(delegate_account_vec: Vec) -> Option> { - if delegate_account_vec.len() != 32 { - return None; - } + pub fn get_delegate(delegate_account: AccountId32) -> Option> { + let delegate_account_vec = delegate_account.encode(); let delegate: AccountIdOf = T::AccountId::decode(&mut delegate_account_vec.as_bytes_ref()).ok()?; @@ -100,8 +99,8 @@ impl Pallet { /// get all delegates info from storage /// - pub fn get_delegates() -> Vec> { - let mut delegates = Vec::>::new(); + pub fn get_delegates() -> Vec> { + let mut delegates = Vec::>::new(); for delegate in as IterableStorageMap>::iter_keys() { let delegate_info = Self::get_delegate_by_existing_account(delegate.clone()); delegates.push(delegate_info); @@ -112,12 +111,16 @@ impl Pallet { /// get all delegate info and staked token amount for a given delegatee account /// - pub fn get_delegated(delegatee_account_vec: Vec) -> Vec<(DelegateInfo, Compact)> { + pub fn get_delegated( + delegatee_account: AccountId32, + ) -> Vec<(DelegateInfo, Compact)> { + let delegatee_account_vec = delegatee_account.encode(); + let Ok(delegatee) = T::AccountId::decode(&mut delegatee_account_vec.as_bytes_ref()) else { return Vec::new(); // No delegates for invalid account }; - let mut delegates: Vec<(DelegateInfo, Compact)> = Vec::new(); + let mut delegates: Vec<(DelegateInfo, Compact)> = Vec::new(); for delegate in as IterableStorageMap>::iter_keys() { let staked_to_this_delegatee = Self::get_stake_for_coldkey_and_hotkey(&delegatee.clone(), &delegate.clone()); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6990cb9071..ca1dd64d69 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -11,7 +11,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod check_nonce; mod migrations; -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Compact, Decode, Encode, MaxEncodedLen}; use frame_support::traits::Imbalance; use frame_support::{ dispatch::DispatchResultWithPostInfo, @@ -30,6 +30,9 @@ use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; use pallet_registry::CanRegisterIdentity; +use pallet_subtensor::rpc_info::{ + delegate_info::DelegateInfo +}; use scale_info::TypeInfo; use smallvec::smallvec; use sp_api::impl_runtime_apis; @@ -1032,7 +1035,7 @@ impl pallet_subtensor::Config for Runtime { type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration; } -use sp_runtime::BoundedVec; +use sp_runtime::{AccountId32, BoundedVec}; pub struct AuraPalletIntrf; impl pallet_admin_utils::AuraInterface> for AuraPalletIntrf { @@ -1389,24 +1392,16 @@ impl_runtime_apis! { } impl subtensor_custom_rpc_runtime_api::DelegateInfoRuntimeApi for Runtime { - fn get_delegates() -> Vec { - let result = SubtensorModule::get_delegates(); - result.encode() + fn get_delegates() -> Vec> { + SubtensorModule::get_delegates() } - 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![] - } + fn get_delegate(delegate_account: AccountId32) -> Option> { + SubtensorModule::get_delegate(delegate_account) } - fn get_delegated(delegatee_account_vec: Vec) -> Vec { - let result = SubtensorModule::get_delegated(delegatee_account_vec); - result.encode() + fn get_delegated(delegatee_account: AccountId32) -> Vec<(DelegateInfo, Compact)> { + SubtensorModule::get_delegated(delegatee_account) } } From 253ee71ad40e38efaf2565c22e75e7b9e445f7de Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 15:01:58 -0400 Subject: [PATCH 2/8] add types for neuron info APIs --- pallets/subtensor/rpc/src/lib.rs | 34 ++++++++++----- pallets/subtensor/runtime-api/src/lib.rs | 11 ++--- pallets/subtensor/src/rpc_info/neuron_info.rs | 41 ++++++++++--------- runtime/src/lib.rs | 33 +++++---------- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index dbae614b0f..fec811f1d4 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -175,9 +175,12 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_neurons_lite(at, netuid).map_err(|e| { - Error::RuntimeError(format!("Unable to get neurons lite info: {:?}", e)).into() - }) + match api.get_neurons_lite(at, netuid) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get neurons lite info: {:?}", e)).into()) + } + Ok(neurons) => Ok(neurons.encode()), + } } fn get_neuron_lite( @@ -189,17 +192,24 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_neuron_lite(at, netuid, uid).map_err(|e| { - Error::RuntimeError(format!("Unable to get neurons lite info: {:?}", e)).into() - }) + match api.get_neuron_lite(at, netuid, uid) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get neuron lite info: {:?}", e)).into()) + } + Ok(neuron) => Ok(neuron.encode()), + } } fn get_neurons(&self, netuid: u16, at: Option<::Hash>) -> RpcResult> { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_neurons(at, netuid) - .map_err(|e| Error::RuntimeError(format!("Unable to get neurons info: {:?}", e)).into()) + match api.get_neurons(at, netuid) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get neurons info: {:?}", e)).into()) + } + Ok(neurons) => Ok(neurons.encode()), + } } fn get_neuron( @@ -211,8 +221,12 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_neuron(at, netuid, uid) - .map_err(|e| Error::RuntimeError(format!("Unable to get neuron info: {:?}", e)).into()) + match api.get_neuron(at, netuid, uid) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get neuron info: {:?}", e)).into()) + } + Ok(neuron) => Ok(neuron.encode()), + } } fn get_subnet_info( diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index 987504efea..cbe0ffdcfa 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -4,7 +4,8 @@ use alloc::vec::Vec; use codec::Compact; use frame_support::sp_runtime::AccountId32; use pallet_subtensor::rpc_info::{ - delegate_info::DelegateInfo + delegate_info::DelegateInfo, + neuron_info::{NeuronInfo, NeuronInfoLite}, }; // Here we declare the runtime API. It is implemented it the `impl` block in @@ -17,10 +18,10 @@ sp_api::decl_runtime_apis! { } pub trait NeuronInfoRuntimeApi { - fn get_neurons(netuid: u16) -> Vec; - fn get_neuron(netuid: u16, uid: u16) -> Vec; - fn get_neurons_lite(netuid: u16) -> Vec; - fn get_neuron_lite(netuid: u16, uid: u16) -> Vec; + fn get_neurons(netuid: u16) -> Vec>; + fn get_neuron(netuid: u16, uid: u16) -> Option>; + fn get_neurons_lite(netuid: u16) -> Vec>; + fn get_neuron_lite(netuid: u16, uid: u16) -> Option>; } pub trait SubnetInfoRuntimeApi { diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index cadd4b6e35..2c83e028ad 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -4,17 +4,17 @@ use frame_support::storage::IterableStorageDoubleMap; extern crate alloc; use codec::Compact; -#[freeze_struct("45e69321f5c74b4b")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct NeuronInfo { - hotkey: T::AccountId, - coldkey: T::AccountId, +#[freeze_struct("d6da7340b3350951")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] +pub struct NeuronInfo { + hotkey: AccountId, + coldkey: AccountId, uid: Compact, netuid: Compact, active: bool, axon_info: AxonInfo, prometheus_info: PrometheusInfo, - stake: Vec<(T::AccountId, Compact)>, // map of coldkey to stake on this neuron/hotkey (includes delegations) + stake: Vec<(AccountId, Compact)>, // map of coldkey to stake on this neuron/hotkey (includes delegations) rank: Compact, emission: Compact, incentive: Compact, @@ -29,17 +29,17 @@ pub struct NeuronInfo { pruning_score: Compact, } -#[freeze_struct("c21f0f4f22bcb2a1")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct NeuronInfoLite { - hotkey: T::AccountId, - coldkey: T::AccountId, +#[freeze_struct("3e9eed057f379b3b")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] +pub struct NeuronInfoLite { + hotkey: AccountId, + coldkey: AccountId, uid: Compact, netuid: Compact, active: bool, axon_info: AxonInfo, prometheus_info: PrometheusInfo, - stake: Vec<(T::AccountId, Compact)>, // map of coldkey to stake on this neuron/hotkey (includes delegations) + stake: Vec<(AccountId, Compact)>, // map of coldkey to stake on this neuron/hotkey (includes delegations) rank: Compact, emission: Compact, incentive: Compact, @@ -54,7 +54,7 @@ pub struct NeuronInfoLite { } impl Pallet { - pub fn get_neurons(netuid: u16) -> Vec> { + pub fn get_neurons(netuid: u16) -> Vec> { if !Self::if_subnet_exist(netuid) { return Vec::new(); } @@ -72,7 +72,7 @@ impl Pallet { neurons } - fn get_neuron_subnet_exists(netuid: u16, uid: u16) -> Option> { + fn get_neuron_subnet_exists(netuid: u16, uid: u16) -> Option> { let hotkey = match Self::get_hotkey_for_net_and_uid(netuid, uid) { Ok(h) => h, Err(_) => return None, @@ -147,7 +147,7 @@ impl Pallet { Some(neuron) } - pub fn get_neuron(netuid: u16, uid: u16) -> Option> { + pub fn get_neuron(netuid: u16, uid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -155,7 +155,10 @@ impl Pallet { Self::get_neuron_subnet_exists(netuid, uid) } - fn get_neuron_lite_subnet_exists(netuid: u16, uid: u16) -> Option> { + fn get_neuron_lite_subnet_exists( + netuid: u16, + uid: u16, + ) -> Option> { let hotkey = match Self::get_hotkey_for_net_and_uid(netuid, uid) { Ok(h) => h, Err(_) => return None, @@ -210,12 +213,12 @@ impl Pallet { Some(neuron) } - pub fn get_neurons_lite(netuid: u16) -> Vec> { + pub fn get_neurons_lite(netuid: u16) -> Vec> { if !Self::if_subnet_exist(netuid) { return Vec::new(); } - let mut neurons: Vec> = Vec::new(); + let mut neurons: Vec> = Vec::new(); let n = Self::get_subnetwork_n(netuid); for uid in 0..n { let neuron = match Self::get_neuron_lite_subnet_exists(netuid, uid) { @@ -228,7 +231,7 @@ impl Pallet { neurons } - pub fn get_neuron_lite(netuid: u16, uid: u16) -> Option> { + pub fn get_neuron_lite(netuid: u16, uid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index ca1dd64d69..71852a3f06 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -31,7 +31,8 @@ use pallet_grandpa::{ }; use pallet_registry::CanRegisterIdentity; use pallet_subtensor::rpc_info::{ - delegate_info::DelegateInfo + delegate_info::DelegateInfo, + neuron_info::{NeuronInfo, NeuronInfoLite}, }; use scale_info::TypeInfo; use smallvec::smallvec; @@ -1406,34 +1407,20 @@ impl_runtime_apis! { } impl subtensor_custom_rpc_runtime_api::NeuronInfoRuntimeApi for Runtime { - fn get_neurons_lite(netuid: u16) -> Vec { - let result = SubtensorModule::get_neurons_lite(netuid); - result.encode() + fn get_neurons_lite(netuid: u16) -> Vec> { + SubtensorModule::get_neurons_lite(netuid) } - 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![] - } + fn get_neuron_lite(netuid: u16, uid: u16) -> Option> { + SubtensorModule::get_neuron_lite(netuid, uid) } - fn get_neurons(netuid: u16) -> Vec { - let result = SubtensorModule::get_neurons(netuid); - result.encode() + fn get_neurons(netuid: u16) -> Vec> { + SubtensorModule::get_neurons(netuid) } - 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![] - } + fn get_neuron(netuid: u16, uid: u16) -> Option> { + SubtensorModule::get_neuron(netuid, uid) } } From 622c0cd4787a01e7d73815e19a74b603ec91578e Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 18:26:52 -0400 Subject: [PATCH 3/8] add types for subnet info APIs --- pallets/subtensor/rpc/src/lib.rs | 26 +++++++++++++----- pallets/subtensor/runtime-api/src/lib.rs | 7 ++--- pallets/subtensor/src/rpc_info/subnet_info.rs | 18 ++++++------- runtime/src/lib.rs | 27 +++++-------------- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index fec811f1d4..85e4529dab 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -237,8 +237,12 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_subnet_info(at, netuid) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) + match api.get_subnet_info(at, netuid) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) + } + Ok(result) => Ok(result.encode()), + } } fn get_subnet_hyperparams( @@ -249,16 +253,26 @@ where let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_subnet_hyperparams(at, netuid) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) + match api.get_subnet_hyperparams(at, netuid) { + Err(e) => Err(Error::RuntimeError(format!( + "Unable to get subnet hyperparam info: {:?}", + e + )) + .into()), + Ok(result) => Ok(result.encode()), + } } fn get_subnets_info(&self, at: Option<::Hash>) -> RpcResult> { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - api.get_subnets_info(at) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into()) + match api.get_subnets_info(at) { + Err(e) => { + Err(Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into()) + } + Ok(result) => Ok(result.encode()), + } } fn get_subnet_info_v2( diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index cbe0ffdcfa..ee38b5a3a0 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -6,6 +6,7 @@ use frame_support::sp_runtime::AccountId32; use pallet_subtensor::rpc_info::{ delegate_info::DelegateInfo, neuron_info::{NeuronInfo, NeuronInfoLite}, + subnet_info::{SubnetHyperparams, SubnetInfo}, }; // Here we declare the runtime API. It is implemented it the `impl` block in @@ -25,11 +26,11 @@ sp_api::decl_runtime_apis! { } pub trait SubnetInfoRuntimeApi { - fn get_subnet_info(netuid: u16) -> Vec; - fn get_subnets_info() -> Vec; + fn get_subnet_info(netuid: u16) -> Option>; + fn get_subnets_info() -> Vec>>; fn get_subnet_info_v2(netuid: u16) -> Vec; fn get_subnets_info_v2() -> Vec; - fn get_subnet_hyperparams(netuid: u16) -> Vec; + fn get_subnet_hyperparams(netuid: u16) -> Option; } pub trait StakeInfoRuntimeApi { diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 9b22e04013..1934968c4c 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -4,9 +4,9 @@ use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; -#[freeze_struct("fe79d58173da662a")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct SubnetInfo { +#[freeze_struct("2a5e9b0845946de0")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] +pub struct SubnetInfo { netuid: Compact, rho: Compact, kappa: Compact, @@ -24,7 +24,7 @@ pub struct SubnetInfo { network_connect: Vec<[u16; 2]>, emission_values: Compact, burn: Compact, - owner: T::AccountId, + owner: AccountId, } #[freeze_struct("65f931972fa13222")] @@ -51,8 +51,8 @@ pub struct SubnetInfov2 { identity: Option, } -#[freeze_struct("55b472510f10e76a")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] +#[freeze_struct("4714b5e2336f7b19")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetHyperparams { rho: Compact, kappa: Compact, @@ -84,7 +84,7 @@ pub struct SubnetHyperparams { } impl Pallet { - pub fn get_subnet_info(netuid: u16) -> Option> { + pub fn get_subnet_info(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -132,7 +132,7 @@ impl Pallet { }) } - pub fn get_subnets_info() -> Vec>> { + pub fn get_subnets_info() -> Vec>> { let mut subnet_netuids = Vec::::new(); let mut max_netuid: u16 = 0; for (netuid, added) in as IterableStorageMap>::iter() { @@ -144,7 +144,7 @@ impl Pallet { } } - let mut subnets_info = Vec::>>::new(); + let mut subnets_info = Vec::>>::new(); for netuid_ in 0..=max_netuid { if subnet_netuids.contains(&netuid_) { subnets_info.push(Self::get_subnet_info(netuid_)); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 71852a3f06..d34d146eaf 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -33,6 +33,7 @@ use pallet_registry::CanRegisterIdentity; use pallet_subtensor::rpc_info::{ delegate_info::DelegateInfo, neuron_info::{NeuronInfo, NeuronInfoLite}, + subnet_info::{SubnetHyperparams, SubnetInfo}, }; use scale_info::TypeInfo; use smallvec::smallvec; @@ -1425,19 +1426,12 @@ impl_runtime_apis! { } 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![] - } + fn get_subnet_info(netuid: u16) -> Option> { + SubtensorModule::get_subnet_info(netuid) } - fn get_subnets_info() -> Vec { - let result = SubtensorModule::get_subnets_info(); - result.encode() + fn get_subnets_info() -> Vec>> { + SubtensorModule::get_subnets_info() } fn get_subnet_info_v2(netuid: u16) -> Vec { @@ -1454,15 +1448,8 @@ impl_runtime_apis! { let result = SubtensorModule::get_subnets_info_v2(); result.encode() } - - 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![] - } + fn get_subnet_hyperparams(netuid: u16) -> Option { + SubtensorModule::get_subnet_hyperparams(netuid) } } From 8ca98f8147a84ec33a1ec88b899f5b735f15fc68 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 18:39:58 -0400 Subject: [PATCH 4/8] add types for stake info APIs --- pallets/subtensor/runtime-api/src/lib.rs | 5 ++- pallets/subtensor/src/rpc_info/stake_info.rs | 41 ++++++-------------- runtime/src/lib.rs | 11 +++--- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index ee38b5a3a0..4b9d903b2f 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -6,6 +6,7 @@ use frame_support::sp_runtime::AccountId32; use pallet_subtensor::rpc_info::{ delegate_info::DelegateInfo, neuron_info::{NeuronInfo, NeuronInfoLite}, + stake_info::StakeInfo, subnet_info::{SubnetHyperparams, SubnetInfo}, }; @@ -34,8 +35,8 @@ sp_api::decl_runtime_apis! { } pub trait StakeInfoRuntimeApi { - fn get_stake_info_for_coldkey( coldkey_account_vec: Vec ) -> Vec; - fn get_stake_info_for_coldkeys( coldkey_account_vecs: Vec> ) -> Vec; + fn get_stake_info_for_coldkey( coldkey_account: AccountId32 ) -> Vec>; + fn get_stake_info_for_coldkeys( coldkey_accounts: Vec ) -> Vec<(AccountId32, Vec>)>; } pub trait SubnetRegistrationRuntimeApi { diff --git a/pallets/subtensor/src/rpc_info/stake_info.rs b/pallets/subtensor/src/rpc_info/stake_info.rs index 1b39e99366..27b3838bd0 100644 --- a/pallets/subtensor/src/rpc_info/stake_info.rs +++ b/pallets/subtensor/src/rpc_info/stake_info.rs @@ -2,27 +2,26 @@ use super::*; use frame_support::pallet_prelude::{Decode, Encode}; extern crate alloc; use codec::Compact; -use sp_core::hexdisplay::AsBytesRef; -#[freeze_struct("86d64c14d71d44b9")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct StakeInfo { - hotkey: T::AccountId, - coldkey: T::AccountId, +#[freeze_struct("4f16c654467bc8b6")] +#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] +pub struct StakeInfo { + hotkey: AccountId, + coldkey: AccountId, stake: Compact, } impl Pallet { fn _get_stake_info_for_coldkeys( coldkeys: Vec, - ) -> Vec<(T::AccountId, Vec>)> { + ) -> Vec<(T::AccountId, Vec>)> { if coldkeys.is_empty() { return Vec::new(); // No coldkeys to check } - let mut stake_info: Vec<(T::AccountId, Vec>)> = Vec::new(); + let mut stake_info: Vec<(T::AccountId, Vec>)> = Vec::new(); for coldkey_ in coldkeys { - let mut stake_info_for_coldkey: Vec> = Vec::new(); + let mut stake_info_for_coldkey: Vec> = Vec::new(); for (hotkey, coldkey, stake) in >::iter() { if coldkey == coldkey_ { @@ -41,19 +40,8 @@ impl Pallet { } pub fn get_stake_info_for_coldkeys( - coldkey_account_vecs: Vec>, - ) -> Vec<(T::AccountId, Vec>)> { - let mut coldkeys: Vec = Vec::new(); - for coldkey_account_vec in coldkey_account_vecs { - if coldkey_account_vec.len() != 32 { - continue; // Invalid coldkey - } - let Ok(coldkey) = T::AccountId::decode(&mut coldkey_account_vec.as_bytes_ref()) else { - continue; - }; - coldkeys.push(coldkey); - } - + coldkeys: Vec, + ) -> Vec<(T::AccountId, Vec>)> { if coldkeys.is_empty() { return Vec::new(); // Invalid coldkey } @@ -61,14 +49,7 @@ impl Pallet { Self::_get_stake_info_for_coldkeys(coldkeys) } - pub fn get_stake_info_for_coldkey(coldkey_account_vec: Vec) -> Vec> { - if coldkey_account_vec.len() != 32 { - return Vec::new(); // Invalid coldkey - } - - let Ok(coldkey) = T::AccountId::decode(&mut coldkey_account_vec.as_bytes_ref()) else { - return Vec::new(); - }; + pub fn get_stake_info_for_coldkey(coldkey: T::AccountId) -> Vec> { let stake_info = Self::_get_stake_info_for_coldkeys(vec![coldkey]); if stake_info.is_empty() { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index d34d146eaf..09f1c9bc31 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -33,6 +33,7 @@ use pallet_registry::CanRegisterIdentity; use pallet_subtensor::rpc_info::{ delegate_info::DelegateInfo, neuron_info::{NeuronInfo, NeuronInfoLite}, + stake_info::StakeInfo, subnet_info::{SubnetHyperparams, SubnetInfo}, }; use scale_info::TypeInfo; @@ -1454,14 +1455,12 @@ impl_runtime_apis! { } impl subtensor_custom_rpc_runtime_api::StakeInfoRuntimeApi for Runtime { - fn get_stake_info_for_coldkey( coldkey_account_vec: Vec ) -> Vec { - let result = SubtensorModule::get_stake_info_for_coldkey( coldkey_account_vec ); - result.encode() + fn get_stake_info_for_coldkey( coldkey_account: AccountId32 ) -> Vec> { + SubtensorModule::get_stake_info_for_coldkey( coldkey_account ) } - fn get_stake_info_for_coldkeys( coldkey_account_vecs: Vec> ) -> Vec { - let result = SubtensorModule::get_stake_info_for_coldkeys( coldkey_account_vecs ); - result.encode() + fn get_stake_info_for_coldkeys( coldkey_accounts: Vec ) -> Vec<(AccountId32, Vec>)> { + SubtensorModule::get_stake_info_for_coldkeys( coldkey_accounts ) } } From c2f53f14263ad3cc1d90958735bd8e0179bbb675 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 18:58:34 -0400 Subject: [PATCH 5/8] remove subnetinfo v2 because we take return types from metadata --- pallets/subtensor/rpc/src/lib.rs | 24 ----- pallets/subtensor/runtime-api/src/lib.rs | 4 +- pallets/subtensor/src/lib.rs | 4 +- pallets/subtensor/src/rpc_info/stake_info.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 99 +------------------ runtime/src/lib.rs | 14 --- 6 files changed, 8 insertions(+), 139 deletions(-) diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index 85e4529dab..4247bf3ac9 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -48,10 +48,6 @@ pub trait SubtensorCustomApi { fn get_subnet_info(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetsInfo")] fn get_subnets_info(&self, at: Option) -> RpcResult>; - #[method(name = "subnetInfo_getSubnetInfo_v2")] - fn get_subnet_info_v2(&self, netuid: u16, at: Option) -> RpcResult>; - #[method(name = "subnetInfo_getSubnetsInf_v2")] - fn get_subnets_info_v2(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetHyperparams")] fn get_subnet_hyperparams(&self, netuid: u16, at: Option) -> RpcResult>; @@ -275,26 +271,6 @@ where } } - fn get_subnet_info_v2( - &self, - netuid: u16, - at: Option<::Hash>, - ) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_subnet_info_v2(at, netuid) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnet info: {:?}", e)).into()) - } - - fn get_subnets_info_v2(&self, at: Option<::Hash>) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_subnets_info_v2(at) - .map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into()) - } - fn get_network_lock_cost(&self, at: Option<::Hash>) -> RpcResult { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index 4b9d903b2f..8cd7860798 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -27,10 +27,8 @@ sp_api::decl_runtime_apis! { } pub trait SubnetInfoRuntimeApi { - fn get_subnet_info(netuid: u16) -> Option>; + fn get_subnet_info(netuid: u16) -> Option>; fn get_subnets_info() -> Vec>>; - fn get_subnet_info_v2(netuid: u16) -> Vec; - fn get_subnets_info_v2() -> Vec; fn get_subnet_hyperparams(netuid: u16) -> Option; } diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 2985736c81..e08f5d4900 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -172,8 +172,8 @@ pub mod pallet { /// Struct for SubnetIdentities. pub type SubnetIdentityOf = SubnetIdentity; /// Data structure for Subnet Identities - #[crate::freeze_struct("f448dc3dad763108")] - #[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)] + #[crate::freeze_struct("4201ebd04ab73869")] + #[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug, TypeInfo)] pub struct SubnetIdentity { /// The name of the subnet pub subnet_name: Vec, diff --git a/pallets/subtensor/src/rpc_info/stake_info.rs b/pallets/subtensor/src/rpc_info/stake_info.rs index 27b3838bd0..43a1e7070a 100644 --- a/pallets/subtensor/src/rpc_info/stake_info.rs +++ b/pallets/subtensor/src/rpc_info/stake_info.rs @@ -3,7 +3,7 @@ use frame_support::pallet_prelude::{Decode, Encode}; extern crate alloc; use codec::Compact; -#[freeze_struct("4f16c654467bc8b6")] +#[freeze_struct("7ba412c8ac3f4677")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct StakeInfo { hotkey: AccountId, diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 1934968c4c..af12d8139e 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -4,7 +4,7 @@ use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; -#[freeze_struct("2a5e9b0845946de0")] +#[freeze_struct("50e2f95a64f9c6f6")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetInfo { netuid: Compact, @@ -25,29 +25,6 @@ pub struct SubnetInfo { emission_values: Compact, burn: Compact, owner: AccountId, -} - -#[freeze_struct("65f931972fa13222")] -#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] -pub struct SubnetInfov2 { - netuid: Compact, - rho: Compact, - kappa: Compact, - difficulty: Compact, - immunity_period: Compact, - max_allowed_validators: Compact, - min_allowed_weights: Compact, - max_weights_limit: Compact, - scaling_law_power: Compact, - subnetwork_n: Compact, - max_allowed_uids: Compact, - blocks_since_last_step: Compact, - tempo: Compact, - network_modality: Compact, - network_connect: Vec<[u16; 2]>, - emission_values: Compact, - burn: Compact, - owner: T::AccountId, identity: Option, } @@ -104,6 +81,8 @@ impl Pallet { let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); let burn: Compact = Self::get_burn_as_u64(netuid).into(); + let identity: Option = SubnetIdentities::::get(netuid); + // DEPRECATED let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { @@ -129,6 +108,7 @@ impl Pallet { emission_values: emission_values.into(), burn, owner: Self::get_subnet_owner(netuid), + identity, }) } @@ -154,77 +134,6 @@ impl Pallet { subnets_info } - pub fn get_subnet_info_v2(netuid: u16) -> Option> { - if !Self::if_subnet_exist(netuid) { - return None; - } - - let rho = Self::get_rho(netuid); - let kappa = Self::get_kappa(netuid); - let difficulty: Compact = Self::get_difficulty_as_u64(netuid).into(); - let immunity_period = Self::get_immunity_period(netuid); - let max_allowed_validators = Self::get_max_allowed_validators(netuid); - let min_allowed_weights = Self::get_min_allowed_weights(netuid); - let max_weights_limit = Self::get_max_weight_limit(netuid); - let scaling_law_power = Self::get_scaling_law_power(netuid); - let subnetwork_n = Self::get_subnetwork_n(netuid); - let max_allowed_uids = Self::get_max_allowed_uids(netuid); - let blocks_since_last_step = Self::get_blocks_since_last_step(netuid); - let tempo = Self::get_tempo(netuid); - let network_modality = >::get(netuid); - let emission_values = Self::get_emission_value(netuid); - let burn: Compact = Self::get_burn_as_u64(netuid).into(); - let identity: Option = SubnetIdentities::::get(netuid); - - // DEPRECATED - let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); - // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { - // network_connect.push([_netuid_, con_req]); - // } - - Some(SubnetInfov2 { - rho: rho.into(), - kappa: kappa.into(), - difficulty, - immunity_period: immunity_period.into(), - netuid: netuid.into(), - max_allowed_validators: max_allowed_validators.into(), - min_allowed_weights: min_allowed_weights.into(), - max_weights_limit: max_weights_limit.into(), - scaling_law_power: scaling_law_power.into(), - subnetwork_n: subnetwork_n.into(), - max_allowed_uids: max_allowed_uids.into(), - blocks_since_last_step: blocks_since_last_step.into(), - tempo: tempo.into(), - network_modality: network_modality.into(), - network_connect, - emission_values: emission_values.into(), - burn, - owner: Self::get_subnet_owner(netuid), - identity, - }) - } - pub fn get_subnets_info_v2() -> Vec>> { - let mut subnet_netuids = Vec::::new(); - let mut max_netuid: u16 = 0; - for (netuid, added) in as IterableStorageMap>::iter() { - if added { - subnet_netuids.push(netuid); - if netuid > max_netuid { - max_netuid = netuid; - } - } - } - - let mut subnets_info = Vec::>>::new(); - for netuid_ in 0..=max_netuid { - if subnet_netuids.contains(&netuid_) { - subnets_info.push(Self::get_subnet_info(netuid_)); - } - } - - subnets_info - } pub fn get_subnet_hyperparams(netuid: u16) -> Option { if !Self::if_subnet_exist(netuid) { return None; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 09f1c9bc31..54bc4bac96 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1435,20 +1435,6 @@ impl_runtime_apis! { SubtensorModule::get_subnets_info() } - fn get_subnet_info_v2(netuid: u16) -> Vec { - let _result = SubtensorModule::get_subnet_info_v2(netuid); - if _result.is_some() { - let result = _result.expect("Could not get SubnetInfo"); - result.encode() - } else { - vec![] - } - } - - fn get_subnets_info_v2() -> Vec { - let result = SubtensorModule::get_subnets_info_v2(); - result.encode() - } fn get_subnet_hyperparams(netuid: u16) -> Option { SubtensorModule::get_subnet_hyperparams(netuid) } From 3e83907762ff682a016a9d44faa76c5a603a106a Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Fri, 27 Sep 2024 19:02:58 -0400 Subject: [PATCH 6/8] remove extra derive --- pallets/subtensor/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index e08f5d4900..2985736c81 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -172,8 +172,8 @@ pub mod pallet { /// Struct for SubnetIdentities. pub type SubnetIdentityOf = SubnetIdentity; /// Data structure for Subnet Identities - #[crate::freeze_struct("4201ebd04ab73869")] - #[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug, TypeInfo)] + #[crate::freeze_struct("f448dc3dad763108")] + #[derive(Encode, Decode, Default, TypeInfo, Clone, PartialEq, Eq, Debug)] pub struct SubnetIdentity { /// The name of the subnet pub subnet_name: Vec, From 2e2467742041340e523dfd537858e2edbd7d06c6 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Sun, 29 Sep 2024 14:42:08 -0400 Subject: [PATCH 7/8] remove duplicate import --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 54bc4bac96..509ef7b772 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1038,7 +1038,7 @@ impl pallet_subtensor::Config for Runtime { type InitialDissolveNetworkScheduleDuration = InitialDissolveNetworkScheduleDuration; } -use sp_runtime::{AccountId32, BoundedVec}; +use sp_runtime::BoundedVec; pub struct AuraPalletIntrf; impl pallet_admin_utils::AuraInterface> for AuraPalletIntrf { From 0fb498d5a80e05f80d4d781e27b8ee369c9bb4fb Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 13 Nov 2024 12:07:14 -0500 Subject: [PATCH 8/8] fix codec workspace ver --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e94ef3dfa3..100137c92c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,9 @@ manual_inspect = "allow" async-trait = "0.1" cargo-husky = { version = "1", default-features = false } clap = "4.5.4" -codec = { version = "3.2.2", default-features = false } +codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [ + "derive", +] } ed25519-dalek = { version = "2.1.0", default-features = false, features = ["alloc"] } enumflags2 = "0.7.9" futures = "0.3.30" @@ -89,6 +91,7 @@ frame-executive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false } frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false } frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false } +frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false } frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }