diff --git a/Cargo.lock b/Cargo.lock index d71ab4dff7..57e9a21afc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6023,7 +6023,6 @@ dependencies = [ "sp-weights", "substrate-fixed", "subtensor-macros", - "subtensor-runtime-common", ] [[package]] @@ -6124,7 +6123,6 @@ dependencies = [ "sp-runtime", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409-7)", "subtensor-macros", - "subtensor-runtime-common", "tle", "w3f-bls", ] @@ -6537,7 +6535,6 @@ dependencies = [ "sp-version", "substrate-fixed", "subtensor-macros", - "subtensor-runtime-common", "tle", "w3f-bls", ] @@ -11039,7 +11036,6 @@ dependencies = [ "sp-rpc", "sp-runtime", "subtensor-custom-rpc-runtime-api", - "subtensor-runtime-common", ] [[package]] @@ -11052,7 +11048,6 @@ dependencies = [ "serde", "sp-api", "sp-runtime", - "subtensor-runtime-common", ] [[package]] @@ -11108,12 +11103,9 @@ version = "0.1.0" dependencies = [ "frame-support", "parity-scale-codec", - "precompile-utils", "scale-info", - "serde", "sp-core", "sp-runtime", - "subtensor-macros", ] [[package]] diff --git a/common/Cargo.toml b/common/Cargo.toml index acbc72897c..d0b43cdc1b 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -13,12 +13,9 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { workspace = true } frame-support = { workspace = true } -precompile-utils = { workspace = true } scale-info = { workspace = true } -serde = { workspace = true } -sp-core = { workspace = true } sp-runtime = { workspace = true } -subtensor-macros = { workspace = true } +sp-core = { workspace = true } [lints] workspace = true @@ -29,9 +26,7 @@ fast-blocks = [] std = [ "codec/std", "frame-support/std", - "precompile-utils/std", "scale-info/std", - "serde/std", "sp-core/std", "sp-runtime/std", ] diff --git a/common/src/lib.rs b/common/src/lib.rs index 1e040ffad5..75b18e3b14 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,15 +1,11 @@ #![cfg_attr(not(feature = "std"), no_std)] -use core::fmt::{self, Display, Formatter}; -use codec::{Compact, CompactAs, Decode, Encode, Error as CodecError, MaxEncodedLen}; -use frame_support::pallet_prelude::*; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use serde::{Deserialize, Serialize}; use sp_runtime::{ MultiSignature, traits::{IdentifyAccount, Verify}, }; -use subtensor_macros::freeze_struct; /// Balance of an account. pub type Balance = u64; @@ -35,75 +31,6 @@ pub type Nonce = u32; /// Transfers below SMALL_TRANSFER_LIMIT are considered small transfers pub const SMALL_TRANSFER_LIMIT: Balance = 500_000_000; // 0.5 TAO -#[freeze_struct("f1746d0b1911967")] -#[repr(transparent)] -#[derive( - Deserialize, - Serialize, - Clone, - Copy, - Decode, - Default, - Encode, - Eq, - Hash, - MaxEncodedLen, - Ord, - PartialEq, - PartialOrd, - RuntimeDebug, - TypeInfo, -)] -pub struct NetUid(u16); - -impl NetUid { - pub const ROOT: NetUid = Self(0); - - pub fn is_root(&self) -> bool { - *self == Self::ROOT - } - - pub fn next(&self) -> NetUid { - Self(self.0.saturating_add(1)) - } -} - -impl Display for NetUid { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - Display::fmt(&self.0, f) - } -} - -impl CompactAs for NetUid { - type As = u16; - - fn encode_as(&self) -> &Self::As { - &self.0 - } - - fn decode_from(v: Self::As) -> Result { - Ok(Self(v)) - } -} - -impl From> for NetUid { - fn from(c: Compact) -> Self { - c.0 - } -} - -impl From for u16 { - fn from(val: NetUid) -> Self { - val.0 - } -} - -impl From for NetUid { - fn from(value: u16) -> Self { - Self(value) - } -} - #[derive( Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, MaxEncodedLen, TypeInfo, )] diff --git a/pallets/admin-utils/Cargo.toml b/pallets/admin-utils/Cargo.toml index bc1ed21712..b3c1410cca 100644 --- a/pallets/admin-utils/Cargo.toml +++ b/pallets/admin-utils/Cargo.toml @@ -32,7 +32,6 @@ substrate-fixed = { workspace = true } pallet-evm-chain-id = { workspace = true } pallet-drand = { workspace = true, default-features = false } sp-consensus-grandpa = { workspace = true } -subtensor-runtime-common = { workspace = true } [dev-dependencies] sp-core = { workspace = true } @@ -68,7 +67,6 @@ std = [ "sp-tracing/std", "sp-weights/std", "substrate-fixed/std", - "subtensor-runtime-common/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index 917d9008ba..022ea815f9 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -57,243 +57,183 @@ mod benchmarks { #[benchmark] fn sudo_set_serving_rate_limit() { #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 100u64/*serving_rate_limit*/)/*sudo_set_serving_rate_limit*/; + _(RawOrigin::Root, 1u16/*netuid*/, 100u64/*serving_rate_limit*/)/*sudo_set_serving_rate_limit*/; } #[benchmark] fn sudo_set_max_difficulty() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 10000u64/*max_difficulty*/)/*sudo_set_max_difficulty*/; + _(RawOrigin::Root, 1u16/*netuid*/, 10000u64/*max_difficulty*/)/*sudo_set_max_difficulty*/; } #[benchmark] fn sudo_set_min_difficulty() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 1000u64/*min_difficulty*/)/*sudo_set_min_difficulty*/; + _(RawOrigin::Root, 1u16/*netuid*/, 1000u64/*min_difficulty*/)/*sudo_set_min_difficulty*/; } #[benchmark] fn sudo_set_weights_set_rate_limit() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 3u64/*rate_limit*/)/*sudo_set_weights_set_rate_limit*/; + _(RawOrigin::Root, 1u16/*netuid*/, 3u64/*rate_limit*/)/*sudo_set_weights_set_rate_limit*/; } #[benchmark] fn sudo_set_weights_version_key() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 1u64/*version_key*/)/*sudo_set_weights_version_key*/; + _(RawOrigin::Root, 1u16/*netuid*/, 1u64/*version_key*/)/*sudo_set_weights_version_key*/; } #[benchmark] fn sudo_set_bonds_moving_average() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 100u64/*bonds_moving_average*/)/*sudo_set_bonds_moving_average*/; + _(RawOrigin::Root, 1u16/*netuid*/, 100u64/*bonds_moving_average*/)/*sudo_set_bonds_moving_average*/; } #[benchmark] fn sudo_set_bonds_penalty() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 100u16/*bonds_penalty*/)/*sudo_set_bonds_penalty*/; + _(RawOrigin::Root, 1u16/*netuid*/, 100u16/*bonds_penalty*/)/*sudo_set_bonds_penalty*/; } #[benchmark] fn sudo_set_max_allowed_validators() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 10u16/*max_allowed_validators*/)/*sudo_set_max_allowed_validators*/; + _(RawOrigin::Root, 1u16/*netuid*/, 10u16/*max_allowed_validators*/)/*sudo_set_max_allowed_validators*/; } #[benchmark] fn sudo_set_difficulty() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 1200000u64/*difficulty*/)/*sudo_set_difficulty*/; + _(RawOrigin::Root, 1u16/*netuid*/, 1200000u64/*difficulty*/)/*sudo_set_difficulty*/; } #[benchmark] fn sudo_set_adjustment_interval() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 12u16/*adjustment_interval*/)/*sudo_set_adjustment_interval*/; + _(RawOrigin::Root, 1u16/*netuid*/, 12u16/*adjustment_interval*/)/*sudo_set_adjustment_interval*/; } #[benchmark] fn sudo_set_target_registrations_per_interval() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 300u16/*target_registrations*/)/*sudo_set_target_registrations_per_interval*/; + _(RawOrigin::Root, 1u16/*netuid*/, 300u16/*target_registrations*/)/*sudo_set_target_registrations_per_interval*/; } #[benchmark] fn sudo_set_activity_cutoff() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 361u16/*activity_cutoff*/)/*sudo_set_activity_cutoff*/; + _(RawOrigin::Root, 1u16/*netuid*/, 361u16/*activity_cutoff*/)/*sudo_set_activity_cutoff*/; } #[benchmark] fn sudo_set_rho() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 300u16/*rho*/)/*sudo_set_rho*/; + _(RawOrigin::Root, 1u16/*netuid*/, 300u16/*rho*/)/*sudo_set_rho*/; } #[benchmark] fn sudo_set_kappa() { pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*sudo_tempo*/ + 1u16, /*netuid*/ + 1u16, /*sudo_tempo*/ ); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 3u16/*kappa*/)/*set_kappa*/; + _(RawOrigin::Root, 1u16/*netuid*/, 3u16/*kappa*/)/*set_kappa*/; } #[benchmark] fn sudo_set_max_allowed_uids() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 4097u16/*max_allowed_uids*/)/*sudo_set_max_allowed_uids*/; + _(RawOrigin::Root, 1u16/*netuid*/, 4097u16/*max_allowed_uids*/)/*sudo_set_max_allowed_uids*/; } #[benchmark] fn sudo_set_min_allowed_weights() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 10u16/*max_allowed_uids*/)/*sudo_set_min_allowed_weights*/; + _(RawOrigin::Root, 1u16/*netuid*/, 10u16/*max_allowed_uids*/)/*sudo_set_min_allowed_weights*/; } #[benchmark] fn sudo_set_immunity_period() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 100u16/*immunity_period*/)/*sudo_set_immunity_period*/; + _(RawOrigin::Root, 1u16/*netuid*/, 100u16/*immunity_period*/)/*sudo_set_immunity_period*/; } #[benchmark] fn sudo_set_max_weight_limit() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 100u16/*max_weight_limit*/)/*sudo_set_max_weight_limit*/; + _(RawOrigin::Root, 1u16/*netuid*/, 100u16/*max_weight_limit*/)/*sudo_set_max_weight_limit*/; } #[benchmark] fn sudo_set_max_registrations_per_block() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 100u16/*max_registrations*/)/*sudo_set_max_registrations_per_block*/; + _(RawOrigin::Root, 1u16/*netuid*/, 100u16/*max_registrations*/)/*sudo_set_max_registrations_per_block*/; } #[benchmark] fn sudo_set_max_burn() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 10u64/*max_burn*/)/*sudo_set_max_burn*/; + _(RawOrigin::Root, 1u16/*netuid*/, 10u64/*max_burn*/)/*sudo_set_max_burn*/; } #[benchmark] fn sudo_set_min_burn() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 10u64/*min_burn*/)/*sudo_set_min_burn*/; + _(RawOrigin::Root, 1u16/*netuid*/, 10u64/*min_burn*/)/*sudo_set_min_burn*/; } #[benchmark] fn sudo_set_network_registration_allowed() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, true/*registration_allowed*/)/*sudo_set_network_registration_allowed*/; + _(RawOrigin::Root, 1u16/*netuid*/, true/*registration_allowed*/)/*sudo_set_network_registration_allowed*/; } /* benchmark_sudo_set_tempo { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo_default: u16 = 1; <------- unused? let tempo: u16 = 15; let modality: u16 = 0; @@ -304,35 +244,32 @@ mod benchmarks { */ #[benchmark] fn sudo_set_tempo() { - pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*tempo*/ - ); + pallet_subtensor::Pallet::::init_new_network(1u16 /*netuid*/, 1u16 /*tempo*/); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 1u16/*tempo*/)/*sudo_set_tempo*/; + _(RawOrigin::Root, 1u16/*netuid*/, 1u16/*tempo*/)/*sudo_set_tempo*/; } #[benchmark] fn sudo_set_commit_reveal_weights_interval() { pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*sudo_tempo*/ + 1u16, /*netuid*/ + 1u16, /*sudo_tempo*/ ); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, 3u64/*interval*/)/*sudo_set_commit_reveal_weights_interval()*/; + _(RawOrigin::Root, 1u16/*netuid*/, 3u64/*interval*/)/*sudo_set_commit_reveal_weights_interval()*/; } #[benchmark] fn sudo_set_commit_reveal_weights_enabled() { pallet_subtensor::Pallet::::init_new_network( - 1u16.into(), /*netuid*/ - 1u16, /*sudo_tempo*/ + 1u16, /*netuid*/ + 1u16, /*sudo_tempo*/ ); #[extrinsic_call] - _(RawOrigin::Root, 1u16.into()/*netuid*/, true/*enabled*/)/*set_commit_reveal_weights_enabled*/; + _(RawOrigin::Root, 1u16/*netuid*/, true/*enabled*/)/*set_commit_reveal_weights_enabled*/; } //impl_benchmark_test_suite!(AdminUtils, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index b4bd58364f..dadf44f677 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -31,7 +31,6 @@ pub mod pallet { use pallet_subtensor::utils::rate_limiting::TransactionType; use sp_runtime::BoundedVec; use substrate_fixed::types::I96F32; - use subtensor_runtime_common::NetUid; /// The main data structure of the module. #[pallet::pallet] @@ -81,14 +80,14 @@ pub mod pallet { /// Event emitted when the Yuma3 enable is toggled. Yuma3EnableToggled { /// The network identifier. - netuid: NetUid, + netuid: u16, /// Indicates if the Yuma3 enable was enabled or disabled. enabled: bool, }, /// Event emitted when Bonds Reset is toggled. BondsResetToggled { /// The network identifier. - netuid: NetUid, + netuid: u16, /// Indicates if the Bonds Reset was enabled or disabled. enabled: bool, }, @@ -201,7 +200,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_serving_rate_limit( origin: OriginFor, - netuid: NetUid, + netuid: u16, serving_rate_limit: u64, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -223,7 +222,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_min_difficulty( origin: OriginFor, - netuid: NetUid, + netuid: u16, min_difficulty: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -250,7 +249,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_difficulty( origin: OriginFor, - netuid: NetUid, + netuid: u16, max_difficulty: u64, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -277,7 +276,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_weights_version_key( origin: OriginFor, - netuid: NetUid, + netuid: u16, weights_version_key: u64, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin.clone(), netuid)?; @@ -327,7 +326,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_weights_set_rate_limit( origin: OriginFor, - netuid: NetUid, + netuid: u16, weights_set_rate_limit: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -357,7 +356,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_adjustment_interval( origin: OriginFor, - netuid: NetUid, + netuid: u16, adjustment_interval: u16, ) -> DispatchResult { ensure_root(origin)?; @@ -388,7 +387,7 @@ pub mod pallet { ))] pub fn sudo_set_adjustment_alpha( origin: OriginFor, - netuid: NetUid, + netuid: u16, adjustment_alpha: u64, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -414,7 +413,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_weight_limit( origin: OriginFor, - netuid: NetUid, + netuid: u16, max_weight_limit: u16, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -441,7 +440,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_immunity_period( origin: OriginFor, - netuid: NetUid, + netuid: u16, immunity_period: u16, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -468,7 +467,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_min_allowed_weights( origin: OriginFor, - netuid: NetUid, + netuid: u16, min_allowed_weights: u16, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -495,7 +494,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_allowed_uids( origin: OriginFor, - netuid: NetUid, + netuid: u16, max_allowed_uids: u16, ) -> DispatchResult { ensure_root(origin)?; @@ -523,7 +522,7 @@ pub mod pallet { #[pallet::weight(Weight::from_parts(19_590_000, 0) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)))] - pub fn sudo_set_kappa(origin: OriginFor, netuid: NetUid, kappa: u16) -> DispatchResult { + pub fn sudo_set_kappa(origin: OriginFor, netuid: u16, kappa: u16) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( @@ -542,7 +541,7 @@ pub mod pallet { #[pallet::weight(Weight::from_parts(16_420_000, 0) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)))] - pub fn sudo_set_rho(origin: OriginFor, netuid: NetUid, rho: u16) -> DispatchResult { + pub fn sudo_set_rho(origin: OriginFor, netuid: u16, rho: u16) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( @@ -563,7 +562,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_activity_cutoff( origin: OriginFor, - netuid: NetUid, + netuid: u16, activity_cutoff: u16, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -600,7 +599,7 @@ pub mod pallet { ))] pub fn sudo_set_network_registration_allowed( origin: OriginFor, - netuid: NetUid, + netuid: u16, registration_allowed: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -628,7 +627,7 @@ pub mod pallet { ))] pub fn sudo_set_network_pow_registration_allowed( origin: OriginFor, - netuid: NetUid, + netuid: u16, registration_allowed: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -653,7 +652,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_target_registrations_per_interval( origin: OriginFor, - netuid: NetUid, + netuid: u16, target_registrations_per_interval: u16, ) -> DispatchResult { ensure_root(origin)?; @@ -683,7 +682,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_min_burn( origin: OriginFor, - netuid: NetUid, + netuid: u16, min_burn: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -710,7 +709,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_burn( origin: OriginFor, - netuid: NetUid, + netuid: u16, max_burn: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -737,7 +736,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_difficulty( origin: OriginFor, - netuid: NetUid, + netuid: u16, difficulty: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -763,7 +762,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_allowed_validators( origin: OriginFor, - netuid: NetUid, + netuid: u16, max_allowed_validators: u16, ) -> DispatchResult { ensure_root(origin)?; @@ -798,7 +797,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_bonds_moving_average( origin: OriginFor, - netuid: NetUid, + netuid: u16, bonds_moving_average: u64, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin.clone(), netuid)?; @@ -832,7 +831,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_bonds_penalty( origin: OriginFor, - netuid: NetUid, + netuid: u16, bonds_penalty: u16, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -859,7 +858,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_max_registrations_per_block( origin: OriginFor, - netuid: NetUid, + netuid: u16, max_registrations_per_block: u16, ) -> DispatchResult { ensure_root(origin)?; @@ -930,7 +929,7 @@ pub mod pallet { #[pallet::weight(Weight::from_parts(19_900_000, 0) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)))] - pub fn sudo_set_tempo(origin: OriginFor, netuid: NetUid, tempo: u16) -> DispatchResult { + pub fn sudo_set_tempo(origin: OriginFor, netuid: u16, tempo: u16) -> DispatchResult { ensure_root(origin)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -1048,7 +1047,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_rao_recycled( origin: OriginFor, - netuid: NetUid, + netuid: u16, rao_recycled: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -1152,7 +1151,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_commit_reveal_weights_enabled( origin: OriginFor, - netuid: NetUid, + netuid: u16, enabled: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -1180,7 +1179,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_liquid_alpha_enabled( origin: OriginFor, - netuid: NetUid, + netuid: u16, enabled: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -1198,7 +1197,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_alpha_values( origin: OriginFor, - netuid: NetUid, + netuid: u16, alpha_low: u16, alpha_high: u16, ) -> DispatchResult { @@ -1256,7 +1255,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_network_max_stake( origin: OriginFor, - _netuid: NetUid, + _netuid: u16, _max_stake: u64, ) -> DispatchResult { // Ensure the call is made by the root account @@ -1353,7 +1352,7 @@ pub mod pallet { .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn sudo_set_commit_reveal_weights_interval( origin: OriginFor, - netuid: NetUid, + netuid: u16, interval: u64, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -1438,7 +1437,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_toggle_transfer( origin: OriginFor, - netuid: NetUid, + netuid: u16, toggle: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -1512,7 +1511,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_subnet_owner_hotkey( origin: OriginFor, - netuid: NetUid, + netuid: u16, hotkey: T::AccountId, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner(origin.clone(), netuid)?; @@ -1541,7 +1540,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_ema_price_halving_period( origin: OriginFor, - netuid: NetUid, + netuid: u16, ema_halving: u64, ) -> DispatchResult { ensure_root(origin)?; @@ -1570,7 +1569,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_alpha_sigmoid_steepness( origin: OriginFor, - netuid: NetUid, + netuid: u16, steepness: u16, ) -> DispatchResult { ensure_root(origin)?; @@ -1597,7 +1596,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_yuma3_enabled( origin: OriginFor, - netuid: NetUid, + netuid: u16, enabled: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -1625,7 +1624,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_bonds_reset_enabled( origin: OriginFor, - netuid: NetUid, + netuid: u16, enabled: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; @@ -1674,7 +1673,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_sn_owner_hotkey( origin: OriginFor, - netuid: NetUid, + netuid: u16, hotkey: T::AccountId, ) -> DispatchResult { pallet_subtensor::Pallet::::do_set_sn_owner_hotkey(origin, netuid, &hotkey) @@ -1696,7 +1695,7 @@ pub mod pallet { #[pallet::weight((0, DispatchClass::Operational, Pays::No))] pub fn sudo_set_subtoken_enabled( origin: OriginFor, - netuid: NetUid, + netuid: u16, subtoken_enabled: bool, ) -> DispatchResult { ensure_root(origin)?; diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index 830c659c42..960348cecd 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -18,7 +18,6 @@ use sp_runtime::{ }; use sp_std::cmp::Ordering; use sp_weights::Weight; -use subtensor_runtime_common::NetUid; type Block = frame_system::mocking::MockBlock; @@ -413,7 +412,7 @@ pub(crate) fn run_to_block(n: u64) { #[allow(dead_code)] pub fn register_ok_neuron( - netuid: NetUid, + netuid: u16, hotkey_account_id: U256, coldkey_account_id: U256, start_nonce: u64, @@ -444,7 +443,7 @@ pub fn register_ok_neuron( } #[allow(dead_code)] -pub fn add_network(netuid: NetUid, tempo: u16) { +pub fn add_network(netuid: u16, tempo: u16) { SubtensorModule::init_new_network(netuid, tempo); SubtensorModule::set_network_registration_allowed(netuid, true); SubtensorModule::set_network_pow_registration_allowed(netuid, true); diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 9e70858566..b5a2c2f945 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -11,7 +11,6 @@ use pallet_subtensor::Event; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{Pair, U256, ed25519}; use substrate_fixed::types::I96F32; -use subtensor_runtime_common::NetUid; use crate::Error; use crate::pallet::PrecompileEnable; @@ -43,7 +42,7 @@ fn test_sudo_set_default_take() { #[test] fn test_sudo_set_serving_rate_limit() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(3); + let netuid: u16 = 3; let to_be_set: u64 = 10; let init_value: u64 = SubtensorModule::get_serving_rate_limit(netuid); assert_eq!( @@ -67,7 +66,7 @@ fn test_sudo_set_serving_rate_limit() { #[test] fn test_sudo_set_min_difficulty() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_min_difficulty(netuid); @@ -82,7 +81,7 @@ fn test_sudo_set_min_difficulty() { assert_eq!( AdminUtils::sudo_set_min_difficulty( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -100,7 +99,7 @@ fn test_sudo_set_min_difficulty() { #[test] fn test_sudo_set_max_difficulty() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_max_difficulty(netuid); @@ -115,7 +114,7 @@ fn test_sudo_set_max_difficulty() { assert_eq!( AdminUtils::sudo_set_max_difficulty( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -133,7 +132,7 @@ fn test_sudo_set_max_difficulty() { #[test] fn test_sudo_set_weights_version_key() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_weights_version_key(netuid); @@ -148,7 +147,7 @@ fn test_sudo_set_weights_version_key() { assert_eq!( AdminUtils::sudo_set_weights_version_key( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -166,7 +165,7 @@ fn test_sudo_set_weights_version_key() { #[test] fn test_sudo_set_weights_version_key_rate_limit() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; let sn_owner = U256::from(1); @@ -229,7 +228,7 @@ fn test_sudo_set_weights_version_key_rate_limit() { fn test_sudo_set_weights_version_key_rate_limit_root() { // root should not be effected by rate limit new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; let sn_owner = U256::from(1); @@ -267,7 +266,7 @@ fn test_sudo_set_weights_version_key_rate_limit_root() { #[test] fn test_sudo_set_weights_set_rate_limit() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_weights_set_rate_limit(netuid); @@ -282,7 +281,7 @@ fn test_sudo_set_weights_set_rate_limit() { assert_eq!( AdminUtils::sudo_set_weights_set_rate_limit( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -306,7 +305,7 @@ fn test_sudo_set_weights_set_rate_limit() { #[test] fn test_sudo_set_adjustment_interval() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_adjustment_interval(netuid); @@ -321,7 +320,7 @@ fn test_sudo_set_adjustment_interval() { assert_eq!( AdminUtils::sudo_set_adjustment_interval( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -339,7 +338,7 @@ fn test_sudo_set_adjustment_interval() { #[test] fn test_sudo_set_adjustment_alpha() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_adjustment_alpha(netuid); @@ -354,7 +353,7 @@ fn test_sudo_set_adjustment_alpha() { assert_eq!( AdminUtils::sudo_set_adjustment_alpha( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -393,7 +392,7 @@ fn test_sudo_subnet_owner_cut() { #[test] fn test_sudo_set_max_weight_limit() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_max_weight_limit(netuid); @@ -408,7 +407,7 @@ fn test_sudo_set_max_weight_limit() { assert_eq!( AdminUtils::sudo_set_max_weight_limit( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -445,7 +444,7 @@ fn test_sudo_set_issuance() { #[test] fn test_sudo_set_immunity_period() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_immunity_period(netuid); @@ -460,7 +459,7 @@ fn test_sudo_set_immunity_period() { assert_eq!( AdminUtils::sudo_set_immunity_period( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -478,7 +477,7 @@ fn test_sudo_set_immunity_period() { #[test] fn test_sudo_set_min_allowed_weights() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_min_allowed_weights(netuid); @@ -493,7 +492,7 @@ fn test_sudo_set_min_allowed_weights() { assert_eq!( AdminUtils::sudo_set_min_allowed_weights( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -511,7 +510,7 @@ fn test_sudo_set_min_allowed_weights() { #[test] fn test_sudo_set_max_allowed_uids() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_max_allowed_uids(netuid); @@ -526,7 +525,7 @@ fn test_sudo_set_max_allowed_uids() { assert_eq!( AdminUtils::sudo_set_max_allowed_uids( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -544,7 +543,7 @@ fn test_sudo_set_max_allowed_uids() { #[test] fn test_sudo_set_and_decrease_max_allowed_uids() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_max_allowed_uids(netuid); @@ -559,7 +558,7 @@ fn test_sudo_set_and_decrease_max_allowed_uids() { assert_eq!( AdminUtils::sudo_set_max_allowed_uids( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -581,7 +580,7 @@ fn test_sudo_set_and_decrease_max_allowed_uids() { #[test] fn test_sudo_set_kappa() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_kappa(netuid); @@ -596,7 +595,7 @@ fn test_sudo_set_kappa() { assert_eq!( AdminUtils::sudo_set_kappa( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -614,7 +613,7 @@ fn test_sudo_set_kappa() { #[test] fn test_sudo_set_rho() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_rho(netuid); @@ -629,7 +628,7 @@ fn test_sudo_set_rho() { assert_eq!( AdminUtils::sudo_set_rho( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -647,7 +646,7 @@ fn test_sudo_set_rho() { #[test] fn test_sudo_set_activity_cutoff() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = pallet_subtensor::MinActivityCutoff::::get(); add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_activity_cutoff(netuid); @@ -662,7 +661,7 @@ fn test_sudo_set_activity_cutoff() { assert_eq!( AdminUtils::sudo_set_activity_cutoff( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -680,7 +679,7 @@ fn test_sudo_set_activity_cutoff() { #[test] fn test_sudo_set_target_registrations_per_interval() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_target_registrations_per_interval(netuid); @@ -695,7 +694,7 @@ fn test_sudo_set_target_registrations_per_interval() { assert_eq!( AdminUtils::sudo_set_target_registrations_per_interval( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -719,7 +718,7 @@ fn test_sudo_set_target_registrations_per_interval() { #[test] fn test_sudo_set_difficulty() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_difficulty_as_u64(netuid); @@ -734,7 +733,7 @@ fn test_sudo_set_difficulty() { assert_eq!( AdminUtils::sudo_set_difficulty( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -764,7 +763,7 @@ fn test_sudo_set_difficulty() { #[test] fn test_sudo_set_max_allowed_validators() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_max_allowed_validators(netuid); @@ -779,7 +778,7 @@ fn test_sudo_set_max_allowed_validators() { assert_eq!( AdminUtils::sudo_set_max_allowed_validators( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -824,7 +823,7 @@ fn test_sudo_set_stake_threshold() { #[test] fn test_sudo_set_bonds_moving_average() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_bonds_moving_average(netuid); @@ -839,7 +838,7 @@ fn test_sudo_set_bonds_moving_average() { assert_eq!( AdminUtils::sudo_set_bonds_moving_average( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -860,7 +859,7 @@ fn test_sudo_set_bonds_moving_average() { #[test] fn test_sudo_set_bonds_penalty() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); let init_value: u16 = SubtensorModule::get_bonds_penalty(netuid); @@ -875,7 +874,7 @@ fn test_sudo_set_bonds_penalty() { assert_eq!( AdminUtils::sudo_set_bonds_penalty( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -893,7 +892,7 @@ fn test_sudo_set_bonds_penalty() { #[test] fn test_sudo_set_rao_recycled() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); let init_value: u64 = SubtensorModule::get_rao_recycled(netuid); @@ -912,7 +911,7 @@ fn test_sudo_set_rao_recycled() { assert_eq!( AdminUtils::sudo_set_rao_recycled( <::RuntimeOrigin>::root(), - netuid.next(), + netuid + 1, to_be_set ), Err(Error::::SubnetDoesNotExist.into()) @@ -955,7 +954,7 @@ fn test_sudo_set_rao_recycled() { #[test] fn test_sudo_set_network_lock_reduction_interval() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 7200; add_network(netuid, 10); @@ -979,7 +978,7 @@ fn test_sudo_set_network_lock_reduction_interval() { #[test] fn test_sudo_set_network_pow_registration_allowed() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: bool = true; add_network(netuid, 10); @@ -1109,7 +1108,7 @@ fn test_sudo_set_min_delegate_take() { #[test] fn test_sudo_set_commit_reveal_weights_enabled() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 10); let to_be_set: bool = true; @@ -1132,7 +1131,7 @@ fn test_sudo_set_commit_reveal_weights_enabled() { #[test] fn test_sudo_set_liquid_alpha_enabled() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let enabled: bool = true; assert_eq!(!enabled, SubtensorModule::get_liquid_alpha_enabled(netuid)); @@ -1149,7 +1148,7 @@ fn test_sudo_set_liquid_alpha_enabled() { #[test] fn test_set_alpha_values_dispatch_info_ok() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let alpha_low: u16 = 12_u16; let alpha_high: u16 = u16::MAX - 10; let call = RuntimeCall::AdminUtils(crate::Call::sudo_set_alpha_values { @@ -1168,7 +1167,7 @@ fn test_set_alpha_values_dispatch_info_ok() { #[test] fn test_sudo_get_set_alpha() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let alpha_low: u16 = 12_u16; let alpha_high: u16 = u16::MAX - 10; @@ -1386,7 +1385,7 @@ fn test_sudo_set_dissolve_network_schedule_duration() { #[test] fn sudo_set_commit_reveal_weights_interval() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 10); let to_be_set = 55; @@ -1566,7 +1565,7 @@ fn test_sets_a_lower_value_clears_small_nominations() { assert!(to_stake < nominator_min_required_stake_1); // Should be removed when set // Create network - let netuid = NetUid::from(2); + let netuid = 2; add_network(netuid, 10); // Register a neuron @@ -1631,7 +1630,7 @@ fn test_sets_a_lower_value_clears_small_nominations() { #[test] fn test_sudo_set_subnet_owner_hotkey() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey: U256 = U256::from(1); let hotkey: U256 = U256::from(2); @@ -1675,7 +1674,7 @@ fn test_sudo_set_subnet_owner_hotkey() { #[test] fn test_sudo_set_ema_halving() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); @@ -1717,7 +1716,7 @@ fn test_sudo_set_ema_halving() { #[test] fn test_set_sn_owner_hotkey_owner() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: U256 = U256::from(3); let bad_origin_coldkey: U256 = U256::from(4); add_network(netuid, 10); @@ -1762,7 +1761,7 @@ fn test_set_sn_owner_hotkey_owner() { #[test] fn test_set_sn_owner_hotkey_root() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: U256 = U256::from(3); add_network(netuid, 10); @@ -1785,7 +1784,7 @@ fn test_set_sn_owner_hotkey_root() { #[test] fn test_sudo_set_bonds_reset_enabled() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let to_be_set: bool = true; let sn_owner = U256::from(1); add_network(netuid, 10); @@ -1822,7 +1821,7 @@ fn test_sudo_set_bonds_reset_enabled() { #[test] fn test_sudo_set_yuma3_enabled() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let to_be_set: bool = true; let sn_owner = U256::from(1); add_network(netuid, 10); diff --git a/pallets/commitments/Cargo.toml b/pallets/commitments/Cargo.toml index efc1a216db..7b2f49ace8 100644 --- a/pallets/commitments/Cargo.toml +++ b/pallets/commitments/Cargo.toml @@ -40,7 +40,6 @@ sha2 = { workspace = true } log = { workspace = true } pallet-subtensor = { path = "../subtensor", default-features = false } -subtensor-runtime-common = { workspace = true } [dev-dependencies] sp-core = { workspace = true } @@ -50,27 +49,26 @@ pallet-balances = { workspace = true } [features] default = ["std"] std = [ - "ark-serialize/std", "codec/std", - "enumflags2/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", - "hex/std", - "log/std", - "pallet-balances/std", - "pallet-drand/std", - "pallet-subtensor/std", - "rand_chacha/std", "scale-info/std", - "sha2/std", + "sp-std/std", + "sp-runtime/std", + "enumflags2/std", + "pallet-balances/std", "sp-core/std", "sp-io/std", - "sp-runtime/std", - "sp-std/std", - "subtensor-runtime-common/std", + "ark-serialize/std", + "log/std", + "pallet-drand/std", "tle/std", "w3f-bls/std", + "hex/std", + "rand_chacha/std", + "sha2/std", + "pallet-subtensor/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/pallets/commitments/src/benchmarking.rs b/pallets/commitments/src/benchmarking.rs index e8efcc42a7..e66f2a07e8 100644 --- a/pallets/commitments/src/benchmarking.rs +++ b/pallets/commitments/src/benchmarking.rs @@ -35,7 +35,7 @@ mod benchmarks { #[benchmark] fn set_commitment() { - let netuid = NetUid::from(1); + let netuid = 1; let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); diff --git a/pallets/commitments/src/lib.rs b/pallets/commitments/src/lib.rs index 217451a00f..5b1ff7f3a8 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -21,7 +21,6 @@ use scale_info::prelude::collections::BTreeSet; use sp_runtime::SaturatedConversion; use sp_runtime::{Saturating, traits::Zero}; use sp_std::{boxed::Box, vec::Vec}; -use subtensor_runtime_common::NetUid; use tle::{ curves::drand::TinyBLS381, stream_ciphers::AESGCMStreamCipherProvider, @@ -79,7 +78,7 @@ pub mod pallet { /// Used to retrieve the given subnet's tempo pub trait GetTempoInterface { /// Used to retreive the epoch index for the given subnet. - fn get_epoch_index(netuid: NetUid, cur_block: u64) -> u64; + fn get_epoch_index(netuid: u16, cur_block: u64) -> u64; } #[pallet::event] @@ -88,14 +87,14 @@ pub mod pallet { /// A commitment was set Commitment { /// The netuid of the commitment - netuid: NetUid, + netuid: u16, /// The account who: T::AccountId, }, /// A timelock-encrypted commitment was set TimelockCommitment { /// The netuid of the commitment - netuid: NetUid, + netuid: u16, /// The account who: T::AccountId, /// The drand round to reveal @@ -104,7 +103,7 @@ pub mod pallet { /// A timelock-encrypted commitment was auto-revealed CommitmentRevealed { /// The netuid of the commitment - netuid: NetUid, + netuid: u16, /// The account who: T::AccountId, }, @@ -126,7 +125,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn timelocked_index)] pub type TimelockedIndex = - StorageValue<_, BTreeSet<(NetUid, T::AccountId)>, ValueQuery>; + StorageValue<_, BTreeSet<(u16, T::AccountId)>, ValueQuery>; /// Identity data by account #[pallet::storage] @@ -134,7 +133,7 @@ pub mod pallet { pub(super) type CommitmentOf = StorageDoubleMap< _, Identity, - NetUid, + u16, Twox64Concat, T::AccountId, Registration, T::MaxFields, BlockNumberFor>, @@ -146,7 +145,7 @@ pub mod pallet { pub(super) type LastCommitment = StorageDoubleMap< _, Identity, - NetUid, + u16, Twox64Concat, T::AccountId, BlockNumberFor, @@ -158,7 +157,7 @@ pub mod pallet { pub(super) type LastBondsReset = StorageDoubleMap< _, Identity, - NetUid, + u16, Twox64Concat, T::AccountId, BlockNumberFor, @@ -170,7 +169,7 @@ pub mod pallet { pub(super) type RevealedCommitments = StorageDoubleMap< _, Identity, - NetUid, + u16, Twox64Concat, T::AccountId, Vec<(Vec, u64)>, // Reveals<(Data, RevealBlock)> @@ -181,15 +180,8 @@ pub mod pallet { /// in the RateLimit window #[pallet::storage] #[pallet::getter(fn used_space_of)] - pub type UsedSpaceOf = StorageDoubleMap< - _, - Identity, - NetUid, - Twox64Concat, - T::AccountId, - UsageTracker, - OptionQuery, - >; + pub type UsedSpaceOf = + StorageDoubleMap<_, Identity, u16, Twox64Concat, T::AccountId, UsageTracker, OptionQuery>; #[pallet::type_value] /// The default Maximum Space @@ -214,7 +206,7 @@ pub mod pallet { ))] pub fn set_commitment( origin: OriginFor, - netuid: NetUid, + netuid: u16, info: Box>, ) -> DispatchResult { let who = ensure_signed(origin.clone())?; @@ -374,21 +366,21 @@ pub mod pallet { // Interfaces to interact with other pallets pub trait CanCommit { - fn can_commit(netuid: NetUid, who: &AccountId) -> bool; + fn can_commit(netuid: u16, who: &AccountId) -> bool; } impl CanCommit for () { - fn can_commit(_: NetUid, _: &A) -> bool { + fn can_commit(_: u16, _: &A) -> bool { false } } pub trait OnMetadataCommitment { - fn on_metadata_commitment(netuid: NetUid, account: &AccountId); + fn on_metadata_commitment(netuid: u16, account: &AccountId); } impl OnMetadataCommitment for () { - fn on_metadata_commitment(_: NetUid, _: &A) {} + fn on_metadata_commitment(_: u16, _: &A) {} } /************************************************************ diff --git a/pallets/commitments/src/mock.rs b/pallets/commitments/src/mock.rs index 8b8e58150e..4e6aa123bd 100644 --- a/pallets/commitments/src/mock.rs +++ b/pallets/commitments/src/mock.rs @@ -87,7 +87,7 @@ impl TypeInfo for TestMaxFields { pub struct TestCanCommit; impl pallet_commitments::CanCommit for TestCanCommit { - fn can_commit(_netuid: NetUid, _who: &u64) -> bool { + fn can_commit(_netuid: u16, _who: &u64) -> bool { true } } @@ -106,10 +106,10 @@ impl pallet_commitments::Config for Test { pub struct MockTempoInterface; impl pallet_commitments::GetTempoInterface for MockTempoInterface { - fn get_epoch_index(netuid: NetUid, cur_block: u64) -> u64 { + fn get_epoch_index(netuid: u16, cur_block: u64) -> u64 { let tempo = 360; // TODO: configure SubtensorModule in this mock let tempo_plus_one: u64 = tempo.saturating_add(1); - let netuid_plus_one: u64 = (u16::from(netuid) as u64).saturating_add(1); + let netuid_plus_one: u64 = (netuid as u64).saturating_add(1); let block_with_offset: u64 = cur_block.saturating_add(netuid_plus_one); block_with_offset.checked_div(tempo_plus_one).unwrap_or(0) diff --git a/pallets/commitments/src/tests.rs b/pallets/commitments/src/tests.rs index 431d5e521b..62e9444b76 100644 --- a/pallets/commitments/src/tests.rs +++ b/pallets/commitments/src/tests.rs @@ -1,6 +1,5 @@ use codec::Encode; use sp_std::prelude::*; -use subtensor_runtime_common::NetUid; #[cfg(test)] use crate::{ @@ -127,16 +126,15 @@ fn set_commitment_works() { assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(1), - 1.into(), + 1, info.clone() )); - let commitment = - Pallet::::commitment_of(NetUid::from(1), 1).expect("Expected not to panic"); + let commitment = Pallet::::commitment_of(1, 1).expect("Expected not to panic"); let initial_deposit: u64 = ::InitialDeposit::get(); assert_eq!(commitment.deposit, initial_deposit); assert_eq!(commitment.block, 1); - assert_eq!(Pallet::::last_commitment(NetUid::from(1), 1), Some(1)); + assert_eq!(Pallet::::last_commitment(1, 1), Some(1)); }); } @@ -153,11 +151,7 @@ fn set_commitment_too_many_fields_panics() { }); // We never get here, because the constructor panics above. - let _ = Pallet::::set_commitment( - frame_system::RawOrigin::Signed(1).into(), - 1.into(), - info, - ); + let _ = Pallet::::set_commitment(frame_system::RawOrigin::Signed(1).into(), 1, info); }); } @@ -176,14 +170,14 @@ fn set_commitment_updates_deposit() { assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(1), - 1.into(), + 1, info1 )); let initial_deposit: u64 = ::InitialDeposit::get(); let field_deposit: u64 = ::FieldDeposit::get(); let expected_deposit1: u64 = initial_deposit + 2u64 * field_deposit; assert_eq!( - Pallet::::commitment_of(NetUid::from(1), 1) + Pallet::::commitment_of(1, 1) .expect("Expected not to panic") .deposit, expected_deposit1 @@ -191,12 +185,12 @@ fn set_commitment_updates_deposit() { assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(1), - 1.into(), + 1, info2 )); let expected_deposit2: u64 = initial_deposit + 3u64 * field_deposit; assert_eq!( - Pallet::::commitment_of(NetUid::from(1), 1) + Pallet::::commitment_of(1, 1) .expect("Expected not to panic") .deposit, expected_deposit2 @@ -214,16 +208,15 @@ fn event_emission_works() { assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(1), - 1.into(), + 1, info )); let events = System::::events(); - let expected_event = RuntimeEvent::Commitments(Event::Commitment { - netuid: 1.into(), - who: 1, - }); - assert!(events.iter().any(|e| e.event == expected_event)); + assert!(events.iter().any(|e| matches!( + &e.event, + RuntimeEvent::Commitments(Event::Commitment { netuid: 1, who: 1 }) + ))); }); } @@ -263,7 +256,7 @@ fn happy_path_timelock_commitments() { }; let who = 123; - let netuid = NetUid::from(42); + let netuid = 42; System::::set_block_number(1); assert_ok!(Pallet::::set_commitment( @@ -300,7 +293,7 @@ fn happy_path_timelock_commitments() { fn reveal_timelocked_commitment_missing_round_does_nothing() { new_test_ext().execute_with(|| { let who = 1; - let netuid = NetUid::from(2); + let netuid = 2; System::::set_block_number(5); let ciphertext = produce_ciphertext(b"My plaintext", 1000); let data = Data::TimelockEncrypted { @@ -327,7 +320,7 @@ fn reveal_timelocked_commitment_missing_round_does_nothing() { fn reveal_timelocked_commitment_cant_deserialize_ciphertext() { new_test_ext().execute_with(|| { let who = 42; - let netuid = NetUid::from(9); + let netuid = 9; System::::set_block_number(10); let good_ct = produce_ciphertext(b"Some data", 1000); let mut corrupted = good_ct.into_inner(); @@ -359,7 +352,7 @@ fn reveal_timelocked_commitment_cant_deserialize_ciphertext() { fn reveal_timelocked_commitment_bad_signature_skips_decryption() { new_test_ext().execute_with(|| { let who = 10; - let netuid = NetUid::from(11); + let netuid = 11; System::::set_block_number(15); let real_ct = produce_ciphertext(b"A valid plaintext", 1000); let data = Data::TimelockEncrypted { @@ -387,7 +380,7 @@ fn reveal_timelocked_commitment_bad_signature_skips_decryption() { fn reveal_timelocked_commitment_empty_decrypted_data_is_skipped() { new_test_ext().execute_with(|| { let who = 2; - let netuid = NetUid::from(3); + let netuid = 3; let commit_block = 100u64; System::::set_block_number(commit_block); let reveal_round = 1000; @@ -446,7 +439,7 @@ fn reveal_timelocked_commitment_single_field_entry_is_removed_after_reveal() { }; let who = 555; - let netuid = NetUid::from(777); + let netuid = 777; System::::set_block_number(1); assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(who), @@ -546,7 +539,7 @@ fn reveal_timelocked_multiple_fields_only_correct_ones_removed() { // 5) Insert the commitment let who = 123; - let netuid = NetUid::from(999); + let netuid = 999; System::::set_block_number(1); assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(who), @@ -609,7 +602,7 @@ fn reveal_timelocked_multiple_fields_only_correct_ones_removed() { #[test] fn test_index_lifecycle_no_timelocks_updates_in_out() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(100); + let netuid = 100; let who = 999; // @@ -674,7 +667,7 @@ fn test_index_lifecycle_no_timelocks_updates_in_out() { #[test] fn two_timelocks_partial_then_full_reveal() { new_test_ext().execute_with(|| { - let netuid_a = NetUid::from(1); + let netuid_a = 1; let who_a = 10; let round_1000 = 1000; let round_2000 = 2000; @@ -776,7 +769,7 @@ fn two_timelocks_partial_then_full_reveal() { #[test] fn single_timelock_reveal_later_round() { new_test_ext().execute_with(|| { - let netuid_b = NetUid::from(2); + let netuid_b = 2; let who_b = 20; let round_2000 = 2000; @@ -848,7 +841,7 @@ fn single_timelock_reveal_later_round() { #[test] fn tempo_based_space_limit_accumulates_in_same_window() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let who = 100; let space_limit = 150; MaxSpace::::set(space_limit); @@ -881,7 +874,7 @@ fn tempo_based_space_limit_accumulates_in_same_window() { #[test] fn tempo_based_space_limit_resets_after_tempo() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(2); + let netuid = 2; let who = 101; MaxSpace::::set(250); @@ -939,8 +932,8 @@ fn tempo_based_space_limit_resets_after_tempo() { #[test] fn tempo_based_space_limit_does_not_affect_different_netuid() { new_test_ext().execute_with(|| { - let netuid_a = NetUid::from(10); - let netuid_b = NetUid::from(20); + let netuid_a = 10; + let netuid_b = 20; let who = 111; let space_limit = 199; MaxSpace::::set(space_limit); @@ -989,7 +982,7 @@ fn tempo_based_space_limit_does_not_affect_different_netuid() { #[test] fn tempo_based_space_limit_does_not_affect_different_user() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(10); + let netuid = 10; let user1 = 123; let user2 = 456; let space_limit = 199; @@ -1039,7 +1032,7 @@ fn tempo_based_space_limit_does_not_affect_different_user() { #[test] fn tempo_based_space_limit_sudo_set_max_space() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(3); + let netuid = 3; let who = 15; MaxSpace::::set(100); @@ -1076,7 +1069,7 @@ fn tempo_based_space_limit_sudo_set_max_space() { fn on_initialize_reveals_matured_timelocks() { new_test_ext().execute_with(|| { let who = 42; - let netuid = NetUid::from(7); + let netuid = 7; let reveal_round = 1000; let message_text = b"Timelock test via on_initialize"; @@ -1166,7 +1159,7 @@ fn set_commitment_unreserve_leftover_fails() { new_test_ext().execute_with(|| { use frame_system::RawOrigin; - let netuid = NetUid::from(999); + let netuid = 999; let who = 99; Balances::make_free_balance_be(&who, 10_000); @@ -1205,7 +1198,7 @@ fn timelocked_index_complex_scenario_works() { new_test_ext().execute_with(|| { System::::set_block_number(1); - let netuid = NetUid::from(42); + let netuid = 42; let user_a = 1000; let user_b = 2000; let user_c = 3000; @@ -1464,7 +1457,7 @@ fn reveal_timelocked_bad_timelocks_are_removed() { // 3) Insert the commitment // let who = 123; - let netuid = NetUid::from(777); + let netuid = 777; System::::set_block_number(1); assert_ok!(Pallet::::set_commitment( RawOrigin::Signed(who).into(), @@ -1538,7 +1531,7 @@ fn reveal_timelocked_bad_timelocks_are_removed() { #[test] fn revealed_commitments_keeps_only_10_items() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let who = 2; let reveal_round = 1000; @@ -1606,7 +1599,7 @@ fn revealed_commitments_keeps_only_10_items() { #[test] fn revealed_commitments_keeps_only_10_newest_with_individual_single_field_commits() { new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let who = 2; let reveal_round = 1000; @@ -1685,7 +1678,7 @@ fn usage_respects_minimum_of_100_bytes() { new_test_ext().execute_with(|| { MaxSpace::::set(1000); - let netuid = NetUid::from(1); + let netuid = 1; let who = 99; System::::set_block_number(1); @@ -1774,12 +1767,12 @@ fn set_commitment_works_with_multiple_raw_fields() { assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(12345), - 99.into(), + 99, Box::new(info_multiple) )); let expected_deposit: BalanceOf = initial_deposit + 3u64 * field_deposit; - let stored = CommitmentOf::::get(NetUid::from(99), 12345).expect("Should be stored"); + let stored = CommitmentOf::::get(99, 12345).expect("Should be stored"); assert_eq!( stored.deposit, expected_deposit, "Deposit must equal initial + 3 * field_deposit" @@ -1787,8 +1780,7 @@ fn set_commitment_works_with_multiple_raw_fields() { assert_eq!(stored.block, cur_block, "Stored block must match cur_block"); - let usage = - UsedSpaceOf::::get(NetUid::from(99), 12345).expect("Expected to not panic"); + let usage = UsedSpaceOf::::get(99, 12345).expect("Expected to not panic"); assert_eq!( usage.used_space, 100, "Usage is clamped to 100 when sum of fields is < 100" @@ -1804,19 +1796,18 @@ fn set_commitment_works_with_multiple_raw_fields() { assert_ok!(Pallet::::set_commitment( RuntimeOrigin::signed(12345), - 99.into(), + 99, Box::new(info_two_fields) )); let expected_deposit2: BalanceOf = initial_deposit + 2u64 * field_deposit; - let stored2 = CommitmentOf::::get(NetUid::from(99), 12345).expect("Should be stored"); + let stored2 = CommitmentOf::::get(99, 12345).expect("Should be stored"); assert_eq!( stored2.deposit, expected_deposit2, "Deposit must have decreased after removing one field" ); - let usage2 = - UsedSpaceOf::::get(NetUid::from(99), 12345).expect("Expected to not panic"); + let usage2 = UsedSpaceOf::::get(99, 12345).expect("Expected to not panic"); let expected_usage2 = 200u64; assert_eq!( usage2.used_space, expected_usage2, @@ -1824,11 +1815,15 @@ fn set_commitment_works_with_multiple_raw_fields() { ); let events = System::::events(); - let expected_event = RuntimeEvent::Commitments(Event::Commitment { - netuid: 99.into(), - who: 12345, + let found_commitment_event = events.iter().any(|e| { + matches!( + e.event, + RuntimeEvent::Commitments(Event::Commitment { + netuid: 99, + who: 12345 + }) + ) }); - let found_commitment_event = events.iter().any(|e| e.event == expected_event); assert!( found_commitment_event, "Expected at least one Event::Commitment to be emitted" @@ -1847,10 +1842,10 @@ fn multiple_timelocked_commitments_reveal_works() { System::::set_block_number(cur_block); let who = 123; - let netuid = NetUid::from(999); + let netuid = 999; // ------------------------------------------- - // 2) Create multiple TLE fields referencing + // 2) Create multiple TLE fields referencing // two known valid Drand rounds: 1000, 2000 // ------------------------------------------- @@ -2027,7 +2022,7 @@ fn mixed_timelocked_and_raw_fields_works() { System::::set_block_number(cur_block); let who = 77; - let netuid = NetUid::from(501); + let netuid = 501; // ------------------------------------------- // 2) Create raw fields and timelocked fields diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index cd9cf258c1..ab17cf5bdc 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -49,16 +49,13 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ". pallet-drand = { path = "../drand", default-features = false } pallet-membership = { workspace = true } hex-literal = { workspace = true } -num-traits = { version = "0.2.19", default-features = false, features = [ - "libm", -] } +num-traits = { version = "0.2.19", default-features = false, features = ["libm"] } tle = { workspace = true, default-features = false } ark-bls12-381 = { workspace = true, default-features = false } ark-serialize = { workspace = true, default-features = false } w3f-bls = { workspace = true, default-features = false } sha2 = { workspace = true } rand_chacha = { workspace = true } -subtensor-runtime-common = { workspace = true } [dev-dependencies] pallet-balances = { workspace = true, features = ["std"] } @@ -73,48 +70,47 @@ sp-std = { workspace = true } pallet-preimage = { workspace = true } [features] +default = ["std"] std = [ - "ark-bls12-381/std", - "ark-serialize/std", "codec/std", "frame-benchmarking/std", "frame-support/std", "frame-system/std", - "hex/std", - "libsecp256k1/std", - "log/std", - "ndarray/std", - "num-traits/std", - "pallet-balances/std", + "scale-info/std", "pallet-collective/std", - "pallet-drand/std", "pallet-membership/std", + "substrate-fixed/std", + "pallet-balances/std", "pallet-preimage/std", "pallet-scheduler/std", "pallet-transaction-payment/std", "pallet-utility/std", - "rand_chacha/std", - "safe-math/std", - "scale-info/std", - "serde/std", - "serde_bytes/std", - "serde_json/std", - "serde_with/std", - "sha2/std", - "share-pool/std", "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-std/std", "sp-tracing/std", "sp-version/std", + "hex/std", + "libsecp256k1/std", + "log/std", + "ndarray/std", + "serde/std", + "serde_bytes/std", + "serde_with/std", "substrate-fixed/std", - "substrate-fixed/std", - "subtensor-runtime-common/std", + "num-traits/std", + "serde_json/std", "tle/std", + "pallet-drand/std", + "ark-bls12-381/std", + "ark-serialize/std", "w3f-bls/std", + "rand_chacha/std", + "safe-math/std", + "sha2/std", + "share-pool/std" ] -default = ["std"] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", @@ -126,7 +122,7 @@ runtime-benchmarks = [ "pallet-collective/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", - "pallet-drand/runtime-benchmarks", + "pallet-drand/runtime-benchmarks" ] try-runtime = [ "frame-support/try-runtime", @@ -139,7 +135,7 @@ try-runtime = [ "pallet-utility/try-runtime", "sp-runtime/try-runtime", "pallet-collective/try-runtime", - "pallet-drand/try-runtime", + "pallet-drand/try-runtime" ] pow-faucet = [] fast-blocks = [] diff --git a/pallets/subtensor/rpc/Cargo.toml b/pallets/subtensor/rpc/Cargo.toml index 47b63b9067..6a2807268d 100644 --- a/pallets/subtensor/rpc/Cargo.toml +++ b/pallets/subtensor/rpc/Cargo.toml @@ -23,19 +23,18 @@ sp-rpc = { workspace = true } sp-runtime = { workspace = true } # local packages -subtensor-runtime-common = { workspace = true } + subtensor-custom-rpc-runtime-api = { path = "../runtime-api", default-features = false } pallet-subtensor = { path = "../../subtensor", default-features = false } [features] default = ["std"] std = [ - "codec/std", - "pallet-subtensor/std", - "serde/std", "sp-api/std", "sp-runtime/std", "subtensor-custom-rpc-runtime-api/std", - "subtensor-runtime-common/std", + "pallet-subtensor/std", + "codec/std", + "serde/std" ] pow-faucet = [] diff --git a/pallets/subtensor/rpc/src/lib.rs b/pallets/subtensor/rpc/src/lib.rs index b6512c6055..b3b60206dd 100644 --- a/pallets/subtensor/rpc/src/lib.rs +++ b/pallets/subtensor/rpc/src/lib.rs @@ -9,7 +9,6 @@ use jsonrpsee::{ use sp_blockchain::HeaderBackend; use sp_runtime::{AccountId32, traits::Block as BlockT}; use std::sync::Arc; -use subtensor_runtime_common::NetUid; use sp_api::ProvideRuntimeApi; @@ -36,44 +35,39 @@ pub trait SubtensorCustomApi { ) -> RpcResult>; #[method(name = "neuronInfo_getNeuronsLite")] - fn get_neurons_lite(&self, netuid: NetUid, at: Option) -> RpcResult>; + fn get_neurons_lite(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "neuronInfo_getNeuronLite")] - fn get_neuron_lite( - &self, - netuid: NetUid, - uid: u16, - at: Option, - ) -> RpcResult>; + fn get_neuron_lite(&self, netuid: u16, uid: u16, at: Option) -> RpcResult>; #[method(name = "neuronInfo_getNeurons")] - fn get_neurons(&self, netuid: NetUid, at: Option) -> RpcResult>; + fn get_neurons(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "neuronInfo_getNeuron")] - fn get_neuron(&self, netuid: NetUid, uid: u16, at: Option) -> RpcResult>; + fn get_neuron(&self, netuid: u16, uid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetInfo")] - fn get_subnet_info(&self, netuid: NetUid, at: Option) -> RpcResult>; + 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: NetUid, at: Option) -> RpcResult>; + 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: NetUid, at: Option) -> RpcResult>; + fn get_subnet_hyperparams(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getAllDynamicInfo")] fn get_all_dynamic_info(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getDynamicInfo")] - fn get_dynamic_info(&self, netuid: NetUid, at: Option) -> RpcResult>; + fn get_dynamic_info(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getAllMetagraphs")] fn get_all_metagraphs(&self, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getMetagraph")] - fn get_metagraph(&self, netuid: NetUid, at: Option) -> RpcResult>; + fn get_metagraph(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getSubnetState")] - fn get_subnet_state(&self, netuid: NetUid, at: Option) -> RpcResult>; + fn get_subnet_state(&self, netuid: u16, at: Option) -> RpcResult>; #[method(name = "subnetInfo_getLockCost")] fn get_network_lock_cost(&self, at: Option) -> RpcResult; #[method(name = "subnetInfo_getSelectiveMetagraph")] fn get_selective_metagraph( &self, - netuid: NetUid, + netuid: u16, metagraph_index: Vec, at: Option, ) -> RpcResult>; @@ -188,7 +182,7 @@ where fn get_neurons_lite( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -204,7 +198,7 @@ where fn get_neuron_lite( &self, - netuid: NetUid, + netuid: u16, uid: u16, at: Option<::Hash>, ) -> RpcResult> { @@ -219,11 +213,7 @@ where } } - fn get_neurons( - &self, - netuid: NetUid, - at: Option<::Hash>, - ) -> RpcResult> { + 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); @@ -237,7 +227,7 @@ where fn get_neuron( &self, - netuid: NetUid, + netuid: u16, uid: u16, at: Option<::Hash>, ) -> RpcResult> { @@ -254,7 +244,7 @@ where fn get_subnet_info( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -270,7 +260,7 @@ where fn get_subnet_hyperparams( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -310,7 +300,7 @@ where fn get_dynamic_info( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -328,7 +318,7 @@ where fn get_metagraph( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -345,7 +335,7 @@ where fn get_subnet_state( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -373,7 +363,7 @@ where fn get_subnet_info_v2( &self, - netuid: NetUid, + netuid: u16, at: Option<::Hash>, ) -> RpcResult> { let api = self.client.runtime_api(); @@ -410,7 +400,7 @@ where fn get_selective_metagraph( &self, - netuid: NetUid, + netuid: u16, metagraph_index: Vec, at: Option<::Hash>, ) -> RpcResult> { diff --git a/pallets/subtensor/runtime-api/Cargo.toml b/pallets/subtensor/runtime-api/Cargo.toml index 1a95b75d16..0812d076d3 100644 --- a/pallets/subtensor/runtime-api/Cargo.toml +++ b/pallets/subtensor/runtime-api/Cargo.toml @@ -17,19 +17,17 @@ sp-runtime = { workspace = true } frame-support = { workspace = true } serde = { workspace = true, features = ["derive"] } codec = { workspace = true } -subtensor-runtime-common = { workspace = true } # local pallet-subtensor = { version = "4.0.0-dev", path = "../../subtensor", default-features = false } [features] default = ["std"] std = [ - "codec/std", + "sp-api/std", + "sp-runtime/std", "frame-support/std", "pallet-subtensor/std", "serde/std", - "sp-api/std", - "sp-runtime/std", - "subtensor-runtime-common/std", + "codec/std" ] pow-faucet = [] diff --git a/pallets/subtensor/runtime-api/src/lib.rs b/pallets/subtensor/runtime-api/src/lib.rs index ac2de7e9d9..1a2f34aa9e 100644 --- a/pallets/subtensor/runtime-api/src/lib.rs +++ b/pallets/subtensor/runtime-api/src/lib.rs @@ -12,7 +12,6 @@ use pallet_subtensor::rpc_info::{ subnet_info::{SubnetHyperparams, SubnetInfo, SubnetInfov2}, }; use sp_runtime::AccountId32; -use subtensor_runtime_common::NetUid; // 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 @@ -20,35 +19,35 @@ sp_api::decl_runtime_apis! { pub trait DelegateInfoRuntimeApi { fn get_delegates() -> Vec>; fn get_delegate( delegate_account: AccountId32 ) -> Option>; - fn get_delegated( delegatee_account: AccountId32 ) -> Vec<(DelegateInfo, (Compact, Compact))>; + fn get_delegated( delegatee_account: AccountId32 ) -> Vec<(DelegateInfo, (Compact, Compact))>; } pub trait NeuronInfoRuntimeApi { - fn get_neurons(netuid: NetUid) -> Vec>; - fn get_neuron(netuid: NetUid, uid: u16) -> Option>; - fn get_neurons_lite(netuid: NetUid) -> Vec>; - fn get_neuron_lite(netuid: NetUid, uid: u16) -> Option>; + 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 { - fn get_subnet_info(netuid: NetUid) -> Option>; + fn get_subnet_info(netuid: u16) -> Option>; fn get_subnets_info() -> Vec>>; - fn get_subnet_info_v2(netuid: NetUid) -> Option>; + fn get_subnet_info_v2(netuid: u16) -> Option>; fn get_subnets_info_v2() -> Vec>>; - fn get_subnet_hyperparams(netuid: NetUid) -> Option; + fn get_subnet_hyperparams(netuid: u16) -> Option; fn get_all_dynamic_info() -> Vec>>; fn get_all_metagraphs() -> Vec>>; - fn get_metagraph(netuid: NetUid) -> Option>; - fn get_dynamic_info(netuid: NetUid) -> Option>; - fn get_subnet_state(netuid: NetUid) -> Option>; - fn get_selective_metagraph(netuid: NetUid, metagraph_indexes: Vec) -> Option>; + fn get_metagraph(netuid: u16) -> Option>; + fn get_dynamic_info(netuid: u16) -> Option>; + fn get_subnet_state(netuid: u16) -> Option>; + fn get_selective_metagraph(netuid: u16, metagraph_indexes: Vec) -> Option>; } pub trait StakeInfoRuntimeApi { fn get_stake_info_for_coldkey( coldkey_account: AccountId32 ) -> Vec>; fn get_stake_info_for_coldkeys( coldkey_accounts: Vec ) -> Vec<(AccountId32, Vec>)>; - fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: NetUid ) -> Option>; - fn get_stake_fee( origin: Option<(AccountId32, NetUid)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, NetUid)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64; + fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: u16 ) -> Option>; + fn get_stake_fee( origin: Option<(AccountId32, u16)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, u16)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64; } pub trait SubnetRegistrationRuntimeApi { diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index f1c7fc4625..1b61addc91 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -22,7 +22,7 @@ mod pallet_benchmarks { #[benchmark] fn register() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; let hotkey: T::AccountId = account("Alice", 0, 1); let coldkey: T::AccountId = account("Test", 0, 2); @@ -49,7 +49,7 @@ mod pallet_benchmarks { #[benchmark] fn set_weights() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 1; let tempo: u16 = 1; @@ -98,7 +98,7 @@ mod pallet_benchmarks { #[benchmark] fn become_delegate() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; Subtensor::::init_new_network(netuid, tempo); @@ -125,7 +125,7 @@ mod pallet_benchmarks { #[benchmark] fn add_stake() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; Subtensor::::init_new_network(netuid, tempo); @@ -158,7 +158,7 @@ mod pallet_benchmarks { #[benchmark] fn serve_axon() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let caller: T::AccountId = whitelisted_caller(); let version: u32 = 2; let ip: u128 = 1676056785; @@ -199,7 +199,7 @@ mod pallet_benchmarks { #[benchmark] fn serve_prometheus() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let caller: T::AccountId = whitelisted_caller(); let version: u32 = 2; let ip: u128 = 1676056785; @@ -234,7 +234,7 @@ mod pallet_benchmarks { #[benchmark] fn burned_register() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let seed: u32 = 1; let hotkey: T::AccountId = account("Alice", 0, seed); let coldkey: T::AccountId = account("Test", 0, seed); @@ -252,7 +252,7 @@ mod pallet_benchmarks { #[benchmark] fn root_register() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let seed: u32 = 1; let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); @@ -294,7 +294,7 @@ mod pallet_benchmarks { #[benchmark] fn commit_weights() { let tempo: u16 = 1; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let uids: Vec = vec![0]; let weight_values: Vec = vec![10]; @@ -339,7 +339,7 @@ mod pallet_benchmarks { #[benchmark] fn reveal_weights() { let tempo: u16 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let uids: Vec = vec![0]; let weight_values: Vec = vec![10]; @@ -414,7 +414,7 @@ mod pallet_benchmarks { #[benchmark] fn set_childkey_take() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey: T::AccountId = account("Cold", 0, 1); let hotkey: T::AccountId = account("Hot", 0, 1); let take: u16 = 1000; @@ -447,7 +447,7 @@ mod pallet_benchmarks { let old_coldkey: T::AccountId = account("old_coldkey", 0, 0); let new_coldkey: T::AccountId = account("new_coldkey", 0, 0); let hotkey1: T::AccountId = account("hotkey1", 0, 0); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let swap_cost: u64 = Subtensor::::get_key_swap_cost(); let free_balance_old: u64 = 12345 + swap_cost; @@ -492,7 +492,7 @@ mod pallet_benchmarks { #[benchmark] fn batch_reveal_weights() { let tempo: u16 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let num_commits: usize = 10; let hotkey: T::AccountId = account("hot", 0, 1); @@ -564,7 +564,7 @@ mod pallet_benchmarks { #[benchmark] fn recycle_alpha() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey: T::AccountId = account("Test", 0, 1); let hotkey: T::AccountId = account("Alice", 0, 1); @@ -605,7 +605,7 @@ mod pallet_benchmarks { #[benchmark] fn burn_alpha() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey: T::AccountId = account("Test", 0, 1); let hotkey: T::AccountId = account("Alice", 0, 1); @@ -643,7 +643,7 @@ mod pallet_benchmarks { #[benchmark] fn start_call() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey: T::AccountId = account("Test", 0, 1); let hotkey: T::AccountId = account("Alice", 0, 1); @@ -680,9 +680,10 @@ mod pallet_benchmarks { fn adjust_senate() { let coldkey: T::AccountId = whitelisted_caller(); let hotkey: T::AccountId = account("Alice", 0, 1); + let root: u16 = Subtensor::::get_root_netuid(); - Subtensor::::init_new_network(NetUid::ROOT, 1); - Uids::::insert(NetUid::ROOT, &hotkey, 0u16); + Subtensor::::init_new_network(root, 1); + Uids::::insert(root, &hotkey, 0u16); #[extrinsic_call] _(RawOrigin::Signed(coldkey.clone()), hotkey.clone()); @@ -690,7 +691,7 @@ mod pallet_benchmarks { #[benchmark] fn add_stake_limit() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; let seed: u32 = 1; @@ -735,7 +736,7 @@ mod pallet_benchmarks { let coldkey: T::AccountId = whitelisted_caller(); let origin: T::AccountId = account("A", 0, 1); let destination: T::AccountId = account("B", 0, 2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; SubtokenEnabled::::insert(netuid, true); Subtensor::::init_new_network(netuid, 1); @@ -782,7 +783,7 @@ mod pallet_benchmarks { #[benchmark] fn remove_stake_limit() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; let seed: u32 = 1; @@ -842,8 +843,8 @@ mod pallet_benchmarks { fn swap_stake_limit() { let coldkey: T::AccountId = whitelisted_caller::>(); let hot: T::AccountId = account("A", 0, 1); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let allow: bool = true; SubtokenEnabled::::insert(netuid1, true); @@ -904,7 +905,7 @@ mod pallet_benchmarks { let coldkey: T::AccountId = whitelisted_caller(); let dest: T::AccountId = account("B", 0, 2); let hot: T::AccountId = account("A", 0, 1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; SubtokenEnabled::::insert(netuid, true); Subtensor::::init_new_network(netuid, 1); @@ -953,8 +954,8 @@ mod pallet_benchmarks { fn swap_stake() { let coldkey: T::AccountId = whitelisted_caller(); let hot: T::AccountId = account("A", 0, 9); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; SubtokenEnabled::::insert(netuid1, true); Subtensor::::init_new_network(netuid1, 1); @@ -1003,9 +1004,9 @@ mod pallet_benchmarks { #[benchmark] fn batch_commit_weights() { let hotkey: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let count: usize = 3; - let mut netuids: Vec> = Vec::new(); + let mut netuids: Vec> = Vec::new(); let mut hashes: Vec = Vec::new(); Subtensor::::init_new_network(netuid, 1); @@ -1040,10 +1041,10 @@ mod pallet_benchmarks { #[benchmark] fn batch_set_weights() { let hotkey: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version: u64 = 1; let entries: Vec<(Compact, Compact)> = vec![(Compact(0u16), Compact(0u16))]; - let netuids: Vec> = vec![Compact(netuid)]; + let netuids: Vec> = vec![Compact(netuid)]; let weights: Vec, Compact)>> = vec![entries.clone()]; let keys: Vec> = vec![Compact(version)]; @@ -1072,7 +1073,7 @@ mod pallet_benchmarks { #[benchmark] fn commit_crv3_weights() { let hotkey: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let vec_commit: Vec = vec![0; MAX_CRV3_COMMIT_SIZE_BYTES as usize]; let commit: BoundedVec<_, _> = vec_commit.try_into().unwrap(); let round: u64 = 0; @@ -1133,7 +1134,7 @@ mod pallet_benchmarks { let hotkey: T::AccountId = account("Alice", 0, 1); let identity: Option = None; - Subtensor::::set_network_registration_allowed(1.into(), true); + Subtensor::::set_network_registration_allowed(1, true); Subtensor::::set_network_rate_limit(1); let amount: u64 = 9_999_999_999_999; Subtensor::::add_balance_to_coldkey_account(&coldkey, amount); @@ -1149,7 +1150,7 @@ mod pallet_benchmarks { #[benchmark] fn serve_axon_tls() { let caller: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version: u32 = 1; let ip: u128 = 0xC0A8_0001; let port: u16 = 30333; @@ -1201,14 +1202,14 @@ mod pallet_benchmarks { let add = vec![]; Subtensor::::create_account_if_non_existent(&coldkey, &hotkey); - Subtensor::::init_new_network(1.into(), 1); + Subtensor::::init_new_network(1, 1); let deposit: u64 = 1_000_000_000u64.saturating_mul(2); Subtensor::::add_balance_to_coldkey_account(&coldkey, deposit); - SubtokenEnabled::::insert(NetUid::from(1), true); + SubtokenEnabled::::insert(1, true); assert_ok!(Subtensor::::burned_register( RawOrigin::Signed(coldkey.clone()).into(), - 1.into(), + 1, hotkey.clone() )); @@ -1228,7 +1229,7 @@ mod pallet_benchmarks { #[benchmark] fn set_subnet_identity() { let coldkey: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let name = b"n".to_vec(); let repo = vec![]; let contact = vec![]; @@ -1256,7 +1257,7 @@ mod pallet_benchmarks { #[benchmark] fn set_tao_weights() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: T::AccountId = account("A", 0, 6); let dests = vec![0u16]; let weights = vec![0u16]; diff --git a/pallets/subtensor/src/coinbase/block_emission.rs b/pallets/subtensor/src/coinbase/block_emission.rs index f1c8478e22..cd9d778b8a 100644 --- a/pallets/subtensor/src/coinbase/block_emission.rs +++ b/pallets/subtensor/src/coinbase/block_emission.rs @@ -5,7 +5,6 @@ use substrate_fixed::{ transcendental::log2, types::{I96F32, U96F32}, }; -use subtensor_runtime_common::NetUid; impl Pallet { /// Calculates the dynamic TAO emission for a given subnet. @@ -30,7 +29,7 @@ impl Pallet { /// It also ensures that the total amount of alpha_in_emission + alpha_out_emission sum to 2 * alpha_block_emission /// It also ensures that 1 < alpha_out_emission < 2 * alpha_block_emission and 0 < alpha_in_emission < alpha_block_emission. pub fn get_dynamic_tao_emission( - netuid: NetUid, + netuid: u16, tao_emission: u64, alpha_block_emission: u64, ) -> (u64, u64, u64) { diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index d003a698e3..a7e658e89a 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -1,7 +1,7 @@ use super::*; +use frame_support::storage::IterableStorageMap; use safe_math::*; use substrate_fixed::types::{U96F32, U110F18}; -use subtensor_runtime_common::NetUid; impl Pallet { /// Executes the necessary operations for each block. @@ -23,7 +23,8 @@ impl Pallet { } fn try_set_pending_children(block_number: u64) { - for netuid in Self::get_all_subnet_netuids() { + let subnets: Vec = Self::get_all_subnet_netuids(); + for &netuid in subnets.iter() { if Self::should_run_epoch(netuid, block_number) { // Set pending children on the epoch. Self::do_set_pending_children(netuid); @@ -37,7 +38,7 @@ impl Pallet { log::debug!("adjust_registration_terms_for_networks"); // --- 1. Iterate through each network. - for (netuid, _) in NetworksAdded::::iter() { + for (netuid, _) in as IterableStorageMap>::iter() { // --- 2. Pull counters for network difficulty. let last_adjustment_block: u64 = Self::get_last_adjustment_block(netuid); let adjustment_interval: u16 = Self::get_adjustment_interval(netuid); @@ -193,7 +194,7 @@ impl Pallet { /// We use U110F18 to avoid any overflows on u64. Also min_difficulty and max_difficulty bound the range. /// pub fn upgraded_difficulty( - netuid: NetUid, + netuid: u16, current_difficulty: u64, registrations_this_interval: u16, target_registrations_per_interval: u16, @@ -227,7 +228,7 @@ impl Pallet { /// We use U110F18 to avoid any overflows on u64. Also min_burn and max_burn bound the range. /// pub fn upgraded_burn( - netuid: NetUid, + netuid: u16, current_burn: u64, registrations_this_interval: u16, target_registrations_per_interval: u16, diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 32ead349a2..1f3a91b339 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -23,7 +23,6 @@ use safe_math::*; use sp_core::Get; use sp_std::vec; use substrate_fixed::types::I64F64; -use subtensor_runtime_common::NetUid; impl Pallet { /// Fetches the total count of root network validators @@ -34,7 +33,7 @@ impl Pallet { /// * 'u16': The total number of root network validators /// pub fn get_num_root_validators() -> u16 { - Self::get_subnetwork_n(NetUid::ROOT) + Self::get_subnetwork_n(Self::get_root_netuid()) } /// Fetches the max validators count of root network. @@ -45,7 +44,7 @@ impl Pallet { /// * 'u16': The max validators count of root network. /// pub fn get_max_root_validators() -> u16 { - Self::get_max_allowed_uids(NetUid::ROOT) + Self::get_max_allowed_uids(Self::get_root_netuid()) } /// Checks for any UIDs in the given list that are either equal to the root netuid or exceed the total number of subnets. @@ -58,7 +57,7 @@ impl Pallet { /// # Returns: /// * 'bool': 'true' if any of the UIDs are invalid, 'false' otherwise. /// - pub fn contains_invalid_root_uids(netuids: &[NetUid]) -> bool { + pub fn contains_invalid_root_uids(netuids: &[u16]) -> bool { for netuid in netuids { if !Self::if_subnet_exist(*netuid) { log::debug!( @@ -80,11 +79,11 @@ impl Pallet { /// pub fn get_root_weights() -> Vec> { // --- 0. The number of validators on the root network. - let n = Self::get_num_root_validators() as usize; + let n: usize = Self::get_num_root_validators() as usize; // --- 1 The number of subnets to validate. log::debug!("subnet size before cast: {:?}", Self::get_num_subnets()); - let k = Self::get_num_subnets() as usize; + let k: usize = Self::get_num_subnets() as usize; log::debug!("n: {:?} k: {:?}", n, k); // --- 2. Initialize a 2D vector with zeros to store the weights. The dimensions are determined @@ -96,8 +95,8 @@ impl Pallet { // --- 3. Iterate over stored weights and fill the matrix. for (uid_i, weights_i) in - as IterableStorageDoubleMap>>::iter_prefix( - NetUid::ROOT, + as IterableStorageDoubleMap>>::iter_prefix( + Self::get_root_netuid(), ) { // --- 4. Iterate over each weight entry in `weights_i` to update the corresponding value in the @@ -109,7 +108,7 @@ impl Pallet { if let Some((w, _)) = weight .iter_mut() .zip(&subnet_list) - .find(|(_, subnet)| *subnet == &NetUid::from(*netuid)) + .find(|(_, subnet)| *subnet == netuid) { *w = I64F64::saturating_from_num(*weight_ij); } @@ -135,9 +134,10 @@ impl Pallet { /// pub fn do_root_register(origin: T::RuntimeOrigin, hotkey: T::AccountId) -> DispatchResult { // --- 0. Get the unique identifier (UID) for the root network. + let root_netuid: u16 = Self::get_root_netuid(); let current_block_number: u64 = Self::get_current_block_as_u64(); ensure!( - Self::if_subnet_exist(NetUid::ROOT), + Self::if_subnet_exist(root_netuid), Error::::RootNetworkDoesNotExist ); @@ -151,21 +151,21 @@ impl Pallet { // --- 2. Ensure that the number of registrations in this block doesn't exceed the allowed limit. ensure!( - Self::get_registrations_this_block(NetUid::ROOT) - < Self::get_max_registrations_per_block(NetUid::ROOT), + Self::get_registrations_this_block(root_netuid) + < Self::get_max_registrations_per_block(root_netuid), Error::::TooManyRegistrationsThisBlock ); // --- 3. Ensure that the number of registrations in this interval doesn't exceed thrice the target limit. ensure!( - Self::get_registrations_this_interval(NetUid::ROOT) - < Self::get_target_registrations_per_interval(NetUid::ROOT).saturating_mul(3), + Self::get_registrations_this_interval(root_netuid) + < Self::get_target_registrations_per_interval(root_netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); // --- 4. Check if the hotkey is already registered. If so, error out. ensure!( - !Uids::::contains_key(NetUid::ROOT, &hotkey), + !Uids::::contains_key(root_netuid, &hotkey), Error::::HotKeyAlreadyRegisteredInSubNet ); @@ -185,7 +185,7 @@ impl Pallet { subnetwork_uid = current_num_root_validators; // --- 12.1.2 Add the new account and make them a member of the Senate. - Self::append_neuron(NetUid::ROOT, &hotkey, current_block_number); + Self::append_neuron(root_netuid, &hotkey, current_block_number); log::debug!("add new neuron: {:?} on uid {:?}", hotkey, subnetwork_uid); } else { // --- 13.1.1 The network is full. Perform replacement. @@ -194,8 +194,12 @@ impl Pallet { let mut lowest_uid: u16 = 0; // Iterate over all keys in the root network to find the neuron with the lowest stake. - for (uid_i, hotkey_i) in Keys::::iter_prefix(NetUid::ROOT) { - let stake_i = Self::get_stake_for_hotkey_on_subnet(&hotkey_i, NetUid::ROOT); + for (uid_i, hotkey_i) in + as IterableStorageDoubleMap>::iter_prefix( + root_netuid, + ) + { + let stake_i: u64 = Self::get_stake_for_hotkey_on_subnet(&hotkey_i, 0); if stake_i < lowest_stake { lowest_stake = stake_i; lowest_uid = uid_i; @@ -203,17 +207,17 @@ impl Pallet { } subnetwork_uid = lowest_uid; let replaced_hotkey: T::AccountId = - Self::get_hotkey_for_net_and_uid(NetUid::ROOT, subnetwork_uid)?; + Self::get_hotkey_for_net_and_uid(root_netuid, subnetwork_uid)?; // --- 13.1.2 The new account has a higher stake than the one being replaced. ensure!( - lowest_stake < Self::get_stake_for_hotkey_on_subnet(&hotkey, NetUid::ROOT), + lowest_stake < Self::get_stake_for_hotkey_on_subnet(&hotkey, 0), Error::::StakeTooLowForRoot ); // --- 13.1.3 The new account has a higher stake than the one being replaced. // Replace the neuron account with new information. - Self::replace_neuron(NetUid::ROOT, lowest_uid, &hotkey, current_block_number); + Self::replace_neuron(root_netuid, lowest_uid, &hotkey, current_block_number); log::debug!( "replace neuron: {:?} with {:?} on uid {:?}", @@ -235,23 +239,19 @@ impl Pallet { // --- 15. Update the registration counters for both the block and interval. #[allow(clippy::arithmetic_side_effects)] // note this RA + clippy false positive is a known substrate issue - RegistrationsThisInterval::::mutate(NetUid::ROOT, |val| *val += 1); + RegistrationsThisInterval::::mutate(root_netuid, |val| *val += 1); #[allow(clippy::arithmetic_side_effects)] // note this RA + clippy false positive is a known substrate issue - RegistrationsThisBlock::::mutate(NetUid::ROOT, |val| *val += 1); + RegistrationsThisBlock::::mutate(root_netuid, |val| *val += 1); // --- 16. Log and announce the successful registration. log::debug!( "RootRegistered(netuid:{:?} uid:{:?} hotkey:{:?})", - NetUid::ROOT, + root_netuid, subnetwork_uid, hotkey ); - Self::deposit_event(Event::NeuronRegistered( - NetUid::ROOT, - subnetwork_uid, - hotkey, - )); + Self::deposit_event(Event::NeuronRegistered(root_netuid, subnetwork_uid, hotkey)); // --- 17. Finish and return success. Ok(()) @@ -270,8 +270,10 @@ impl Pallet { // * 'DispatchResult': A result type indicating success or failure of the registration. // pub fn do_adjust_senate(origin: T::RuntimeOrigin, hotkey: T::AccountId) -> DispatchResult { + // --- 0. Get the unique identifier (UID) for the root network. + let root_netuid: u16 = Self::get_root_netuid(); ensure!( - Self::if_subnet_exist(NetUid::ROOT), + Self::if_subnet_exist(root_netuid), Error::::RootNetworkDoesNotExist ); @@ -285,7 +287,7 @@ impl Pallet { // --- 2. Check if the hotkey is already registered to the root network. If not, error out. ensure!( - Uids::::contains_key(NetUid::ROOT, &hotkey), + Uids::::contains_key(root_netuid, &hotkey), Error::::HotKeyNotRegisteredInSubNet ); @@ -330,9 +332,12 @@ impl Pallet { // * 'Result, Error>': A result containing the replaced member, if any. // fn join_senate_if_eligible(hotkey: &T::AccountId) -> Result, Error> { + // Get the root network UID. + let root_netuid: u16 = Self::get_root_netuid(); + // --- 1. Check the hotkey is registered in the root network. ensure!( - Uids::::contains_key(NetUid::ROOT, hotkey), + Uids::::contains_key(root_netuid, hotkey), Error::::HotKeyNotRegisteredInSubNet ); @@ -343,7 +348,7 @@ impl Pallet { ); // --- 3. Grab the hotkey's stake. - let current_stake = Self::get_stake_for_hotkey_on_subnet(hotkey, NetUid::ROOT); + let current_stake = Self::get_stake_for_hotkey_on_subnet(hotkey, Self::get_root_netuid()); // Add the hotkey to the Senate. // If we're full, we'll swap out the lowest stake member. @@ -352,14 +357,15 @@ impl Pallet { if (members.len() as u32) == T::SenateMembers::max_members() { let mut sorted_members = members.clone(); sorted_members.sort_by(|a, b| { - let a_stake = Self::get_stake_for_hotkey_on_subnet(a, NetUid::ROOT); - let b_stake = Self::get_stake_for_hotkey_on_subnet(b, NetUid::ROOT); + let a_stake = Self::get_stake_for_hotkey_on_subnet(a, Self::get_root_netuid()); + let b_stake = Self::get_stake_for_hotkey_on_subnet(b, Self::get_root_netuid()); b_stake.cmp(&a_stake) }); if let Some(last) = sorted_members.last() { - let last_stake = Self::get_stake_for_hotkey_on_subnet(last, NetUid::ROOT); + let last_stake = + Self::get_stake_for_hotkey_on_subnet(last, Self::get_root_netuid()); if last_stake < current_stake { // Swap the member with the lowest stake. @@ -434,7 +440,7 @@ impl Pallet { /// * 'SubNetworkDoesNotExist': If the specified network does not exist. /// * 'NotSubnetOwner': If the caller does not own the specified subnet. /// - pub fn user_remove_network(coldkey: T::AccountId, netuid: NetUid) -> dispatch::DispatchResult { + pub fn user_remove_network(coldkey: T::AccountId, netuid: u16) -> dispatch::DispatchResult { // --- 1. Ensure this subnet exists. ensure!( Self::if_subnet_exist(netuid), @@ -475,7 +481,7 @@ impl Pallet { /// # Note: /// This function does not emit any events, nor does it raise any errors. It silently /// returns if any internal checks fail. - pub fn remove_network(netuid: NetUid) { + pub fn remove_network(netuid: u16) { // --- 1. Return balance to subnet owner. let owner_coldkey: T::AccountId = SubnetOwner::::get(netuid); let reserved_amount: u64 = Self::get_subnet_locked_balance(netuid); @@ -506,20 +512,20 @@ impl Pallet { // --- 9. Iterate over stored weights and fill the matrix. for (uid_i, weights_i) in - as IterableStorageDoubleMap>>::iter_prefix( - NetUid::ROOT, + as IterableStorageDoubleMap>>::iter_prefix( + Self::get_root_netuid(), ) { // Create a new vector to hold modified weights. - let mut modified_weights = weights_i.clone(); + let mut modified_weights: Vec<(u16, u16)> = weights_i.clone(); // Iterate over each weight entry to potentially update it. for (subnet_id, weight) in modified_weights.iter_mut() { - if subnet_id == &u16::from(netuid) { + if subnet_id == &netuid { // If the condition matches, modify the weight *weight = 0; // Set weight to 0 for the matching subnet_id. } } - Weights::::insert(NetUid::ROOT, uid_i, modified_weights); + Weights::::insert(Self::get_root_netuid(), uid_i, modified_weights); } // --- 10. Remove various network-related parameters. @@ -615,7 +621,7 @@ impl Pallet { lock_cost } - pub fn get_network_registered_block(netuid: NetUid) -> u64 { + pub fn get_network_registered_block(netuid: u16) -> u64 { NetworkRegisteredAt::::get(netuid) } pub fn get_network_immunity_period() -> u64 { diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 833f0e7c8f..00b0c2fa55 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -2,7 +2,6 @@ use super::*; use alloc::collections::BTreeMap; use safe_math::*; use substrate_fixed::types::U96F32; -use subtensor_runtime_common::NetUid; use tle::stream_ciphers::AESGCMStreamCipherProvider; use tle::tlock::tld; @@ -39,13 +38,13 @@ impl Pallet { log::debug!("Current block: {:?}", current_block); // --- 1. Get all netuids (filter out root) - let subnets: Vec = Self::get_all_subnet_netuids() + let subnets: Vec = Self::get_all_subnet_netuids() .into_iter() - .filter(|netuid| *netuid != NetUid::ROOT) + .filter(|netuid| *netuid != 0) .collect(); log::debug!("All subnet netuids: {:?}", subnets); // Filter out subnets with no first emission block number. - let subnets_to_emit_to: Vec = subnets + let subnets_to_emit_to: Vec = subnets .clone() .into_iter() .filter(|netuid| FirstEmissionBlockNumber::::get(*netuid).is_some()) @@ -53,7 +52,7 @@ impl Pallet { log::debug!("Subnets to emit to: {:?}", subnets_to_emit_to); // --- 2. Get sum of tao reserves ( in a later version we will switch to prices. ) - let mut total_moving_prices = U96F32::saturating_from_num(0.0); + let mut total_moving_prices: U96F32 = U96F32::saturating_from_num(0.0); // Only get price EMA for subnets that we emit to. for netuid_i in subnets_to_emit_to.iter() { // Get and update the moving price of each subnet adding the total together. @@ -64,9 +63,9 @@ impl Pallet { // --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out) // Computation is described in detail in the dtao whitepaper. - let mut tao_in: BTreeMap = BTreeMap::new(); - let mut alpha_in: BTreeMap = BTreeMap::new(); - let mut alpha_out: BTreeMap = BTreeMap::new(); + let mut tao_in: BTreeMap = BTreeMap::new(); + let mut alpha_in: BTreeMap = BTreeMap::new(); + let mut alpha_out: BTreeMap = BTreeMap::new(); // Only calculate for subnets that we are emitting to. for netuid_i in subnets_to_emit_to.iter() { // Get subnet price. @@ -144,7 +143,7 @@ impl Pallet { // Remove owner cuts here so that we can properly seperate root dividends in the next step. // Owner cuts are accumulated and then fed to the drain at the end of this func. let cut_percent: U96F32 = Self::get_float_subnet_owner_cut(); - let mut owner_cuts: BTreeMap = BTreeMap::new(); + let mut owner_cuts: BTreeMap = BTreeMap::new(); for netuid_i in subnets_to_emit_to.iter() { // Get alpha out. let alpha_out_i: U96F32 = *alpha_out.get(netuid_i).unwrap_or(&asfloat!(0)); @@ -169,7 +168,7 @@ impl Pallet { let alpha_out_i: U96F32 = *alpha_out.get(netuid_i).unwrap_or(&asfloat!(0.0)); log::debug!("alpha_out_i: {:?}", alpha_out_i); // Get total TAO on root. - let root_tao: U96F32 = asfloat!(SubnetTAO::::get(NetUid::ROOT)); + let root_tao: U96F32 = asfloat!(SubnetTAO::::get(0)); log::debug!("root_tao: {:?}", root_tao); // Get total ALPHA on subnet. let alpha_issuance: U96F32 = asfloat!(Self::get_alpha_issuance(*netuid_i)); @@ -264,7 +263,7 @@ impl Pallet { } pub fn calculate_dividends_and_incentives( - netuid: NetUid, + netuid: u16, hotkey_emission: Vec<(T::AccountId, u64, u64)>, ) -> (BTreeMap, BTreeMap) { // Accumulate emission of dividends and incentive per hotkey. @@ -395,7 +394,7 @@ impl Pallet { } pub fn distribute_dividends_and_incentives( - netuid: NetUid, + netuid: u16, owner_cut: u64, incentives: BTreeMap, alpha_dividends: BTreeMap, @@ -484,12 +483,16 @@ impl Pallet { Self::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey, &Owner::::get(hotkey.clone()), - NetUid::ROOT, + Self::get_root_netuid(), tou64!(tao_take), ); // Give rest to nominators. log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao); - Self::increase_stake_for_hotkey_on_subnet(&hotkey, NetUid::ROOT, tou64!(root_tao)); + Self::increase_stake_for_hotkey_on_subnet( + &hotkey, + Self::get_root_netuid(), + tou64!(root_tao), + ); // Record root dividends for this validator on this subnet. TaoDividendsPerSubnet::::mutate(netuid, hotkey.clone(), |divs| { *divs = divs.saturating_add(tou64!(root_tao)); @@ -498,7 +501,7 @@ impl Pallet { } pub fn get_stake_map( - netuid: NetUid, + netuid: u16, hotkeys: Vec<&T::AccountId>, ) -> BTreeMap { let mut stake_map: BTreeMap = BTreeMap::new(); @@ -506,14 +509,15 @@ impl Pallet { // Get hotkey ALPHA on subnet. let alpha_stake: u64 = Self::get_stake_for_hotkey_on_subnet(hotkey, netuid); // Get hotkey TAO on root. - let root_stake: u64 = Self::get_stake_for_hotkey_on_subnet(hotkey, NetUid::ROOT); + let root_stake: u64 = + Self::get_stake_for_hotkey_on_subnet(hotkey, Self::get_root_netuid()); stake_map.insert(hotkey.clone(), (alpha_stake, root_stake)); } stake_map } pub fn calculate_dividend_and_incentive_distribution( - netuid: NetUid, + netuid: u16, pending_tao: u64, pending_validator_alpha: u64, hotkey_emission: Vec<(T::AccountId, u64, u64)>, @@ -543,7 +547,7 @@ impl Pallet { } pub fn drain_pending_emission( - netuid: NetUid, + netuid: u16, pending_alpha: u64, pending_tao: u64, pending_swapped: u64, @@ -606,7 +610,7 @@ impl Pallet { /// Returns the self contribution of a hotkey on a subnet. /// This is the portion of the hotkey's stake that is provided by itself, and not delegated to other hotkeys. - pub fn get_self_contribution(hotkey: &T::AccountId, netuid: NetUid) -> u64 { + pub fn get_self_contribution(hotkey: &T::AccountId, netuid: u16) -> u64 { // Get all childkeys for this hotkey. let childkeys = Self::get_children(hotkey, netuid); let mut remaining_proportion: U96F32 = U96F32::saturating_from_num(1.0); @@ -621,8 +625,10 @@ impl Pallet { let tao_weight: U96F32 = Self::get_tao_weight(); // Get the hotkey's stake including weight - let root_stake: U96F32 = - U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet(hotkey, NetUid::ROOT)); + let root_stake: U96F32 = U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet( + hotkey, + Self::get_root_netuid(), + )); let alpha_stake: U96F32 = U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet(hotkey, netuid)); @@ -652,7 +658,7 @@ impl Pallet { /// pub fn get_parent_child_dividends_distribution( hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, dividends: u64, ) -> Vec<(T::AccountId, u64)> { // hotkey dividends. @@ -705,7 +711,7 @@ impl Pallet { // Get the parent's root and subnet-specific (alpha) stakes let parent_root: U96F32 = U96F32::saturating_from_num( - Self::get_stake_for_hotkey_on_subnet(&parent, NetUid::ROOT), + Self::get_stake_for_hotkey_on_subnet(&parent, Self::get_root_netuid()), ); let parent_alpha: U96F32 = U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet(&parent, netuid)); @@ -807,7 +813,7 @@ impl Pallet { /// /// # Returns /// * `bool` - True if the epoch should run, false otherwise. - pub fn should_run_epoch(netuid: NetUid, current_block: u64) -> bool { + pub fn should_run_epoch(netuid: u16, current_block: u64) -> bool { Self::blocks_until_next_epoch(netuid, Self::get_tempo(netuid), current_block) == 0 } @@ -822,11 +828,11 @@ impl Pallet { /// 100 1 98 /// Special case: tempo = 0, the network never runs. /// - pub fn blocks_until_next_epoch(netuid: NetUid, tempo: u16, block_number: u64) -> u64 { + pub fn blocks_until_next_epoch(netuid: u16, tempo: u16, block_number: u64) -> u64 { if tempo == 0 { return u64::MAX; } - let netuid_plus_one = (u16::from(netuid) as u64).saturating_add(1); + let netuid_plus_one = (netuid as u64).saturating_add(1); let tempo_plus_one = (tempo as u64).saturating_add(1); let adjusted_block = block_number.wrapping_add(netuid_plus_one); let remainder = adjusted_block.checked_rem(tempo_plus_one).unwrap_or(0); @@ -834,7 +840,7 @@ impl Pallet { } /// The `reveal_crv3_commits` function is run at the very beginning of epoch `n`, - pub fn reveal_crv3_commits(netuid: NetUid) -> dispatch::DispatchResult { + pub fn reveal_crv3_commits(netuid: u16) -> dispatch::DispatchResult { use ark_serialize::CanonicalDeserialize; use frame_support::traits::OriginTrait; use tle::curves::drand::TinyBLS381; diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 715eb89f69..c550135123 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -4,13 +4,12 @@ use frame_support::IterableStorageDoubleMap; use safe_math::*; use sp_std::vec; use substrate_fixed::types::{I32F32, I64F64, I96F32}; -use subtensor_runtime_common::NetUid; impl Pallet { /// Calculates reward consensus and returns the emissions for uids/hotkeys in a given `netuid`. /// (Dense version used only for testing purposes.) #[allow(clippy::indexing_slicing)] - pub fn epoch_dense(netuid: NetUid, rao_emission: u64) -> Vec<(T::AccountId, u64, u64)> { + pub fn epoch_dense(netuid: u16, rao_emission: u64) -> Vec<(T::AccountId, u64, u64)> { // Get subnetwork size. let n: u16 = Self::get_subnetwork_n(netuid); log::trace!("n: {:?}", n); @@ -76,7 +75,7 @@ impl Pallet { // =========== let hotkeys: Vec<(u16, T::AccountId)> = - as IterableStorageDoubleMap>::iter_prefix(netuid) + as IterableStorageDoubleMap>::iter_prefix(netuid) .collect(); log::trace!("hotkeys: {:?}", &hotkeys); @@ -439,7 +438,7 @@ impl Pallet { /// - Print debugging outputs. /// #[allow(clippy::indexing_slicing)] - pub fn epoch(netuid: NetUid, rao_emission: u64) -> Vec<(T::AccountId, u64, u64)> { + pub fn epoch(netuid: u16, rao_emission: u64) -> Vec<(T::AccountId, u64, u64)> { // Get subnetwork size. let n: u16 = Self::get_subnetwork_n(netuid); log::trace!("Number of Neurons in Network: {:?}", n); @@ -483,7 +482,7 @@ impl Pallet { // =========== let hotkeys: Vec<(u16, T::AccountId)> = - as IterableStorageDoubleMap>::iter_prefix(netuid) + as IterableStorageDoubleMap>::iter_prefix(netuid) .collect(); log::debug!("hotkeys: {:?}", &hotkeys); @@ -880,19 +879,19 @@ impl Pallet { .collect() } - pub fn get_float_rho(netuid: NetUid) -> I32F32 { + pub fn get_float_rho(netuid: u16) -> I32F32 { I32F32::saturating_from_num(Self::get_rho(netuid)) } - pub fn get_float_kappa(netuid: NetUid) -> I32F32 { + pub fn get_float_kappa(netuid: u16) -> I32F32 { I32F32::saturating_from_num(Self::get_kappa(netuid)) .safe_div(I32F32::saturating_from_num(u16::MAX)) } - pub fn get_float_bonds_penalty(netuid: NetUid) -> I32F32 { + pub fn get_float_bonds_penalty(netuid: u16) -> I32F32 { I32F32::saturating_from_num(Self::get_bonds_penalty(netuid)) .safe_div(I32F32::saturating_from_num(u16::MAX)) } - pub fn get_block_at_registration(netuid: NetUid) -> Vec { + pub fn get_block_at_registration(netuid: u16) -> Vec { let n = Self::get_subnetwork_n(netuid); let block_at_registration: Vec = (0..n) .map(|neuron_uid| { @@ -907,14 +906,12 @@ impl Pallet { } /// Output unnormalized sparse weights, input weights are assumed to be row max-upscaled in u16. - pub fn get_weights_sparse(netuid: NetUid) -> Vec> { - let n = Self::get_subnetwork_n(netuid) as usize; + pub fn get_weights_sparse(netuid: u16) -> Vec> { + let n: usize = Self::get_subnetwork_n(netuid) as usize; let mut weights: Vec> = vec![vec![]; n]; for (uid_i, weights_i) in - as IterableStorageDoubleMap>>::iter_prefix( - netuid, - ) - .filter(|(uid_i, _)| *uid_i < n as u16) + as IterableStorageDoubleMap>>::iter_prefix(netuid) + .filter(|(uid_i, _)| *uid_i < n as u16) { for (uid_j, weight_ij) in weights_i.iter().filter(|(uid_j, _)| *uid_j < n as u16) { weights @@ -927,14 +924,12 @@ impl Pallet { } /// Output unnormalized weights in [n, n] matrix, input weights are assumed to be row max-upscaled in u16. - pub fn get_weights(netuid: NetUid) -> Vec> { - let n = Self::get_subnetwork_n(netuid) as usize; + pub fn get_weights(netuid: u16) -> Vec> { + let n: usize = Self::get_subnetwork_n(netuid) as usize; let mut weights: Vec> = vec![vec![I32F32::saturating_from_num(0.0); n]; n]; for (uid_i, weights_vec) in - as IterableStorageDoubleMap>>::iter_prefix( - netuid, - ) - .filter(|(uid_i, _)| *uid_i < n as u16) + as IterableStorageDoubleMap>>::iter_prefix(netuid) + .filter(|(uid_i, _)| *uid_i < n as u16) { for (uid_j, weight_ij) in weights_vec .into_iter() @@ -952,14 +947,12 @@ impl Pallet { } /// Output unnormalized sparse bonds, input bonds are assumed to be column max-upscaled in u16. - pub fn get_bonds_sparse(netuid: NetUid) -> Vec> { - let n = Self::get_subnetwork_n(netuid) as usize; + pub fn get_bonds_sparse(netuid: u16) -> Vec> { + let n: usize = Self::get_subnetwork_n(netuid) as usize; let mut bonds: Vec> = vec![vec![]; n]; for (uid_i, bonds_vec) in - as IterableStorageDoubleMap>>::iter_prefix( - netuid, - ) - .filter(|(uid_i, _)| *uid_i < n as u16) + as IterableStorageDoubleMap>>::iter_prefix(netuid) + .filter(|(uid_i, _)| *uid_i < n as u16) { for (uid_j, bonds_ij) in bonds_vec { bonds @@ -972,14 +965,12 @@ impl Pallet { } /// Output unnormalized bonds in [n, n] matrix, input bonds are assumed to be column max-upscaled in u16. - pub fn get_bonds(netuid: NetUid) -> Vec> { + pub fn get_bonds(netuid: u16) -> Vec> { let n: usize = Self::get_subnetwork_n(netuid) as usize; let mut bonds: Vec> = vec![vec![I32F32::saturating_from_num(0.0); n]; n]; for (uid_i, bonds_vec) in - as IterableStorageDoubleMap>>::iter_prefix( - netuid, - ) - .filter(|(uid_i, _)| *uid_i < n as u16) + as IterableStorageDoubleMap>>::iter_prefix(netuid) + .filter(|(uid_i, _)| *uid_i < n as u16) { for (uid_j, bonds_ij) in bonds_vec.into_iter().filter(|(uid_j, _)| *uid_j < n as u16) { *bonds @@ -993,7 +984,7 @@ impl Pallet { bonds } - pub fn get_bonds_fixed_proportion(netuid: NetUid) -> Vec> { + pub fn get_bonds_fixed_proportion(netuid: u16) -> Vec> { let mut bonds = Self::get_bonds(netuid); bonds.iter_mut().for_each(|bonds_row| { bonds_row @@ -1003,7 +994,7 @@ impl Pallet { bonds } - pub fn get_bonds_sparse_fixed_proportion(netuid: NetUid) -> Vec> { + pub fn get_bonds_sparse_fixed_proportion(netuid: u16) -> Vec> { let mut bonds = Self::get_bonds_sparse(netuid); bonds.iter_mut().for_each(|bonds_row| { bonds_row @@ -1025,7 +1016,7 @@ impl Pallet { pub fn compute_ema_bonds_normal_sparse( bonds_delta: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], - netuid: NetUid, + netuid: u16, ) -> Vec> { // Retrieve the bonds moving average for the given network ID and scale it down. let bonds_moving_average: I64F64 = @@ -1059,7 +1050,7 @@ impl Pallet { pub fn compute_ema_bonds_normal( bonds_delta: &[Vec], bonds: &[Vec], - netuid: NetUid, + netuid: u16, ) -> Vec> { // Retrieve the bonds moving average for the given network ID and scale it down. let bonds_moving_average: I64F64 = @@ -1093,7 +1084,7 @@ impl Pallet { /// # Returns: /// A vector of EMA bonds. pub fn compute_bonds( - netuid: NetUid, + netuid: u16, weights: &[Vec], // weights_for_bonds bonds: &[Vec], consensus: &[I32F32], @@ -1133,7 +1124,7 @@ impl Pallet { /// # Returns: /// A vector of EMA bonds. pub fn compute_bonds_sparse( - netuid: NetUid, + netuid: u16, weights: &[Vec<(u16, I32F32)>], bonds: &[Vec<(u16, I32F32)>], consensus: &[I32F32], @@ -1173,7 +1164,7 @@ impl Pallet { /// # Returns: /// A matrix of alphas pub fn compute_liquid_alpha_values( - netuid: NetUid, + netuid: u16, weights: &[Vec], // current epoch weights bonds: &[Vec], // previous epoch bonds consensus: &[I32F32], // previous epoch consensus weights @@ -1219,7 +1210,7 @@ impl Pallet { /// # Returns: /// A dense matrix of alphas pub fn compute_liquid_alpha_values_sparse( - netuid: NetUid, + netuid: u16, weights: &[Vec<(u16, I32F32)>], // current epoch weights bonds: &[Vec<(u16, I32F32)>], // previous epoch bonds consensus: &[I32F32], // previous epoch consensus weights @@ -1310,7 +1301,7 @@ impl Pallet { clamp_value(alpha, alpha_low, alpha_high) } - pub fn compute_disabled_liquid_alpha(netuid: NetUid) -> I32F32 { + pub fn compute_disabled_liquid_alpha(netuid: u16) -> I32F32 { // Retrieve the bonds moving average for the given network ID and scale it down. let bonds_moving_average: I64F64 = I64F64::from_num(Self::get_bonds_moving_average(netuid)) .saturating_div(I64F64::from_num(1_000_000)); @@ -1324,7 +1315,7 @@ impl Pallet { pub fn do_set_alpha_values( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, alpha_low: u16, alpha_high: u16, ) -> Result<(), DispatchError> { @@ -1363,7 +1354,7 @@ impl Pallet { Ok(()) } - pub fn do_reset_bonds(netuid: NetUid, account_id: &T::AccountId) -> Result<(), DispatchError> { + pub fn do_reset_bonds(netuid: u16, account_id: &T::AccountId) -> Result<(), DispatchError> { // check bonds reset enabled for this subnet let bonds_reset_enabled: bool = Self::get_bonds_reset(netuid); if !bonds_reset_enabled { @@ -1371,7 +1362,11 @@ impl Pallet { } if let Ok(uid) = Self::get_uid_for_net_and_hotkey(netuid, account_id) { - for (i, bonds_vec) in Bonds::::iter_prefix(netuid) { + for (i, bonds_vec) in + as IterableStorageDoubleMap>>::iter_prefix( + netuid, + ) + { Bonds::::insert( netuid, i, diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 0f728fea1c..8be8c58c95 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -28,7 +28,6 @@ use sp_runtime::{ transaction_validity::{TransactionValidity, TransactionValidityError}, }; use sp_std::marker::PhantomData; -use subtensor_runtime_common::NetUid; // ============================ // ==== Benchmark Imports ===== @@ -86,7 +85,6 @@ pub mod pallet { use sp_std::vec::Vec; use substrate_fixed::types::{I96F32, U64F64}; use subtensor_macros::freeze_struct; - use subtensor_runtime_common::NetUid; #[cfg(not(feature = "std"))] use alloc::boxed::Box; @@ -863,7 +861,7 @@ pub mod pallet { pub type LastHotkeySwapOnNetuid = StorageDoubleMap< _, Identity, - NetUid, + u16, Blake2_128Concat, T::AccountId, u64, @@ -917,8 +915,8 @@ pub mod pallet { Blake2_128Concat, T::AccountId, // First key: hotkey Identity, - NetUid, // Second key: netuid - u16, // Value: take + u16, // Second key: netuid + u16, // Value: take ValueQuery, >; #[pallet::storage] @@ -926,7 +924,7 @@ pub mod pallet { pub type PendingChildKeys = StorageDoubleMap< _, Identity, - NetUid, + u16, Blake2_128Concat, T::AccountId, (Vec<(u64, T::AccountId)>, u64), @@ -940,7 +938,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, Vec<(u64, T::AccountId)>, ValueQuery, DefaultAccountLinkage, @@ -952,7 +950,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, Vec<(u64, T::AccountId)>, ValueQuery, DefaultAccountLinkage, @@ -961,7 +959,7 @@ pub mod pallet { pub type AlphaDividendsPerSubnet = StorageDoubleMap< _, Identity, - NetUid, + u16, Blake2_128Concat, T::AccountId, u64, @@ -972,7 +970,7 @@ pub mod pallet { pub type TaoDividendsPerSubnet = StorageDoubleMap< _, Identity, - NetUid, + u16, Blake2_128Concat, T::AccountId, u64, @@ -993,7 +991,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, u64, ValueQuery, DefaultZeroU64, @@ -1019,28 +1017,28 @@ pub mod pallet { pub type SubnetMovingAlpha = StorageValue<_, I96F32, ValueQuery, DefaultMovingAlpha>; #[pallet::storage] // --- MAP ( netuid ) --> moving_price | The subnet moving price. pub type SubnetMovingPrice = - StorageMap<_, Identity, NetUid, I96F32, ValueQuery, DefaultMovingPrice>; + StorageMap<_, Identity, u16, I96F32, ValueQuery, DefaultMovingPrice>; #[pallet::storage] // --- MAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network. pub type SubnetVolume = - StorageMap<_, Identity, NetUid, u128, ValueQuery, DefaultZeroU128>; + StorageMap<_, Identity, u16, u128, ValueQuery, DefaultZeroU128>; #[pallet::storage] // --- MAP ( netuid ) --> tao_in_subnet | Returns the amount of TAO in the subnet. pub type SubnetTAO = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( netuid ) --> alpha_in_emission | Returns the amount of alph in emission into the pool per block. pub type SubnetAlphaInEmission = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( netuid ) --> alpha_out_emission | Returns the amount of alpha out emission into the network per block. pub type SubnetAlphaOutEmission = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( netuid ) --> tao_in_emission | Returns the amount of tao emitted into this subent on the last block. pub type SubnetTaoInEmission = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( netuid ) --> alpha_supply_in_pool | Returns the amount of alpha in the pool. pub type SubnetAlphaIn = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( netuid ) --> alpha_supply_in_subnet | Returns the amount of alpha in the subnet. pub type SubnetAlphaOut = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( cold ) --> Vec | Maps coldkey to hotkeys that stake to it pub type StakingHotkeys = StorageMap<_, Blake2_128Concat, T::AccountId, Vec, ValueQuery>; @@ -1064,7 +1062,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, u64, ValueQuery, DefaultZeroU64, @@ -1075,7 +1073,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, u64, ValueQuery, DefaultZeroU64, @@ -1087,7 +1085,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, U64F64, ValueQuery, DefaultSharePoolZero, @@ -1098,14 +1096,14 @@ pub mod pallet { ( NMapKey, // hot NMapKey, // cold - NMapKey, // subnet + NMapKey, // subnet ), U64F64, // Shares ValueQuery, >; #[pallet::storage] // --- MAP ( netuid ) --> token_symbol | Returns the token symbol for a subnet. pub type TokenSymbol = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, DefaultUnicodeVecU8>; + StorageMap<_, Identity, u16, Vec, ValueQuery, DefaultUnicodeVecU8>; /// ============================ /// ==== Global Parameters ===== @@ -1116,7 +1114,7 @@ pub mod pallet { #[pallet::storage] /// --- ITEM( global_max_registrations_per_block ) pub type MaxRegistrationsPerBlock = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultMaxRegistrationsPerBlock>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMaxRegistrationsPerBlock>; #[pallet::storage] /// --- ITEM( total_number_of_existing_networks ) pub type TotalNetworks = StorageValue<_, u16, ValueQuery>; @@ -1166,42 +1164,40 @@ pub mod pallet { /// ============================ #[pallet::storage] // --- MAP ( netuid ) --> transfer_toggle pub type TransferToggle = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultTrue>; + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultTrue>; #[pallet::storage] // --- MAP ( netuid ) --> total_subnet_locked pub type SubnetLocked = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] // --- MAP ( netuid ) --> largest_locked pub type LargestLocked = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; /// ================= /// ==== Tempos ===== /// ================= #[pallet::storage] // --- MAP ( netuid ) --> tempo - pub type Tempo = StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultTempo>; + pub type Tempo = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultTempo>; /// ============================ /// ==== Subnet Parameters ===== /// ============================ /// --- MAP ( netuid ) --> block number of first emission #[pallet::storage] - pub type FirstEmissionBlockNumber = - StorageMap<_, Identity, NetUid, u64, OptionQuery>; + pub type FirstEmissionBlockNumber = StorageMap<_, Identity, u16, u64, OptionQuery>; /// --- MAP ( netuid ) --> subnet mechanism #[pallet::storage] pub type SubnetMechanism = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultZeroU16>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultZeroU16>; #[pallet::storage] /// --- MAP ( netuid ) --> subnetwork_n (Number of UIDs in the network). - pub type SubnetworkN = StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultN>; + pub type SubnetworkN = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultN>; #[pallet::storage] /// --- MAP ( netuid ) --> modality TEXT: 0, IMAGE: 1, TENSOR: 2 - pub type NetworkModality = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultModality>; + pub type NetworkModality = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultModality>; #[pallet::storage] /// --- MAP ( netuid ) --> network_is_added pub type NetworksAdded = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultNeworksAdded>; + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultNeworksAdded>; #[pallet::storage] /// --- DMAP ( hotkey, netuid ) --> bool pub type IsNetworkMember = StorageDoubleMap< @@ -1209,7 +1205,7 @@ pub mod pallet { Blake2_128Concat, T::AccountId, Identity, - NetUid, + u16, bool, ValueQuery, DefaultIsNetworkMember, @@ -1217,177 +1213,174 @@ pub mod pallet { #[pallet::storage] /// --- MAP ( netuid ) --> network_registration_allowed pub type NetworkRegistrationAllowed = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultRegistrationAllowed>; + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultRegistrationAllowed>; #[pallet::storage] /// --- MAP ( netuid ) --> network_pow_allowed pub type NetworkPowRegistrationAllowed = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultRegistrationAllowed>; + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultRegistrationAllowed>; #[pallet::storage] /// --- MAP ( netuid ) --> block_created pub type NetworkRegisteredAt = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultNetworkRegisteredAt>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultNetworkRegisteredAt>; #[pallet::storage] /// --- MAP ( netuid ) --> pending_emission pub type PendingEmission = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultPendingEmission>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultPendingEmission>; #[pallet::storage] /// --- MAP ( netuid ) --> pending_root_emission - pub type PendingRootDivs = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + pub type PendingRootDivs = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] /// --- MAP ( netuid ) --> pending_alpha_swapped pub type PendingAlphaSwapped = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] /// --- MAP ( netuid ) --> pending_owner_cut - pub type PendingOwnerCut = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultZeroU64>; + pub type PendingOwnerCut = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64>; #[pallet::storage] /// --- MAP ( netuid ) --> blocks_since_last_step pub type BlocksSinceLastStep = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultBlocksSinceLastStep>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultBlocksSinceLastStep>; #[pallet::storage] /// --- MAP ( netuid ) --> last_mechanism_step_block pub type LastMechansimStepBlock = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultLastMechanismStepBlock>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultLastMechanismStepBlock>; #[pallet::storage] /// --- MAP ( netuid ) --> subnet_owner pub type SubnetOwner = - StorageMap<_, Identity, NetUid, T::AccountId, ValueQuery, DefaultSubnetOwner>; + StorageMap<_, Identity, u16, T::AccountId, ValueQuery, DefaultSubnetOwner>; #[pallet::storage] /// --- MAP ( netuid ) --> subnet_owner_hotkey pub type SubnetOwnerHotkey = - StorageMap<_, Identity, NetUid, T::AccountId, ValueQuery, DefaultSubnetOwner>; + StorageMap<_, Identity, u16, T::AccountId, ValueQuery, DefaultSubnetOwner>; #[pallet::storage] /// --- MAP ( netuid ) --> serving_rate_limit pub type ServingRateLimit = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultServingRateLimit>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultServingRateLimit>; #[pallet::storage] /// --- MAP ( netuid ) --> Rho - pub type Rho = StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultRho>; + pub type Rho = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultRho>; #[pallet::storage] /// --- MAP ( netuid ) --> AlphaSigmoidSteepness pub type AlphaSigmoidSteepness = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultAlphaSigmoidSteepness>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultAlphaSigmoidSteepness>; #[pallet::storage] /// --- MAP ( netuid ) --> Kappa - pub type Kappa = StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultKappa>; + pub type Kappa = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultKappa>; #[pallet::storage] /// --- MAP ( netuid ) --> registrations_this_interval - pub type RegistrationsThisInterval = - StorageMap<_, Identity, NetUid, u16, ValueQuery>; + pub type RegistrationsThisInterval = StorageMap<_, Identity, u16, u16, ValueQuery>; #[pallet::storage] /// --- MAP ( netuid ) --> pow_registrations_this_interval pub type POWRegistrationsThisInterval = - StorageMap<_, Identity, NetUid, u16, ValueQuery>; + StorageMap<_, Identity, u16, u16, ValueQuery>; #[pallet::storage] /// --- MAP ( netuid ) --> burn_registrations_this_interval pub type BurnRegistrationsThisInterval = - StorageMap<_, Identity, NetUid, u16, ValueQuery>; + StorageMap<_, Identity, u16, u16, ValueQuery>; #[pallet::storage] /// --- MAP ( netuid ) --> max_allowed_uids pub type MaxAllowedUids = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultMaxAllowedUids>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMaxAllowedUids>; #[pallet::storage] /// --- MAP ( netuid ) --> immunity_period pub type ImmunityPeriod = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultImmunityPeriod>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultImmunityPeriod>; #[pallet::storage] /// --- MAP ( netuid ) --> activity_cutoff pub type ActivityCutoff = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultActivityCutoff>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultActivityCutoff>; #[pallet::storage] /// --- MAP ( netuid ) --> max_weight_limit pub type MaxWeightsLimit = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultMaxWeightsLimit>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMaxWeightsLimit>; #[pallet::storage] /// --- MAP ( netuid ) --> weights_version_key pub type WeightsVersionKey = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultWeightsVersionKey>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultWeightsVersionKey>; #[pallet::storage] /// --- MAP ( netuid ) --> min_allowed_weights pub type MinAllowedWeights = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultMinAllowedWeights>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMinAllowedWeights>; #[pallet::storage] /// --- MAP ( netuid ) --> max_allowed_validators pub type MaxAllowedValidators = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultMaxAllowedValidators>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMaxAllowedValidators>; #[pallet::storage] /// --- MAP ( netuid ) --> adjustment_interval pub type AdjustmentInterval = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultAdjustmentInterval>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultAdjustmentInterval>; #[pallet::storage] /// --- MAP ( netuid ) --> bonds_moving_average pub type BondsMovingAverage = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultBondsMovingAverage>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultBondsMovingAverage>; #[pallet::storage] /// --- MAP ( netuid ) --> bonds_penalty pub type BondsPenalty = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultBondsPenalty>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultBondsPenalty>; #[pallet::storage] /// --- MAP ( netuid ) --> bonds_reset pub type BondsResetOn = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultBondsResetOn>; + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultBondsResetOn>; /// --- MAP ( netuid ) --> weights_set_rate_limit #[pallet::storage] pub type WeightsSetRateLimit = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultWeightsSetRateLimit>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultWeightsSetRateLimit>; #[pallet::storage] /// --- MAP ( netuid ) --> validator_prune_len pub type ValidatorPruneLen = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultValidatorPruneLen>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultValidatorPruneLen>; #[pallet::storage] /// --- MAP ( netuid ) --> scaling_law_power pub type ScalingLawPower = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultScalingLawPower>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultScalingLawPower>; #[pallet::storage] /// --- MAP ( netuid ) --> target_registrations_this_interval pub type TargetRegistrationsPerInterval = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultTargetRegistrationsPerInterval>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultTargetRegistrationsPerInterval>; #[pallet::storage] /// --- MAP ( netuid ) --> adjustment_alpha pub type AdjustmentAlpha = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultAdjustmentAlpha>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultAdjustmentAlpha>; #[pallet::storage] /// --- MAP ( netuid ) --> commit reveal v2 weights are enabled pub type CommitRevealWeightsEnabled = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultCommitRevealWeightsEnabled>; + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultCommitRevealWeightsEnabled>; #[pallet::storage] /// --- MAP ( netuid ) --> Burn - pub type Burn = StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultBurn>; + pub type Burn = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultBurn>; #[pallet::storage] /// --- MAP ( netuid ) --> Difficulty - pub type Difficulty = StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultDifficulty>; + pub type Difficulty = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultDifficulty>; #[pallet::storage] /// --- MAP ( netuid ) --> MinBurn - pub type MinBurn = StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultMinBurn>; + pub type MinBurn = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultMinBurn>; #[pallet::storage] /// --- MAP ( netuid ) --> MaxBurn - pub type MaxBurn = StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultMaxBurn>; + pub type MaxBurn = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultMaxBurn>; #[pallet::storage] /// --- MAP ( netuid ) --> MinDifficulty pub type MinDifficulty = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultMinDifficulty>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultMinDifficulty>; #[pallet::storage] /// --- MAP ( netuid ) --> MaxDifficulty pub type MaxDifficulty = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultMaxDifficulty>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultMaxDifficulty>; #[pallet::storage] /// --- MAP ( netuid ) --> Block at last adjustment. pub type LastAdjustmentBlock = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultLastAdjustmentBlock>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultLastAdjustmentBlock>; #[pallet::storage] /// --- MAP ( netuid ) --> Registrations of this Block. pub type RegistrationsThisBlock = - StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultRegistrationsThisBlock>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultRegistrationsThisBlock>; #[pallet::storage] /// --- MAP ( netuid ) --> Halving time of average moving price. pub type EMAPriceHalvingBlocks = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultEMAPriceMovingBlocks>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultEMAPriceMovingBlocks>; #[pallet::storage] /// --- MAP ( netuid ) --> global_RAO_recycled_for_registration pub type RAORecycledForRegistration = - StorageMap<_, Identity, NetUid, u64, ValueQuery, DefaultRAORecycledForRegistration>; + StorageMap<_, Identity, u16, u64, ValueQuery, DefaultRAORecycledForRegistration>; #[pallet::storage] /// --- ITEM ( tx_rate_limit ) pub type TxRateLimit = StorageValue<_, u64, ValueQuery, DefaultTxRateLimit>; @@ -1402,96 +1395,84 @@ pub mod pallet { #[pallet::storage] /// --- MAP ( netuid ) --> Whether or not Liquid Alpha is enabled pub type LiquidAlphaOn = - StorageMap<_, Blake2_128Concat, NetUid, bool, ValueQuery, DefaultLiquidAlpha>; + StorageMap<_, Blake2_128Concat, u16, bool, ValueQuery, DefaultLiquidAlpha>; #[pallet::storage] /// --- MAP ( netuid ) --> Whether or not Yuma3 is enabled - pub type Yuma3On = - StorageMap<_, Blake2_128Concat, NetUid, bool, ValueQuery, DefaultYuma3>; + pub type Yuma3On = StorageMap<_, Blake2_128Concat, u16, bool, ValueQuery, DefaultYuma3>; #[pallet::storage] /// MAP ( netuid ) --> (alpha_low, alpha_high) pub type AlphaValues = - StorageMap<_, Identity, NetUid, (u16, u16), ValueQuery, DefaultAlphaValues>; + StorageMap<_, Identity, u16, (u16, u16), ValueQuery, DefaultAlphaValues>; #[pallet::storage] /// --- MAP ( netuid ) --> If subtoken trading enabled - pub type SubtokenEnabled = - StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultFalse>; + pub type SubtokenEnabled = StorageMap<_, Identity, u16, bool, ValueQuery, DefaultFalse>; /// ======================================= /// ==== Subnetwork Consensus Storage ==== /// ======================================= #[pallet::storage] // --- DMAP ( netuid ) --> stake_weight | weight for stake used in YC. pub(super) type StakeWeight = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- DMAP ( netuid, hotkey ) --> uid pub type Uids = - StorageDoubleMap<_, Identity, NetUid, Blake2_128Concat, T::AccountId, u16, OptionQuery>; + StorageDoubleMap<_, Identity, u16, Blake2_128Concat, T::AccountId, u16, OptionQuery>; #[pallet::storage] /// --- DMAP ( netuid, uid ) --> hotkey - pub type Keys = StorageDoubleMap< - _, - Identity, - NetUid, - Identity, - u16, - T::AccountId, - ValueQuery, - DefaultKey, - >; + pub type Keys = + StorageDoubleMap<_, Identity, u16, Identity, u16, T::AccountId, ValueQuery, DefaultKey>; #[pallet::storage] /// --- MAP ( netuid ) --> (hotkey, se, ve) pub type LoadedEmission = - StorageMap<_, Identity, NetUid, Vec<(T::AccountId, u64, u64)>, OptionQuery>; + StorageMap<_, Identity, u16, Vec<(T::AccountId, u64, u64)>, OptionQuery>; #[pallet::storage] /// --- MAP ( netuid ) --> active pub type Active = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyBoolVec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyBoolVec>; #[pallet::storage] /// --- MAP ( netuid ) --> rank - pub type Rank = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + pub type Rank = StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> trust - pub type Trust = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + pub type Trust = StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> consensus pub type Consensus = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> incentive pub type Incentive = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> dividends pub type Dividends = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> emission pub type Emission = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU64Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU64Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> last_update pub type LastUpdate = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU64Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU64Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> validator_trust pub type ValidatorTrust = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> pruning_scores pub type PruningScores = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyU16Vec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyU16Vec>; #[pallet::storage] /// --- MAP ( netuid ) --> validator_permit pub type ValidatorPermit = - StorageMap<_, Identity, NetUid, Vec, ValueQuery, EmptyBoolVec>; + StorageMap<_, Identity, u16, Vec, ValueQuery, EmptyBoolVec>; #[pallet::storage] /// --- DMAP ( netuid, uid ) --> weights pub type Weights = StorageDoubleMap< _, Identity, - NetUid, + u16, Identity, u16, Vec<(u16, u16)>, @@ -1503,7 +1484,7 @@ pub mod pallet { pub type Bonds = StorageDoubleMap< _, Identity, - NetUid, + u16, Identity, u16, Vec<(u16, u16)>, @@ -1515,7 +1496,7 @@ pub mod pallet { pub type BlockAtRegistration = StorageDoubleMap< _, Identity, - NetUid, + u16, Identity, u16, u64, @@ -1524,21 +1505,14 @@ pub mod pallet { >; #[pallet::storage] /// --- MAP ( netuid, hotkey ) --> axon_info - pub type Axons = StorageDoubleMap< - _, - Identity, - NetUid, - Blake2_128Concat, - T::AccountId, - AxonInfoOf, - OptionQuery, - >; + pub type Axons = + StorageDoubleMap<_, Identity, u16, Blake2_128Concat, T::AccountId, AxonInfoOf, OptionQuery>; /// --- MAP ( netuid, hotkey ) --> certificate #[pallet::storage] pub type NeuronCertificates = StorageDoubleMap< _, Identity, - NetUid, + u16, Blake2_128Concat, T::AccountId, NeuronCertificateOf, @@ -1549,7 +1523,7 @@ pub mod pallet { pub type Prometheus = StorageDoubleMap< _, Identity, - NetUid, + u16, Blake2_128Concat, T::AccountId, PrometheusInfoOf, @@ -1565,11 +1539,11 @@ pub mod pallet { #[pallet::storage] // --- MAP ( netuid ) --> identity. (DEPRECATED for V2) pub type SubnetIdentities = - StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOf, OptionQuery>; + StorageMap<_, Blake2_128Concat, u16, SubnetIdentityOf, OptionQuery>; #[pallet::storage] // --- MAP ( netuid ) --> identityV2 pub type SubnetIdentitiesV2 = - StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOfV2, OptionQuery>; + StorageMap<_, Blake2_128Concat, u16, SubnetIdentityOfV2, OptionQuery>; /// ================================= /// ==== Axon / Promo Endpoints ===== @@ -1579,7 +1553,7 @@ pub mod pallet { _, ( NMapKey, // hot - NMapKey, // netuid + NMapKey, // netuid NMapKey, // extrinsic enum. ), u64, @@ -1605,7 +1579,7 @@ pub mod pallet { pub type WeightCommits = StorageDoubleMap< _, Twox64Concat, - NetUid, + u16, Twox64Concat, T::AccountId, VecDeque<(H256, u64, u64, u64)>, @@ -1616,7 +1590,7 @@ pub mod pallet { pub type CRV3WeightCommits = StorageDoubleMap< _, Twox64Concat, - NetUid, + u16, Twox64Concat, u64, VecDeque<( @@ -1629,7 +1603,7 @@ pub mod pallet { #[pallet::storage] /// --- Map (netuid) --> Number of epochs allowed for commit reveal periods pub type RevealPeriodEpochs = - StorageMap<_, Twox64Concat, NetUid, u64, ValueQuery, DefaultRevealPeriodEpochs>; + StorageMap<_, Twox64Concat, u16, u64, ValueQuery, DefaultRevealPeriodEpochs>; #[pallet::storage] /// --- Map (coldkey, hotkey) --> u64 the last block at which stake was added/removed. @@ -1649,7 +1623,7 @@ pub mod pallet { #[pallet::storage] /// --- DMAP (netuid, uid) --> (H160, last_block_where_ownership_was_proven) pub type AssociatedEvmAddress = - StorageDoubleMap<_, Twox64Concat, NetUid, Twox64Concat, u16, (H160, u64), OptionQuery>; + StorageDoubleMap<_, Twox64Concat, u16, Twox64Concat, u16, (H160, u64), OptionQuery>; /// ================== /// ==== Genesis ===== @@ -1677,7 +1651,7 @@ pub mod pallet { // ---- Subtensor helper functions. impl Pallet { /// Returns the transaction priority for setting weights. - pub fn get_priority_set_weights(hotkey: &T::AccountId, netuid: NetUid) -> u64 { + pub fn get_priority_set_weights(hotkey: &T::AccountId, netuid: u16) -> u64 { if let Ok(uid) = Self::get_uid_for_net_and_hotkey(netuid, hotkey) { // TODO rethink this. let _stake = Self::get_inherited_for_hotkey_on_subnet(hotkey, netuid); @@ -1709,15 +1683,15 @@ pub mod pallet { } /// Is the caller allowed to set weights - pub fn check_weights_min_stake(hotkey: &T::AccountId, netuid: NetUid) -> bool { + pub fn check_weights_min_stake(hotkey: &T::AccountId, netuid: u16) -> bool { // Blacklist weights transactions for low stake peers. let (total_stake, _, _) = Self::get_stake_weights_for_hotkey_on_subnet(hotkey, netuid); total_stake >= Self::get_stake_threshold() } /// Helper function to check if register is allowed - pub fn checked_allowed_register(netuid: NetUid) -> bool { - if netuid.is_root() { + pub fn checked_allowed_register(netuid: u16) -> bool { + if netuid == Self::get_root_netuid() { return false; } if !Self::if_subnet_exist(netuid) { @@ -1740,7 +1714,7 @@ pub mod pallet { } /// Ensure subtoken enalbed - pub fn ensure_subtoken_enabled(subnet: NetUid) -> Result<(), Error> { + pub fn ensure_subtoken_enabled(subnet: u16) -> Result<(), Error> { ensure!( SubtokenEnabled::::get(subnet), Error::::SubtokenDisabled @@ -1840,7 +1814,7 @@ where u64::MAX } - pub fn get_priority_set_weights(who: &T::AccountId, netuid: NetUid) -> u64 { + pub fn get_priority_set_weights(who: &T::AccountId, netuid: u16) -> u64 { Pallet::::get_priority_set_weights(who, netuid) } @@ -1852,7 +1826,7 @@ where Pallet::::get_priority_staking(coldkey, hotkey, stake_amount) } - pub fn check_weights_min_stake(who: &T::AccountId, netuid: NetUid) -> bool { + pub fn check_weights_min_stake(who: &T::AccountId, netuid: u16) -> bool { Pallet::::check_weights_min_stake(who, netuid) } @@ -2561,5 +2535,5 @@ impl CollectiveInterface for () { #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)] pub enum RateLimitKey { // The setting sn owner hotkey operation is rate limited per netuid - SetSNOwnerHotkey(NetUid), + SetSNOwnerHotkey(u16), } diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index ad76d90ae2..d1a6f36884 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -82,7 +82,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn set_weights( origin: OriginFor, - netuid: NetUid, + netuid: u16, dests: Vec, weights: Vec, version_key: u64, @@ -125,7 +125,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, - netuids: Vec>, + netuids: Vec>, weights: Vec, Compact)>>, version_keys: Vec>, ) -> DispatchResult { @@ -157,7 +157,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, commit_hash: H256, ) -> DispatchResult { Self::do_commit_weights(origin, netuid, commit_hash) @@ -191,7 +191,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_commit_weights( origin: OriginFor, - netuids: Vec>, + netuids: Vec>, commit_hashes: Vec, ) -> DispatchResult { Self::do_batch_commit_weights(origin, netuids, commit_hashes) @@ -240,7 +240,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn reveal_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, uids: Vec, values: Vec, salt: Vec, @@ -284,7 +284,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_crv3_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, commit: BoundedVec>, reveal_round: u64, ) -> DispatchResult { @@ -336,7 +336,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn batch_reveal_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, uids_list: Vec>, values_list: Vec>, salts_list: Vec>, @@ -418,7 +418,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Normal, Pays::No))] pub fn set_tao_weights( _origin: OriginFor, - _netuid: NetUid, + _netuid: u16, _hotkey: T::AccountId, _dests: Vec, _weights: Vec, @@ -591,7 +591,7 @@ mod dispatches { pub fn add_stake( origin: OriginFor, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, amount_staked: u64, ) -> DispatchResult { Self::do_add_stake(origin, hotkey, netuid, amount_staked) @@ -635,7 +635,7 @@ mod dispatches { pub fn remove_stake( origin: OriginFor, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, amount_unstaked: u64, ) -> DispatchResult { Self::do_remove_stake(origin, hotkey, netuid, amount_unstaked) @@ -698,7 +698,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon( origin: OriginFor, - netuid: NetUid, + netuid: u16, version: u32, ip: u128, port: u16, @@ -782,7 +782,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_axon_tls( origin: OriginFor, - netuid: NetUid, + netuid: u16, version: u32, ip: u128, port: u16, @@ -832,7 +832,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))] pub fn serve_prometheus( origin: OriginFor, - netuid: NetUid, + netuid: u16, version: u32, ip: u128, port: u16, @@ -894,7 +894,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(23)), DispatchClass::Normal, Pays::No))] pub fn register( origin: OriginFor, - netuid: NetUid, + netuid: u16, block_number: u64, nonce: u64, work: Vec, @@ -929,7 +929,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(29)), DispatchClass::Normal, Pays::No))] pub fn burned_register( origin: OriginFor, - netuid: NetUid, + netuid: u16, hotkey: T::AccountId, ) -> DispatchResult { Self::do_burned_registration(origin, netuid, hotkey) @@ -944,7 +944,7 @@ mod dispatches { origin: OriginFor, hotkey: T::AccountId, new_hotkey: T::AccountId, - netuid: Option, + netuid: Option, ) -> DispatchResultWithPostInfo { Self::do_swap_hotkey(origin, &hotkey, &new_hotkey, netuid) } @@ -1021,7 +1021,7 @@ mod dispatches { pub fn set_childkey_take( origin: OriginFor, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, take: u16, ) -> DispatchResult { let coldkey = ensure_signed(origin)?; @@ -1229,7 +1229,7 @@ mod dispatches { pub fn dissolve_network( origin: OriginFor, coldkey: T::AccountId, - netuid: NetUid, + netuid: u16, ) -> DispatchResult { ensure_root(origin)?; Self::user_remove_network(coldkey, netuid) @@ -1287,7 +1287,7 @@ mod dispatches { pub fn set_children( origin: T::RuntimeOrigin, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, children: Vec<(u64, T::AccountId)>, ) -> DispatchResultWithPostInfo { Self::do_schedule_children(origin, hotkey, netuid, children)?; @@ -1407,7 +1407,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Operational, Pays::Yes))] pub fn schedule_dissolve_network( _origin: OriginFor, - _netuid: NetUid, + _netuid: u16, ) -> DispatchResultWithPostInfo { Err(Error::::CallDisabled.into()) @@ -1512,7 +1512,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::Yes))] pub fn set_subnet_identity( origin: OriginFor, - netuid: NetUid, + netuid: u16, subnet_name: Vec, github_repo: Vec, subnet_contact: Vec, @@ -1642,8 +1642,8 @@ mod dispatches { origin: T::RuntimeOrigin, origin_hotkey: T::AccountId, destination_hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, ) -> DispatchResult { Self::do_move_stake( @@ -1685,8 +1685,8 @@ mod dispatches { origin: T::RuntimeOrigin, destination_coldkey: T::AccountId, hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, ) -> DispatchResult { Self::do_transfer_stake( @@ -1729,8 +1729,8 @@ mod dispatches { pub fn swap_stake( origin: T::RuntimeOrigin, hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, ) -> DispatchResult { Self::do_swap_stake( @@ -1791,7 +1791,7 @@ mod dispatches { pub fn add_stake_limit( origin: OriginFor, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, amount_staked: u64, limit_price: u64, allow_partial: bool, @@ -1855,7 +1855,7 @@ mod dispatches { pub fn remove_stake_limit( origin: OriginFor, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, amount_unstaked: u64, limit_price: u64, allow_partial: bool, @@ -1902,8 +1902,8 @@ mod dispatches { pub fn swap_stake_limit( origin: T::RuntimeOrigin, hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, limit_price: u64, allow_partial: bool, @@ -1958,7 +1958,7 @@ mod dispatches { DispatchClass::Operational, Pays::Yes ))] - pub fn start_call(origin: T::RuntimeOrigin, netuid: NetUid) -> DispatchResult { + pub fn start_call(origin: T::RuntimeOrigin, netuid: u16) -> DispatchResult { Self::do_start_call(origin, netuid)?; Ok(()) } @@ -1998,7 +1998,7 @@ mod dispatches { ))] pub fn associate_evm_key( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, hotkey: T::AccountId, evm_key: H160, block_number: u64, @@ -2027,7 +2027,7 @@ mod dispatches { origin: T::RuntimeOrigin, hotkey: T::AccountId, amount: u64, - netuid: NetUid, + netuid: u16, ) -> DispatchResult { Self::do_recycle_alpha(origin, hotkey, amount, netuid) } @@ -2052,7 +2052,7 @@ mod dispatches { origin: T::RuntimeOrigin, hotkey: T::AccountId, amount: u64, - netuid: NetUid, + netuid: u16, ) -> DispatchResult { Self::do_burn_alpha(origin, hotkey, amount, netuid) } diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs index b327376aad..e331769fca 100644 --- a/pallets/subtensor/src/macros/events.rs +++ b/pallets/subtensor/src/macros/events.rs @@ -10,90 +10,83 @@ mod events { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// a new network is added. - NetworkAdded(NetUid, u16), + NetworkAdded(u16, u16), /// a network is removed. - NetworkRemoved(NetUid), + NetworkRemoved(u16), /// stake has been transferred from the a coldkey account onto the hotkey staking account. - StakeAdded(T::AccountId, T::AccountId, u64, u64, NetUid, u64), + StakeAdded(T::AccountId, T::AccountId, u64, u64, u16, u64), /// stake has been removed from the hotkey staking account onto the coldkey account. - StakeRemoved(T::AccountId, T::AccountId, u64, u64, NetUid, u64), + StakeRemoved(T::AccountId, T::AccountId, u64, u64, u16, u64), /// stake has been moved from origin (hotkey, subnet ID) to destination (hotkey, subnet ID) of this amount (in TAO). - StakeMoved( - T::AccountId, - T::AccountId, - NetUid, - T::AccountId, - NetUid, - u64, - ), + StakeMoved(T::AccountId, T::AccountId, u16, T::AccountId, u16, u64), /// a caller successfully sets their weights on a subnetwork. - WeightsSet(NetUid, u16), + WeightsSet(u16, u16), /// a new neuron account has been registered to the chain. - NeuronRegistered(NetUid, u16, T::AccountId), + NeuronRegistered(u16, u16, T::AccountId), /// multiple uids have been concurrently registered. BulkNeuronsRegistered(u16, u16), /// FIXME: Not used yet BulkBalancesSet(u16, u16), /// max allowed uids has been set for a subnetwork. - MaxAllowedUidsSet(NetUid, u16), + MaxAllowedUidsSet(u16, u16), /// the max weight limit has been set for a subnetwork. - MaxWeightLimitSet(NetUid, u16), + MaxWeightLimitSet(u16, u16), /// the difficulty has been set for a subnet. - DifficultySet(NetUid, u64), + DifficultySet(u16, u64), /// the adjustment interval is set for a subnet. - AdjustmentIntervalSet(NetUid, u16), + AdjustmentIntervalSet(u16, u16), /// registration per interval is set for a subnet. - RegistrationPerIntervalSet(NetUid, u16), + RegistrationPerIntervalSet(u16, u16), /// we set max registrations per block. - MaxRegistrationsPerBlockSet(NetUid, u16), + MaxRegistrationsPerBlockSet(u16, u16), /// an activity cutoff is set for a subnet. - ActivityCutoffSet(NetUid, u16), + ActivityCutoffSet(u16, u16), /// Rho value is set. - RhoSet(NetUid, u16), + RhoSet(u16, u16), /// steepness of the sigmoid used to compute alpha values. - AlphaSigmoidSteepnessSet(NetUid, u16), + AlphaSigmoidSteepnessSet(u16, u16), /// Kappa is set for a subnet. - KappaSet(NetUid, u16), + KappaSet(u16, u16), /// minimum allowed weight is set for a subnet. - MinAllowedWeightSet(NetUid, u16), + MinAllowedWeightSet(u16, u16), /// the validator pruning length has been set. - ValidatorPruneLenSet(NetUid, u64), + ValidatorPruneLenSet(u16, u64), /// the scaling law power has been set for a subnet. - ScalingLawPowerSet(NetUid, u16), + ScalingLawPowerSet(u16, u16), /// weights set rate limit has been set for a subnet. - WeightsSetRateLimitSet(NetUid, u64), + WeightsSetRateLimitSet(u16, u64), /// immunity period is set for a subnet. - ImmunityPeriodSet(NetUid, u16), + ImmunityPeriodSet(u16, u16), /// bonds moving average is set for a subnet. - BondsMovingAverageSet(NetUid, u64), + BondsMovingAverageSet(u16, u64), /// bonds penalty is set for a subnet. - BondsPenaltySet(NetUid, u16), + BondsPenaltySet(u16, u16), /// bonds reset is set for a subnet. - BondsResetOnSet(NetUid, bool), + BondsResetOnSet(u16, bool), /// setting the max number of allowed validators on a subnet. - MaxAllowedValidatorsSet(NetUid, u16), + MaxAllowedValidatorsSet(u16, u16), /// the axon server information is added to the network. - AxonServed(NetUid, T::AccountId), + AxonServed(u16, T::AccountId), /// the prometheus server information is added to the network. - PrometheusServed(NetUid, T::AccountId), + PrometheusServed(u16, T::AccountId), /// a hotkey has become a delegate. DelegateAdded(T::AccountId, T::AccountId, u16), /// the default take is set. DefaultTakeSet(u16), /// weights version key is set for a network. - WeightsVersionKeySet(NetUid, u64), + WeightsVersionKeySet(u16, u64), /// setting min difficulty on a network. - MinDifficultySet(NetUid, u64), + MinDifficultySet(u16, u64), /// setting max difficulty on a network. - MaxDifficultySet(NetUid, u64), + MaxDifficultySet(u16, u64), /// setting the prometheus serving rate limit. - ServingRateLimitSet(NetUid, u64), + ServingRateLimitSet(u16, u64), /// setting burn on a network. - BurnSet(NetUid, u64), + BurnSet(u16, u64), /// setting max burn on a network. - MaxBurnSet(NetUid, u64), + MaxBurnSet(u16, u64), /// setting min burn on a network. - MinBurnSet(NetUid, u64), + MinBurnSet(u16, u64), /// setting the transaction rate limit. TxRateLimitSet(u64), /// setting the delegate take transaction rate limit. @@ -109,19 +102,19 @@ mod events { /// a sudo call is done. Sudid(DispatchResult), /// registration is allowed/disallowed for a subnet. - RegistrationAllowed(NetUid, bool), + RegistrationAllowed(u16, bool), /// POW registration is allowed/disallowed for a subnet. - PowRegistrationAllowed(NetUid, bool), + PowRegistrationAllowed(u16, bool), /// setting tempo on a network - TempoSet(NetUid, u16), + TempoSet(u16, u16), /// setting the RAO recycled for registration. - RAORecycledForRegistrationSet(NetUid, u64), + RAORecycledForRegistrationSet(u16, u64), /// min stake is set for validators to set weights. StakeThresholdSet(u64), /// setting the minimum required stake amount for senate registration. SenateRequiredStakePercentSet(u64), /// setting the adjustment alpha on a subnet. - AdjustmentAlphaSet(NetUid, u64), + AdjustmentAlphaSet(u16, u64), /// the faucet it called on the test net. Faucet(T::AccountId, u64), /// the subnet owner cut is set. @@ -197,9 +190,9 @@ mod events { coldkey: T::AccountId, }, /// Setting of children of a hotkey have been scheduled - SetChildrenScheduled(T::AccountId, NetUid, u64, Vec<(u64, T::AccountId)>), + SetChildrenScheduled(T::AccountId, u16, u64, Vec<(u64, T::AccountId)>), /// The children of a hotkey have been set - SetChildren(T::AccountId, NetUid, Vec<(u64, T::AccountId)>), + SetChildren(T::AccountId, u16, Vec<(u64, T::AccountId)>), // /// The hotkey emission tempo has been set // HotkeyEmissionTempoSet(u64), // /// The network maximum stake has been set @@ -207,15 +200,15 @@ mod events { /// The identity of a coldkey has been set ChainIdentitySet(T::AccountId), /// The identity of a subnet has been set - SubnetIdentitySet(NetUid), + SubnetIdentitySet(u16), /// The identity of a subnet has been removed - SubnetIdentityRemoved(NetUid), + SubnetIdentityRemoved(u16), /// A dissolve network extrinsic scheduled. DissolveNetworkScheduled { /// The account ID schedule the dissolve network extrisnic account: T::AccountId, /// network ID will be dissolved - netuid: NetUid, + netuid: u16, /// extrinsic execution block number execution_block: BlockNumberFor, }, @@ -228,33 +221,33 @@ mod events { /// - **who**: The account ID of the user committing the weights. /// - **netuid**: The network identifier. /// - **commit_hash**: The hash representing the committed weights. - CRV3WeightsCommitted(T::AccountId, NetUid, H256), + CRV3WeightsCommitted(T::AccountId, u16, H256), /// Weights have been successfully committed. /// /// - **who**: The account ID of the user committing the weights. /// - **netuid**: The network identifier. /// - **commit_hash**: The hash representing the committed weights. - WeightsCommitted(T::AccountId, NetUid, H256), + WeightsCommitted(T::AccountId, u16, H256), /// Weights have been successfully revealed. /// /// - **who**: The account ID of the user revealing the weights. /// - **netuid**: The network identifier. /// - **commit_hash**: The hash of the revealed weights. - WeightsRevealed(T::AccountId, NetUid, H256), + WeightsRevealed(T::AccountId, u16, H256), /// Weights have been successfully batch revealed. /// /// - **who**: The account ID of the user revealing the weights. /// - **netuid**: The network identifier. /// - **revealed_hashes**: A vector of hashes representing each revealed weight set. - WeightsBatchRevealed(T::AccountId, NetUid, Vec), + WeightsBatchRevealed(T::AccountId, u16, Vec), /// A batch of weights (or commits) have been force-set. /// /// - **netuids**: The netuids these weights were successfully set/committed for. /// - **who**: The hotkey that set this batch. - BatchWeightsCompleted(Vec>, T::AccountId), + BatchWeightsCompleted(Vec>, T::AccountId), /// A batch extrinsic completed but with some errors. BatchCompletedWithErrors(), @@ -267,55 +260,48 @@ mod events { /// Stake has been transferred from one coldkey to another on the same subnet. /// Parameters: /// (origin_coldkey, destination_coldkey, hotkey, origin_netuid, destination_netuid, amount) - StakeTransferred( - T::AccountId, - T::AccountId, - T::AccountId, - NetUid, - NetUid, - u64, - ), + StakeTransferred(T::AccountId, T::AccountId, T::AccountId, u16, u16, u64), /// Stake has been swapped from one subnet to another for the same coldkey-hotkey pair. /// /// Parameters: /// (coldkey, hotkey, origin_netuid, destination_netuid, amount) - StakeSwapped(T::AccountId, T::AccountId, NetUid, NetUid, u64), + StakeSwapped(T::AccountId, T::AccountId, u16, u16, u64), /// Event called when transfer is toggled on a subnet. /// /// Parameters: /// (netuid, bool) - TransferToggle(NetUid, bool), + TransferToggle(u16, bool), /// The owner hotkey for a subnet has been set. /// /// Parameters: /// (netuid, new_hotkey) - SubnetOwnerHotkeySet(NetUid, T::AccountId), + SubnetOwnerHotkeySet(u16, T::AccountId), /// FirstEmissionBlockNumber is set via start call extrinsic /// /// Parameters: /// netuid /// block number - FirstEmissionBlockNumberSet(NetUid, u64), + FirstEmissionBlockNumberSet(u16, u64), /// Alpha has been recycled, reducing AlphaOut on a subnet. /// /// Parameters: /// (coldkey, hotkey, amount, subnet_id) - AlphaRecycled(T::AccountId, T::AccountId, u64, NetUid), + AlphaRecycled(T::AccountId, T::AccountId, u64, u16), /// Alpha have been burned without reducing AlphaOut. /// /// Parameters: /// (coldkey, hotkey, amount, subnet_id) - AlphaBurned(T::AccountId, T::AccountId, u64, NetUid), + AlphaBurned(T::AccountId, T::AccountId, u64, u16), /// An EVM key has been associated with a hotkey. EvmKeyAssociated { /// The subnet that the hotkey belongs to. - netuid: NetUid, + netuid: u16, /// The hotkey associated with the EVM key. hotkey: T::AccountId, /// The EVM key being associated with the hotkey. @@ -328,19 +314,19 @@ mod events { /// /// - **netuid**: The network identifier. /// - **who**: The account ID of the user revealing the weights. - CRV3WeightsRevealed(NetUid, T::AccountId), + CRV3WeightsRevealed(u16, T::AccountId), /// Commit-Reveal periods has been successfully set. /// /// - **netuid**: The network identifier. /// - **periods**: The number of epochs before the reveal. - CommitRevealPeriodsSet(NetUid, u64), + CommitRevealPeriodsSet(u16, u64), /// Commit-Reveal has been successfully toggled. /// /// - **netuid**: The network identifier. /// - **Enabled**: Is Commit-Reveal enabled. - CommitRevealEnabled(NetUid, bool), + CommitRevealEnabled(u16, bool), /// the hotkey is swapped HotkeySwappedOnSubnet { @@ -351,7 +337,7 @@ mod events { /// the account ID of new hotkey new_hotkey: T::AccountId, /// the subnet ID - netuid: NetUid, + netuid: u16, }, } } diff --git a/pallets/subtensor/src/macros/genesis.rs b/pallets/subtensor/src/macros/genesis.rs index ff8f4864b4..f1288c5a63 100644 --- a/pallets/subtensor/src/macros/genesis.rs +++ b/pallets/subtensor/src/macros/genesis.rs @@ -11,91 +11,98 @@ mod genesis { // Set initial total issuance from balances TotalIssuance::::put(self.balances_issuance); + // Get the root network uid. + let root_netuid: u16 = 0; + // Set the root network as added. - NetworksAdded::::insert(NetUid::ROOT, true); + NetworksAdded::::insert(root_netuid, true); // Increment the number of total networks. TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); // Set the number of validators to 1. - SubnetworkN::::insert(NetUid::ROOT, 0); + SubnetworkN::::insert(root_netuid, 0); // Set the maximum number to the number of senate members. - MaxAllowedUids::::insert(NetUid::ROOT, 64u16); + MaxAllowedUids::::insert(root_netuid, 64u16); // Set the maximum number to the number of validators to all members. - MaxAllowedValidators::::insert(NetUid::ROOT, 64u16); + MaxAllowedValidators::::insert(root_netuid, 64u16); // Set the min allowed weights to zero, no weights restrictions. - MinAllowedWeights::::insert(NetUid::ROOT, 0); + MinAllowedWeights::::insert(root_netuid, 0); // Set the max weight limit to infitiy, no weight restrictions. - MaxWeightsLimit::::insert(NetUid::ROOT, u16::MAX); + MaxWeightsLimit::::insert(root_netuid, u16::MAX); // Add default root tempo. - Tempo::::insert(NetUid::ROOT, 100); + Tempo::::insert(root_netuid, 100); // Set the root network as open. - NetworkRegistrationAllowed::::insert(NetUid::ROOT, true); + NetworkRegistrationAllowed::::insert(root_netuid, true); // Set target registrations for validators as 1 per block. - TargetRegistrationsPerInterval::::insert(NetUid::ROOT, 1); + TargetRegistrationsPerInterval::::insert(root_netuid, 1); - let netuid = NetUid::from(1); - let hotkey = DefaultAccount::::get(); - SubnetMechanism::::insert(netuid, 1); // Make dynamic. - Owner::::insert(hotkey.clone(), hotkey.clone()); - SubnetAlphaIn::::insert(netuid, 10_000_000_000); - SubnetTAO::::insert(netuid, 10_000_000_000); - NetworksAdded::::insert(netuid, true); - TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); - SubnetworkN::::insert(netuid, 0); - MaxAllowedUids::::insert(netuid, 256u16); - MaxAllowedValidators::::insert(netuid, 64u16); - MinAllowedWeights::::insert(netuid, 0); - MaxWeightsLimit::::insert(netuid, u16::MAX); - Tempo::::insert(netuid, 100); - NetworkRegistrationAllowed::::insert(netuid, true); - SubnetOwner::::insert(netuid, hotkey.clone()); - SubnetLocked::::insert(netuid, 1); - LargestLocked::::insert(netuid, 1); - Alpha::::insert( - // Lock the initial funds making this key the owner. - (hotkey.clone(), hotkey.clone(), netuid), - U64F64::saturating_from_num(1_000_000_000), - ); - TotalHotkeyAlpha::::insert(hotkey.clone(), netuid, 1_000_000_000); - TotalHotkeyShares::::insert( - hotkey.clone(), - netuid, - U64F64::saturating_from_num(1_000_000_000), - ); - // TotalColdkeyAlpha::::insert(hotkey.clone(), netuid, 1_000_000_000); - SubnetAlphaOut::::insert(netuid, 1_000_000_000); - let mut staking_hotkeys = StakingHotkeys::::get(hotkey.clone()); - if !staking_hotkeys.contains(&hotkey) { - staking_hotkeys.push(hotkey.clone()); - StakingHotkeys::::insert(hotkey.clone(), staking_hotkeys.clone()); - } + for net in 1..2 { + let netuid: u16 = net as u16; + let hotkey = DefaultAccount::::get(); + SubnetMechanism::::insert(netuid, 1); // Make dynamic. + Owner::::insert(hotkey.clone(), hotkey.clone()); + SubnetAlphaIn::::insert(netuid, 10_000_000_000); + SubnetTAO::::insert(netuid, 10_000_000_000); + NetworksAdded::::insert(netuid, true); + TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); + SubnetworkN::::insert(netuid, 0); + MaxAllowedUids::::insert(netuid, 256u16); + MaxAllowedValidators::::insert(netuid, 64u16); + MinAllowedWeights::::insert(netuid, 0); + MaxWeightsLimit::::insert(netuid, u16::MAX); + Tempo::::insert(netuid, 100); + NetworkRegistrationAllowed::::insert(netuid, true); + SubnetOwner::::insert(netuid, hotkey.clone()); + SubnetLocked::::insert(netuid, 1); + LargestLocked::::insert(netuid, 1); + Alpha::::insert( + // Lock the initial funds making this key the owner. + (hotkey.clone(), hotkey.clone(), netuid), + U64F64::saturating_from_num(1_000_000_000), + ); + TotalHotkeyAlpha::::insert(hotkey.clone(), netuid, 1_000_000_000); + TotalHotkeyShares::::insert( + hotkey.clone(), + netuid, + U64F64::saturating_from_num(1_000_000_000), + ); + // TotalColdkeyAlpha::::insert(hotkey.clone(), netuid, 1_000_000_000); + SubnetAlphaOut::::insert(netuid, 1_000_000_000); + let mut staking_hotkeys = StakingHotkeys::::get(hotkey.clone()); + if !staking_hotkeys.contains(&hotkey) { + staking_hotkeys.push(hotkey.clone()); + StakingHotkeys::::insert(hotkey.clone(), staking_hotkeys.clone()); + } - let block_number = Pallet::::get_current_block_as_u64(); - - SubnetworkN::::insert(netuid, 1); - Rank::::mutate(netuid, |v| v.push(0)); - Trust::::mutate(netuid, |v| v.push(0)); - Active::::mutate(netuid, |v| v.push(true)); - Emission::::mutate(netuid, |v| v.push(0)); - Consensus::::mutate(netuid, |v| v.push(0)); - Incentive::::mutate(netuid, |v| v.push(0)); - Dividends::::mutate(netuid, |v| v.push(0)); - LastUpdate::::mutate(netuid, |v| v.push(block_number)); - PruningScores::::mutate(netuid, |v| v.push(0)); - ValidatorTrust::::mutate(netuid, |v| v.push(0)); - ValidatorPermit::::mutate(netuid, |v| v.push(false)); - Keys::::insert(netuid, 0, hotkey.clone()); // Make hotkey - uid association. - Uids::::insert(netuid, hotkey.clone(), 0); // Make uid - hotkey association. - BlockAtRegistration::::insert(netuid, 0, block_number); // Fill block at registration. - IsNetworkMember::::insert(hotkey.clone(), netuid, true); // Fill network is member. + let block_number = Pallet::::get_current_block_as_u64(); + for next_uid_s in 0..1 { + let next_uid: u16 = next_uid_s as u16; + SubnetworkN::::insert(netuid, next_uid.saturating_add(1)); + Rank::::mutate(netuid, |v| v.push(0)); + Trust::::mutate(netuid, |v| v.push(0)); + Active::::mutate(netuid, |v| v.push(true)); + Emission::::mutate(netuid, |v| v.push(0)); + Consensus::::mutate(netuid, |v| v.push(0)); + Incentive::::mutate(netuid, |v| v.push(0)); + Dividends::::mutate(netuid, |v| v.push(0)); + LastUpdate::::mutate(netuid, |v| v.push(block_number)); + PruningScores::::mutate(netuid, |v| v.push(0)); + ValidatorTrust::::mutate(netuid, |v| v.push(0)); + ValidatorPermit::::mutate(netuid, |v| v.push(false)); + Keys::::insert(netuid, next_uid, hotkey.clone()); // Make hotkey - uid association. + Uids::::insert(netuid, hotkey.clone(), next_uid); // Make uid - hotkey association. + BlockAtRegistration::::insert(netuid, next_uid, block_number); // Fill block at registration. + IsNetworkMember::::insert(hotkey.clone(), netuid, true); // Fill network is member. + } + } } } } diff --git a/pallets/subtensor/src/macros/hooks.rs b/pallets/subtensor/src/macros/hooks.rs index 5e30388735..d53c54dd56 100644 --- a/pallets/subtensor/src/macros/hooks.rs +++ b/pallets/subtensor/src/macros/hooks.rs @@ -147,8 +147,7 @@ mod hooks { if let Some(slot) = block_number.checked_rem(hotkey_swap_on_subnet_interval) { // only handle the subnet with the same residue as current block number by HotkeySwapOnSubnetInterval for netuid in netuids.iter().filter(|netuid| { - (u16::from(**netuid) as u64).checked_rem(hotkey_swap_on_subnet_interval) - == Some(slot) + (**netuid as u64).checked_rem(hotkey_swap_on_subnet_interval) == Some(slot) }) { // Iterate over all the coldkeys in the subnet for (coldkey, swap_block_number) in diff --git a/pallets/subtensor/src/migrations/migrate_create_root_network.rs b/pallets/subtensor/src/migrations/migrate_create_root_network.rs index 24e2251c38..c413d1f078 100644 --- a/pallets/subtensor/src/migrations/migrate_create_root_network.rs +++ b/pallets/subtensor/src/migrations/migrate_create_root_network.rs @@ -6,7 +6,6 @@ use frame_support::{ weights::Weight, }; use sp_std::vec::Vec; -use subtensor_runtime_common::NetUid; // TODO (camfairchild): TEST MIGRATION @@ -40,44 +39,47 @@ pub mod deprecated_loaded_emission_format { /// let weight = migrate_create_root_network::(); /// ``` pub fn migrate_create_root_network() -> Weight { + // Define the root network UID + let root_netuid: u16 = 0; + // Initialize weight counter let mut weight = T::DbWeight::get().reads(1); // Check if root network already exists - if NetworksAdded::::get(NetUid::ROOT) { + if NetworksAdded::::get(root_netuid) { // Return early if root network already exists return weight; } // Set the root network as added - NetworksAdded::::insert(NetUid::ROOT, true); + NetworksAdded::::insert(root_netuid, true); // Increment the total number of networks TotalNetworks::::mutate(|n| *n = n.saturating_add(1)); // Set the maximum number of UIDs to the number of senate members - MaxAllowedUids::::insert(NetUid::ROOT, 64); + MaxAllowedUids::::insert(root_netuid, 64); // Set the maximum number of validators to all members - MaxAllowedValidators::::insert(NetUid::ROOT, 64); + MaxAllowedValidators::::insert(root_netuid, 64); // Set the minimum allowed weights to zero (no weight restrictions) - MinAllowedWeights::::insert(NetUid::ROOT, 0); + MinAllowedWeights::::insert(root_netuid, 0); // Set the maximum weight limit to u16::MAX (no weight restrictions) - MaxWeightsLimit::::insert(NetUid::ROOT, u16::MAX); + MaxWeightsLimit::::insert(root_netuid, u16::MAX); // Set default root tempo - Tempo::::insert(NetUid::ROOT, 100); + Tempo::::insert(root_netuid, 100); // Set the root network as open for registration - NetworkRegistrationAllowed::::insert(NetUid::ROOT, true); + NetworkRegistrationAllowed::::insert(root_netuid, true); // Set target registrations for validators as 1 per block - TargetRegistrationsPerInterval::::insert(NetUid::ROOT, 1); + TargetRegistrationsPerInterval::::insert(root_netuid, 1); // TODO: Consider if WeightsSetRateLimit should be set - // WeightsSetRateLimit::::insert(NetUid::ROOT, 7200); + // WeightsSetRateLimit::::insert(root_netuid, 7200); // Accrue weight for database writes weight.saturating_accrue(T::DbWeight::get().writes(8)); diff --git a/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs b/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs index 068fcc35b3..d12a58ed37 100644 --- a/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs +++ b/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs @@ -7,7 +7,6 @@ use frame_support::{ }; use log::info; use sp_std::vec::Vec; -use subtensor_runtime_common::NetUid; /// Constant for logging purposes const LOG_TARGET: &str = "migrate_delete_subnet_21"; @@ -51,10 +50,10 @@ pub fn migrate_delete_subnet_21() -> Weight { let onchain_version = Pallet::::on_chain_storage_version(); // Only runs if we haven't already updated version past above new_storage_version and subnet 21 exists. - if onchain_version < new_storage_version && Pallet::::if_subnet_exist(NetUid::from(21)) { + if onchain_version < new_storage_version && Pallet::::if_subnet_exist(21) { info!(target: LOG_TARGET, ">>> Removing subnet 21 {:?}", onchain_version); - let netuid = NetUid::from(21); + let netuid = 21; // We do this all manually as we don't want to call code related to giving subnet owner back their locked token cost. // Remove network count diff --git a/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs b/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs index fde7e09920..0e85c56554 100644 --- a/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs +++ b/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs @@ -50,14 +50,14 @@ pub fn migrate_delete_subnet_3() -> Weight { let onchain_version = Pallet::::on_chain_storage_version(); // Only proceed if current version is less than the new version and subnet 3 exists - if onchain_version < new_storage_version && Pallet::::if_subnet_exist(3.into()) { + if onchain_version < new_storage_version && Pallet::::if_subnet_exist(3) { info!( target: LOG_TARGET, "Removing subnet 3. Current version: {:?}", onchain_version ); - let netuid = NetUid::from(3); + let netuid = 3; // Remove network count SubnetworkN::::remove(netuid); diff --git a/pallets/subtensor/src/migrations/migrate_rao.rs b/pallets/subtensor/src/migrations/migrate_rao.rs index f4cd87b356..975ab55c11 100644 --- a/pallets/subtensor/src/migrations/migrate_rao.rs +++ b/pallets/subtensor/src/migrations/migrate_rao.rs @@ -25,7 +25,7 @@ pub fn migrate_rao() -> Weight { String::from_utf8_lossy(&migration_name) ); - let netuids: Vec = as IterableStorageMap>::iter() + let netuids: Vec = as IterableStorageMap>::iter() .map(|(netuid, _)| netuid) .collect(); weight = weight.saturating_add(T::DbWeight::get().reads_writes(netuids.len() as u64, 0)); @@ -62,12 +62,12 @@ pub fn migrate_rao() -> Weight { NetworkMinLockCost::::set(1_000_000_000); // Set tao weight. TaoWeight::::set(3_320_413_933_267_719_290); - for netuid in netuids.iter() { - if netuid.is_root() { + for netuid in netuids.iter().clone() { + if *netuid == 0 { // Give root a single RAO in pool to avoid any catestrophic division by zero. SubnetAlphaIn::::insert(netuid, 1_000_000_000); SubnetMechanism::::insert(netuid, 0); // Set to zero mechanism. - TokenSymbol::::insert(netuid, Pallet::::get_symbol_for_subnet(NetUid::ROOT)); + TokenSymbol::::insert(netuid, Pallet::::get_symbol_for_subnet(0)); continue; } let owner = SubnetOwner::::get(netuid); diff --git a/pallets/subtensor/src/migrations/migrate_set_first_emission_block_number.rs b/pallets/subtensor/src/migrations/migrate_set_first_emission_block_number.rs index 2da7cef51a..04ad306218 100644 --- a/pallets/subtensor/src/migrations/migrate_set_first_emission_block_number.rs +++ b/pallets/subtensor/src/migrations/migrate_set_first_emission_block_number.rs @@ -26,7 +26,7 @@ pub fn migrate_set_first_emission_block_number() -> Weight { let netuids = Pallet::::get_all_subnet_netuids(); let current_block_number = Pallet::::get_current_block_as_u64(); for netuid in netuids.iter() { - if !netuid.is_root() { + if *netuid != 0 { FirstEmissionBlockNumber::::insert(netuid, current_block_number); } } diff --git a/pallets/subtensor/src/migrations/migrate_set_min_burn.rs b/pallets/subtensor/src/migrations/migrate_set_min_burn.rs index 8a74e1e51c..a38badfbb1 100644 --- a/pallets/subtensor/src/migrations/migrate_set_min_burn.rs +++ b/pallets/subtensor/src/migrations/migrate_set_min_burn.rs @@ -24,13 +24,13 @@ pub fn migrate_set_min_burn() -> Weight { String::from_utf8_lossy(&migration_name) ); - let netuids: Vec = as IterableStorageMap>::iter() + let netuids: Vec = as IterableStorageMap>::iter() .map(|(netuid, _)| netuid) .collect(); weight = weight.saturating_add(T::DbWeight::get().reads(netuids.len() as u64)); - for netuid in netuids.iter() { - if netuid.is_root() { + for netuid in netuids.iter().clone() { + if *netuid == 0 { continue; } // Set min burn to the newest initial min burn diff --git a/pallets/subtensor/src/migrations/migrate_set_min_difficulty.rs b/pallets/subtensor/src/migrations/migrate_set_min_difficulty.rs index bdc6c993e2..6d859925ae 100644 --- a/pallets/subtensor/src/migrations/migrate_set_min_difficulty.rs +++ b/pallets/subtensor/src/migrations/migrate_set_min_difficulty.rs @@ -24,13 +24,13 @@ pub fn migrate_set_min_difficulty() -> Weight { String::from_utf8_lossy(&migration_name) ); - let netuids: Vec = as IterableStorageMap>::iter() + let netuids: Vec = as IterableStorageMap>::iter() .map(|(netuid, _)| netuid) .collect(); weight = weight.saturating_add(T::DbWeight::get().reads(netuids.len() as u64)); - for netuid in netuids.iter() { - if netuid.is_root() { + for netuid in netuids.iter().clone() { + if *netuid == 0 { continue; } // Set min difficulty to 10 million for all subnets diff --git a/pallets/subtensor/src/migrations/migrate_set_subtoken_enabled.rs b/pallets/subtensor/src/migrations/migrate_set_subtoken_enabled.rs index 3b0d236f99..da4386c4b8 100644 --- a/pallets/subtensor/src/migrations/migrate_set_subtoken_enabled.rs +++ b/pallets/subtensor/src/migrations/migrate_set_subtoken_enabled.rs @@ -25,7 +25,7 @@ pub fn migrate_set_subtoken_enabled() -> Weight { // ------------------------------ let netuids = Pallet::::get_all_subnet_netuids(); for netuid in netuids.iter() { - if !netuid.is_root() { + if *netuid != 0 { // set it as true if start call executed and value exists for first emission block number SubtokenEnabled::::insert( netuid, diff --git a/pallets/subtensor/src/migrations/migrate_to_v1_separate_emission.rs b/pallets/subtensor/src/migrations/migrate_to_v1_separate_emission.rs index b97acaa4a3..5d28337dcb 100644 --- a/pallets/subtensor/src/migrations/migrate_to_v1_separate_emission.rs +++ b/pallets/subtensor/src/migrations/migrate_to_v1_separate_emission.rs @@ -72,7 +72,7 @@ pub fn migrate_to_v1_separate_emission() -> Weight { // Translate old storage values to new format LoadedEmission::::translate::, u64)>, _>( - |netuid: NetUid, + |netuid: u16, netuid_emissions: Vec<(AccountIdOf, u64)>| -> Option, u64, u64)>> { info!(target: LOG_TARGET, " Do migration of netuid: {:?}...", netuid); diff --git a/pallets/subtensor/src/migrations/migrate_transfer_ownership_to_foundation.rs b/pallets/subtensor/src/migrations/migrate_transfer_ownership_to_foundation.rs index 10a93784bb..8d1bd437c6 100644 --- a/pallets/subtensor/src/migrations/migrate_transfer_ownership_to_foundation.rs +++ b/pallets/subtensor/src/migrations/migrate_transfer_ownership_to_foundation.rs @@ -65,13 +65,13 @@ pub fn migrate_transfer_ownership_to_foundation(coldkey: [u8; 32]) -> weight.saturating_accrue(T::DbWeight::get().reads(1)); // Transfer ownership of subnets 1 and 11 to the foundation - SubnetOwner::::insert(NetUid::from(1), coldkey_account.clone()); - SubnetOwner::::insert(NetUid::from(11), coldkey_account); + SubnetOwner::::insert(1, coldkey_account.clone()); + SubnetOwner::::insert(11, coldkey_account); // Set the registration time for subnet 1 to extend immunity period - NetworkRegisteredAt::::insert(NetUid::from(1), current_block.saturating_add(13 * 7200)); + NetworkRegisteredAt::::insert(1, current_block.saturating_add(13 * 7200)); // Set the registration time for subnet 11 to the current block - NetworkRegisteredAt::::insert(NetUid::from(11), current_block); + NetworkRegisteredAt::::insert(11, current_block); weight.saturating_accrue(T::DbWeight::get().writes(4)); diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index 94e4034b66..f0a2447e4f 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -6,17 +6,16 @@ use substrate_fixed::types::U64F64; extern crate alloc; use alloc::collections::BTreeMap; use codec::Compact; -use subtensor_runtime_common::NetUid; -#[freeze_struct("1fafc4fcf28cba7a")] +#[freeze_struct("7cd21f57627d2d0d")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct DelegateInfo { pub delegate_ss58: AccountId, pub take: Compact, - pub nominators: Vec<(AccountId, Vec<(Compact, Compact)>)>, // map of nominator_ss58 to netuid and stake amount + pub nominators: Vec<(AccountId, Vec<(Compact, Compact)>)>, // map of nominator_ss58 to netuid and stake amount pub owner_ss58: AccountId, - pub registrations: Vec>, // Vec of netuid this delegate is registered on - pub validator_permits: Vec>, // Vec of netuid this delegate has validator permit on + pub registrations: Vec>, // Vec of netuid this delegate is registered on + pub validator_permits: Vec>, // Vec of netuid this delegate has validator permit on pub return_per_1000: Compact, // Delegators current daily return per 1000 TAO staked minus take fee pub total_daily_return: Compact, // Delegators current daily return } @@ -54,9 +53,8 @@ impl Pallet { delegate: AccountIdOf, skip_nominators: bool, ) -> DelegateInfo { - let mut nominators = Vec::<(T::AccountId, Vec<(Compact, Compact)>)>::new(); - let mut nominator_map = - BTreeMap::, Compact)>>::new(); + let mut nominators = Vec::<(T::AccountId, Vec<(Compact, Compact)>)>::new(); + let mut nominator_map = BTreeMap::, Compact)>>::new(); if !skip_nominators { let mut alpha_share_pools = vec![]; @@ -70,7 +68,7 @@ impl Pallet { continue; } - if let Some(alpha_share_pool) = alpha_share_pools.get(u16::from(netuid) as usize) { + if let Some(alpha_share_pool) = alpha_share_pools.get(netuid as usize) { let coldkey_stake = alpha_share_pool.get_value_from_shares(alpha_stake); nominator_map @@ -86,7 +84,7 @@ impl Pallet { } let registrations = Self::get_registered_networks_for_hotkey(&delegate.clone()); - let mut validator_permits = Vec::>::new(); + let mut validator_permits = Vec::>::new(); let mut emissions_per_day: U64F64 = U64F64::saturating_from_num(0); for netuid in registrations.iter() { @@ -110,7 +108,7 @@ impl Pallet { let take: Compact = >::get(delegate.clone()).into(); let total_stake: U64F64 = - Self::get_stake_for_hotkey_on_subnet(&delegate.clone(), NetUid::ROOT).into(); + Self::get_stake_for_hotkey_on_subnet(&delegate.clone(), Self::get_root_netuid()).into(); let return_per_1000: U64F64 = Self::return_per_1000_tao(take, total_stake, emissions_per_day); @@ -153,8 +151,8 @@ impl Pallet { /// pub fn get_delegated( delegatee: T::AccountId, - ) -> Vec<(DelegateInfo, (Compact, Compact))> { - let mut delegates: Vec<(DelegateInfo, (Compact, Compact))> = + ) -> Vec<(DelegateInfo, (Compact, Compact))> { + let mut delegates: Vec<(DelegateInfo, (Compact, Compact))> = Vec::new(); for delegate in as IterableStorageMap>::iter_keys() { // Staked to this delegate, so add to list diff --git a/pallets/subtensor/src/rpc_info/dynamic_info.rs b/pallets/subtensor/src/rpc_info/dynamic_info.rs index 4e5400aba0..b363931d9c 100644 --- a/pallets/subtensor/src/rpc_info/dynamic_info.rs +++ b/pallets/subtensor/src/rpc_info/dynamic_info.rs @@ -4,12 +4,11 @@ use codec::Compact; use frame_support::pallet_prelude::{Decode, Encode}; use substrate_fixed::types::I96F32; use subtensor_macros::freeze_struct; -use subtensor_runtime_common::NetUid; -#[freeze_struct("d813a7696ae616af")] +#[freeze_struct("7fbd2013e8262885")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct DynamicInfo { - netuid: Compact, + netuid: Compact, owner_hotkey: AccountId, owner_coldkey: AccountId, subnet_name: Vec>, @@ -33,7 +32,7 @@ pub struct DynamicInfo { } impl Pallet { - pub fn get_dynamic_info(netuid: NetUid) -> Option> { + pub fn get_dynamic_info(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -71,7 +70,7 @@ impl Pallet { }) } pub fn get_all_dynamic_info() -> Vec>> { - let netuids = Self::get_all_subnet_netuids(); + let netuids: Vec = Self::get_all_subnet_netuids(); let mut dynamic_info = Vec::>>::new(); for netuid in netuids.clone().iter() { dynamic_info.push(Self::get_dynamic_info(*netuid)); diff --git a/pallets/subtensor/src/rpc_info/metagraph.rs b/pallets/subtensor/src/rpc_info/metagraph.rs index b6839290a5..9d61d12470 100644 --- a/pallets/subtensor/src/rpc_info/metagraph.rs +++ b/pallets/subtensor/src/rpc_info/metagraph.rs @@ -7,13 +7,12 @@ use frame_support::pallet_prelude::{Decode, Encode}; use substrate_fixed::types::I64F64; use substrate_fixed::types::I96F32; use subtensor_macros::freeze_struct; -use subtensor_runtime_common::NetUid; -#[freeze_struct("ea9ff0b8daeaa5ed")] +#[freeze_struct("cb3ff125c0c35c9e")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct Metagraph { // Subnet index - netuid: Compact, + netuid: Compact, // Name and symbol name: Vec>, // name @@ -109,11 +108,11 @@ pub struct Metagraph { alpha_dividends_per_hotkey: Vec<(AccountId, Compact)>, // List of dividend payout in alpha via subnet. } -#[freeze_struct("d21755f360424f37")] +#[freeze_struct("2eca518cf84390fa")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SelectiveMetagraph { // Subnet index - netuid: Compact, + netuid: Compact, // Name and symbol name: Option>>, // name @@ -378,7 +377,7 @@ where { fn default() -> Self { Self { - netuid: NetUid::ROOT.into(), + netuid: 0.into(), name: None, symbol: None, identity: None, @@ -612,7 +611,7 @@ impl SelectiveMetagraphIndex { } } impl Pallet { - pub fn get_metagraph(netuid: NetUid) -> Option> { + pub fn get_metagraph(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -788,7 +787,7 @@ impl Pallet { }) } pub fn get_all_metagraphs() -> Vec>> { - let netuids = Self::get_all_subnet_netuids(); + let netuids: Vec = Self::get_all_subnet_netuids(); let mut metagraphs = Vec::>>::new(); for netuid in netuids.clone().iter() { metagraphs.push(Self::get_metagraph(*netuid)); @@ -797,7 +796,7 @@ impl Pallet { } pub fn get_selective_metagraph( - netuid: NetUid, + netuid: u16, metagraph_indexes: Vec, ) -> Option> { if !Self::if_subnet_exist(netuid) { @@ -813,7 +812,7 @@ impl Pallet { } fn get_single_selective_metagraph( - netuid: NetUid, + netuid: u16, metagraph_index: u16, ) -> SelectiveMetagraph { match SelectiveMetagraphIndex::from_index(metagraph_index as usize) { @@ -1373,10 +1372,10 @@ impl Pallet { } } - fn get_validators(netuid: NetUid) -> SelectiveMetagraph { + fn get_validators(netuid: u16) -> SelectiveMetagraph { let stake_threshold = Self::get_stake_threshold(); let hotkeys: Vec<(u16, T::AccountId)> = - as IterableStorageDoubleMap>::iter_prefix(netuid) + as IterableStorageDoubleMap>::iter_prefix(netuid) .collect(); let validator_permits: Vec = Self::get_validator_permit(netuid); @@ -1417,7 +1416,7 @@ impl Pallet { fn test_selective_metagraph() { let mut metagraph = SelectiveMetagraph::::default(); let expected = SelectiveMetagraph:: { - netuid: NetUid::ROOT.into(), + netuid: 0_u16.into(), name: None, symbol: None, identity: None, @@ -1497,7 +1496,7 @@ fn test_selective_metagraph() { let wrong_index: usize = 100; let metagraph_name = SelectiveMetagraph:: { - netuid: NetUid::ROOT.into(), + netuid: 0_u16.into(), name: Some(vec![1_u8].into_iter().map(Compact).collect()), ..Default::default() }; @@ -1512,7 +1511,7 @@ fn test_selective_metagraph() { let alph_low_index: usize = 50; let metagraph_alpha_low = SelectiveMetagraph:: { - netuid: NetUid::ROOT.into(), + netuid: 0_u16.into(), alpha_low: Some(0_u16.into()), ..Default::default() }; diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index 337b89212d..4838b376f9 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -2,15 +2,14 @@ use super::*; use frame_support::pallet_prelude::{Decode, Encode}; extern crate alloc; use codec::Compact; -use subtensor_runtime_common::NetUid; -#[freeze_struct("3bddc0abfa5445a6")] +#[freeze_struct("d6da7340b3350951")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct NeuronInfo { hotkey: AccountId, coldkey: AccountId, uid: Compact, - netuid: Compact, + netuid: Compact, active: bool, axon_info: AxonInfo, prometheus_info: PrometheusInfo, @@ -29,13 +28,13 @@ pub struct NeuronInfo { pruning_score: Compact, } -#[freeze_struct("e2a6a95696a82c4f")] +#[freeze_struct("3e9eed057f379b3b")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct NeuronInfoLite { hotkey: AccountId, coldkey: AccountId, uid: Compact, - netuid: Compact, + netuid: Compact, active: bool, axon_info: AxonInfo, prometheus_info: PrometheusInfo, @@ -54,7 +53,7 @@ pub struct NeuronInfoLite { } impl Pallet { - pub fn get_neurons(netuid: NetUid) -> Vec> { + pub fn get_neurons(netuid: u16) -> Vec> { if !Self::if_subnet_exist(netuid) { return Vec::new(); } @@ -72,7 +71,7 @@ impl Pallet { neurons } - fn get_neuron_subnet_exists(netuid: NetUid, 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, @@ -96,10 +95,10 @@ impl Pallet { let last_update = Self::get_last_update_for_uid(netuid, uid); let validator_permit = Self::get_validator_permit_for_uid(netuid, uid); - let weights = Weights::::get(netuid, uid) - .into_iter() + let weights = >::get(netuid, uid) + .iter() .filter_map(|(i, w)| { - if w > 0 { + if *w > 0 { Some((i.into(), w.into())) } else { None @@ -147,7 +146,7 @@ impl Pallet { Some(neuron) } - pub fn get_neuron(netuid: NetUid, uid: u16) -> Option> { + pub fn get_neuron(netuid: u16, uid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -156,7 +155,7 @@ impl Pallet { } fn get_neuron_lite_subnet_exists( - netuid: NetUid, + netuid: u16, uid: u16, ) -> Option> { let hotkey = match Self::get_hotkey_for_net_and_uid(netuid, uid) { @@ -211,7 +210,7 @@ impl Pallet { Some(neuron) } - pub fn get_neurons_lite(netuid: NetUid) -> Vec> { + pub fn get_neurons_lite(netuid: u16) -> Vec> { if !Self::if_subnet_exist(netuid) { return Vec::new(); } @@ -229,7 +228,7 @@ impl Pallet { neurons } - pub fn get_neuron_lite(netuid: NetUid, uid: u16) -> Option> { + pub fn get_neuron_lite(netuid: u16, uid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } diff --git a/pallets/subtensor/src/rpc_info/show_subnet.rs b/pallets/subtensor/src/rpc_info/show_subnet.rs index aa5b2f4d36..9b66439fa2 100644 --- a/pallets/subtensor/src/rpc_info/show_subnet.rs +++ b/pallets/subtensor/src/rpc_info/show_subnet.rs @@ -4,12 +4,11 @@ use crate::epoch::math::*; use codec::Compact; use frame_support::pallet_prelude::{Decode, Encode}; use substrate_fixed::types::I64F64; -use subtensor_runtime_common::NetUid; -#[freeze_struct("11f58860434dd863")] +#[freeze_struct("7954f39fd0755b28")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetState { - netuid: Compact, + netuid: Compact, hotkeys: Vec, coldkeys: Vec, active: Vec, @@ -80,7 +79,7 @@ impl Pallet { /// /// * `Option>` - An optional `SubnetState` struct containing the collected data for the subnet. /// Returns `None` if the subnet does not exist. - pub fn get_subnet_state(netuid: NetUid) -> Option> { + pub fn get_subnet_state(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } diff --git a/pallets/subtensor/src/rpc_info/stake_info.rs b/pallets/subtensor/src/rpc_info/stake_info.rs index 56a0a066cb..8a3888061f 100644 --- a/pallets/subtensor/src/rpc_info/stake_info.rs +++ b/pallets/subtensor/src/rpc_info/stake_info.rs @@ -3,14 +3,13 @@ use frame_support::pallet_prelude::{Decode, Encode}; extern crate alloc; use codec::Compact; use substrate_fixed::types::U96F32; -use subtensor_runtime_common::NetUid; -#[freeze_struct("56f5e9f33e5ec9da")] +#[freeze_struct("5cfb3c84c3af3116")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct StakeInfo { hotkey: AccountId, coldkey: AccountId, - netuid: Compact, + netuid: Compact, stake: Compact, locked: Compact, emission: Compact, @@ -26,7 +25,7 @@ impl Pallet { if coldkeys.is_empty() { return Vec::new(); // No coldkeys to check } - let netuids = Self::get_all_subnet_netuids(); + let netuids: Vec = Self::get_all_subnet_netuids(); let mut stake_info: Vec<(T::AccountId, Vec>)> = Vec::new(); for coldkey_i in coldkeys.clone().iter() { // Get all hotkeys associated with this coldkey. @@ -91,7 +90,7 @@ impl Pallet { pub fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: T::AccountId, coldkey_account: T::AccountId, - netuid: NetUid, + netuid: u16, ) -> Option> { let alpha: u64 = Self::get_stake_for_hotkey_and_coldkey_on_subnet( &hotkey_account, @@ -116,17 +115,18 @@ impl Pallet { } pub fn get_stake_fee( - origin: Option<(T::AccountId, NetUid)>, + origin: Option<(T::AccountId, u16)>, origin_coldkey_account: T::AccountId, - destination: Option<(T::AccountId, NetUid)>, + destination: Option<(T::AccountId, u16)>, destination_coldkey_account: T::AccountId, amount: u64, ) -> u64 { - let origin_ = if let Some((ref origin_hotkey, origin_netuid)) = origin { - Some((origin_hotkey, origin_netuid)) - } else { - None - }; + let origin_: Option<(&T::AccountId, u16)> = + if let Some((ref origin_hotkey, origin_netuid)) = origin { + Some((origin_hotkey, origin_netuid)) + } else { + None + }; let destination_ = if let Some((ref destination_hotkey, destination_netuid)) = destination { Some((destination_hotkey, destination_netuid)) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 636b72899b..6e9e722295 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -3,12 +3,11 @@ use frame_support::pallet_prelude::{Decode, Encode}; use frame_support::storage::IterableStorageMap; extern crate alloc; use codec::Compact; -use subtensor_runtime_common::NetUid; -#[freeze_struct("dd2293544ffd8f2e")] +#[freeze_struct("1eee6f3911800c6b")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetInfo { - netuid: Compact, + netuid: Compact, rho: Compact, kappa: Compact, difficulty: Compact, @@ -28,10 +27,10 @@ pub struct SubnetInfo { owner: AccountId, } -#[freeze_struct("42d9a1f1761c3b31")] +#[freeze_struct("a86ee623525247cc")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug, TypeInfo)] pub struct SubnetInfov2 { - netuid: Compact, + netuid: Compact, rho: Compact, kappa: Compact, difficulty: Compact, @@ -85,7 +84,7 @@ pub struct SubnetHyperparams { } impl Pallet { - pub fn get_subnet_info(netuid: NetUid) -> Option> { + pub fn get_subnet_info(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -133,28 +132,28 @@ impl Pallet { } pub fn get_subnets_info() -> Vec>> { - let mut subnet_netuids = Vec::::new(); + let mut subnet_netuids = Vec::::new(); let mut max_netuid: u16 = 0; - for (netuid, added) in as IterableStorageMap>::iter() { + for (netuid, added) in as IterableStorageMap>::iter() { if added { subnet_netuids.push(netuid); - if u16::from(netuid) > max_netuid { - max_netuid = u16::from(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_.into()) { - subnets_info.push(Self::get_subnet_info(netuid_.into())); + if subnet_netuids.contains(&netuid_) { + subnets_info.push(Self::get_subnet_info(netuid_)); } } subnets_info } - pub fn get_subnet_info_v2(netuid: NetUid) -> Option> { + pub fn get_subnet_info_v2(netuid: u16) -> Option> { if !Self::if_subnet_exist(netuid) { return None; } @@ -205,28 +204,28 @@ impl Pallet { } pub fn get_subnets_info_v2() -> Vec>> { - let mut subnet_netuids = Vec::::new(); + let mut subnet_netuids = Vec::::new(); let mut max_netuid: u16 = 0; - for (netuid, added) in as IterableStorageMap>::iter() { + for (netuid, added) in as IterableStorageMap>::iter() { if added { subnet_netuids.push(netuid); - if u16::from(netuid) > max_netuid { - max_netuid = u16::from(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_.into()) { - subnets_info.push(Self::get_subnet_info_v2(netuid_.into())); + if subnet_netuids.contains(&netuid_) { + subnets_info.push(Self::get_subnet_info_v2(netuid_)); } } subnets_info } - pub fn get_subnet_hyperparams(netuid: NetUid) -> Option { + pub fn get_subnet_hyperparams(netuid: u16) -> Option { if !Self::if_subnet_exist(netuid) { return None; } diff --git a/pallets/subtensor/src/staking/add_stake.rs b/pallets/subtensor/src/staking/add_stake.rs index f04bffe898..258cd40b8b 100644 --- a/pallets/subtensor/src/staking/add_stake.rs +++ b/pallets/subtensor/src/staking/add_stake.rs @@ -1,6 +1,5 @@ use super::*; use substrate_fixed::types::I96F32; -use subtensor_runtime_common::NetUid; impl Pallet { /// ---- The implementation for the extrinsic add_stake: Adds stake to a hotkey account. @@ -38,7 +37,7 @@ impl Pallet { pub fn do_add_stake( origin: T::RuntimeOrigin, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, stake_to_be_added: u64, ) -> dispatch::DispatchResult { // 1. We check that the transaction is signed by the caller and retrieve the T::AccountId coldkey information. @@ -125,7 +124,7 @@ impl Pallet { pub fn do_add_stake_limit( origin: T::RuntimeOrigin, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, stake_to_be_added: u64, limit_price: u64, allow_partial: bool, @@ -182,11 +181,11 @@ impl Pallet { } // Returns the maximum amount of RAO that can be executed with price limit - pub fn get_max_amount_add(netuid: NetUid, limit_price: u64) -> Result> { + pub fn get_max_amount_add(netuid: u16, limit_price: u64) -> Result> { // Corner case: root and stao // There's no slippage for root or stable subnets, so if limit price is 1e9 rao or // higher, then max_amount equals u64::MAX, otherwise it is 0. - if netuid.is_root() || SubnetMechanism::::get(netuid) == 0 { + if (netuid == Self::get_root_netuid()) || (SubnetMechanism::::get(netuid)) == 0 { if limit_price >= 1_000_000_000 { return Ok(u64::MAX); } else { diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index aacc448952..9ee04f36a8 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -1,7 +1,6 @@ use super::*; use safe_math::*; use substrate_fixed::types::U96F32; -use subtensor_runtime_common::NetUid; use frame_support::traits::{ Imbalance, @@ -166,7 +165,7 @@ impl Pallet { pub fn clear_small_nomination_if_required( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, ) { // Verify if the account is a nominator account by checking ownership of the hotkey by the coldkey. if !Self::coldkey_owns_hotkey(coldkey, hotkey) { diff --git a/pallets/subtensor/src/staking/move_stake.rs b/pallets/subtensor/src/staking/move_stake.rs index 56cdf69511..d743fb7a18 100644 --- a/pallets/subtensor/src/staking/move_stake.rs +++ b/pallets/subtensor/src/staking/move_stake.rs @@ -2,7 +2,6 @@ use super::*; use safe_math::*; use sp_core::Get; use substrate_fixed::types::{U64F64, U96F32}; -use subtensor_runtime_common::NetUid; impl Pallet { /// Moves stake from one hotkey to another across subnets. @@ -30,8 +29,8 @@ impl Pallet { origin: T::RuntimeOrigin, origin_hotkey: T::AccountId, destination_hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, ) -> dispatch::DispatchResult { // Check that the origin is signed by the origin_hotkey. @@ -84,7 +83,7 @@ impl Pallet { /// /// # Events /// Emits a `TransferToggle` event upon successful completion. - pub fn toggle_transfer(netuid: NetUid, toggle: bool) -> dispatch::DispatchResult { + pub fn toggle_transfer(netuid: u16, toggle: bool) -> dispatch::DispatchResult { TransferToggle::::insert(netuid, toggle); log::debug!( "TransferToggle( netuid: {:?}, toggle: {:?} ) ", @@ -124,8 +123,8 @@ impl Pallet { origin: T::RuntimeOrigin, destination_coldkey: T::AccountId, hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, ) -> dispatch::DispatchResult { // Ensure the extrinsic is signed by the origin_coldkey. @@ -194,8 +193,8 @@ impl Pallet { pub fn do_swap_stake( origin: T::RuntimeOrigin, hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, ) -> dispatch::DispatchResult { // Ensure the extrinsic is signed by the coldkey. @@ -264,8 +263,8 @@ impl Pallet { pub fn do_swap_stake_limit( origin: T::RuntimeOrigin, hotkey: T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, limit_price: u64, allow_partial: bool, @@ -315,8 +314,8 @@ impl Pallet { destination_coldkey: &T::AccountId, origin_hotkey: &T::AccountId, destination_hotkey: &T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, maybe_limit_price: Option, maybe_allow_partial: Option, @@ -411,8 +410,8 @@ impl Pallet { /// In the corner case when SubnetTAO(2) == SubnetTAO(1), no slippage is going to occur. /// pub fn get_max_amount_move( - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, limit_price: u64, ) -> Result> { let tao: U64F64 = U64F64::saturating_from_num(1_000_000_000); @@ -420,8 +419,10 @@ impl Pallet { // Corner case: both subnet IDs are root or stao // There's no slippage for root or stable subnets, so slippage is always 0. // The price always stays at 1.0, return 0 if price is expected to raise. - if (origin_netuid.is_root() || SubnetMechanism::::get(origin_netuid) == 0) - && (destination_netuid.is_root() || SubnetMechanism::::get(destination_netuid) == 0) + if ((origin_netuid == Self::get_root_netuid()) + || (SubnetMechanism::::get(origin_netuid)) == 0) + && ((destination_netuid == Self::get_root_netuid()) + || (SubnetMechanism::::get(destination_netuid)) == 0) { if limit_price > tao.saturating_to_num::() { return Err(Error::ZeroMaxStakeAmount); @@ -432,8 +433,9 @@ impl Pallet { // Corner case: Origin is root or stable, destination is dynamic // Same as adding stake with limit price - if (origin_netuid.is_root() || SubnetMechanism::::get(origin_netuid) == 0) - && (SubnetMechanism::::get(destination_netuid) == 1) + if ((origin_netuid == Self::get_root_netuid()) + || (SubnetMechanism::::get(origin_netuid)) == 0) + && ((SubnetMechanism::::get(destination_netuid)) == 1) { if limit_price == 0 { return Ok(u64::MAX); @@ -449,8 +451,9 @@ impl Pallet { // Corner case: Origin is dynamic, destination is root or stable // Same as removing stake with limit price - if (destination_netuid.is_root() || SubnetMechanism::::get(destination_netuid) == 0) - && (SubnetMechanism::::get(origin_netuid) == 1) + if ((destination_netuid == Self::get_root_netuid()) + || (SubnetMechanism::::get(destination_netuid)) == 0) + && ((SubnetMechanism::::get(origin_netuid)) == 1) { return Self::get_max_amount_remove(origin_netuid, limit_price); } diff --git a/pallets/subtensor/src/staking/recycle_alpha.rs b/pallets/subtensor/src/staking/recycle_alpha.rs index 5bb9f2da1c..ef3cea2b29 100644 --- a/pallets/subtensor/src/staking/recycle_alpha.rs +++ b/pallets/subtensor/src/staking/recycle_alpha.rs @@ -1,6 +1,5 @@ use super::*; use crate::{Error, system::ensure_signed}; -use subtensor_runtime_common::NetUid; impl Pallet { /// Recycles alpha from a cold/hot key pair, reducing AlphaOut on a subnet @@ -19,7 +18,7 @@ impl Pallet { origin: T::RuntimeOrigin, hotkey: T::AccountId, amount: u64, - netuid: NetUid, + netuid: u16, ) -> DispatchResult { let coldkey: T::AccountId = ensure_signed(origin)?; @@ -29,7 +28,7 @@ impl Pallet { ); ensure!( - !netuid.is_root(), + netuid != Self::get_root_netuid(), Error::::CannotBurnOrRecycleOnRootSubnet ); @@ -88,7 +87,7 @@ impl Pallet { origin: T::RuntimeOrigin, hotkey: T::AccountId, amount: u64, - netuid: NetUid, + netuid: u16, ) -> DispatchResult { let coldkey = ensure_signed(origin)?; @@ -98,7 +97,7 @@ impl Pallet { ); ensure!( - !netuid.is_root(), + netuid != Self::get_root_netuid(), Error::::CannotBurnOrRecycleOnRootSubnet ); diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index 0fa7e94977..e1b09a0032 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -1,6 +1,5 @@ use super::*; use substrate_fixed::types::U96F32; -use subtensor_runtime_common::NetUid; impl Pallet { /// ---- The implementation for the extrinsic remove_stake: Removes stake from a hotkey account and adds it onto a coldkey. @@ -38,7 +37,7 @@ impl Pallet { pub fn do_remove_stake( origin: T::RuntimeOrigin, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, alpha_unstaked: u64, ) -> dispatch::DispatchResult { // 1. We check the transaction is signed by the caller and retrieve the T::AccountId coldkey information. @@ -132,7 +131,7 @@ impl Pallet { ); // 3. Get all netuids. - let netuids = Self::get_all_subnet_netuids(); + let netuids: Vec = Self::get_all_subnet_netuids(); log::debug!("All subnet netuids: {:?}", netuids); // 4. Iterate through all subnets and remove stake. @@ -224,7 +223,7 @@ impl Pallet { ); // 3. Get all netuids. - let netuids = Self::get_all_subnet_netuids(); + let netuids: Vec = Self::get_all_subnet_netuids(); log::debug!("All subnet netuids: {:?}", netuids); // 4. Iterate through all subnets and remove stake. @@ -234,7 +233,7 @@ impl Pallet { continue; } // If not Root network. - if !netuid.is_root() { + if netuid != Self::get_root_netuid() { // Ensure that the hotkey has enough stake to withdraw. let alpha_unstaked = Self::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid); @@ -279,7 +278,7 @@ impl Pallet { Self::stake_into_subnet( &hotkey, &coldkey, - NetUid::ROOT, + Self::get_root_netuid(), total_tao_unstaked, 0, // no fee for restaking ); @@ -332,7 +331,7 @@ impl Pallet { pub fn do_remove_stake_limit( origin: T::RuntimeOrigin, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, alpha_unstaked: u64, limit_price: u64, allow_partial: bool, @@ -393,11 +392,11 @@ impl Pallet { } // Returns the maximum amount of RAO that can be executed with price limit - pub fn get_max_amount_remove(netuid: NetUid, limit_price: u64) -> Result> { + pub fn get_max_amount_remove(netuid: u16, limit_price: u64) -> Result> { // Corner case: root and stao // There's no slippage for root or stable subnets, so if limit price is 1e9 rao or // lower, then max_amount equals u64::MAX, otherwise it is 0. - if netuid.is_root() || SubnetMechanism::::get(netuid) == 0 { + if (netuid == Self::get_root_netuid()) || (SubnetMechanism::::get(netuid)) == 0 { if limit_price <= 1_000_000_000 { return Ok(u64::MAX); } else { diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index dc2da75785..2d2ebaec47 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -1,6 +1,5 @@ use super::*; use sp_core::Get; -use subtensor_runtime_common::NetUid; impl Pallet { /// ---- The implementation for the extrinsic do_set_child_singular: Sets a single child. @@ -37,7 +36,7 @@ impl Pallet { pub fn do_schedule_children( origin: T::RuntimeOrigin, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, children: Vec<(u64, T::AccountId)>, ) -> DispatchResult { // Check that the caller has signed the transaction. (the coldkey of the pairing) @@ -62,7 +61,7 @@ impl Pallet { // Check that this delegation is not on the root network. Child hotkeys are not valid on root. ensure!( - !netuid.is_root(), + netuid != Self::get_root_netuid(), Error::::RegistrationNotPermittedOnRootSubnet ); @@ -171,7 +170,7 @@ impl Pallet { /// 1. **Old Children Cleanup**: Removes the hotkey from the parent list of its old children. /// 2. **New Children Assignment**: Assigns the new child to the hotkey and updates the parent list for the new child. /// - pub fn do_set_pending_children(netuid: NetUid) { + pub fn do_set_pending_children(netuid: u16) { let current_block = Self::get_current_block_as_u64(); // Iterate over all pending children of this subnet and set as needed @@ -252,7 +251,7 @@ impl Pallet { /// ``` /// let children = SubtensorModule::get_children(&hotkey, netuid); */ - pub fn get_children(hotkey: &T::AccountId, netuid: NetUid) -> Vec<(u64, T::AccountId)> { + pub fn get_children(hotkey: &T::AccountId, netuid: u16) -> Vec<(u64, T::AccountId)> { ChildKeys::::get(hotkey, netuid) } @@ -269,7 +268,7 @@ impl Pallet { /// ``` /// let parents = SubtensorModule::get_parents(&child, netuid); */ - pub fn get_parents(child: &T::AccountId, netuid: NetUid) -> Vec<(u64, T::AccountId)> { + pub fn get_parents(child: &T::AccountId, netuid: u16) -> Vec<(u64, T::AccountId)> { ParentKeys::::get(child, netuid) } @@ -303,7 +302,7 @@ impl Pallet { pub fn do_set_childkey_take( coldkey: T::AccountId, hotkey: T::AccountId, - netuid: NetUid, + netuid: u16, take: u16, ) -> DispatchResult { // Ensure the coldkey owns the hotkey @@ -374,7 +373,7 @@ impl Pallet { /// * `u16` /// - The childkey take value. This is a percentage represented as a value between 0 /// and 10000, where 10000 represents 100%. - pub fn get_childkey_take(hotkey: &T::AccountId, netuid: NetUid) -> u16 { + pub fn get_childkey_take(hotkey: &T::AccountId, netuid: u16) -> u16 { ChildkeyTake::::get(hotkey, netuid) } } diff --git a/pallets/subtensor/src/staking/stake_utils.rs b/pallets/subtensor/src/staking/stake_utils.rs index 6629fd562d..135e531653 100644 --- a/pallets/subtensor/src/staking/stake_utils.rs +++ b/pallets/subtensor/src/staking/stake_utils.rs @@ -3,7 +3,6 @@ use safe_math::*; use share_pool::{SharePool, SharePoolDataOperations}; use sp_std::ops::Neg; use substrate_fixed::types::{I64F64, I96F32, U64F64, U96F32, U110F18}; -use subtensor_runtime_common::NetUid; impl Pallet { /// Retrieves the total alpha issuance for a given subnet. @@ -16,7 +15,7 @@ impl Pallet { /// /// # Returns /// * `u64` - The total alpha issuance for the specified subnet. - pub fn get_alpha_issuance(netuid: NetUid) -> u64 { + pub fn get_alpha_issuance(netuid: u16) -> u64 { SubnetAlphaIn::::get(netuid).saturating_add(SubnetAlphaOut::::get(netuid)) } @@ -31,8 +30,8 @@ impl Pallet { /// /// # Returns /// * `I96F32` - The price of alpha for the specified subnet. - pub fn get_alpha_price(netuid: NetUid) -> U96F32 { - if netuid.is_root() { + pub fn get_alpha_price(netuid: u16) -> U96F32 { + if netuid == Self::get_root_netuid() { return U96F32::saturating_from_num(1.0); // Root. } if SubnetMechanism::::get(netuid) == 0 { @@ -46,9 +45,9 @@ impl Pallet { .unwrap_or(U96F32::saturating_from_num(0)) } } - pub fn get_moving_alpha_price(netuid: NetUid) -> U96F32 { + pub fn get_moving_alpha_price(netuid: u16) -> U96F32 { let one = U96F32::saturating_from_num(1.0); - if netuid.is_root() { + if netuid == Self::get_root_netuid() { // Root. one } else if SubnetMechanism::::get(netuid) == 0 { @@ -59,7 +58,7 @@ impl Pallet { } } - pub fn update_moving_price(netuid: NetUid) { + pub fn update_moving_price(netuid: u16) { let blocks_since_start_call = U96F32::saturating_from_num({ // We expect FirstEmissionBlockNumber to be set earlier, and we take the block when // `start_call` was called (first block before FirstEmissionBlockNumber). @@ -145,7 +144,7 @@ impl Pallet { /// pub fn get_stake_weights_for_hotkey_on_subnet( hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, ) -> (I64F64, I64F64, I64F64) { // Retrieve the global tao weight. let tao_weight = I64F64::saturating_from_num(Self::get_tao_weight()); @@ -171,9 +170,7 @@ impl Pallet { /// Calculates the weighted combination of alpha and global tao for hotkeys on a subnet. /// - pub fn get_stake_weights_for_network( - netuid: NetUid, - ) -> (Vec, Vec, Vec) { + pub fn get_stake_weights_for_network(netuid: u16) -> (Vec, Vec, Vec) { // Retrieve the global tao weight. let tao_weight: I64F64 = I64F64::saturating_from_num(Self::get_tao_weight()); log::debug!("tao_weight: {:?}", tao_weight); @@ -251,9 +248,10 @@ impl Pallet { /// /// # Note /// This function uses saturating arithmetic to prevent overflows. - pub fn get_tao_inherited_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: NetUid) -> u64 { - let initial_tao: U96F32 = - U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet(hotkey, NetUid::ROOT)); + pub fn get_tao_inherited_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16) -> u64 { + let initial_tao: U96F32 = U96F32::saturating_from_num( + Self::get_stake_for_hotkey_on_subnet(hotkey, Self::get_root_netuid()), + ); // Initialize variables to track alpha allocated to children and inherited from parents. let mut tao_to_children: U96F32 = U96F32::saturating_from_num(0); @@ -298,10 +296,9 @@ impl Pallet { // Step 4: Calculate the total tao inherited from parents. for (proportion, parent) in parents { // Retrieve the parent's total stake on this subnet. - let parent_tao = U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet( - &parent, - NetUid::ROOT, - )); + let parent_tao: U96F32 = U96F32::saturating_from_num( + Self::get_stake_for_hotkey_on_subnet(&parent, Self::get_root_netuid()), + ); log::trace!( "Parent tao for parent {:?} on subnet {}: {:?}", parent, @@ -310,7 +307,7 @@ impl Pallet { ); // Convert the proportion to a normalized value between 0 and 1. - let normalized_proportion = U96F32::saturating_from_num(proportion) + let normalized_proportion: U96F32 = U96F32::saturating_from_num(proportion) .safe_div(U96F32::saturating_from_num(u64::MAX)); log::trace!( "Normalized proportion from parent: {:?}", @@ -345,7 +342,7 @@ impl Pallet { finalized_tao.saturating_to_num::() } - pub fn get_inherited_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: NetUid) -> u64 { + pub fn get_inherited_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16) -> u64 { // Step 1: Retrieve the initial total stake (alpha) for the hotkey on the specified subnet. let initial_alpha: U96F32 = U96F32::saturating_from_num(Self::get_stake_for_hotkey_on_subnet(hotkey, netuid)); @@ -355,7 +352,7 @@ impl Pallet { netuid, initial_alpha ); - if netuid.is_root() { + if netuid == 0 { return initial_alpha.saturating_to_num::(); } @@ -470,7 +467,7 @@ impl Pallet { pub fn has_enough_stake_on_subnet( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, decrement: u64, ) -> bool { // Retrieve the current stake for this hotkey-coldkey pair on the subnet @@ -502,7 +499,7 @@ impl Pallet { pub fn get_stake_for_hotkey_and_coldkey_on_subnet( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, ) -> u64 { let alpha_share_pool = Self::get_alpha_share_pool(hotkey.clone(), netuid); alpha_share_pool.try_get_value(coldkey).unwrap_or(0) @@ -522,7 +519,7 @@ impl Pallet { /// /// # Note /// This function returns the cumulative stake across all coldkeys associated with this hotkey on the subnet. - pub fn get_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: NetUid) -> u64 { + pub fn get_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16) -> u64 { // Retrieve and return the total alpha this hotkey owns on this subnet. // This value represents the sum of stakes from all coldkeys associated with this hotkey. TotalHotkeyAlpha::::get(hotkey, netuid) @@ -537,7 +534,7 @@ impl Pallet { /// * `netuid` - The unique identifier of the subnet. /// * `amount` - The amount of alpha to be added. /// - pub fn increase_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: NetUid, amount: u64) { + pub fn increase_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16, amount: u64) { let mut alpha_share_pool = Self::get_alpha_share_pool(hotkey.clone(), netuid); alpha_share_pool.update_value_for_all(amount as i64); } @@ -551,7 +548,7 @@ impl Pallet { /// * `netuid` - The unique identifier of the subnet. /// * `amount` - The amount of alpha to be added. /// - pub fn decrease_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: NetUid, amount: u64) { + pub fn decrease_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16, amount: u64) { let mut alpha_share_pool = Self::get_alpha_share_pool(hotkey.clone(), netuid); alpha_share_pool.update_value_for_all((amount as i64).neg()); } @@ -569,7 +566,7 @@ impl Pallet { pub fn increase_stake_for_hotkey_and_coldkey_on_subnet( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, amount: u64, ) -> u64 { if amount > 0 { @@ -591,7 +588,7 @@ impl Pallet { pub fn try_increase_stake_for_hotkey_and_coldkey_on_subnet( hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, amount: u64, ) -> bool { let mut alpha_share_pool = Self::get_alpha_share_pool(hotkey.clone(), netuid); @@ -611,7 +608,7 @@ impl Pallet { pub fn decrease_stake_for_hotkey_and_coldkey_on_subnet( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, amount: u64, ) -> u64 { let mut alpha_share_pool = Self::get_alpha_share_pool(hotkey.clone(), netuid); @@ -637,7 +634,7 @@ impl Pallet { /// If new alpha_reserve is about to drop below DefaultMinimumPoolLiquidity, /// then don't do it. /// - pub fn sim_swap_tao_for_alpha(netuid: NetUid, tao: u64) -> Option { + pub fn sim_swap_tao_for_alpha(netuid: u16, tao: u64) -> Option { // Step 1: Get the mechanism type for the subnet (0 for Stable, 1 for Dynamic) let mechanism_id: u16 = SubnetMechanism::::get(netuid); // Step 2: Initialized vars. @@ -676,7 +673,7 @@ impl Pallet { /// If new tao_reserve is about to drop below DefaultMinimumPoolLiquidity, /// then don't do it. /// - pub fn sim_swap_alpha_for_tao(netuid: NetUid, alpha: u64) -> Option { + pub fn sim_swap_alpha_for_tao(netuid: u16, alpha: u64) -> Option { // Step 1: Get the mechanism type for the subnet (0 for Stable, 1 for Dynamic) let mechanism_id: u16 = SubnetMechanism::::get(netuid); // Step 2: Swap alpha and attain tao @@ -713,7 +710,7 @@ impl Pallet { /// Swaps TAO for the alpha token on the subnet. /// /// Updates TaoIn, AlphaIn, and AlphaOut - pub fn swap_tao_for_alpha(netuid: NetUid, tao: u64) -> u64 { + pub fn swap_tao_for_alpha(netuid: u16, tao: u64) -> u64 { if let Some(alpha) = Self::sim_swap_tao_for_alpha(netuid, tao) { // Step 4. Decrease Alpha reserves. SubnetAlphaIn::::mutate(netuid, |total| { @@ -745,7 +742,7 @@ impl Pallet { /// Swaps a subnet's Alpba token for TAO. /// /// Updates TaoIn, AlphaIn, and AlphaOut - pub fn swap_alpha_for_tao(netuid: NetUid, alpha: u64) -> u64 { + pub fn swap_alpha_for_tao(netuid: u16, alpha: u64) -> u64 { if let Some(tao) = Self::sim_swap_alpha_for_tao(netuid, alpha) { // Step 4: Increase Alpha reserves. SubnetAlphaIn::::mutate(netuid, |total| { @@ -780,7 +777,7 @@ impl Pallet { pub fn unstake_from_subnet( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, alpha: u64, fee: u64, ) -> u64 { @@ -839,7 +836,7 @@ impl Pallet { pub(crate) fn stake_into_subnet( hotkey: &T::AccountId, coldkey: &T::AccountId, - netuid: NetUid, + netuid: u16, tao: u64, fee: u64, ) -> u64 { @@ -893,7 +890,7 @@ impl Pallet { pub fn get_alpha_share_pool( hotkey: ::AccountId, - netuid: NetUid, + netuid: u16, ) -> SharePool, HotkeyAlphaSharePoolDataOperations> { let ops = HotkeyAlphaSharePoolDataOperations::new(hotkey, netuid); SharePool::, HotkeyAlphaSharePoolDataOperations>::new(ops) @@ -904,7 +901,7 @@ impl Pallet { pub fn validate_add_stake( coldkey: &T::AccountId, hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, stake_to_be_added: u64, max_amount: u64, allow_partial: bool, @@ -960,7 +957,7 @@ impl Pallet { pub fn validate_remove_stake( coldkey: &T::AccountId, hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, alpha_unstaked: u64, max_amount: u64, allow_partial: bool, @@ -1010,7 +1007,7 @@ impl Pallet { only_alpha: bool, ) -> Result<(), Error> { // Get all netuids (filter out root) - let subnets = Self::get_all_subnet_netuids(); + let subnets: Vec = Self::get_all_subnet_netuids(); // Ensure that the hotkey account exists this is only possible through registration. ensure!( @@ -1020,7 +1017,7 @@ impl Pallet { let mut unstaking_any = false; for netuid in subnets.iter() { - if only_alpha && netuid.is_root() { + if only_alpha && (*netuid == Self::get_root_netuid()) { continue; } @@ -1046,8 +1043,8 @@ impl Pallet { destination_coldkey: &T::AccountId, origin_hotkey: &T::AccountId, destination_hotkey: &T::AccountId, - origin_netuid: NetUid, - destination_netuid: NetUid, + origin_netuid: u16, + destination_netuid: u16, alpha_amount: u64, max_amount: u64, maybe_allow_partial: Option, @@ -1150,9 +1147,9 @@ impl Pallet { } pub(crate) fn calculate_staking_fee( - origin: Option<(&T::AccountId, NetUid)>, + origin: Option<(&T::AccountId, u16)>, _origin_coldkey: &T::AccountId, - destination: Option<(&T::AccountId, NetUid)>, + destination: Option<(&T::AccountId, u16)>, _destination_coldkey: &T::AccountId, alpha_estimate: U96F32, ) -> u64 { @@ -1167,7 +1164,9 @@ impl Pallet { } } - if origin_netuid.is_root() || SubnetMechanism::::get(origin_netuid) == 0 { + if origin_netuid == Self::get_root_netuid() + || SubnetMechanism::::get(origin_netuid) == 0 + { // If the origin netuid is root, or the subnet mechanism is 0, use the default fee DefaultStakingFee::::get() } else { @@ -1217,13 +1216,13 @@ impl Pallet { #[derive(Debug)] pub struct HotkeyAlphaSharePoolDataOperations { - netuid: NetUid, + netuid: u16, hotkey: ::AccountId, _marker: sp_std::marker::PhantomData, } impl HotkeyAlphaSharePoolDataOperations { - fn new(hotkey: ::AccountId, netuid: NetUid) -> Self { + fn new(hotkey: ::AccountId, netuid: u16) -> Self { HotkeyAlphaSharePoolDataOperations { netuid, hotkey, diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index b01abec248..5c698c1b33 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -2,13 +2,12 @@ use super::*; use sp_core::{H256, U256}; use sp_io::hashing::{keccak_256, sha2_256}; use sp_runtime::Saturating; -use subtensor_runtime_common::NetUid; use system::pallet_prelude::BlockNumberFor; const LOG_TARGET: &str = "runtime::subtensor::registration"; impl Pallet { - pub fn register_neuron(netuid: NetUid, hotkey: &T::AccountId) -> u16 { + pub fn register_neuron(netuid: u16, hotkey: &T::AccountId) -> u16 { // Init param let neuron_uid: u16; let block_number: u64 = Self::get_current_block_as_u64(); @@ -65,7 +64,7 @@ impl Pallet { /// pub fn do_burned_registration( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, hotkey: T::AccountId, ) -> DispatchResult { // --- 1. Check that the caller has signed the transaction. (the coldkey of the pairing) @@ -79,7 +78,7 @@ impl Pallet { // --- 2. Ensure the passed network is valid. ensure!( - !netuid.is_root(), + netuid != Self::get_root_netuid(), Error::::RegistrationNotPermittedOnRootSubnet ); ensure!( @@ -214,7 +213,7 @@ impl Pallet { /// pub fn do_registration( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, block_number: u64, nonce: u64, work: Vec, @@ -238,7 +237,7 @@ impl Pallet { // --- 2. Ensure the passed network is valid. ensure!( - !netuid.is_root(), + netuid != Self::get_root_netuid(), Error::::RegistrationNotPermittedOnRootSubnet ); ensure!( @@ -407,7 +406,7 @@ impl Pallet { /// If all neurons are in immunity period, the neuron with the lowest pruning score is pruned. If there is a tie for /// the lowest pruning score, the immune neuron registered earliest is pruned. /// Ties for earliest registration are broken by the neuron with the lowest uid. - pub fn get_neuron_to_prune(netuid: NetUid) -> u16 { + pub fn get_neuron_to_prune(netuid: u16) -> u16 { let mut min_score: u16 = u16::MAX; let mut min_score_in_immunity: u16 = u16::MAX; let mut earliest_registration: u64 = u64::MAX; @@ -585,7 +584,7 @@ impl Pallet { /// Helper function for creating nonce and work. pub fn create_work_for_block_number( - netuid: NetUid, + netuid: u16, block_number: u64, start_nonce: u64, hotkey: &T::AccountId, diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index ae1c97cc7c..bee81bfae6 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -1,5 +1,4 @@ use super::*; -use subtensor_runtime_common::NetUid; impl Pallet { /// ---- The implementation for the extrinsic serve_axon which sets the ip endpoint information for a uid on a network. @@ -57,7 +56,7 @@ impl Pallet { /// pub fn do_serve_axon( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, version: u32, ip: u128, port: u16, @@ -161,7 +160,7 @@ impl Pallet { /// pub fn do_serve_prometheus( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, version: u32, ip: u128, port: u16, @@ -221,7 +220,7 @@ impl Pallet { *********************************/ pub fn axon_passes_rate_limit( - netuid: NetUid, + netuid: u16, prev_axon_info: &AxonInfoOf, current_block: u64, ) -> bool { @@ -231,7 +230,7 @@ impl Pallet { } pub fn prometheus_passes_rate_limit( - netuid: NetUid, + netuid: u16, prev_prometheus_info: &PrometheusInfoOf, current_block: u64, ) -> bool { @@ -240,7 +239,7 @@ impl Pallet { rate_limit == 0 || last_serve == 0 || current_block.saturating_sub(last_serve) >= rate_limit } - pub fn get_axon_info(netuid: NetUid, hotkey: &T::AccountId) -> AxonInfoOf { + pub fn get_axon_info(netuid: u16, hotkey: &T::AccountId) -> AxonInfoOf { if let Some(axons) = Axons::::get(netuid, hotkey) { axons } else { @@ -257,7 +256,7 @@ impl Pallet { } } - pub fn get_prometheus_info(netuid: NetUid, hotkey: &T::AccountId) -> PrometheusInfoOf { + pub fn get_prometheus_info(netuid: u16, hotkey: &T::AccountId) -> PrometheusInfoOf { if let Some(prometheus) = Prometheus::::get(netuid, hotkey) { prometheus } else { @@ -320,7 +319,7 @@ impl Pallet { pub fn validate_serve_axon( hotkey_id: &T::AccountId, - netuid: NetUid, + netuid: u16, version: u32, ip: u128, port: u16, diff --git a/pallets/subtensor/src/subnets/subnet.rs b/pallets/subtensor/src/subnets/subnet.rs index ff9762353c..b122bfa049 100644 --- a/pallets/subtensor/src/subnets/subnet.rs +++ b/pallets/subtensor/src/subnets/subnet.rs @@ -1,8 +1,19 @@ use super::*; +use frame_support::IterableStorageMap; use sp_core::Get; -use subtensor_runtime_common::NetUid; impl Pallet { + /// Retrieves the unique identifier (UID) for the root network. + /// + /// The root network is a special case and has a fixed UID of 0. + /// + /// # Returns: + /// * 'u16': The UID for the root network. + /// + pub fn get_root_netuid() -> u16 { + 0 + } + /// Fetches the total count of subnets. /// /// This function retrieves the total number of subnets present on the chain. @@ -21,7 +32,7 @@ impl Pallet { /// # Returns: /// * 'bool': Whether the subnet exists. /// - pub fn if_subnet_exist(netuid: NetUid) -> bool { + pub fn if_subnet_exist(netuid: u16) -> bool { NetworksAdded::::get(netuid) } @@ -33,8 +44,8 @@ impl Pallet { /// # Returns: /// * 'Vec': Netuids of all subnets. /// - pub fn get_all_subnet_netuids() -> Vec { - NetworksAdded::::iter() + pub fn get_all_subnet_netuids() -> Vec { + as IterableStorageMap>::iter() .map(|(netuid, _)| netuid) .collect() } @@ -50,7 +61,7 @@ impl Pallet { /// # Returns: /// * 'u16': The subnet mechanism /// - pub fn get_subnet_mechanism(netuid: NetUid) -> u16 { + pub fn get_subnet_mechanism(netuid: u16) -> u16 { SubnetMechanism::::get(netuid) } @@ -61,14 +72,14 @@ impl Pallet { /// /// # Returns /// * `u16` - The next available mechanism ID. - pub fn get_next_netuid() -> NetUid { - let mut next_netuid = NetUid::from(1); // do not allow creation of root - let netuids = Self::get_all_subnet_netuids(); + pub fn get_next_netuid() -> u16 { + let mut next_netuid = 1; // do not allow creation of root + let netuids: Vec = Self::get_all_subnet_netuids(); loop { if !netuids.contains(&next_netuid) { break next_netuid; } - next_netuid = next_netuid.next(); + next_netuid = next_netuid.saturating_add(1); } } @@ -92,7 +103,7 @@ impl Pallet { /// # Returns /// /// * `bool` - `true` if registrations are allowed for the subnet, `false` otherwise. - pub fn is_registration_allowed(netuid: NetUid) -> bool { + pub fn is_registration_allowed(netuid: u16) -> bool { Self::get_subnet_hyperparams(netuid) .map(|params| params.registration_allowed) .unwrap_or(false) @@ -149,7 +160,7 @@ impl Pallet { ); // --- 5. Determine the netuid to register. - let netuid_to_register = Self::get_next_netuid(); + let netuid_to_register: u16 = Self::get_next_netuid(); // --- 6. Perform the lock operation. let actual_tao_lock_amount: u64 = @@ -234,7 +245,7 @@ impl Pallet { } /// Sets initial and custom parameters for a new network. - pub fn init_new_network(netuid: NetUid, tempo: u16) { + pub fn init_new_network(netuid: u16, tempo: u16) { // --- 1. Set network to 0 size. SubnetworkN::::insert(netuid, 0); @@ -329,7 +340,7 @@ impl Pallet { /// # Returns /// /// * `DispatchResult`: A result indicating the success or failure of the operation. - pub fn do_start_call(origin: T::RuntimeOrigin, netuid: NetUid) -> DispatchResult { + pub fn do_start_call(origin: T::RuntimeOrigin, netuid: u16) -> DispatchResult { ensure!( Self::if_subnet_exist(netuid), Error::::SubNetworkDoesNotExist @@ -391,7 +402,7 @@ impl Pallet { /// This function is rate-limited to one call per subnet per interval (e.g., one week). pub fn do_set_sn_owner_hotkey( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, hotkey: &T::AccountId, ) -> DispatchResult { // Ensure the caller is either root or subnet owner. @@ -426,7 +437,7 @@ impl Pallet { Ok(()) } - pub fn is_valid_subnet_for_emission(netuid: NetUid) -> bool { + pub fn is_valid_subnet_for_emission(netuid: u16) -> bool { FirstEmissionBlockNumber::::get(netuid).is_some() } } diff --git a/pallets/subtensor/src/subnets/symbols.rs b/pallets/subtensor/src/subnets/symbols.rs index b06d4807f5..1aae9c3a0c 100644 --- a/pallets/subtensor/src/subnets/symbols.rs +++ b/pallets/subtensor/src/subnets/symbols.rs @@ -1,9 +1,8 @@ use super::*; -use subtensor_runtime_common::NetUid; /// Returns the Unicode symbol as a Vec for a given netuid. impl Pallet { - pub fn get_name_for_subnet(netuid: NetUid) -> Vec { + pub fn get_name_for_subnet(netuid: u16) -> Vec { SubnetIdentitiesV2::::try_get(netuid) .and_then(|identity| { if !identity.subnet_name.is_empty() { @@ -13,7 +12,7 @@ impl Pallet { } }) .unwrap_or_else(|_| { - match u16::from(netuid) { + match netuid { 0 => b"root".to_vec(), // Τ (Upper case Tau) 1 => b"apex".to_vec(), // α (Alpha) 2 => b"omron".to_vec(), // β (Beta) @@ -458,8 +457,8 @@ impl Pallet { }) } - pub fn get_symbol_for_subnet(netuid: NetUid) -> Vec { - match u16::from(netuid) { + pub fn get_symbol_for_subnet(netuid: u16) -> Vec { + match netuid { // Greek Alphabet (Lowercase) 0 => b"\xCE\xA4".to_vec(), // Τ (Upper case Tau) 1 => b"\xCE\xB1".to_vec(), // α (Alpha) diff --git a/pallets/subtensor/src/subnets/uids.rs b/pallets/subtensor/src/subnets/uids.rs index fa25b0b9ca..008fc03669 100644 --- a/pallets/subtensor/src/subnets/uids.rs +++ b/pallets/subtensor/src/subnets/uids.rs @@ -1,11 +1,10 @@ use super::*; use frame_support::storage::IterableStorageDoubleMap; use sp_std::vec; -use subtensor_runtime_common::NetUid; impl Pallet { /// Returns the number of filled slots on a network. - pub fn get_subnetwork_n(netuid: NetUid) -> u16 { + pub fn get_subnetwork_n(netuid: u16) -> u16 { SubnetworkN::::get(netuid) } @@ -17,7 +16,7 @@ impl Pallet { } /// Resets the trust, emission, consensus, incentive, dividends of the neuron to default - pub fn clear_neuron(netuid: NetUid, neuron_uid: u16) { + pub fn clear_neuron(netuid: u16, neuron_uid: u16) { let neuron_index: usize = neuron_uid.into(); Emission::::mutate(netuid, |v| Self::set_element_at(v, neuron_index, 0)); Trust::::mutate(netuid, |v| Self::set_element_at(v, neuron_index, 0)); @@ -29,7 +28,7 @@ impl Pallet { /// Replace the neuron under this uid. pub fn replace_neuron( - netuid: NetUid, + netuid: u16, uid_to_replace: u16, new_hotkey: &T::AccountId, block_number: u64, @@ -83,7 +82,7 @@ impl Pallet { } /// Appends the uid to the network. - pub fn append_neuron(netuid: NetUid, new_hotkey: &T::AccountId, block_number: u64) { + pub fn append_neuron(netuid: u16, new_hotkey: &T::AccountId, block_number: u64) { // 1. Get the next uid. This is always equal to subnetwork_n. let next_uid: u16 = Self::get_subnetwork_n(netuid); log::debug!( @@ -118,20 +117,20 @@ impl Pallet { /// Returns true if the uid is set on the network. /// - pub fn is_uid_exist_on_network(netuid: NetUid, uid: u16) -> bool { + pub fn is_uid_exist_on_network(netuid: u16, uid: u16) -> bool { Keys::::contains_key(netuid, uid) } /// Returns true if the hotkey holds a slot on the network. /// - pub fn is_hotkey_registered_on_network(netuid: NetUid, hotkey: &T::AccountId) -> bool { + pub fn is_hotkey_registered_on_network(netuid: u16, hotkey: &T::AccountId) -> bool { Uids::::contains_key(netuid, hotkey) } /// Returs the hotkey under the network uid as a Result. Ok if the uid is taken. /// pub fn get_hotkey_for_net_and_uid( - netuid: NetUid, + netuid: u16, neuron_uid: u16, ) -> Result { Keys::::try_get(netuid, neuron_uid) @@ -141,7 +140,7 @@ impl Pallet { /// Returns the uid of the hotkey in the network as a Result. Ok if the hotkey has a slot. /// pub fn get_uid_for_net_and_hotkey( - netuid: NetUid, + netuid: u16, hotkey: &T::AccountId, ) -> Result { Uids::::try_get(netuid, hotkey) @@ -150,7 +149,7 @@ impl Pallet { /// Returns the stake of the uid on network or 0 if it doesnt exist. /// - pub fn get_stake_for_uid_and_subnetwork(netuid: NetUid, neuron_uid: u16) -> u64 { + pub fn get_stake_for_uid_and_subnetwork(netuid: u16, neuron_uid: u16) -> u64 { if let Ok(hotkey) = Self::get_hotkey_for_net_and_uid(netuid, neuron_uid) { Self::get_stake_for_hotkey_on_subnet(&hotkey, netuid) } else { @@ -160,13 +159,12 @@ impl Pallet { /// Return a list of all networks a hotkey is registered on. /// - pub fn get_registered_networks_for_hotkey(hotkey: &T::AccountId) -> Vec { - let mut all_networks: Vec = vec![]; - for (network, is_registered) in as IterableStorageDoubleMap< - T::AccountId, - NetUid, - bool, - >>::iter_prefix(hotkey) + pub fn get_registered_networks_for_hotkey(hotkey: &T::AccountId) -> Vec { + let mut all_networks: Vec = vec![]; + for (network, is_registered) in + as IterableStorageDoubleMap>::iter_prefix( + hotkey, + ) { if is_registered { all_networks.push(network) @@ -178,11 +176,10 @@ impl Pallet { /// Return true if a hotkey is registered on any network. /// pub fn is_hotkey_registered_on_any_network(hotkey: &T::AccountId) -> bool { - for (_, is_registered) in as IterableStorageDoubleMap< - T::AccountId, - NetUid, - bool, - >>::iter_prefix(hotkey) + for (_, is_registered) in + as IterableStorageDoubleMap>::iter_prefix( + hotkey, + ) { if is_registered { return true; @@ -193,7 +190,7 @@ impl Pallet { /// Return true if a hotkey is registered on specific network. /// - pub fn is_hotkey_registered_on_specific_network(hotkey: &T::AccountId, netuid: NetUid) -> bool { + pub fn is_hotkey_registered_on_specific_network(hotkey: &T::AccountId, netuid: u16) -> bool { IsNetworkMember::::contains_key(hotkey, netuid) } } diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 427846938a..ec6c9949bc 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -8,7 +8,6 @@ use sp_runtime::{ traits::{BlakeTwo256, Hash}, }; use sp_std::{collections::vec_deque::VecDeque, vec}; -use subtensor_runtime_common::NetUid; impl Pallet { /// ---- The implementation for committing weight hashes. @@ -41,7 +40,7 @@ impl Pallet { /// - Emitted upon successfully storing the weight hash. pub fn do_commit_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, commit_hash: H256, ) -> DispatchResult { // 1. Verify the caller's signature (hotkey). @@ -139,7 +138,7 @@ impl Pallet { /// pub fn do_batch_commit_weights( origin: T::RuntimeOrigin, - netuids: Vec>, + netuids: Vec>, commit_hashes: Vec, ) -> dispatch::DispatchResult { // --- 1. Check the caller's signature. This is the hotkey of a registered account. @@ -229,7 +228,7 @@ impl Pallet { /// - Emitted upon successfully storing the weight hash. pub fn do_commit_crv3_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, commit: BoundedVec>, reveal_round: u64, ) -> DispatchResult { @@ -339,7 +338,7 @@ impl Pallet { /// - The revealed hash does not match any committed hash. pub fn do_reveal_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, uids: Vec, values: Vec, salt: Vec, @@ -480,7 +479,7 @@ impl Pallet { /// - The input vectors are of mismatched lengths. pub fn do_batch_reveal_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, uids_list: Vec>, values_list: Vec>, salts_list: Vec>, @@ -676,7 +675,7 @@ impl Pallet { /// pub fn do_set_weights( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, uids: Vec, values: Vec, version_key: u64, @@ -692,7 +691,10 @@ impl Pallet { ); // --- Check that the netuid is not the root network. - ensure!(!netuid.is_root(), Error::::CanNotSetRootNetworkWeights); + ensure!( + netuid != Self::get_root_netuid(), + Error::::CanNotSetRootNetworkWeights + ); // --- 2. Check that the length of uid list and value list are equal for this network. ensure!( @@ -827,7 +829,7 @@ impl Pallet { /// pub fn do_batch_set_weights( origin: T::RuntimeOrigin, - netuids: Vec>, + netuids: Vec>, weights: Vec, Compact)>>, version_keys: Vec>, ) -> dispatch::DispatchResult { @@ -899,7 +901,7 @@ impl Pallet { /// Returns true if version_key is up-to-date. /// - pub fn check_version_key(netuid: NetUid, version_key: u64) -> bool { + pub fn check_version_key(netuid: u16, version_key: u64) -> bool { let network_version_key: u64 = WeightsVersionKey::::get(netuid); log::debug!( "check_version_key( network_version_key:{:?}, version_key:{:?} )", @@ -911,7 +913,7 @@ impl Pallet { /// Checks if the neuron has set weights within the weights_set_rate_limit. /// - pub fn check_rate_limit(netuid: NetUid, neuron_uid: u16, current_block: u64) -> bool { + pub fn check_rate_limit(netuid: u16, neuron_uid: u16, current_block: u64) -> bool { if Self::is_uid_exist_on_network(netuid, neuron_uid) { // --- 1. Ensure that the diff between current and last_set weights is greater than limit. let last_set_weights: u64 = Self::get_last_update_for_uid(netuid, neuron_uid); @@ -926,7 +928,7 @@ impl Pallet { } /// Checks for any invalid uids on this network. - pub fn contains_invalid_uids(netuid: NetUid, uids: &[u16]) -> bool { + pub fn contains_invalid_uids(netuid: u16, uids: &[u16]) -> bool { for uid in uids { if !Self::is_uid_exist_on_network(netuid, *uid) { log::debug!( @@ -958,7 +960,7 @@ impl Pallet { } /// Returns True if setting self-weight or has validator permit. - pub fn check_validator_permit(netuid: NetUid, uid: u16, uids: &[u16], weights: &[u16]) -> bool { + pub fn check_validator_permit(netuid: u16, uid: u16, uids: &[u16], weights: &[u16]) -> bool { // Check self weight. Allowed to set single value for self weight. if Self::is_self_weight(uid, uids, weights) { return true; @@ -968,7 +970,7 @@ impl Pallet { } /// Returns True if the uids and weights are have a valid length for uid on network. - pub fn check_length(netuid: NetUid, uid: u16, uids: &[u16], weights: &[u16]) -> bool { + pub fn check_length(netuid: u16, uid: u16, uids: &[u16], weights: &[u16]) -> bool { let subnet_n: usize = Self::get_subnetwork_n(netuid) as usize; let min_allowed_length: usize = Self::get_min_allowed_weights(netuid) as usize; let min_allowed: usize = { @@ -981,7 +983,7 @@ impl Pallet { // Check self weight. Allowed to set single value for self weight. // Or check that this is the root netuid. - if !netuid.is_root() && Self::is_self_weight(uid, uids, weights) { + if netuid != Self::get_root_netuid() && Self::is_self_weight(uid, uids, weights) { return true; } // Check if number of weights exceeds min. @@ -1006,7 +1008,7 @@ impl Pallet { } /// Returns False if the weights exceed the max_weight_limit for this network. - pub fn max_weight_limited(netuid: NetUid, uid: u16, uids: &[u16], weights: &[u16]) -> bool { + pub fn max_weight_limited(netuid: u16, uid: u16, uids: &[u16], weights: &[u16]) -> bool { // Allow self weights to exceed max weight limit. if Self::is_self_weight(uid, uids, weights) { return true; @@ -1037,13 +1039,13 @@ impl Pallet { } /// Returns False is the number of uids exceeds the allowed number of uids for this network. - pub fn check_len_uids_within_allowed(netuid: NetUid, uids: &[u16]) -> bool { + pub fn check_len_uids_within_allowed(netuid: u16, uids: &[u16]) -> bool { let subnetwork_n: u16 = Self::get_subnetwork_n(netuid); // we should expect at most subnetwork_n uids. uids.len() <= subnetwork_n as usize } - pub fn is_reveal_block_range(netuid: NetUid, commit_block: u64) -> bool { + pub fn is_reveal_block_range(netuid: u16, commit_block: u64) -> bool { let current_block: u64 = Self::get_current_block_as_u64(); let commit_epoch: u64 = Self::get_epoch_index(netuid, commit_block); let current_epoch: u64 = Self::get_epoch_index(netuid, current_block); @@ -1053,16 +1055,16 @@ impl Pallet { current_epoch == commit_epoch.saturating_add(reveal_period) } - pub fn get_epoch_index(netuid: NetUid, block_number: u64) -> u64 { + pub fn get_epoch_index(netuid: u16, block_number: u64) -> u64 { let tempo: u64 = Self::get_tempo(netuid) as u64; let tempo_plus_one: u64 = tempo.saturating_add(1); - let netuid_plus_one: u64 = (u16::from(netuid) as u64).saturating_add(1); + let netuid_plus_one: u64 = (netuid as u64).saturating_add(1); let block_with_offset: u64 = block_number.saturating_add(netuid_plus_one); block_with_offset.checked_div(tempo_plus_one).unwrap_or(0) } - pub fn is_commit_expired(netuid: NetUid, commit_block: u64) -> bool { + pub fn is_commit_expired(netuid: u16, commit_block: u64) -> bool { let current_block: u64 = Self::get_current_block_as_u64(); let current_epoch: u64 = Self::get_epoch_index(netuid, current_block); let commit_epoch: u64 = Self::get_epoch_index(netuid, commit_block); @@ -1071,11 +1073,11 @@ impl Pallet { current_epoch > commit_epoch.saturating_add(reveal_period) } - pub fn get_reveal_blocks(netuid: NetUid, commit_block: u64) -> (u64, u64) { + pub fn get_reveal_blocks(netuid: u16, commit_block: u64) -> (u64, u64) { let reveal_period: u64 = Self::get_reveal_period(netuid); let tempo: u64 = Self::get_tempo(netuid) as u64; let tempo_plus_one: u64 = tempo.saturating_add(1); - let netuid_plus_one: u64 = (u16::from(netuid) as u64).saturating_add(1); + let netuid_plus_one: u64 = (netuid as u64).saturating_add(1); let commit_epoch: u64 = Self::get_epoch_index(netuid, commit_block); let reveal_epoch: u64 = commit_epoch.saturating_add(reveal_period); @@ -1088,11 +1090,11 @@ impl Pallet { (first_reveal_block, last_reveal_block) } - pub fn set_reveal_period(netuid: NetUid, reveal_period: u64) { + pub fn set_reveal_period(netuid: u16, reveal_period: u64) { RevealPeriodEpochs::::insert(netuid, reveal_period); Self::deposit_event(Event::CommitRevealPeriodsSet(netuid, reveal_period)); } - pub fn get_reveal_period(netuid: NetUid) -> u64 { + pub fn get_reveal_period(netuid: u16) -> u64 { RevealPeriodEpochs::::get(netuid) } } diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index 4b598c77d6..733535c2ad 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -27,7 +27,7 @@ impl Pallet { origin: T::RuntimeOrigin, old_hotkey: &T::AccountId, new_hotkey: &T::AccountId, - netuid: Option, + netuid: Option, ) -> DispatchResultWithPostInfo { // 1. Ensure the origin is signed and get the coldkey let coldkey = ensure_signed(origin)?; @@ -163,7 +163,7 @@ impl Pallet { weight: &mut Weight, ) -> DispatchResult { // 1. keep the old hotkey alpha values for the case where hotkey staked by multiple coldkeys. - let old_alpha_values: Vec<((T::AccountId, NetUid), U64F64)> = + let old_alpha_values: Vec<((T::AccountId, u16), U64F64)> = Alpha::::iter_prefix((old_hotkey,)).collect(); weight.saturating_accrue(T::DbWeight::get().reads(old_alpha_values.len() as u64)); @@ -261,7 +261,7 @@ impl Pallet { coldkey: &T::AccountId, old_hotkey: &T::AccountId, new_hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, init_weight: Weight, ) -> DispatchResultWithPostInfo { // 1. Ensure coldkey not swap hotkey too frequently @@ -343,7 +343,7 @@ impl Pallet { old_hotkey: &T::AccountId, new_hotkey: &T::AccountId, weight: &mut Weight, - netuid: NetUid, + netuid: u16, ) { // 1. Swap total hotkey alpha for all subnets it exists on. // TotalHotkeyAlpha( hotkey, netuid ) -> alpha -- the total alpha that the hotkey has on a specific subnet. @@ -564,7 +564,7 @@ impl Pallet { // 9. Swap Alpha // Alpha( hotkey, coldkey, netuid ) -> alpha - let old_alpha_values: Vec<((T::AccountId, NetUid), U64F64)> = + let old_alpha_values: Vec<((T::AccountId, u16), U64F64)> = Alpha::::iter_prefix((old_hotkey,)).collect(); weight.saturating_accrue(T::DbWeight::get().reads(old_alpha_values.len() as u64)); weight.saturating_accrue(T::DbWeight::get().writes(old_alpha_values.len() as u64)); diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 556b19c380..1a9016f13f 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -28,7 +28,7 @@ fn test_do_set_child_singular_success() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -52,7 +52,7 @@ fn test_do_set_child_singular_network_does_not_exist() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(999); // Non-existent network + let netuid: u16 = 999; // Non-existent network let proportion: u64 = 1000; // Attempt to set child @@ -75,7 +75,7 @@ fn test_do_set_child_singular_invalid_child() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -105,7 +105,7 @@ fn test_do_set_child_singular_non_associated_coldkey() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey with a different coldkey @@ -133,7 +133,7 @@ fn test_do_set_child_singular_root_network() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::ROOT; // Root network + let netuid: u16 = SubtensorModule::get_root_netuid(); // Root network let proportion: u64 = 1000; // Add network and register hotkey @@ -167,7 +167,7 @@ fn test_do_set_child_singular_old_children_cleanup() { let hotkey = U256::from(2); let old_child = U256::from(3); let new_child = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -205,7 +205,7 @@ fn test_do_set_child_singular_new_children_assignment() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -238,7 +238,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -279,7 +279,7 @@ fn test_do_set_child_singular_multiple_children() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion1: u64 = 500; let proportion2: u64 = 500; @@ -318,7 +318,7 @@ fn test_do_set_child_singular_multiple_children() { #[test] fn test_add_singular_child() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let child = U256::from(1); let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -371,7 +371,7 @@ fn test_add_singular_child() { #[test] fn test_get_stake_for_hotkey_on_subnet() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let parent = U256::from(1); let child = U256::from(2); let coldkey1 = U256::from(3); @@ -423,7 +423,7 @@ fn test_do_revoke_child_singular_success() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey add_network(netuid, 13, 0); @@ -452,7 +452,7 @@ fn test_do_set_empty_children_network_does_not_exist() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(999); // Non-existent network + let netuid: u16 = 999; // Non-existent network // Attempt to revoke child assert_err!( SubtensorModule::do_schedule_children( @@ -477,7 +477,7 @@ fn test_do_revoke_child_singular_non_associated_coldkey() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey with a different coldkey add_network(netuid, 13, 0); @@ -508,7 +508,7 @@ fn test_do_revoke_child_singular_child_not_associated() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -539,7 +539,7 @@ fn test_do_schedule_children_multiple_success() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion1: u64 = 1000; let proportion2: u64 = 2000; @@ -579,7 +579,7 @@ fn test_do_schedule_children_multiple_network_does_not_exist() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child1 = U256::from(3); - let netuid = NetUid::from(999); // Non-existent network + let netuid: u16 = 999; // Non-existent network let proportion: u64 = 1000; // Attempt to set children @@ -606,7 +606,7 @@ fn test_do_schedule_children_multiple_invalid_child() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -638,7 +638,7 @@ fn test_do_schedule_children_multiple_non_associated_coldkey() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey with a different coldkey @@ -670,7 +670,7 @@ fn test_do_schedule_children_multiple_root_network() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::ROOT; // Root network + let netuid: u16 = SubtensorModule::get_root_netuid(); // Root network let proportion: u64 = 1000; // Add network and register hotkey @@ -705,7 +705,7 @@ fn test_do_schedule_children_multiple_old_children_cleanup() { let old_child = U256::from(3); let new_child1 = U256::from(4); let new_child2 = U256::from(5); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -751,7 +751,7 @@ fn test_do_schedule_children_multiple_proportion_edge_cases() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -792,7 +792,7 @@ fn test_do_schedule_children_multiple_overwrite_existing() { let child1 = U256::from(3); let child2 = U256::from(4); let child3 = U256::from(5); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -850,7 +850,7 @@ fn test_childkey_take_functionality() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -926,7 +926,7 @@ fn test_childkey_take_rate_limiting() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -1030,7 +1030,6 @@ fn test_multiple_networks_childkey_take() { // Create 10 networks and set up neurons (skip network 0) for netuid in 1..NUM_NETWORKS { - let netuid = NetUid::from(netuid); // Add network add_network(netuid, 13, 0); @@ -1038,7 +1037,7 @@ fn test_multiple_networks_childkey_take() { register_ok_neuron(netuid, hotkey, coldkey, 0); // Set a unique childkey take value for each network - let take_value = u16::from(netuid.next()) * 100; // Values will be 200, 300, ..., 1000 + let take_value = (netuid + 1) * 100; // Values will be 200, 300, ..., 1000 assert_ok!(SubtensorModule::set_childkey_take( RuntimeOrigin::signed(coldkey), hotkey, @@ -1061,8 +1060,8 @@ fn test_multiple_networks_childkey_take() { // Verify all networks have different childkey take values for i in 1..NUM_NETWORKS { for j in (i + 1)..NUM_NETWORKS { - let take_i = SubtensorModule::get_childkey_take(&hotkey, i.into()); - let take_j = SubtensorModule::get_childkey_take(&hotkey, j.into()); + let take_i = SubtensorModule::get_childkey_take(&hotkey, i); + let take_j = SubtensorModule::get_childkey_take(&hotkey, j); assert_ne!( take_i, take_j, "Childkey take values should be different for networks {} and {}", @@ -1072,12 +1071,8 @@ fn test_multiple_networks_childkey_take() { } // Attempt to set childkey take again (should fail due to rate limit) - let result = SubtensorModule::set_childkey_take( - RuntimeOrigin::signed(coldkey), - hotkey, - 1.into(), - 1100, - ); + let result = + SubtensorModule::set_childkey_take(RuntimeOrigin::signed(coldkey), hotkey, 1, 1100); assert_noop!(result, Error::::TxChildkeyTakeRateLimitExceeded); // Advance blocks to bypass rate limit @@ -1087,12 +1082,12 @@ fn test_multiple_networks_childkey_take() { assert_ok!(SubtensorModule::set_childkey_take( RuntimeOrigin::signed(coldkey), hotkey, - 1.into(), + 1, 1100 )); // Verify the new take value - let new_take = SubtensorModule::get_childkey_take(&hotkey, 1.into()); + let new_take = SubtensorModule::get_childkey_take(&hotkey, 1); assert_eq!(new_take, 1100, "Childkey take not updated after rate limit"); }); } @@ -1108,7 +1103,7 @@ fn test_do_schedule_children_multiple_empty_list() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -1138,7 +1133,7 @@ fn test_do_revoke_children_multiple_success() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion1: u64 = 1000; let proportion2: u64 = 2000; @@ -1184,7 +1179,7 @@ fn test_do_revoke_children_multiple_network_does_not_exist() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(999); // Non-existent network + let netuid: u16 = 999; // Non-existent network // Attempt to revoke children assert_err!( SubtensorModule::do_schedule_children( @@ -1211,7 +1206,7 @@ fn test_do_revoke_children_multiple_non_associated_coldkey() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey with a different coldkey add_network(netuid, 13, 0); @@ -1246,7 +1241,7 @@ fn test_do_revoke_children_multiple_partial_revocation() { let child1 = U256::from(3); let child2 = U256::from(4); let child3 = U256::from(5); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -1303,7 +1298,7 @@ fn test_do_revoke_children_multiple_non_existent_children() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child1 = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -1339,7 +1334,7 @@ fn test_do_revoke_children_multiple_empty_list() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // Add network and register hotkey add_network(netuid, 13, 0); @@ -1370,7 +1365,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { let child1 = U256::from(3); let child2 = U256::from(4); let child3 = U256::from(5); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion1: u64 = 1000; let proportion2: u64 = 2000; let proportion3: u64 = 3000; @@ -1439,7 +1434,7 @@ fn test_children_stake_values() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let coldkey = U256::from(1); let hotkey = U256::from(2); @@ -1512,7 +1507,7 @@ fn test_children_stake_values() { #[test] fn test_get_parents_chain() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey = U256::from(1); let num_keys: usize = 5; let proportion = u64::MAX / 2; // 50% stake allocation @@ -1656,7 +1651,7 @@ fn test_get_parents_chain() { #[test] fn test_get_stake_for_hotkey_on_subnet_basic() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -1681,7 +1676,7 @@ fn test_get_stake_for_hotkey_on_subnet_basic() { #[test] fn test_get_stake_for_hotkey_on_subnet_multiple_coldkeys() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let coldkey1 = U256::from(2); let coldkey2 = U256::from(3); @@ -1719,7 +1714,7 @@ fn test_get_stake_for_hotkey_on_subnet_single_parent_child() { let parent = U256::from(1); let child = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, parent, coldkey, 0); register_ok_neuron(netuid, child, coldkey, 0); @@ -1756,7 +1751,7 @@ fn test_get_stake_for_hotkey_on_subnet_multiple_parents_single_child() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let parent1 = U256::from(1); let parent2 = U256::from(2); @@ -1811,7 +1806,7 @@ fn test_get_stake_for_hotkey_on_subnet_single_parent_multiple_children() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let parent = U256::from(1); let child1 = U256::from(2); @@ -1875,7 +1870,7 @@ fn test_get_stake_for_hotkey_on_subnet_edge_cases() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let parent = U256::from(1); let child1 = U256::from(2); @@ -1939,7 +1934,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let parent = U256::from(1); let child1 = U256::from(2); @@ -2133,8 +2128,8 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { #[test] fn test_get_stake_for_hotkey_on_subnet_multiple_networks() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -2170,7 +2165,7 @@ fn test_do_set_child_below_min_stake() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -2205,8 +2200,8 @@ fn test_do_remove_stake_clears_pending_childkeys() { let coldkey = U256::from(1); let hotkey = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(0); - let child_netuid = NetUid::from(1); + let netuid: u16 = 0; + let child_netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -2267,7 +2262,7 @@ fn test_do_set_child_cooldown_period() { let coldkey = U256::from(1); let parent = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -2340,7 +2335,7 @@ fn test_do_set_pending_children_runs_in_epoch() { let coldkey = U256::from(1); let parent = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -2405,11 +2400,12 @@ fn test_revoke_child_no_min_stake_check() { let coldkey = U256::from(1); let parent = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let root: u16 = 0; + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey - add_network(NetUid::ROOT, 13, 0); + add_network(root, 13, 0); add_network(netuid, 13, 0); register_ok_neuron(netuid, parent, coldkey, 0); @@ -2418,7 +2414,7 @@ fn test_revoke_child_no_min_stake_check() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &parent, &coldkey, - NetUid::ROOT, + root, StakeThreshold::::get(), ); @@ -2438,7 +2434,7 @@ fn test_revoke_child_no_min_stake_check() { SubtensorModule::decrease_stake_for_hotkey_and_coldkey_on_subnet( &parent, &coldkey, - NetUid::ROOT, + root, StakeThreshold::::get(), ); @@ -2478,7 +2474,7 @@ fn test_do_set_child_registration_disabled() { let coldkey = U256::from(1); let parent = U256::from(2); let child = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion: u64 = 1000; // Add network and register hotkey @@ -2536,7 +2532,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { let hotkey = U256::from(2); let child = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo = 13; // Add network and register hotkey @@ -2591,7 +2587,7 @@ fn test_childkey_set_weights_single_parent() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); Tempo::::insert(netuid, 1); // Define hotkeys @@ -2700,7 +2696,7 @@ fn test_set_weights_no_parent() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let hotkey: U256 = U256::from(2); let spare_hk: U256 = U256::from(3); @@ -2810,7 +2806,7 @@ fn test_childkey_take_drain() { let miner_coldkey = U256::from(5); let miner_hotkey = U256::from(6); let nominator = U256::from(7); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let subnet_tempo = 10; let stake = 100_000_000_000; let proportion: u64 = u64::MAX / 2; @@ -2926,7 +2922,7 @@ fn test_parent_child_chain_emission() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); Tempo::::insert(netuid, 1); // Setup large LPs to prevent slippage @@ -3135,7 +3131,7 @@ fn test_parent_child_chain_emission() { #[test] fn test_parent_child_chain_epoch() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Set owner cut to 0 SubtensorModule::set_subnet_owner_cut(0_u16); @@ -3266,7 +3262,7 @@ fn test_parent_child_chain_epoch() { #[test] fn test_dividend_distribution_with_children() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Set owner cut to 0 SubtensorModule::set_subnet_owner_cut(0_u16); @@ -3491,7 +3487,7 @@ fn test_dividend_distribution_with_children() { #[test] fn test_dynamic_parent_child_relationships() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Define hotkeys and coldkeys @@ -3746,7 +3742,7 @@ fn test_do_set_child_as_sn_owner_not_enough_stake() { let proportion: u64 = 1000; - let netuid = add_dynamic_network(&sn_owner_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&sn_owner_hotkey, &coldkey); register_ok_neuron(netuid, child_hotkey, child_coldkey, 0); // Verify stake of sn_owner_hotkey is NOT enough @@ -3791,7 +3787,7 @@ fn test_do_set_child_as_sn_owner_not_enough_stake() { #[test] fn test_dividend_distribution_with_children_same_coldkey_owner() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Set SN owner cut to 0 SubtensorModule::set_subnet_owner_cut(0_u16); @@ -3967,7 +3963,7 @@ fn test_pending_cooldown_one_day() { let hotkey = U256::from(2); let child1 = U256::from(3); let child2 = U256::from(4); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let proportion1: u64 = 1000; let proportion2: u64 = 2000; @@ -3999,7 +3995,7 @@ fn test_do_set_childkey_take_success() { // Setup let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let take = 5000; // Add network and register hotkey @@ -4028,7 +4024,7 @@ fn test_do_set_childkey_take_non_associated_coldkey() { let coldkey = U256::from(1); let hotkey = U256::from(2); let hotkey2 = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let take = 5000; // Add network and register hotkey @@ -4049,7 +4045,7 @@ fn test_do_set_childkey_take_invalid_take_value() { // Setup let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let take = SubtensorModule::get_max_childkey_take() + 1; // Add network and register hotkey @@ -4070,7 +4066,7 @@ fn test_do_set_childkey_take_rate_limit_exceeded() { // Setup let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let initial_take = 3000; let higher_take = 5000; let lower_take = 1000; diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 338b8ad9a2..1345f36b7d 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -48,10 +48,10 @@ fn test_dynamic_function_various_values() { for &tao_in in tao_in_values.iter() { for &alpha_emission in alpha_emission_values.iter() { // Set the price. - SubnetMechanism::::insert(NetUid::from(1), 1); - SubnetTAO::::insert(NetUid::from(1), (price * 1_000_000_000.0) as u64); - SubnetAlphaIn::::insert(NetUid::from(1), 1_000_000_000); - let (tao_in_emission, alpha_in_emission, alpha_out_emission) = SubtensorModule::get_dynamic_tao_emission(1.into(), tao_in, alpha_emission); + SubnetMechanism::::insert(1, 1); + SubnetTAO::::insert(1, (price * 1_000_000_000.0) as u64); + SubnetAlphaIn::::insert(1, 1_000_000_000); + let (tao_in_emission, alpha_in_emission, alpha_out_emission) = SubtensorModule::get_dynamic_tao_emission( 1, tao_in, alpha_emission); assert!(tao_in_emission <= tao_in, "tao_in_emission is greater than tao_in"); assert!(alpha_in_emission <= alpha_emission, "alpha_in_emission is greater than alpha_emission"); assert!(alpha_out_emission <= 2 * alpha_emission, "alpha_out_emission is greater than 2 * alpha_emission"); @@ -86,7 +86,7 @@ fn test_coinbase_basecase() { #[test] fn test_coinbase_tao_issuance_base() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let emission: u64 = 1_234_567; add_network(netuid, 1, 0); assert_eq!(SubnetTAO::::get(netuid), 0); @@ -101,7 +101,7 @@ fn test_coinbase_tao_issuance_base() { #[test] fn test_coinbase_tao_issuance_base_low() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let emission: u64 = 1; add_network(netuid, 1, 0); assert_eq!(SubnetTAO::::get(netuid), 0); @@ -122,9 +122,9 @@ fn test_coinbase_tao_issuance_base_low() { #[test] fn test_coinbase_tao_issuance_multiple() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); - let netuid3 = NetUid::from(3); + let netuid1: u16 = 1; + let netuid2: u16 = 2; + let netuid3: u16 = 3; let emission: u64 = 3_333_333; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -150,8 +150,8 @@ fn test_coinbase_tao_issuance_multiple() { #[test] fn test_coinbase_tao_issuance_different_prices() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let emission: u64 = 100_000_000; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -183,7 +183,7 @@ fn test_coinbase_tao_issuance_different_prices() { #[test] fn test_coinbase_moving_prices() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Set price to 1.0 SubnetTAO::::insert(netuid, 1_000_000); @@ -239,7 +239,7 @@ fn test_coinbase_moving_prices() { #[test] fn test_update_moving_price_initial() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Set current price to 1.0 SubnetTAO::::insert(netuid, 1_000_000); @@ -264,7 +264,7 @@ fn test_update_moving_price_initial() { #[test] fn test_update_moving_price_after_time() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // Set current price to 1.0 SubnetTAO::::insert(netuid, 1_000_000); @@ -293,8 +293,8 @@ fn test_update_moving_price_after_time() { #[test] fn test_coinbase_alpha_issuance_base() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let emission: u64 = 1_000_000; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -322,8 +322,8 @@ fn test_coinbase_alpha_issuance_base() { #[test] fn test_coinbase_alpha_issuance_different() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let emission: u64 = 1_000_000; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -357,8 +357,8 @@ fn test_coinbase_alpha_issuance_different() { #[test] fn test_coinbase_alpha_issuance_with_cap_trigger() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let emission: u64 = 1_000_000; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -398,8 +398,8 @@ fn test_coinbase_alpha_issuance_with_cap_trigger() { #[test] fn test_coinbase_alpha_issuance_with_cap_trigger_and_block_emission() { new_test_ext(1).execute_with(|| { - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1: u16 = 1; + let netuid2: u16 = 2; let emission: u64 = 1_000_000; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -437,7 +437,7 @@ fn test_coinbase_alpha_issuance_with_cap_trigger_and_block_emission() { #[test] fn test_owner_cut_base() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); SubtensorModule::set_tempo(netuid, 10000); // Large number (dont drain) SubtensorModule::set_subnet_owner_cut(0); @@ -453,12 +453,12 @@ fn test_owner_cut_base() { #[test] fn test_pending_swapped() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let emission: u64 = 1_000_000; add_network(netuid, 1, 0); SubtensorModule::run_coinbase(U96F32::from_num(0)); assert_eq!(PendingAlphaSwapped::::get(netuid), 0); // Zero tao weight and no root. - SubnetTAO::::insert(NetUid::ROOT, 1_000_000_000); // Add root weight. + SubnetTAO::::insert(0, 1_000_000_000); // Add root weight. SubtensorModule::run_coinbase(U96F32::from_num(0)); assert_eq!(PendingAlphaSwapped::::get(netuid), 0); // Zero tao weight with 1 root. SubtensorModule::set_tempo(netuid, 10000); // Large number (dont drain) @@ -476,14 +476,14 @@ fn test_pending_swapped() { // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base --exact --show-output --nocapture #[test] fn test_drain_base() { - new_test_ext(1).execute_with(|| SubtensorModule::drain_pending_emission(0.into(), 0, 0, 0, 0)); + new_test_ext(1).execute_with(|| SubtensorModule::drain_pending_emission(0, 0, 0, 0, 0)); } // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_base_with_subnet --exact --show-output --nocapture #[test] fn test_drain_base_with_subnet() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); SubtensorModule::drain_pending_emission(netuid, 0, 0, 0, 0) }); @@ -493,7 +493,7 @@ fn test_drain_base_with_subnet() { #[test] fn test_drain_base_with_subnet_with_single_staker_not_registered() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -516,7 +516,7 @@ fn test_drain_base_with_subnet_with_single_staker_not_registered() { #[test] fn test_drain_base_with_subnet_with_single_staker_registered() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -540,7 +540,8 @@ fn test_drain_base_with_subnet_with_single_staker_registered() { #[test] fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let root: u16 = 0; + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -552,7 +553,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey, &coldkey, - NetUid::ROOT, + root, stake_before, ); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -566,11 +567,8 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { SubtensorModule::drain_pending_emission(netuid, pending_alpha, pending_tao, 0, 0); let stake_after = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid); - let root_after = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey, - &coldkey, - NetUid::ROOT, - ); + let root_after = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, root); close(stake_before + pending_alpha, stake_after, 10); // Registered gets all alpha emission. close(stake_before + pending_tao, root_after, 10); // Registered gets all tao emission }); @@ -580,7 +578,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { #[test] fn test_drain_base_with_subnet_with_two_stakers_registered() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); @@ -615,7 +613,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered() { #[test] fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let root: u16 = 0; + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); @@ -635,7 +634,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey1, &coldkey, - NetUid::ROOT, + root, stake_before, ); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -647,7 +646,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey2, &coldkey, - NetUid::ROOT, + root, stake_before, ); let pending_tao: u64 = 1_000_000_000; @@ -655,18 +654,12 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { SubtensorModule::drain_pending_emission(netuid, pending_alpha, pending_tao, 0, 0); let stake_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, netuid); - let root_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey1, - &coldkey, - NetUid::ROOT, - ); + let root_after1 = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, root); let stake_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, netuid); - let root_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey2, - &coldkey, - NetUid::ROOT, - ); + let root_after2 = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, root); close(stake_before + pending_alpha / 2, stake_after1, 10); // Registered gets 1/2 emission close(stake_before + pending_alpha / 2, stake_after2, 10); // Registered gets 1/2 emission. close(stake_before + pending_tao / 2, root_after1, 10); // Registered gets 1/2 tao emission @@ -678,7 +671,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { #[test] fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let root: u16 = 0; + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); @@ -698,7 +692,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey1, &coldkey, - NetUid::ROOT, + root, 2 * stake_before, // Hotkey 1 has twice as much root weight. ); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -710,7 +704,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey2, &coldkey, - NetUid::ROOT, + root, stake_before, ); let pending_tao: u64 = 1_000_000_000; @@ -718,18 +712,12 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am SubtensorModule::drain_pending_emission(netuid, pending_alpha, pending_tao, 0, 0); let stake_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, netuid); - let root_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey1, - &coldkey, - NetUid::ROOT, - ); + let root_after1 = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, root); let stake_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, netuid); - let root_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey2, - &coldkey, - NetUid::ROOT, - ); + let root_after2 = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, root); let expected_stake = I96F32::from_num(stake_before) + (I96F32::from_num(pending_alpha) * I96F32::from_num(1.0 / 2.0)); assert_abs_diff_eq!(expected_stake.to_num::(), stake_after1, epsilon = 10); // Registered gets 50% of alpha emission @@ -750,7 +738,8 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts_half_tao_weight() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let root: u16 = 0; + let netuid: u16 = 1; add_network(netuid, 1, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); @@ -770,7 +759,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey1, &coldkey, - NetUid::ROOT, + root, 2 * stake_before, // Hotkey 1 has twice as much root weight. ); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -782,7 +771,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey2, &coldkey, - NetUid::ROOT, + root, stake_before, ); let pending_tao: u64 = 1_000_000_000; @@ -790,18 +779,12 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am SubtensorModule::drain_pending_emission(netuid, pending_alpha, pending_tao, 0, 0); let stake_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, netuid); - let root_after1 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey1, - &coldkey, - NetUid::ROOT, - ); + let root_after1 = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey1, &coldkey, root); let stake_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, netuid); - let root_after2 = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey2, - &coldkey, - NetUid::ROOT, - ); + let root_after2 = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey2, &coldkey, root); let expected_stake = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(1.0 / 2.0); assert_abs_diff_eq!(expected_stake.to_num::(), stake_after1, epsilon = 10); @@ -823,7 +806,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am #[test] fn test_drain_alpha_childkey_parentkey() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); let parent = U256::from(1); let child = U256::from(2); @@ -865,8 +848,9 @@ fn test_drain_alpha_childkey_parentkey() { fn test_get_root_children() { new_test_ext(1).execute_with(|| { // Init netuid 1 - let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); + let root: u16 = 0; + let alpha: u16 = 1; + add_network(root, 1, 0); add_network(alpha, 1, 0); // Set TAO weight to 1. @@ -894,14 +878,14 @@ fn test_get_root_children() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &alice, &cold, - NetUid::ROOT, + root, alice_root_stake, ); let bob_root_stake: u64 = 1_000_000_000; SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &bob, &cold, - NetUid::ROOT, + root, alice_root_stake, ); @@ -922,16 +906,16 @@ fn test_get_root_children() { ); // Set Bob as 100% child of Alice on root. - // mock_set_children_no_epochs( NetUid::ROOT, &alice, &[(u64::MAX, bob)]); + // mock_set_children_no_epochs( root, &alice, &[(u64::MAX, bob)]); mock_set_children_no_epochs(alpha, &alice, &[(u64::MAX, bob)]); // Assert Alice and Bob stake on root and netuid assert_eq!( - SubtensorModule::get_stake_for_hotkey_on_subnet(&alice, NetUid::ROOT), + SubtensorModule::get_stake_for_hotkey_on_subnet(&alice, root), alice_root_stake ); assert_eq!( - SubtensorModule::get_stake_for_hotkey_on_subnet(&bob, NetUid::ROOT), + SubtensorModule::get_stake_for_hotkey_on_subnet(&bob, root), bob_root_stake ); assert_eq!( @@ -945,7 +929,7 @@ fn test_get_root_children() { // Assert Alice and Bob inherited stakes assert_eq!( - SubtensorModule::get_inherited_for_hotkey_on_subnet(&alice, NetUid::ROOT), + SubtensorModule::get_inherited_for_hotkey_on_subnet(&alice, root), alice_root_stake ); assert_eq!( @@ -953,7 +937,7 @@ fn test_get_root_children() { 0 ); assert_eq!( - SubtensorModule::get_inherited_for_hotkey_on_subnet(&bob, NetUid::ROOT), + SubtensorModule::get_inherited_for_hotkey_on_subnet(&bob, root), bob_root_stake ); assert_eq!( @@ -988,8 +972,9 @@ fn test_get_root_children() { fn test_get_root_children_drain() { new_test_ext(1).execute_with(|| { // Init netuid 1 - let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); + let root: u16 = 0; + let alpha: u16 = 1; + add_network(root, 1, 0); add_network(alpha, 1, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1014,14 +999,14 @@ fn test_get_root_children_drain() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &alice, &cold_alice, - NetUid::ROOT, + root, alice_root_stake, ); let bob_root_stake: u64 = 1_000_000_000; SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &bob, &cold_bob, - NetUid::ROOT, + root, alice_root_stake, ); // Add stake for Alice and Bob on netuid. @@ -1077,11 +1062,11 @@ fn test_get_root_children_drain() { // Alice and Bob both made half of the dividends. assert_eq!( - SubtensorModule::get_stake_for_hotkey_on_subnet(&alice, NetUid::ROOT), + SubtensorModule::get_stake_for_hotkey_on_subnet(&alice, root), alice_root_stake + pending_root / 2 ); assert_eq!( - SubtensorModule::get_stake_for_hotkey_on_subnet(&bob, NetUid::ROOT), + SubtensorModule::get_stake_for_hotkey_on_subnet(&bob, root), bob_root_stake + pending_root / 2 ); @@ -1111,8 +1096,9 @@ fn test_get_root_children_drain() { fn test_get_root_children_drain_half_proportion() { new_test_ext(1).execute_with(|| { // Init netuid 1 - let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); + let root: u16 = 0; + let alpha: u16 = 1; + add_network(root, 1, 0); add_network(alpha, 1, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1137,14 +1123,14 @@ fn test_get_root_children_drain_half_proportion() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &alice, &cold_alice, - NetUid::ROOT, + root, alice_root_stake, ); let bob_root_stake: u64 = 1_000_000_000; SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &bob, &cold_bob, - NetUid::ROOT, + root, alice_root_stake, ); // Add stake for Alice and Bob on netuid. @@ -1193,8 +1179,9 @@ fn test_get_root_children_drain_half_proportion() { fn test_get_root_children_drain_with_take() { new_test_ext(1).execute_with(|| { // Init netuid 1 - let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); + let root: u16 = 0; + let alpha: u16 = 1; + add_network(root, 1, 0); add_network(alpha, 1, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1219,14 +1206,14 @@ fn test_get_root_children_drain_with_take() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &alice, &cold_alice, - NetUid::ROOT, + root, alice_root_stake, ); let bob_root_stake: u64 = 1_000_000_000; SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &bob, &cold_bob, - NetUid::ROOT, + root, alice_root_stake, ); // Add stake for Alice and Bob on netuid. @@ -1270,8 +1257,9 @@ fn test_get_root_children_drain_with_take() { fn test_get_root_children_drain_with_half_take() { new_test_ext(1).execute_with(|| { // Init netuid 1 - let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); + let root: u16 = 0; + let alpha: u16 = 1; + add_network(root, 1, 0); add_network(alpha, 1, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1296,14 +1284,14 @@ fn test_get_root_children_drain_with_half_take() { SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &alice, &cold_alice, - NetUid::ROOT, + root, alice_root_stake, ); let bob_root_stake: u64 = 1_000_000_000; SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &bob, &cold_bob, - NetUid::ROOT, + root, alice_root_stake, ); // Add stake for Alice and Bob on netuid. @@ -1351,8 +1339,9 @@ fn test_get_root_children_drain_with_half_take() { // fn test_get_root_children_with_weights() { // new_test_ext(1).execute_with(|| { // // Init netuid 1 -// let alpha = NetUid::from(1); -// add_network(NetUid::ROOT, 1, 0); +// let root: u16 = 0; +// let alpha: u16 = 1; +// add_network(root, 1, 0); // add_network(alpha, 1, 0); // // Set TAO weight to 1. // SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1376,14 +1365,14 @@ fn test_get_root_children_drain_with_half_take() { // SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( // &alice, // &cold, -// NetUid::ROOT, +// root, // alice_root_stake, // ); // let bob_root_stake: u64 = 1_000_000_000; // SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( // &bob, // &cold, -// NetUid::ROOT, +// root, // alice_root_stake, // ); // // Add stake for Alice and Bob on netuid. @@ -1966,7 +1955,7 @@ fn test_drain_pending_emission_zero_emission() { #[test] fn test_run_coinbase_not_started() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let tempo = 2; let sn_owner_hk = U256::from(7); @@ -2048,7 +2037,7 @@ fn test_run_coinbase_not_started() { #[test] fn test_run_coinbase_not_started_start_after() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let tempo = 2; let sn_owner_hk = U256::from(7); diff --git a/pallets/subtensor/src/tests/consensus.rs b/pallets/subtensor/src/tests/consensus.rs index b11cd44e06..e1db49203e 100644 --- a/pallets/subtensor/src/tests/consensus.rs +++ b/pallets/subtensor/src/tests/consensus.rs @@ -118,7 +118,7 @@ fn distribute_nodes( } #[allow(dead_code)] -fn uid_stats(netuid: NetUid, uid: u16) { +fn uid_stats(netuid: u16, uid: u16) { log::info!( "stake: {:?}", SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))) @@ -148,7 +148,7 @@ fn uid_stats(netuid: NetUid, uid: u16) { #[allow(clippy::too_many_arguments)] fn init_run_epochs( - netuid: NetUid, + netuid: u16, n: u16, validators: &[u16], servers: &[u16], @@ -401,7 +401,7 @@ fn split_graph( // Test consensus guarantees with an epoch on a graph with 4096 nodes, of which the first 128 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other. Asserts that the major emission ratio >= major stake ratio. // #[test] // fn test_consensus_guarantees() { -// let netuid = NetUid::from(0); +// let netuid: u16 = 0; // let network_n: u16 = 512; // let validators_n: u16 = 64; // let epochs: u16 = 1; @@ -486,7 +486,7 @@ fn split_graph( #[test] #[ignore] // Not an automated test! fn map_consensus_guarantees() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let network_n: u16 = 512; let validators_n: u16 = 64; let epochs: u16 = 1; diff --git a/pallets/subtensor/src/tests/delegate_info.rs b/pallets/subtensor/src/tests/delegate_info.rs index 8168755439..fa9aa942f7 100644 --- a/pallets/subtensor/src/tests/delegate_info.rs +++ b/pallets/subtensor/src/tests/delegate_info.rs @@ -5,7 +5,6 @@ use frame_support::assert_ok; use scale_info::prelude::collections::HashMap; use sp_core::U256; use substrate_fixed::types::U64F64; -use subtensor_runtime_common::NetUid; #[test] fn test_return_per_1000_tao() { @@ -111,7 +110,7 @@ fn test_get_delegated() { delegatee_4, ]; let to_stakes = [to_stake_0, to_stake_1, to_stake_2, to_stake_3, to_stake_4]; - let mut expected_stake_map: HashMap>> = + let mut expected_stake_map: HashMap>> = HashMap::new(); for (i, to_stake) in to_stakes.iter().enumerate() { @@ -148,10 +147,15 @@ fn test_get_delegated() { if let Some(expected_under_delegate) = coldkey_stakes_map.get(&delegate_info.delegate_ss58) { - if let Some(expected_stake) = expected_under_delegate.get(&netuid.0) { + if let Some(expected_stake) = + expected_under_delegate.get(&u16::from(*netuid)) + { assert_eq!(u64::from(*staked), *expected_stake); } else { - panic!("Netuid {} not found in expected stake map", netuid.0); + panic!( + "Netuid {} not found in expected stake map", + u16::from(*netuid) + ); }; } else { panic!( diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 78ac8620c9..d6c151b64f 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -1,7 +1,6 @@ #![allow(clippy::unwrap_used)] use sp_core::U256; -use subtensor_runtime_common::NetUid; use super::mock::*; @@ -10,7 +9,7 @@ use super::mock::*; fn test_registration_difficulty_adjustment() { new_test_ext(1).execute_with(|| { // Create Net 1 - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; let modality: u16 = 1; add_network(netuid, tempo, modality); diff --git a/pallets/subtensor/src/tests/emission.rs b/pallets/subtensor/src/tests/emission.rs index ecd2df544b..c4d8d51e3c 100644 --- a/pallets/subtensor/src/tests/emission.rs +++ b/pallets/subtensor/src/tests/emission.rs @@ -1,5 +1,3 @@ -use subtensor_runtime_common::NetUid; - use super::mock::*; // 1. Test Zero Tempo @@ -9,7 +7,7 @@ use super::mock::*; fn test_zero_tempo() { new_test_ext(1).execute_with(|| { assert_eq!( - SubtensorModule::blocks_until_next_epoch(1.into(), 0, 100), + SubtensorModule::blocks_until_next_epoch(1, 0, 100), u64::MAX ); }); @@ -21,15 +19,9 @@ fn test_zero_tempo() { #[test] fn test_regular_case() { new_test_ext(1).execute_with(|| { - assert_eq!(SubtensorModule::blocks_until_next_epoch(1.into(), 10, 5), 3); - assert_eq!( - SubtensorModule::blocks_until_next_epoch(2.into(), 20, 15), - 2 - ); - assert_eq!( - SubtensorModule::blocks_until_next_epoch(3.into(), 30, 25), - 1 - ); + assert_eq!(SubtensorModule::blocks_until_next_epoch(1, 10, 5), 3); + assert_eq!(SubtensorModule::blocks_until_next_epoch(2, 20, 15), 2); + assert_eq!(SubtensorModule::blocks_until_next_epoch(3, 30, 25), 1); }); } @@ -40,11 +32,11 @@ fn test_regular_case() { fn test_boundary_conditions() { new_test_ext(1).execute_with(|| { assert_eq!( - SubtensorModule::blocks_until_next_epoch(u16::MAX.into(), u16::MAX, u64::MAX), + SubtensorModule::blocks_until_next_epoch(u16::MAX, u16::MAX, u64::MAX), 0 ); assert_eq!( - SubtensorModule::blocks_until_next_epoch(u16::MAX.into(), u16::MAX, 0), + SubtensorModule::blocks_until_next_epoch(u16::MAX, u16::MAX, 0), u16::MAX as u64 ); }); @@ -57,7 +49,7 @@ fn test_boundary_conditions() { fn test_overflow_handling() { new_test_ext(1).execute_with(|| { assert_eq!( - SubtensorModule::blocks_until_next_epoch(u16::MAX.into(), u16::MAX, u64::MAX - 1), + SubtensorModule::blocks_until_next_epoch(u16::MAX, u16::MAX, u64::MAX - 1), 1 ); }); @@ -69,14 +61,8 @@ fn test_overflow_handling() { #[test] fn test_epoch_alignment() { new_test_ext(1).execute_with(|| { - assert_eq!( - SubtensorModule::blocks_until_next_epoch(1.into(), 10, 9), - 10 - ); - assert_eq!( - SubtensorModule::blocks_until_next_epoch(2.into(), 20, 21), - 17 - ); + assert_eq!(SubtensorModule::blocks_until_next_epoch(1, 10, 9), 10); + assert_eq!(SubtensorModule::blocks_until_next_epoch(2, 20, 21), 17); }); } @@ -86,9 +72,9 @@ fn test_epoch_alignment() { #[test] fn test_different_network_ids() { new_test_ext(1).execute_with(|| { - assert_eq!(SubtensorModule::blocks_until_next_epoch(1.into(), 10, 5), 3); - assert_eq!(SubtensorModule::blocks_until_next_epoch(2.into(), 10, 5), 2); - assert_eq!(SubtensorModule::blocks_until_next_epoch(3.into(), 10, 5), 1); + assert_eq!(SubtensorModule::blocks_until_next_epoch(1, 10, 5), 3); + assert_eq!(SubtensorModule::blocks_until_next_epoch(2, 10, 5), 2); + assert_eq!(SubtensorModule::blocks_until_next_epoch(3, 10, 5), 1); }); } @@ -99,7 +85,7 @@ fn test_different_network_ids() { fn test_large_tempo_values() { new_test_ext(1).execute_with(|| { assert_eq!( - SubtensorModule::blocks_until_next_epoch(1.into(), u16::MAX - 1, 100), + SubtensorModule::blocks_until_next_epoch(1, u16::MAX - 1, 100), u16::MAX as u64 - 103 ); }); @@ -112,7 +98,7 @@ fn test_large_tempo_values() { fn test_consecutive_blocks() { new_test_ext(1).execute_with(|| { let tempo = 10; - let netuid = NetUid::from(1); + let netuid = 1; let mut last_result = SubtensorModule::blocks_until_next_epoch(netuid, tempo, 0); for i in 1..tempo - 1 { let current_result = SubtensorModule::blocks_until_next_epoch(netuid, tempo, i as u64); @@ -128,12 +114,9 @@ fn test_consecutive_blocks() { #[test] fn test_wrap_around_behavior() { new_test_ext(1).execute_with(|| { + assert_eq!(SubtensorModule::blocks_until_next_epoch(1, 10, u64::MAX), 9); assert_eq!( - SubtensorModule::blocks_until_next_epoch(1.into(), 10, u64::MAX), - 9 - ); - assert_eq!( - SubtensorModule::blocks_until_next_epoch(1.into(), 10, u64::MAX - 1), + SubtensorModule::blocks_until_next_epoch(1, 10, u64::MAX - 1), 10 ); }); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 0e567796d7..2557709912 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -111,7 +111,7 @@ fn distribute_nodes( } #[allow(dead_code)] -fn uid_stats(netuid: NetUid, uid: u16) { +fn uid_stats(netuid: u16, uid: u16) { log::info!( "stake: {:?}", SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))) @@ -141,7 +141,7 @@ fn uid_stats(netuid: NetUid, uid: u16) { #[allow(clippy::too_many_arguments)] fn init_run_epochs( - netuid: NetUid, + netuid: u16, n: u16, validators: &[u16], servers: &[u16], @@ -402,7 +402,7 @@ fn init_run_epochs( // Test consensus guarantees with an epoch on a graph with 4096 nodes, of which the first 128 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other. Asserts that the major emission ratio >= major stake ratio. // #[test] // fn test_consensus_guarantees() { -// let netuid = NetUid::from(0); +// let netuid: u16 = 0; // let network_n: u16 = 512; // let validators_n: u16 = 64; // let epochs: u16 = 1; @@ -493,7 +493,7 @@ fn init_run_epochs( // fn test_overflow() { // new_test_ext(1).execute_with(|| { // log::info!("test_overflow:"); -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // add_network(netuid, 1, 0); // SubtensorModule::set_max_allowed_uids(netuid, 3); // SubtensorModule::increase_stake_on_coldkey_hotkey_account( @@ -557,7 +557,7 @@ fn init_run_epochs( fn test_1_graph() { new_test_ext(1).execute_with(|| { log::info!("test_1_graph:"); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey = U256::from(0); let hotkey = U256::from(0); let uid: u16 = 0; @@ -603,7 +603,7 @@ fn test_10_graph() { new_test_ext(1).execute_with(|| { log::info!("test_10_graph"); // Function for adding a nodes to the graph. - pub fn add_node(netuid: NetUid, coldkey: U256, hotkey: U256, uid: u16, stake_amount: u64) { + pub fn add_node(netuid: u16, coldkey: U256, hotkey: U256, uid: u16, stake_amount: u64) { log::info!( "+Add net:{:?} coldkey:{:?} hotkey:{:?} uid:{:?} stake_amount: {:?} subn: {:?}", netuid, @@ -625,7 +625,7 @@ fn test_10_graph() { // Build the graph with 10 items // each with 1 stake and self weights. let n: usize = 10; - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, u16::MAX - 1, 0); // set higher tempo to avoid built-in epoch, then manual epoch instead SubtensorModule::set_max_allowed_uids(netuid, n as u16); for i in 0..10 { @@ -667,7 +667,7 @@ fn test_10_graph() { // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::epoch::test_512_graph --exact --show-output --nocapture #[test] fn test_512_graph() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let network_n: u16 = 512; let validators_n: u16 = 64; let max_stake_per_validator: u64 = 328_125_000_000_000; // 21_000_000_000_000_000 / 64 @@ -740,7 +740,7 @@ fn test_512_graph() { // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::epoch::test_512_graph_random_weights --exact --show-output --nocapture #[test] fn test_512_graph_random_weights() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let network_n: u16 = 512; let validators_n: u16 = 64; let epochs: u16 = 1; @@ -846,7 +846,7 @@ fn test_512_graph_random_weights() { // Test an epoch on a graph with 4096 nodes, of which the first 256 are validators setting non-self weights, and the rest servers setting only self-weights. // #[test] // fn test_4096_graph() { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let network_n: u16 = 4096; // let validators_n: u16 = 256; // let epochs: u16 = 1; @@ -923,7 +923,7 @@ fn test_512_graph_random_weights() { // #[test] // fn test_16384_graph_sparse() { // new_test_ext(1).execute_with(|| { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let n: u16 = 16384; // let validators_n: u16 = 512; // let validators: Vec = (0..validators_n).collect(); @@ -989,7 +989,7 @@ fn test_bonds() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 8; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; let max_stake: u64 = 4; let stakes: Vec = vec![1, 2, 3, 4, 0, 0, 0, 0]; @@ -1333,7 +1333,7 @@ fn test_active_stake() { System::set_block_number(0); let sparse: bool = true; let n: u16 = 4; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 1; let block_number: u64 = System::block_number(); let stake: u64 = 1; @@ -1540,7 +1540,7 @@ fn test_outdated_weights() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 4; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 0; let mut block_number: u64 = System::block_number(); let stake: u64 = 1; @@ -1727,7 +1727,7 @@ fn test_zero_weights() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 2; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead let mut block_number: u64 = 0; let stake: u64 = 1; @@ -1921,7 +1921,7 @@ fn test_deregistered_miner_bonds() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 4; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let high_tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead let stake: u64 = 1; @@ -2098,7 +2098,7 @@ fn test_deregistered_miner_bonds() { // Test that epoch assigns validator permits to highest stake uids that are over the stake threshold, varies uid interleaving and stake values. #[test] fn test_validator_permits() { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = u16::MAX - 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead for interleave in 0..3 { for (network_n, validators_n) in [(2, 1), (4, 2), (8, 4)] { @@ -2226,7 +2226,7 @@ fn test_validator_permits() { #[test] fn test_get_set_alpha() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let alpha_low: u16 = 12_u16; let alpha_high: u16 = u16::MAX - 10; @@ -2377,7 +2377,7 @@ fn test_blocks_since_last_step() { new_test_ext(1).execute_with(|| { System::set_block_number(0); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 7200; add_network(netuid, tempo, 0); @@ -2478,7 +2478,7 @@ fn test_can_set_self_weight_as_subnet_owner() { #[test] fn test_epoch_outputs_single_staker_registered_no_weights() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let high_tempo: u16 = u16::MAX - 1; // Don't run automatically. add_network(netuid, high_tempo, 0); @@ -2553,7 +2553,7 @@ fn test_epoch_outputs_single_staker_registered_no_weights() { // ``` // #[test] // fn _map_consensus_guarantees() { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let network_n: u16 = 512; // let validators_n: u16 = 64; // let epochs: u16 = 1; @@ -2630,7 +2630,7 @@ pub fn assert_approx_eq(left: I32F32, right: I32F32, epsilon: I32F32) { } // test Yuma 3 scenarios over a sequence of epochs. -fn setup_yuma_3_scenario(netuid: NetUid, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { +fn setup_yuma_3_scenario(netuid: u16, n: u16, sparse: bool, max_stake: u64, stakes: Vec) { let block_number = System::block_number(); let tempo: u16 = 1; // high tempo to skip automatic epochs in on_initialize, use manual epochs instead add_network(netuid, tempo, 0); @@ -2690,7 +2690,7 @@ fn setup_yuma_3_scenario(netuid: NetUid, n: u16, sparse: bool, max_stake: u64, s run_epoch(netuid, sparse); } -fn run_epoch(netuid: NetUid, sparse: bool) { +fn run_epoch(netuid: u16, sparse: bool) { next_block_no_epoch(netuid); if sparse { SubtensorModule::epoch(netuid, 1_000_000_000); @@ -2700,7 +2700,7 @@ fn run_epoch(netuid: NetUid, sparse: bool) { } fn run_epoch_and_check_bonds_dividends( - netuid: NetUid, + netuid: u16, sparse: bool, target_bonds: &[Vec], target_dividends: &[f32], @@ -2727,7 +2727,7 @@ fn run_epoch_and_check_bonds_dividends( } } -fn set_yuma_3_weights(netuid: NetUid, weights: Vec>, indices: Vec) { +fn set_yuma_3_weights(netuid: u16, weights: Vec>, indices: Vec) { for (uid, weight) in weights.iter().enumerate() { assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(uid as u64)), @@ -2744,7 +2744,7 @@ fn test_yuma_3_kappa_moves_first() { for sparse in [true, false].iter() { new_test_ext(1).execute_with(|| { let n: u16 = 5; // 3 validators, 2 servers - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_stake: u64 = 8; // Validator A: kappa / Big validator (0.8) - moves first @@ -2847,7 +2847,7 @@ fn test_yuma_3_kappa_moves_second() { for sparse in [true, false].iter() { new_test_ext(1).execute_with(|| { let n: u16 = 5; // 3 validators, 2 servers - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_stake: u64 = 8; // Validator A: kappa / Big validator (0.8) - moves second @@ -2949,7 +2949,7 @@ fn test_yuma_3_kappa_moves_last() { for sparse in [true, false].iter() { new_test_ext(1).execute_with(|| { let n: u16 = 5; // 3 validators, 2 servers - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_stake: u64 = 8; // Validator A: kappa / Big validator (0.8) - moves last @@ -3051,7 +3051,7 @@ fn test_yuma_3_one_epoch_switch() { for sparse in [true, false].iter() { new_test_ext(1).execute_with(|| { let n: u16 = 5; // 3 validators, 2 servers - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_stake: u64 = 8; // Equal stake validators @@ -3136,7 +3136,7 @@ fn test_yuma_3_one_epoch_switch() { fn test_yuma_3_liquid_alpha_disabled() { for sparse in [true, false].iter() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let n: u16 = 5; // 3 validators, 2 servers let max_stake: u64 = 8; @@ -3225,7 +3225,7 @@ fn test_yuma_3_liquid_alpha_disabled() { fn test_yuma_3_stable_miner() { for sparse in [true, false].iter() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let n: u16 = 6; // 3 validators, 3 servers let max_stake: u64 = 8; @@ -3340,7 +3340,7 @@ fn test_yuma_3_bonds_reset() { new_test_ext(1).execute_with(|| { let sparse: bool = true; let n: u16 = 5; // 3 validators, 2 servers - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_stake: u64 = 8; // "Case 8 - big vali moves late, then late" diff --git a/pallets/subtensor/src/tests/evm.rs b/pallets/subtensor/src/tests/evm.rs index 95d0c4e6db..fd0ea51061 100644 --- a/pallets/subtensor/src/tests/evm.rs +++ b/pallets/subtensor/src/tests/evm.rs @@ -32,7 +32,7 @@ fn sign_evm_message>(pair: &ecdsa::Pair, message: M) -> ecdsa::Si #[test] fn test_associate_evm_key_success() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; @@ -81,7 +81,7 @@ fn test_associate_evm_key_success() { #[test] fn test_associate_evm_key_different_block_number_success() { new_test_ext(100).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; @@ -128,7 +128,7 @@ fn test_associate_evm_key_different_block_number_success() { #[test] fn test_associate_evm_key_coldkey_does_not_own_hotkey() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; @@ -165,7 +165,7 @@ fn test_associate_evm_key_coldkey_does_not_own_hotkey() { #[test] fn test_associate_evm_key_hotkey_not_registered_in_subnet() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; @@ -203,7 +203,7 @@ fn test_associate_evm_key_hotkey_not_registered_in_subnet() { #[test] fn test_associate_evm_key_using_wrong_hash_function() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index adb4601724..1dfac06ad5 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -37,8 +37,8 @@ fn test_initialise_ti() { new_test_ext(1).execute_with(|| { pallet_balances::TotalIssuance::::put(1000); - crate::SubnetTAO::::insert(NetUid::from(1), 100); - crate::SubnetTAO::::insert(NetUid::from(2), 5); + crate::SubnetTAO::::insert(1, 100); + crate::SubnetTAO::::insert(2, 5); // Ensure values are NOT initialized prior to running migration assert!(crate::TotalIssuance::::get() == 0); @@ -59,11 +59,11 @@ fn test_initialise_ti() { fn test_migration_transfer_nets_to_foundation() { new_test_ext(1).execute_with(|| { // Create subnet 1 - add_network(1.into(), 1, 0); + add_network(1, 1, 0); // Create subnet 11 - add_network(11.into(), 1, 0); + add_network(11, 1, 0); - log::info!("{:?}", SubtensorModule::get_subnet_owner(1.into())); + log::info!("{:?}", SubtensorModule::get_subnet_owner(1)); //assert_eq!(SubtensorModule::::get_subnet_owner(1), ); // Run the migration to transfer ownership @@ -71,7 +71,7 @@ fn test_migration_transfer_nets_to_foundation() { hex_literal::hex!["feabaafee293d3b76dae304e2f9d885f77d2b17adab9e17e921b321eccd61c77"]; crate::migrations::migrate_transfer_ownership_to_foundation::migrate_transfer_ownership_to_foundation::(hex); - log::info!("new owner: {:?}", SubtensorModule::get_subnet_owner(1.into())); + log::info!("new owner: {:?}", SubtensorModule::get_subnet_owner(1)); }) } @@ -79,13 +79,13 @@ fn test_migration_transfer_nets_to_foundation() { fn test_migration_delete_subnet_3() { new_test_ext(1).execute_with(|| { // Create subnet 3 - add_network(3.into(), 1, 0); - assert!(SubtensorModule::if_subnet_exist(3.into())); + add_network(3, 1, 0); + assert!(SubtensorModule::if_subnet_exist(3)); // Run the migration to transfer ownership crate::migrations::migrate_delete_subnet_3::migrate_delete_subnet_3::(); - assert!(!SubtensorModule::if_subnet_exist(3.into())); + assert!(!SubtensorModule::if_subnet_exist(3)); }) } @@ -93,13 +93,13 @@ fn test_migration_delete_subnet_3() { fn test_migration_delete_subnet_21() { new_test_ext(1).execute_with(|| { // Create subnet 21 - add_network(21.into(), 1, 0); - assert!(SubtensorModule::if_subnet_exist(21.into())); + add_network(21, 1, 0); + assert!(SubtensorModule::if_subnet_exist(21)); // Run the migration to transfer ownership crate::migrations::migrate_delete_subnet_21::migrate_delete_subnet_21::(); - assert!(!SubtensorModule::if_subnet_exist(21.into())); + assert!(!SubtensorModule::if_subnet_exist(21)); }) } @@ -115,7 +115,7 @@ fn test_migrate_commit_reveal_2() { let storage_prefix_interval = twox_128("WeightCommitRevealInterval".as_bytes()); let storage_prefix_commits = twox_128("WeightCommits".as_bytes()); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let interval_value: u64 = 50u64; // Construct the full key for WeightCommitRevealInterval @@ -385,7 +385,7 @@ fn test_migrate_commit_reveal_2() { fn test_migrate_subnet_volume() { new_test_ext(1).execute_with(|| { // Setup initial state - let netuid_1 = NetUid::from(1); + let netuid_1: u16 = 1; add_network(netuid_1, 1, 0); // SubnetValue for netuid 1 key @@ -422,7 +422,7 @@ fn test_migrate_subnet_volume() { #[test] fn test_migrate_set_first_emission_block_number() { new_test_ext(1).execute_with(|| { - let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; + let netuids: [u16; 3] = [1, 2, 3]; let block_number = 100; for netuid in netuids.iter() { add_network(*netuid, 1, 0); @@ -433,7 +433,7 @@ fn test_migrate_set_first_emission_block_number() { let expected_weight: Weight = ::DbWeight::get().reads(3) + ::DbWeight::get().writes(netuids.len() as u64); assert_eq!(weight, expected_weight); - assert_eq!(FirstEmissionBlockNumber::::get(NetUid::ROOT), None); + assert_eq!(FirstEmissionBlockNumber::::get(0), None); for netuid in netuids.iter() { assert_eq!(FirstEmissionBlockNumber::::get(netuid), Some(block_number)); } @@ -443,13 +443,13 @@ fn test_migrate_set_first_emission_block_number() { #[test] fn test_migrate_set_subtoken_enable() { new_test_ext(1).execute_with(|| { - let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; + let netuids: [u16; 3] = [1, 2, 3]; let block_number = 100; for netuid in netuids.iter() { add_network(*netuid, 1, 0); } - let new_netuid = NetUid::from(4); + let new_netuid = 4; add_network_without_emission_block(new_netuid, 1, 0); let weight = @@ -470,7 +470,7 @@ fn test_migrate_set_subtoken_enable() { fn test_migrate_remove_zero_total_hotkey_alpha() { new_test_ext(1).execute_with(|| { const MIGRATION_NAME: &str = "migrate_remove_zero_total_hotkey_alpha"; - let netuid = NetUid::from(1u16); + let netuid = 1u16; let hotkey_zero = U256::from(100u64); let hotkey_nonzero = U256::from(101u64); @@ -524,7 +524,7 @@ fn test_migrate_revealed_commitments() { // Example keys for the DoubleMap: // Key1 (netuid) uses Identity (no hash) // Key2 (account) uses Twox64Concat - let netuid = NetUid::from(123); + let netuid: u16 = 123; let account_id: u64 = 999; // Or however your test `AccountId` is represented // Construct the full storage key for `RevealedCommitments(netuid, account_id)` diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 53972ef391..dd2ad1d7c9 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -19,7 +19,6 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; use sp_std::cmp::Ordering; -use subtensor_runtime_common::NetUid; use crate::*; @@ -638,7 +637,7 @@ pub(crate) fn run_to_block_ext(n: u64, enable_events: bool) { } #[allow(dead_code)] -pub(crate) fn next_block_no_epoch(netuid: NetUid) -> u64 { +pub(crate) fn next_block_no_epoch(netuid: u16) -> u64 { // high tempo to skip automatic epochs in on_initialize let high_tempo: u16 = u16::MAX - 1; let old_tempo: u16 = SubtensorModule::get_tempo(netuid); @@ -651,7 +650,7 @@ pub(crate) fn next_block_no_epoch(netuid: NetUid) -> u64 { } #[allow(dead_code)] -pub(crate) fn run_to_block_no_epoch(netuid: NetUid, n: u64) { +pub(crate) fn run_to_block_no_epoch(netuid: u16, n: u64) { // high tempo to skip automatic epochs in on_initialize let high_tempo: u16 = u16::MAX - 1; let old_tempo: u16 = SubtensorModule::get_tempo(netuid); @@ -662,7 +661,7 @@ pub(crate) fn run_to_block_no_epoch(netuid: NetUid, n: u64) { } #[allow(dead_code)] -pub(crate) fn step_epochs(count: u16, netuid: NetUid) { +pub(crate) fn step_epochs(count: u16, netuid: u16) { for _ in 0..count { let blocks_to_next_epoch = SubtensorModule::blocks_until_next_epoch( netuid, @@ -696,7 +695,7 @@ pub(crate) fn next_block() -> u64 { #[allow(dead_code)] pub fn register_ok_neuron( - netuid: NetUid, + netuid: u16, hotkey_account_id: U256, coldkey_account_id: U256, start_nonce: u64, @@ -727,7 +726,7 @@ pub fn register_ok_neuron( } #[allow(dead_code)] -pub fn add_network(netuid: NetUid, tempo: u16, _modality: u16) { +pub fn add_network(netuid: u16, tempo: u16, _modality: u16) { SubtensorModule::init_new_network(netuid, tempo); SubtensorModule::set_network_registration_allowed(netuid, true); SubtensorModule::set_network_pow_registration_allowed(netuid, true); @@ -736,14 +735,14 @@ pub fn add_network(netuid: NetUid, tempo: u16, _modality: u16) { } #[allow(dead_code)] -pub fn add_network_without_emission_block(netuid: NetUid, tempo: u16, _modality: u16) { +pub fn add_network_without_emission_block(netuid: u16, tempo: u16, _modality: u16) { SubtensorModule::init_new_network(netuid, tempo); SubtensorModule::set_network_registration_allowed(netuid, true); SubtensorModule::set_network_pow_registration_allowed(netuid, true); } #[allow(dead_code)] -pub fn add_network_disable_subtoken(netuid: NetUid, tempo: u16, _modality: u16) { +pub fn add_network_disable_subtoken(netuid: u16, tempo: u16, _modality: u16) { SubtensorModule::init_new_network(netuid, tempo); SubtensorModule::set_network_registration_allowed(netuid, true); SubtensorModule::set_network_pow_registration_allowed(netuid, true); @@ -751,7 +750,7 @@ pub fn add_network_disable_subtoken(netuid: NetUid, tempo: u16, _modality: u16) } #[allow(dead_code)] -pub fn add_dynamic_network(hotkey: &U256, coldkey: &U256) -> NetUid { +pub fn add_dynamic_network(hotkey: &U256, coldkey: &U256) -> u16 { let netuid = SubtensorModule::get_next_netuid(); let lock_cost = SubtensorModule::get_network_lock_cost(); SubtensorModule::add_balance_to_coldkey_account(coldkey, lock_cost); @@ -768,7 +767,7 @@ pub fn add_dynamic_network(hotkey: &U256, coldkey: &U256) -> NetUid { } #[allow(dead_code)] -pub fn add_dynamic_network_without_emission_block(hotkey: &U256, coldkey: &U256) -> NetUid { +pub fn add_dynamic_network_without_emission_block(hotkey: &U256, coldkey: &U256) -> u16 { let netuid = SubtensorModule::get_next_netuid(); let lock_cost = SubtensorModule::get_network_lock_cost(); SubtensorModule::add_balance_to_coldkey_account(coldkey, lock_cost); @@ -784,20 +783,20 @@ pub fn add_dynamic_network_without_emission_block(hotkey: &U256, coldkey: &U256) // Helper function to set up a neuron with stake #[allow(dead_code)] -pub fn setup_neuron_with_stake(netuid: NetUid, hotkey: U256, coldkey: U256, stake: u64) { +pub fn setup_neuron_with_stake(netuid: u16, hotkey: U256, coldkey: U256, stake: u64) { register_ok_neuron(netuid, hotkey, coldkey, stake); increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, stake, netuid); } #[allow(dead_code)] -pub fn wait_set_pending_children_cooldown(netuid: NetUid) { +pub fn wait_set_pending_children_cooldown(netuid: u16) { let cooldown = DefaultPendingCooldown::::get(); step_block(cooldown as u16); // Wait for cooldown to pass step_epochs(1, netuid); // Run next epoch } #[allow(dead_code)] -pub fn wait_and_set_pending_children(netuid: NetUid) { +pub fn wait_and_set_pending_children(netuid: u16) { let original_block = System::block_number(); wait_set_pending_children_cooldown(netuid); SubtensorModule::do_set_pending_children(netuid); @@ -808,7 +807,7 @@ pub fn wait_and_set_pending_children(netuid: NetUid) { pub fn mock_schedule_children( coldkey: &U256, parent: &U256, - netuid: NetUid, + netuid: u16, child_vec: &[(u64, U256)], ) { // Set minimum stake for setting children @@ -824,13 +823,13 @@ pub fn mock_schedule_children( } #[allow(dead_code)] -pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: NetUid, child_vec: &[(u64, U256)]) { +pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec: &[(u64, U256)]) { mock_schedule_children(coldkey, parent, netuid, child_vec); wait_and_set_pending_children(netuid); } #[allow(dead_code)] -pub fn mock_set_children_no_epochs(netuid: NetUid, parent: &U256, child_vec: &[(u64, U256)]) { +pub fn mock_set_children_no_epochs(netuid: u16, parent: &U256, child_vec: &[(u64, U256)]) { let backup_block = SubtensorModule::get_current_block_as_u64(); PendingChildKeys::::insert(netuid, parent, (child_vec, 0)); System::set_block_number(1); @@ -840,7 +839,7 @@ pub fn mock_set_children_no_epochs(netuid: NetUid, parent: &U256, child_vec: &[( // Helper function to wait for the rate limit #[allow(dead_code)] -pub fn step_rate_limit(transaction_type: &TransactionType, netuid: NetUid) { +pub fn step_rate_limit(transaction_type: &TransactionType, netuid: u16) { // Check rate limit let limit = SubtensorModule::get_rate_limit_on_subnet(transaction_type, netuid); @@ -855,7 +854,7 @@ pub fn increase_stake_on_coldkey_hotkey_account( coldkey: &U256, hotkey: &U256, tao_staked: u64, - netuid: NetUid, + netuid: u16, ) { let fee = 0; SubtensorModule::stake_into_subnet(hotkey, coldkey, netuid, tao_staked, fee); @@ -867,7 +866,7 @@ pub fn increase_stake_on_coldkey_hotkey_account( /// * `hotkey` - The hotkey account ID. /// * `increment` - The amount to be incremented. #[allow(dead_code)] -pub fn increase_stake_on_hotkey_account(hotkey: &U256, increment: u64, netuid: NetUid) { +pub fn increase_stake_on_hotkey_account(hotkey: &U256, increment: u64, netuid: u16) { increase_stake_on_coldkey_hotkey_account( &SubtensorModule::get_owning_coldkey_for_hotkey(hotkey), hotkey, diff --git a/pallets/subtensor/src/tests/move_stake.rs b/pallets/subtensor/src/tests/move_stake.rs index fd8b890f96..dd85ab9075 100644 --- a/pallets/subtensor/src/tests/move_stake.rs +++ b/pallets/subtensor/src/tests/move_stake.rs @@ -13,7 +13,7 @@ fn test_do_move_success() { new_test_ext(1).execute_with(|| { let subnet_owner_coldkey = U256::from(1001); let subnet_owner_hotkey = U256::from(1002); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let coldkey = U256::from(1); let origin_hotkey = U256::from(2); let destination_hotkey = U256::from(3); @@ -141,7 +141,7 @@ fn test_do_move_nonexistent_subnet() { let coldkey = U256::from(1); let origin_hotkey = U256::from(2); let destination_hotkey = U256::from(3); - let nonexistent_netuid = NetUid::from(99); // Assuming this subnet doesn't exist + let nonexistent_netuid = 99; // Assuming this subnet doesn't exist let stake_amount = 1_000_000; let fee = 0; @@ -240,7 +240,7 @@ fn test_do_move_nonexistent_destination_hotkey() { let coldkey = U256::from(1); let origin_hotkey = U256::from(2); let nonexistent_destination_hotkey = U256::from(99); // Assuming this hotkey doesn't exist - let netuid = NetUid::from(1); + let netuid = 1; let stake_amount = 1_000_000; let fee = 0; @@ -518,7 +518,7 @@ fn test_do_move_wrong_origin() { let wrong_coldkey = U256::from(99); let origin_hotkey = U256::from(2); let destination_hotkey = U256::from(3); - let netuid = NetUid::from(1); + let netuid = 1; let stake_amount = DefaultMinStake::::get() * 10; let fee = 0; @@ -738,7 +738,7 @@ fn test_do_move_max_values() { let origin_hotkey = U256::from(2); let destination_hotkey = U256::from(3); let max_stake = u64::MAX; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let fee = 0; // Set up initial stake with maximum value @@ -797,8 +797,8 @@ fn test_moving_too_little_unstakes() { let fee = DefaultStakingFee::::get(); //add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); - let netuid2 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid2: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, amount + fee); @@ -886,7 +886,7 @@ fn test_do_transfer_nonexistent_subnet() { let origin_coldkey = U256::from(1); let destination_coldkey = U256::from(2); let hotkey = U256::from(3); - let nonexistent_netuid = NetUid::from(9999); + let nonexistent_netuid = 9999; let stake_amount = DefaultMinStake::::get() * 5; assert_noop!( @@ -1153,8 +1153,8 @@ fn test_do_swap_nonexistent_subnet() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let nonexistent_netuid1 = NetUid::from(9998); - let nonexistent_netuid2 = NetUid::from(9999); + let nonexistent_netuid1: u16 = 9998; + let nonexistent_netuid2: u16 = 9999; let stake_amount = 1_000_000; SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey); @@ -1666,9 +1666,9 @@ fn test_move_stake_specific_stake_into_subnet_fail() { let tao_staked = 200_000_000; //add network - let netuid = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey); + let netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey); - let origin_netuid = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey); + let origin_netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey); // Register hotkey on netuid register_ok_neuron(netuid, hotkey_account_id, hotkey_owner_account_id, 0); diff --git a/pallets/subtensor/src/tests/networks.rs b/pallets/subtensor/src/tests/networks.rs index ff14a641db..7dda0502c1 100644 --- a/pallets/subtensor/src/tests/networks.rs +++ b/pallets/subtensor/src/tests/networks.rs @@ -8,7 +8,7 @@ use sp_core::U256; fn test_registration_ok() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(2); + let netuid: u16 = 2; let tempo: u16 = 13; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(0); // Neighbour of the beast, har har @@ -45,7 +45,7 @@ fn test_registration_ok() { // fn test_schedule_dissolve_network_execution() { // new_test_ext(1).execute_with(|| { // let block_number: u64 = 0; -// let netuid = NetUid::from(2); +// let netuid: u16 = 2; // let tempo: u16 = 13; // let hotkey_account_id: U256 = U256::from(1); // let coldkey_account_id = U256::from(0); // Neighbour of the beast, har har @@ -97,7 +97,7 @@ fn test_registration_ok() { // fn test_non_owner_schedule_dissolve_network_execution() { // new_test_ext(1).execute_with(|| { // let block_number: u64 = 0; -// let netuid = NetUid::from(2); +// let netuid: u16 = 2; // let tempo: u16 = 13; // let hotkey_account_id: U256 = U256::from(1); // let coldkey_account_id = U256::from(0); // Neighbour of the beast, har har @@ -151,7 +151,7 @@ fn test_registration_ok() { // fn test_new_owner_schedule_dissolve_network_execution() { // new_test_ext(1).execute_with(|| { // let block_number: u64 = 0; -// let netuid = NetUid::from(2); +// let netuid: u16 = 2; // let tempo: u16 = 13; // let hotkey_account_id: U256 = U256::from(1); // let coldkey_account_id = U256::from(0); // Neighbour of the beast, har har @@ -209,7 +209,7 @@ fn test_registration_ok() { // fn test_schedule_dissolve_network_execution_with_coldkey_swap() { // new_test_ext(1).execute_with(|| { // let block_number: u64 = 0; -// let netuid = NetUid::from(2); +// let netuid: u16 = 2; // let tempo: u16 = 13; // let hotkey_account_id: U256 = U256::from(1); // let coldkey_account_id = U256::from(0); // Neighbour of the beast, har har @@ -294,7 +294,7 @@ fn test_register_subnet_low_lock_cost() { let subnet_owner_coldkey = U256::from(1); let subnet_owner_hotkey = U256::from(2); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); assert!(SubtensorModule::if_subnet_exist(netuid)); // Ensure that both Subnet TAO and Subnet Alpha In equal to (actual) lock_cost @@ -317,7 +317,7 @@ fn test_register_subnet_high_lock_cost() { let subnet_owner_coldkey = U256::from(1); let subnet_owner_hotkey = U256::from(2); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); assert!(SubtensorModule::if_subnet_exist(netuid)); // Ensure that both Subnet TAO and Subnet Alpha In equal to 100 TAO diff --git a/pallets/subtensor/src/tests/neuron_info.rs b/pallets/subtensor/src/tests/neuron_info.rs index a954ef6e26..c51c1e7dad 100644 --- a/pallets/subtensor/src/tests/neuron_info.rs +++ b/pallets/subtensor/src/tests/neuron_info.rs @@ -1,12 +1,11 @@ use super::mock::*; use sp_core::U256; -use subtensor_runtime_common::NetUid; #[test] fn test_get_neuron_none() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uid: u16 = 42; let neuron = SubtensorModule::get_neuron(netuid, uid); @@ -17,7 +16,7 @@ fn test_get_neuron_none() { #[test] fn test_get_neuron_some() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; @@ -38,7 +37,7 @@ fn test_get_neuron_some() { #[test] fn test_get_neurons_list() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 2; let modality: u16 = 2; @@ -63,7 +62,7 @@ fn test_get_neurons_list() { #[test] fn test_get_neurons_empty() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let neuron_count = 0; let neurons = SubtensorModule::get_neurons(netuid); diff --git a/pallets/subtensor/src/tests/recycle_alpha.rs b/pallets/subtensor/src/tests/recycle_alpha.rs index 277d56c81f..b142e5d3c9 100644 --- a/pallets/subtensor/src/tests/recycle_alpha.rs +++ b/pallets/subtensor/src/tests/recycle_alpha.rs @@ -422,7 +422,7 @@ fn test_recycle_errors() { RuntimeOrigin::signed(coldkey), hotkey, 100_000, - 99.into() // non-existent subnet + 99 // non-existent subnet ), Error::::SubNetworkDoesNotExist ); @@ -432,7 +432,7 @@ fn test_recycle_errors() { RuntimeOrigin::signed(coldkey), hotkey, 100_000, - NetUid::ROOT, + SubtensorModule::get_root_netuid(), ), Error::::CannotBurnOrRecycleOnRootSubnet ); @@ -504,7 +504,7 @@ fn test_burn_errors() { RuntimeOrigin::signed(coldkey), hotkey, 100_000, - 99.into() // non-existent subnet + 99 // non-existent subnet ), Error::::SubNetworkDoesNotExist ); @@ -514,7 +514,7 @@ fn test_burn_errors() { RuntimeOrigin::signed(coldkey), hotkey, 100_000, - NetUid::ROOT, + SubtensorModule::get_root_netuid(), ), Error::::CannotBurnOrRecycleOnRootSubnet ); diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index d3dd827898..3a8ce39ba3 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,7 +11,6 @@ use frame_support::{assert_err, assert_noop, assert_ok}; use frame_system::Config; use sp_core::U256; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; -use subtensor_runtime_common::NetUid; /******************************************** subscribing::subscribe() tests @@ -23,7 +22,7 @@ fn test_registration_subscribe_ok_dispatch_info_ok() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; let nonce: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let work: Vec = vec![0; 32]; let hotkey: U256 = U256::from(0); let coldkey: U256 = U256::from(0); @@ -49,7 +48,7 @@ fn test_registration_subscribe_ok_dispatch_info_ok() { #[test] fn test_registration_difficulty() { new_test_ext(1).execute_with(|| { - assert_eq!(SubtensorModule::get_difficulty(1.into()).as_u64(), 10000); + assert_eq!(SubtensorModule::get_difficulty(1).as_u64(), 10000); }); } @@ -57,7 +56,7 @@ fn test_registration_difficulty() { fn test_registration_invalid_seal_hotkey() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id_1: U256 = U256::from(1); let hotkey_account_id_2: U256 = U256::from(2); @@ -104,7 +103,7 @@ fn test_registration_invalid_seal_hotkey() { fn test_registration_ok() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har @@ -160,7 +159,7 @@ fn test_registration_ok() { fn test_registration_without_neuron_slot() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har @@ -193,7 +192,7 @@ fn test_registration_without_neuron_slot() { #[test] fn test_registration_under_limit() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let block_number: u64 = 0; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); @@ -245,7 +244,7 @@ fn test_registration_under_limit() { #[test] fn test_registration_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let block_number: u64 = 0; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); @@ -293,7 +292,7 @@ fn test_registration_rate_limit_exceeded() { #[test] fn test_burned_registration_under_limit() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); let who: ::AccountId = coldkey_account_id; @@ -337,7 +336,7 @@ fn test_burned_registration_under_limit() { #[test] fn test_burned_registration_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); let who: ::AccountId = coldkey_account_id; @@ -375,7 +374,7 @@ fn test_burned_registration_rate_limit_exceeded() { fn test_burned_registration_rate_allows_burn_adjustment() { // We need to be able to register more than the *target* registrations per interval new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); let who: ::AccountId = coldkey_account_id; @@ -422,7 +421,7 @@ fn test_burned_registration_rate_allows_burn_adjustment() { #[test] fn test_burned_registration_ok() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let burn_cost = 1000; @@ -469,7 +468,7 @@ fn test_burned_registration_ok() { #[test] fn test_burn_registration_without_neuron_slot() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let burn_cost = 1000; @@ -495,7 +494,7 @@ fn test_burn_registration_without_neuron_slot() { #[test] fn test_burn_registration_doesnt_write_on_failure() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let burn_cost = 1000; @@ -535,7 +534,7 @@ fn test_burn_registration_doesnt_write_on_failure() { #[test] fn test_burn_adjustment() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let init_burn_cost: u64 = InitialMinBurn::get() + 10_000; let adjustment_interval = 1; @@ -586,7 +585,7 @@ fn test_burn_adjustment() { #[test] fn test_burn_registration_pruning_scenarios() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let burn_cost = 1000; let coldkey_account_id = U256::from(667); @@ -702,7 +701,7 @@ fn test_burn_registration_pruning_scenarios() { #[test] fn test_registration_too_many_registrations_per_block() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; add_network(netuid, tempo, 0); SubtensorModule::set_max_registrations_per_block(netuid, 10); @@ -898,7 +897,7 @@ fn test_registration_too_many_registrations_per_block() { #[test] fn test_registration_too_many_registrations_per_interval() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; add_network(netuid, tempo, 0); SubtensorModule::set_max_registrations_per_block(netuid, 11); @@ -1090,7 +1089,7 @@ fn test_registration_immunity_period() { //impl this test when epoch impl and ca fn test_registration_already_active_hotkey() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(667); @@ -1143,7 +1142,7 @@ fn test_registration_already_active_hotkey() { fn test_registration_invalid_seal() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(667); @@ -1171,7 +1170,7 @@ fn test_registration_invalid_block_number() { new_test_ext(1).execute_with(|| { System::set_block_number(0); let block_number: u64 = 1; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(667); @@ -1202,7 +1201,7 @@ fn test_registration_invalid_block_number() { fn test_registration_invalid_difficulty() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(667); @@ -1235,7 +1234,7 @@ fn test_registration_invalid_difficulty() { fn test_registration_failed_no_signature() { new_test_ext(1).execute_with(|| { let block_number: u64 = 1; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( @@ -1263,7 +1262,7 @@ fn test_registration_failed_no_signature() { fn test_registration_get_uid_to_prune_all_in_immunity_period() { new_test_ext(1).execute_with(|| { System::set_block_number(0); - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); log::info!("add network"); register_ok_neuron(netuid, U256::from(0), U256::from(0), 39420842); @@ -1279,7 +1278,7 @@ fn test_registration_get_uid_to_prune_all_in_immunity_period() { SubtensorModule::get_neuron_block_at_registration(netuid, 0), 0 ); - assert_eq!(SubtensorModule::get_neuron_to_prune(NetUid::ROOT), 0); + assert_eq!(SubtensorModule::get_neuron_to_prune(0), 0); }); } @@ -1287,7 +1286,7 @@ fn test_registration_get_uid_to_prune_all_in_immunity_period() { fn test_registration_get_uid_to_prune_none_in_immunity_period() { new_test_ext(1).execute_with(|| { System::set_block_number(0); - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); log::info!("add network"); register_ok_neuron(netuid, U256::from(0), U256::from(0), 39420842); @@ -1305,14 +1304,14 @@ fn test_registration_get_uid_to_prune_none_in_immunity_period() { ); step_block(3); assert_eq!(SubtensorModule::get_current_block_as_u64(), 3); - assert_eq!(SubtensorModule::get_neuron_to_prune(NetUid::ROOT), 0); + assert_eq!(SubtensorModule::get_neuron_to_prune(0), 0); }); } #[test] fn test_registration_pruning() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let block_number: u64 = 0; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); @@ -1388,7 +1387,7 @@ fn test_registration_pruning() { #[test] fn test_registration_get_neuron_metadata() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let block_number: u64 = 0; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); @@ -1424,8 +1423,8 @@ fn test_registration_get_neuron_metadata() { #[test] fn test_registration_add_network_size() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid: u16 = 1; + let netuid2: u16 = 2; let block_number: u64 = 0; let hotkey_account_id = U256::from(1); let hotkey_account_id1 = U256::from(2); @@ -1494,8 +1493,8 @@ fn test_registration_add_network_size() { #[test] fn test_burn_registration_increase_recycled_rao() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid: u16 = 1; + let netuid2: u16 = 2; let hotkey_account_id = U256::from(1); let coldkey_account_id = U256::from(667); @@ -1543,9 +1542,9 @@ fn test_burn_registration_increase_recycled_rao() { fn test_full_pass_through() { new_test_ext(1).execute_with(|| { // Create 3 networks. - let netuid0 = NetUid::from(1); - let netuid1 = NetUid::from(2); - let netuid2 = NetUid::from(3); + let netuid0: u16 = 1; + let netuid1: u16 = 2; + let netuid2: u16 = 3; // With 3 tempos let tempo0: u16 = 2; @@ -1962,7 +1961,7 @@ fn test_full_pass_through() { fn test_registration_origin_hotkey_mismatch() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id_1: U256 = U256::from(1); let hotkey_account_id_2: U256 = U256::from(2); @@ -1997,7 +1996,7 @@ fn test_registration_origin_hotkey_mismatch() { fn test_registration_disabled() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id: U256 = U256::from(668); @@ -2033,7 +2032,7 @@ fn test_registration_disabled() { // #[test] // fn test_hotkey_swap_ok() { // new_test_ext(1).execute_with(|| { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let tempo: u16 = 13; // let hotkey_account_id = U256::from(1); // let burn_cost = 1000; @@ -2073,7 +2072,7 @@ fn test_registration_disabled() { // #[test] // fn test_hotkey_swap_not_owner() { // new_test_ext(1).execute_with(|| { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let tempo: u16 = 13; // let hotkey_account_id = U256::from(1); // let burn_cost = 1000; @@ -2109,7 +2108,7 @@ fn test_registration_disabled() { // #[test] // fn test_hotkey_swap_same_key() { // new_test_ext(1).execute_with(|| { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let tempo: u16 = 13; // let hotkey_account_id = U256::from(1); // let burn_cost = 1000; @@ -2143,7 +2142,7 @@ fn test_registration_disabled() { // #[test] // fn test_hotkey_swap_registered_key() { // new_test_ext(1).execute_with(|| { -// let netuid = NetUid::from(1); +// let netuid: u16 = 1; // let tempo: u16 = 13; // let hotkey_account_id = U256::from(1); // let burn_cost = 1000; diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index a71a97b1e2..52b0c240c2 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -61,7 +61,7 @@ fn test_senate_join_works() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(6); let burn_cost = 1000; @@ -135,7 +135,7 @@ fn test_senate_vote_works() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let senate_hotkey = U256::from(1); let hotkey_account_id = U256::from(6); @@ -248,7 +248,7 @@ fn test_senate_vote_not_member() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let senate_hotkey = U256::from(1); let hotkey_account_id = U256::from(6); @@ -309,7 +309,7 @@ fn test_senate_leave_works() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(6); let burn_cost = 1000; @@ -382,7 +382,7 @@ fn test_senate_leave_vote_removal() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let senate_hotkey = U256::from(1); let hotkey_account_id = U256::from(6); @@ -472,14 +472,15 @@ fn test_senate_leave_vote_removal() { // Fill the root network with many large stake keys. // This removes all other keys. // Add two networks. - let other_netuid = NetUid::from(5); + let root_netuid: u16 = 0; + let other_netuid: u16 = 5; add_network(other_netuid, 1, 0); SubtensorModule::set_burn(other_netuid, 0); SubtensorModule::set_max_registrations_per_block(other_netuid, 1000); SubtensorModule::set_target_registrations_per_interval(other_netuid, 1000); - SubtensorModule::set_max_registrations_per_block(NetUid::ROOT, 1000); - SubtensorModule::set_target_registrations_per_interval(NetUid::ROOT, 1000); - SubtokenEnabled::::insert(NetUid::ROOT, true); + SubtensorModule::set_max_registrations_per_block(root_netuid, 1000); + SubtensorModule::set_target_registrations_per_interval(root_netuid, 1000); + SubtokenEnabled::::insert(root_netuid, true); SubtokenEnabled::::insert(other_netuid, true); for i in 0..200 { @@ -497,7 +498,7 @@ fn test_senate_leave_vote_removal() { assert_ok!(SubtensorModule::add_stake( <::RuntimeOrigin>::signed(cold), hot, - NetUid::ROOT, + root_netuid, 100_000_000 + (i as u64) )); // Register them on the root network. @@ -507,13 +508,13 @@ fn test_senate_leave_vote_removal() { )); // Check succesfull registration. assert!(SubtensorModule::get_uid_for_net_and_hotkey(other_netuid, &hot).is_ok()); - assert!(SubtensorModule::get_uid_for_net_and_hotkey(NetUid::ROOT, &hot).is_ok()); + assert!(SubtensorModule::get_uid_for_net_and_hotkey(root_netuid, &hot).is_ok()); // Check that they are all delegates assert!(SubtensorModule::hotkey_is_delegate(&hot)); } // No longer a root member assert!( - SubtensorModule::get_uid_for_net_and_hotkey(NetUid::ROOT, &hotkey_account_id).is_err() + SubtensorModule::get_uid_for_net_and_hotkey(root_netuid, &hotkey_account_id).is_err() ); // No longer a member of the senate assert!(!Senate::is_member(&hotkey_account_id)); @@ -530,7 +531,7 @@ fn test_senate_not_leave_when_stake_removed() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(6); let burn_cost = 1000; @@ -614,7 +615,7 @@ fn test_senate_join_current_delegate() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(6); let burn_cost = 1000; @@ -688,12 +689,12 @@ fn test_adjust_senate_events() { new_test_ext().execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(6); let burn_cost = 1000; let coldkey_account_id = U256::from(667); - let root_netuid = NetUid::ROOT; + let root_netuid = SubtensorModule::get_root_netuid(); let fee = DefaultStakingFee::::get(); let max_senate_size: u16 = SenateMaxMembers::get() as u16; diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index faf68b2e81..6711862a6b 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -32,7 +32,7 @@ mod test { #[test] fn test_serving_subscribe_ok_dispatch_info_ok() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version: u32 = 2; let ip: u128 = 1676056785; let port: u16 = 128; @@ -65,7 +65,7 @@ fn test_serving_subscribe_ok_dispatch_info_ok() { fn test_serving_ok() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -103,7 +103,7 @@ fn test_serving_ok() { fn test_serving_tls_ok() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -161,7 +161,7 @@ fn test_serving_tls_ok() { fn test_serving_set_metadata_update() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -225,7 +225,7 @@ fn test_serving_set_metadata_update() { fn test_axon_serving_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -307,7 +307,7 @@ fn test_axon_serving_rate_limit_exceeded() { fn test_axon_invalid_port() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -340,7 +340,7 @@ fn test_axon_invalid_port() { #[test] fn test_prometheus_serving_subscribe_ok_dispatch_info_ok() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version: u32 = 2; let ip: u128 = 1676056785; let port: u16 = 128; @@ -367,7 +367,7 @@ fn test_prometheus_serving_subscribe_ok_dispatch_info_ok() { fn test_prometheus_serving_ok() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -396,7 +396,7 @@ fn test_prometheus_serving_ok() { fn test_prometheus_serving_set_metadata_update() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -442,7 +442,7 @@ fn test_prometheus_serving_set_metadata_update() { fn test_prometheus_serving_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -505,7 +505,7 @@ fn test_prometheus_serving_rate_limit_exceeded() { fn test_prometheus_invalid_port() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let version: u32 = 2; let ip: u128 = 1676056785; @@ -660,7 +660,7 @@ fn test_do_set_identity() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid = 1; // Register a hotkey for the coldkey add_network(netuid, 13, 0); @@ -847,7 +847,7 @@ fn test_set_and_get_identity() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid = 1; // Register a hotkey for the coldkey add_network(netuid, 13, 0); @@ -989,7 +989,7 @@ fn test_migrate_identities_to_v2() { let old_subnet_contact = b"subnet@example".to_vec(); SubnetIdentities::::insert( - NetUid::from(42), + 42u16, SubnetIdentity { subnet_name: old_subnet_name.clone(), github_repo: old_github_repo.clone(), @@ -999,7 +999,7 @@ fn test_migrate_identities_to_v2() { assert!(Identities::::get(account_id_1).is_some()); assert!(Identities::::get(account_id_2).is_some()); - assert!(SubnetIdentities::::get(NetUid::from(42)).is_some()); + assert!(SubnetIdentities::::get(42u16).is_some()); assert!(!HasMigrationRun::::get( b"migrate_identities_to_v2".to_vec() )); @@ -1012,7 +1012,7 @@ fn test_migrate_identities_to_v2() { ); assert!(Identities::::get(account_id_1).is_none()); assert!(Identities::::get(account_id_2).is_none()); - assert!(SubnetIdentities::::get(NetUid::from(42)).is_none()); + assert!(SubnetIdentities::::get(42u16).is_none()); let new_identity_1 = IdentitiesV2::::get(account_id_1) .expect("ChainOne should be migrated to IdentitiesV2"); @@ -1032,7 +1032,7 @@ fn test_migrate_identities_to_v2() { assert_eq!(new_identity_2.url, chaintwo_url); assert_eq!(new_identity_2.github_repo, b"".to_vec()); - let new_subnet_identity = SubnetIdentitiesV2::::get(NetUid::from(42)) + let new_subnet_identity = SubnetIdentitiesV2::::get(42u16) .expect("SubnetExample should be migrated to SubnetIdentitiesV2"); let expected_subnet_url = b"".to_vec(); @@ -1061,7 +1061,7 @@ fn test_do_set_subnet_identity() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid = 1; // Register a hotkey for the coldkey add_network(netuid, 13, 0); @@ -1243,7 +1243,7 @@ fn test_is_valid_subnet_identity() { fn test_set_identity_for_non_existent_subnet() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); - let netuid = NetUid::from(999); // Non-existent subnet ID + let netuid = 999; // Non-existent subnet ID // Subnet identity data let subnet_name = b"Non-existent Subnet".to_vec(); @@ -1275,7 +1275,7 @@ fn test_set_identity_for_non_existent_subnet() { #[test] fn test_set_subnet_identity_dispatch_info_ok() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let subnet_name: Vec = b"JesusSubnet".to_vec(); let github_repo: Vec = b"bible.com".to_vec(); let subnet_contact: Vec = b"https://www.vatican.va".to_vec(); @@ -1310,7 +1310,7 @@ fn test_serve_axon_validate() { new_test_ext(0).execute_with(|| { let hotkey = U256::from(1); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version: u32 = 2; let ip: u128 = 1676056785; let port: u16 = 128; diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index b0fc25fc8c..4d8d765e65 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -22,7 +22,7 @@ fn test_add_stake_dispatch_info_ok() { new_test_ext(1).execute_with(|| { let hotkey = U256::from(0); let amount_staked = 5000; - let netuid = NetUid::from(1); + let netuid = 1; let call = RuntimeCall::SubtensorModule(SubtensorCall::add_stake { hotkey, netuid, @@ -47,7 +47,7 @@ fn test_add_stake_ok_no_emission() { let fee = DefaultStakingFee::::get(); //add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, amount); @@ -100,12 +100,12 @@ fn test_dividends_with_run_to_block() { let initial_stake: u64 = 5000; //add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); Tempo::::insert(netuid, 13); // Register neuron, this will set a self weight SubtensorModule::set_max_registrations_per_block(netuid, 3); - SubtensorModule::set_max_allowed_uids(1.into(), 5); + SubtensorModule::set_max_allowed_uids(1, 5); register_ok_neuron(netuid, neuron_src_hotkey_id, coldkey_account_id, 192213123); register_ok_neuron(netuid, neuron_dest_hotkey_id, coldkey_account_id, 12323); @@ -149,7 +149,7 @@ fn test_add_stake_err_signature() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(654); // bogus let amount = 20000; // Not used - let netuid = NetUid::from(1); + let netuid = 1; assert_err!( SubtensorModule::add_stake(RawOrigin::None.into(), hotkey_account_id, netuid, amount), @@ -187,7 +187,7 @@ fn test_add_stake_ok_neuron_does_not_belong_to_coldkey() { let coldkey_id = U256::from(544); let hotkey_id = U256::from(54544); let other_cold_key = U256::from(99498); - let netuid = add_dynamic_network(&hotkey_id, &coldkey_id); + let netuid: u16 = add_dynamic_network(&hotkey_id, &coldkey_id); let stake = DefaultMinStake::::get() * 10; // Give it some $$$ in his coldkey balance @@ -209,7 +209,7 @@ fn test_add_stake_err_not_enough_belance() { let coldkey_id = U256::from(544); let hotkey_id = U256::from(54544); let stake = DefaultMinStake::::get() * 10; - let netuid = add_dynamic_network(&hotkey_id, &coldkey_id); + let netuid: u16 = add_dynamic_network(&hotkey_id, &coldkey_id); // Lets try to stake with 0 balance in cold key account assert!(SubtensorModule::get_coldkey_balance(&coldkey_id) < stake); @@ -233,7 +233,7 @@ fn test_add_stake_total_balance_no_change() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(551337); let coldkey_account_id = U256::from(51337); - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give it some $$$ in his coldkey balance let initial_balance = 10000; @@ -283,7 +283,7 @@ fn test_add_stake_total_issuance_no_change() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(561337); let coldkey_account_id = U256::from(61337); - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give it some $$$ in his coldkey balance let initial_balance = 10000; @@ -334,7 +334,7 @@ fn test_remove_stake_dispatch_info_ok() { new_test_ext(1).execute_with(|| { let hotkey = U256::from(0); let amount_unstaked = 5000; - let netuid = NetUid::from(1); + let netuid = 1; let call = RuntimeCall::SubtensorModule(SubtensorCall::remove_stake { hotkey, netuid, @@ -360,7 +360,7 @@ fn test_remove_stake_ok_no_emission() { let coldkey_account_id = U256::from(4343); let hotkey_account_id = U256::from(4968585); let amount = DefaultMinStake::::get() * 10; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); // Some basic assertions @@ -429,7 +429,7 @@ fn test_remove_stake_amount_too_low() { let coldkey_account_id = U256::from(4343); let hotkey_account_id = U256::from(4968585); let amount = 10_000; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); // Some basic assertions @@ -469,7 +469,7 @@ fn test_remove_stake_err_signature() { new_test_ext(1).execute_with(|| { let hotkey_account_id = U256::from(4968585); let amount = 10000; // Amount to be removed - let netuid = NetUid::from(1); + let netuid = 1; assert_err!( SubtensorModule::remove_stake( @@ -490,7 +490,7 @@ fn test_remove_stake_ok_hotkey_does_not_belong_to_coldkey() { let hotkey_id = U256::from(54544); let other_cold_key = U256::from(99498); let amount = DefaultMinStake::::get() * 10; - let netuid = add_dynamic_network(&hotkey_id, &coldkey_id); + let netuid: u16 = add_dynamic_network(&hotkey_id, &coldkey_id); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -543,7 +543,7 @@ fn test_remove_stake_total_balance_no_change() { let hotkey_account_id = U256::from(571337); let coldkey_account_id = U256::from(71337); let amount = DefaultMinStake::::get() * 10; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); // Some basic assertions @@ -691,7 +691,7 @@ fn test_remove_stake_total_issuance_no_change() { let hotkey_account_id = U256::from(581337); let coldkey_account_id = U256::from(81337); let amount = DefaultMinStake::::get() * 10; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let fee = DefaultStakingFee::::get(); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); @@ -831,7 +831,7 @@ fn test_remove_prev_epoch_stake() { let hotkey_account_id = U256::from(581337); let coldkey_account_id = U256::from(81337); let amount = *amount_to_stake; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); // Give it some $$$ in his coldkey balance @@ -881,7 +881,7 @@ fn test_staking_sets_div_variables() { let hotkey_account_id = U256::from(581337); let coldkey_account_id = U256::from(81337); let amount = 100_000_000_000; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let tempo = 10; Tempo::::insert(netuid, tempo); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); @@ -977,7 +977,7 @@ fn test_add_stake_to_hotkey_account_ok() { let hotkey_id = U256::from(5445); let coldkey_id = U256::from(5443433); let amount = 10_000; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey_id, coldkey_id, 192213123); // There is no stake in the system at first, other than the network initial lock so result; @@ -1012,7 +1012,7 @@ fn test_remove_stake_from_hotkey_account() { let hotkey_id = U256::from(5445); let coldkey_id = U256::from(5443433); let amount = 10_000; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey_id, coldkey_id, 192213123); // Add some stake that can be removed @@ -1188,7 +1188,7 @@ fn test_hotkey_belongs_to_coldkey_ok() { new_test_ext(1).execute_with(|| { let hotkey_id = U256::from(4434334); let coldkey_id = U256::from(34333); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let start_nonce: u64 = 0; add_network(netuid, tempo, 0); @@ -1238,7 +1238,7 @@ fn test_has_enough_stake_yes() { let hotkey_id = U256::from(4334); let coldkey_id = U256::from(87989); let intial_amount = 10_000; - let netuid = NetUid::from(add_dynamic_network(&hotkey_id, &coldkey_id)); + let netuid = add_dynamic_network(&hotkey_id, &coldkey_id); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey_id, &coldkey_id, @@ -1334,7 +1334,7 @@ fn test_has_enough_stake_no_for_zero() { #[test] fn test_non_existent_account() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &U256::from(0), &(U256::from(0)), @@ -1412,7 +1412,7 @@ fn test_clear_small_nominations() { let hot2 = U256::from(2); let cold1 = U256::from(3); let cold2 = U256::from(4); - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let amount = DefaultMinStake::::get() * 10; let fee: u64 = DefaultMinStake::::get(); let init_balance = amount + fee + ExistentialDeposit::get(); @@ -1589,7 +1589,7 @@ fn test_delegate_take_can_be_decreased() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1624,7 +1624,7 @@ fn test_can_set_min_take_ok() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1656,7 +1656,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1691,7 +1691,7 @@ fn test_delegate_take_can_be_increased() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1726,7 +1726,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1765,7 +1765,7 @@ fn test_delegate_take_can_be_increased_to_limit() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1803,7 +1803,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1845,7 +1845,7 @@ fn test_rate_limits_enforced_on_increase_take() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -1905,7 +1905,7 @@ fn test_rate_limits_enforced_on_decrease_before_increase_take() { SubtensorModule::add_balance_to_coldkey_account(&coldkey0, 100000); // Register the neuron to a new network - let netuid = NetUid::from(1); + let netuid = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); @@ -2035,7 +2035,7 @@ fn test_get_total_delegated_stake_no_delegations() { new_test_ext(1).execute_with(|| { let delegate = U256::from(1); let coldkey = U256::from(2); - let netuid = NetUid::from(1u16); + let netuid = 1u16; add_network(netuid, 1, 0); register_ok_neuron(netuid, delegate, coldkey, 0); @@ -2230,7 +2230,7 @@ fn test_mining_emission_distribution_validator_valiminer_miner() { let validator_miner_hotkey = U256::from(4); let miner_coldkey = U256::from(5); let miner_hotkey = U256::from(6); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let subnet_tempo = 10; let stake = 100_000_000_000; @@ -2323,7 +2323,7 @@ fn test_staking_too_little_fails() { let amount = 10_000; //add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, amount); @@ -2584,7 +2584,7 @@ fn test_add_stake_limit_validate() { let amount = 900_000_000_000; // add network - let netuid = add_dynamic_network(&hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&hotkey, &coldkey); // Force-set alpha in and tao reserve to make price equal 1.5 let tao_reserve: U96F32 = U96F32::from_num(150_000_000_000_u64); @@ -2640,7 +2640,7 @@ fn test_remove_stake_limit_validate() { let unstake_amount = 150_000_000_000; // add network - let netuid = add_dynamic_network(&hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&hotkey, &coldkey); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -2891,31 +2891,31 @@ fn test_max_amount_add_root() { new_test_ext(0).execute_with(|| { // 0 price on root => max is 0 assert_eq!( - SubtensorModule::get_max_amount_add(NetUid::ROOT, 0), + SubtensorModule::get_max_amount_add(0, 0), Err(Error::::ZeroMaxStakeAmount) ); // 0.999999... price on root => max is 0 assert_eq!( - SubtensorModule::get_max_amount_add(NetUid::ROOT, 999_999_999), + SubtensorModule::get_max_amount_add(0, 999_999_999), Err(Error::::ZeroMaxStakeAmount) ); // 1.0 price on root => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_add(NetUid::ROOT, 1_000_000_000), + SubtensorModule::get_max_amount_add(0, 1_000_000_000), Ok(u64::MAX) ); // 1.000...001 price on root => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_add(NetUid::ROOT, 1_000_000_001), + SubtensorModule::get_max_amount_add(0, 1_000_000_001), Ok(u64::MAX) ); // 2.0 price on root => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_add(NetUid::ROOT, 2_000_000_000), + SubtensorModule::get_max_amount_add(0, 2_000_000_000), Ok(u64::MAX) ); }); @@ -2924,7 +2924,7 @@ fn test_max_amount_add_root() { #[test] fn test_max_amount_add_stable() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // 0 price => max is 0 @@ -3128,38 +3128,35 @@ fn test_max_amount_add_dynamic() { fn test_max_amount_remove_root() { new_test_ext(0).execute_with(|| { // 0 price on root => max is u64::MAX - assert_eq!( - SubtensorModule::get_max_amount_remove(NetUid::ROOT, 0), - Ok(u64::MAX) - ); + assert_eq!(SubtensorModule::get_max_amount_remove(0, 0), Ok(u64::MAX)); // 0.5 price on root => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_remove(NetUid::ROOT, 500_000_000), + SubtensorModule::get_max_amount_remove(0, 500_000_000), Ok(u64::MAX) ); // 0.999999... price on root => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_remove(NetUid::ROOT, 999_999_999), + SubtensorModule::get_max_amount_remove(0, 999_999_999), Ok(u64::MAX) ); // 1.0 price on root => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_remove(NetUid::ROOT, 1_000_000_000), + SubtensorModule::get_max_amount_remove(0, 1_000_000_000), Ok(u64::MAX) ); // 1.000...001 price on root => max is 0 assert_eq!( - SubtensorModule::get_max_amount_remove(NetUid::ROOT, 1_000_000_001), + SubtensorModule::get_max_amount_remove(0, 1_000_000_001), Err(Error::::ZeroMaxStakeAmount) ); // 2.0 price on root => max is 0 assert_eq!( - SubtensorModule::get_max_amount_remove(NetUid::ROOT, 2_000_000_000), + SubtensorModule::get_max_amount_remove(0, 2_000_000_000), Err(Error::::ZeroMaxStakeAmount) ); }); @@ -3168,7 +3165,7 @@ fn test_max_amount_remove_root() { #[test] fn test_max_amount_remove_stable() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // 0 price => max is u64::MAX @@ -3367,38 +3364,35 @@ fn test_max_amount_remove_dynamic() { fn test_max_amount_move_root_root() { new_test_ext(0).execute_with(|| { // 0 price on (root, root) exchange => max is u64::MAX - assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, NetUid::ROOT, 0), - Ok(u64::MAX) - ); + assert_eq!(SubtensorModule::get_max_amount_move(0, 0, 0), Ok(u64::MAX)); // 0.5 price on (root, root) => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, NetUid::ROOT, 500_000_000), + SubtensorModule::get_max_amount_move(0, 0, 500_000_000), Ok(u64::MAX) ); // 0.999999... price on (root, root) => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, NetUid::ROOT, 999_999_999), + SubtensorModule::get_max_amount_move(0, 0, 999_999_999), Ok(u64::MAX) ); // 1.0 price on (root, root) => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, NetUid::ROOT, 1_000_000_000), + SubtensorModule::get_max_amount_move(0, 0, 1_000_000_000), Ok(u64::MAX) ); // 1.000...001 price on (root, root) => max is 0 assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, NetUid::ROOT, 1_000_000_001), + SubtensorModule::get_max_amount_move(0, 0, 1_000_000_001), Err(Error::::ZeroMaxStakeAmount) ); // 2.0 price on (root, root) => max is 0 assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, NetUid::ROOT, 2_000_000_000), + SubtensorModule::get_max_amount_move(0, 0, 2_000_000_000), Err(Error::::ZeroMaxStakeAmount) ); }); @@ -3408,42 +3402,42 @@ fn test_max_amount_move_root_root() { #[test] fn test_max_amount_move_root_stable() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); // 0 price on (root, stable) exchange => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, netuid, 0), + SubtensorModule::get_max_amount_move(0, netuid, 0), Ok(u64::MAX) ); // 0.5 price on (root, stable) => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, netuid, 500_000_000), + SubtensorModule::get_max_amount_move(0, netuid, 500_000_000), Ok(u64::MAX) ); // 0.999999... price on (root, stable) => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, netuid, 999_999_999), + SubtensorModule::get_max_amount_move(0, netuid, 999_999_999), Ok(u64::MAX) ); // 1.0 price on (root, stable) => max is u64::MAX assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, netuid, 1_000_000_000), + SubtensorModule::get_max_amount_move(0, netuid, 1_000_000_000), Ok(u64::MAX) ); // 1.000...001 price on (root, stable) => max is 0 assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, netuid, 1_000_000_001), + SubtensorModule::get_max_amount_move(0, netuid, 1_000_000_001), Err(Error::::ZeroMaxStakeAmount) ); // 2.0 price on (root, stable) => max is 0 assert_eq!( - SubtensorModule::get_max_amount_move(NetUid::ROOT, netuid, 2_000_000_000), + SubtensorModule::get_max_amount_move(0, netuid, 2_000_000_000), Err(Error::::ZeroMaxStakeAmount) ); }); @@ -3454,7 +3448,7 @@ fn test_max_amount_move_root_stable() { fn test_max_amount_move_stable_dynamic() { new_test_ext(0).execute_with(|| { // Add stable subnet - let stable_netuid = NetUid::from(1); + let stable_netuid: u16 = 1; add_network(stable_netuid, 1, 0); // Add dynamic subnet @@ -3528,7 +3522,7 @@ fn test_max_amount_move_stable_dynamic() { fn test_max_amount_move_dynamic_stable() { new_test_ext(0).execute_with(|| { // Add stable subnet - let stable_netuid = NetUid::from(1); + let stable_netuid: u16 = 1; add_network(stable_netuid, 1, 0); // Add dynamic subnet @@ -3850,7 +3844,7 @@ fn test_add_stake_limit_ok() { let fee = DefaultStakingFee::::get(); // add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Forse-set alpha in and tao reserve to make price equal 1.5 let tao_reserve: U96F32 = U96F32::from_num(150_000_000_000_u64); @@ -3916,7 +3910,7 @@ fn test_add_stake_limit_fill_or_kill() { let amount = 900_000_000_000; // over the maximum // add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Force-set alpha in and tao reserve to make price equal 1.5 let tao_reserve: U96F32 = U96F32::from_num(150_000_000_000_u64); @@ -3973,7 +3967,7 @@ fn test_add_stake_limit_partial_zero_max_stake_amount_error() { let tao_reserve: U96F32 = U96F32::from_num(5_032_494_439_940_u64); let alpha_in: U96F32 = U96F32::from_num(186_268_425_402_874_u64); - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); SubnetTAO::::insert(netuid, tao_reserve.to_num::()); SubnetAlphaIn::::insert(netuid, alpha_in.to_num::()); @@ -4003,7 +3997,7 @@ fn test_remove_stake_limit_ok() { let fee = DefaultStakingFee::::get(); // add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -4064,7 +4058,7 @@ fn test_remove_stake_limit_fill_or_kill() { let unstake_amount = 150_000_000_000; // add network - let netuid = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); + let netuid: u16 = add_dynamic_network(&hotkey_account_id, &coldkey_account_id); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -4130,7 +4124,7 @@ fn test_add_stake_specific_stake_into_subnet_fail() { let tao_staked = 200_000_000; //add network - let netuid = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey); + let netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey); // Register hotkey on netuid register_ok_neuron(netuid, hotkey_account_id, hotkey_owner_account_id, 0); @@ -4194,7 +4188,7 @@ fn test_remove_99_9991_per_cent_stake_removes_all() { let hotkey_account_id = U256::from(581337); let coldkey_account_id = U256::from(81337); let amount = 10_000_000_000; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let mut fee = DefaultStakingFee::::get(); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); @@ -4252,7 +4246,7 @@ fn test_remove_99_9989_per_cent_stake_leaves_a_little() { let hotkey_account_id = U256::from(581337); let coldkey_account_id = U256::from(81337); let amount = 10_000_000_000; - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let fee = DefaultStakingFee::::get(); register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, 192213123); @@ -4311,8 +4305,9 @@ fn test_move_stake_limit_partial() { let move_amount = 150_000_000_000; // add network - let origin_netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); - let destination_netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let origin_netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let destination_netuid: u16 = + add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(origin_netuid, hotkey, coldkey, 192213123); register_ok_neuron(destination_netuid, hotkey, coldkey, 192213123); @@ -4371,7 +4366,7 @@ fn test_unstake_all_hits_liquidity_min() { let stake_amount = 190_000_000_000; // 190 Alpha - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey, coldkey, 192213123); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -4418,7 +4413,7 @@ fn test_unstake_all_alpha_hits_liquidity_min() { let stake_amount = 190_000_000_000; // 190 Alpha - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey, coldkey, 192213123); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -4465,7 +4460,7 @@ fn test_unstake_all_alpha_works() { let stake_amount = 190_000_000_000; // 190 Alpha - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey, coldkey, 192213123); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -4497,11 +4492,8 @@ fn test_unstake_all_alpha_works() { let new_alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid); assert_abs_diff_eq!(new_alpha, 0, epsilon = 1_000,); - let new_root = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey, - &coldkey, - NetUid::ROOT, - ); + let new_root = + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, 0); assert!(new_root > 100_000); }); } @@ -4516,7 +4508,7 @@ fn test_unstake_all_works() { let stake_amount = 190_000_000_000; // 190 Alpha - let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + let netuid: u16 = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); register_ok_neuron(netuid, hotkey, coldkey, 192213123); // Give the neuron some stake to remove SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -4560,7 +4552,7 @@ fn test_increase_stake_for_hotkey_and_coldkey_on_subnet_adds_to_staking_hotkeys_ let coldkey1 = U256::from(2); let hotkey = U256::from(3); - let netuid = NetUid::from(1); + let netuid = 1; let stake_amount = 100_000_000_000; // Check no entry in the staking hotkeys map diff --git a/pallets/subtensor/src/tests/staking2.rs b/pallets/subtensor/src/tests/staking2.rs index 7b50dd5e85..6fbabf83b2 100644 --- a/pallets/subtensor/src/tests/staking2.rs +++ b/pallets/subtensor/src/tests/staking2.rs @@ -12,7 +12,7 @@ use substrate_fixed::types::{I96F32, U96F32}; #[test] fn test_stake_base_case() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let tao_to_swap = 1_000_000_000; // 1 TAO // Set up the subnet with dynamic mechanism @@ -78,7 +78,7 @@ fn test_stake_base_case() { #[test] fn test_share_based_staking() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let primary_hotkey = U256::from(1); let primary_coldkey = U256::from(2); let stake_amount = 1_000_000_000; // 1 TAO @@ -403,7 +403,7 @@ fn test_share_based_staking_denominator_precision() { .iter() .for_each(|test_case| { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let hotkey1 = U256::from(1); let coldkey1 = U256::from(2); let stake_amount = test_case.0; @@ -457,7 +457,7 @@ fn test_share_based_staking_stake_unstake_inject() { .iter() .for_each(|test_case| { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let hotkey1 = U256::from(1); let coldkey1 = U256::from(2); let coldkey2 = U256::from(3); @@ -527,7 +527,7 @@ fn test_share_based_staking_stake_inject_stake_new() { .iter() .for_each(|test_case| { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid = 1; let hotkey1 = U256::from(1); let coldkey1 = U256::from(2); let coldkey2 = U256::from(3); @@ -633,9 +633,9 @@ fn test_stake_fee_api() { let hotkey2 = U256::from(3); let coldkey2 = U256::from(4); - let netuid0 = NetUid::from(1); - let netuid1 = NetUid::from(2); - let root_netuid = NetUid::ROOT; + let netuid0 = 1; + let netuid1 = 2; + let root_netuid = SubtensorModule::get_root_netuid(); let alpha_divs = 100_000_000_000; let total_hotkey_alpha = 100_000_000_000; @@ -823,9 +823,9 @@ fn test_stake_fee_calculation() { let hotkey2 = U256::from(3); let coldkey2 = U256::from(4); - let netuid0 = NetUid::from(1); - let netuid1 = NetUid::from(2); - let root_netuid = NetUid::ROOT; + let netuid0 = 1; + let netuid1 = 2; + let root_netuid = SubtensorModule::get_root_netuid(); // Set SubnetMechanism to 1 (Dynamic) SubnetMechanism::::insert(netuid0, 1); SubnetMechanism::::insert(netuid1, 1); diff --git a/pallets/subtensor/src/tests/subnet.rs b/pallets/subtensor/src/tests/subnet.rs index 3800a801f9..c95a841736 100644 --- a/pallets/subtensor/src/tests/subnet.rs +++ b/pallets/subtensor/src/tests/subnet.rs @@ -11,7 +11,7 @@ use sp_core::U256; #[test] fn test_do_start_call_ok() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let coldkey_account_id = U256::from(0); @@ -39,7 +39,7 @@ fn test_do_start_call_ok() { #[test] fn test_do_start_call_fail_with_not_existed_subnet() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey_account_id = U256::from(0); assert_noop!( SubtensorModule::start_call( @@ -54,7 +54,7 @@ fn test_do_start_call_fail_with_not_existed_subnet() { #[test] fn test_do_start_call_fail_not_owner() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let coldkey_account_id = U256::from(0); let wrong_owner_account_id = U256::from(1); @@ -78,7 +78,7 @@ fn test_do_start_call_fail_not_owner() { #[test] fn test_do_start_call_fail_with_cannot_start_call_now() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let coldkey_account_id = U256::from(0); @@ -99,7 +99,7 @@ fn test_do_start_call_fail_with_cannot_start_call_now() { #[test] fn test_do_start_call_fail_for_set_again() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let coldkey_account_id = U256::from(0); @@ -129,7 +129,7 @@ fn test_do_start_call_fail_for_set_again() { #[test] fn test_do_start_call_ok_with_same_block_number_after_coinbase() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let coldkey_account_id = U256::from(0); @@ -205,7 +205,6 @@ fn test_no_duplicates_in_get_symbol_for_subnet() { let mut seen = HashSet::new(); for netuid in 0u16..=438 { - let netuid = NetUid::from(netuid); let symbol = Pallet::::get_symbol_for_subnet(netuid); assert!( seen.insert(symbol.clone()), @@ -223,7 +222,7 @@ fn test_subtoken_enable() { // ensure_subtoken_enabled new_test_ext(1).execute_with(|| { let account = U256::from(0); - let netuid = NetUid::from(1); + let netuid: u16 = 1; // let to_be_set: u64 = 10 add_network_disable_subtoken(netuid, 10, 0); assert!(!SubtokenEnabled::::get(netuid)); @@ -247,8 +246,8 @@ fn test_subtoken_enable() { fn test_subtoken_enable_reject_trading_before_enable() { // ensure_subtoken_enabled new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid: u16 = 1; + let netuid2: u16 = 2; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(2); let hotkey_account_2_id: U256 = U256::from(3); @@ -424,8 +423,8 @@ fn test_subtoken_enable_reject_trading_before_enable() { #[test] fn test_subtoken_enable_trading_ok_with_enable() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid: u16 = 1; + let netuid2: u16 = 2; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(2); let hotkey_account_2_id: U256 = U256::from(3); @@ -537,8 +536,8 @@ fn test_subtoken_enable_trading_ok_with_enable() { fn test_subtoken_enable_ok_for_burn_register_before_enable() { // ensure_subtoken_enabled new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid: u16 = 1; + let netuid2: u16 = 2; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(2); let hotkey_account_2_id: U256 = U256::from(3); diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index e2afc98c89..385830904c 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -53,7 +53,7 @@ fn test_swap_subnet_owner() { new_test_ext(1).execute_with(|| { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); - let netuid = NetUid::from(1u16); + let netuid = 1u16; add_network(netuid, 1, 0); SubnetOwner::::insert(netuid, old_coldkey); @@ -80,7 +80,7 @@ fn test_swap_total_coldkey_stake() { let other_hotkey = U256::from(5); let stake = DefaultMinStake::::get() * 10; - let netuid = NetUid::from(1u16); + let netuid = 1u16; add_network(netuid, 1, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake * 2 + 1_000); register_ok_neuron(netuid, hotkey, old_coldkey, 1001000); @@ -242,8 +242,8 @@ fn test_swap_with_multiple_subnets() { new_test_ext(1).execute_with(|| { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1 = 1u16; + let netuid2 = 2u16; add_network(netuid1, 1, 0); add_network(netuid2, 1, 0); @@ -288,7 +288,7 @@ fn test_swap_idempotency() { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); let hotkey = U256::from(3); - let netuid = NetUid::from(1u16); + let netuid = 1u16; let stake = DefaultMinStake::::get() * 10; // Add a network @@ -340,8 +340,8 @@ fn test_swap_with_max_values() { let hotkey = U256::from(5); let hotkey2 = U256::from(6); let other_coldkey = U256::from(7); - let netuid = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid = 1u16; + let netuid2 = 2u16; let stake = 10_000; let max_stake = 21_000_000_000_000_000; // 21 Million TAO; max possible balance. let fee = DefaultStakingFee::::get(); @@ -412,7 +412,7 @@ fn test_swap_with_non_existent_new_coldkey() { let new_coldkey = U256::from(2); let hotkey = U256::from(3); let stake = DefaultMinStake::::get() * 10; - let netuid = NetUid::from(1u16); + let netuid = 1u16; let fee = DefaultStakingFee::::get(); add_network(netuid, 1, 0); @@ -535,7 +535,7 @@ fn test_swap_concurrent_modifications() { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); let hotkey = U256::from(3); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let initial_stake = 1_000_000_000_000; let additional_stake = 500_000_000_000; let initial_stake_alpha = @@ -616,7 +616,7 @@ fn test_swap_with_invalid_subnet_ownership() { new_test_ext(1).execute_with(|| { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); - let netuid = NetUid::from(1u16); + let netuid = 1u16; SubnetOwner::::insert(netuid, old_coldkey); @@ -643,7 +643,7 @@ fn test_do_swap_coldkey_success() { let new_coldkey = U256::from(2); let hotkey1 = U256::from(3); let hotkey2 = U256::from(4); - let netuid = NetUid::from(1u16); + let netuid = 1u16; let stake_amount1 = DefaultMinStake::::get() * 10; let stake_amount2 = DefaultMinStake::::get() * 20; let swap_cost = SubtensorModule::get_key_swap_cost(); @@ -828,7 +828,7 @@ fn test_swap_stake_for_coldkey() { // Setup initial state // Add a network - let netuid = NetUid::from(1u16); + let netuid = 1u16; add_network(netuid, 1, 0); // Register hotkeys @@ -984,7 +984,7 @@ fn test_swap_staking_hotkeys_for_coldkey() { // Setup initial state // Add a network - let netuid = NetUid::from(1u16); + let netuid = 1u16; add_network(netuid, 1, 0); // Give some balance to old coldkey SubtensorModule::add_balance_to_coldkey_account( @@ -1051,7 +1051,7 @@ fn test_swap_delegated_stake_for_coldkey() { let stake_amount1 = DefaultMinStake::::get() * 10; let stake_amount2 = DefaultMinStake::::get() * 20; let mut weight = Weight::zero(); - let netuid = NetUid::from(1u16); + let netuid = 1u16; let fee = DefaultStakingFee::::get(); // Setup initial state @@ -1174,8 +1174,8 @@ fn test_swap_subnet_owner_for_coldkey() { new_test_ext(1).execute_with(|| { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1 = 1u16; + let netuid2 = 2u16; let mut weight = Weight::zero(); // Initialize SubnetOwner for old_coldkey @@ -1203,7 +1203,7 @@ fn test_do_swap_coldkey_with_subnet_ownership() { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); let hotkey = U256::from(3); - let netuid = NetUid::from(1u16); + let netuid = 1u16; let stake_amount: u64 = 1000u64; let swap_cost = SubtensorModule::get_key_swap_cost(); @@ -1237,7 +1237,7 @@ fn test_coldkey_has_associated_hotkeys() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let hotkey = U256::from(2); - let netuid = NetUid::from(1u16); + let netuid = 1u16; // Setup initial state add_network(netuid, 13, 0); @@ -1260,9 +1260,9 @@ fn test_coldkey_swap_total() { let hotkey1 = U256::from(2); let hotkey2 = U256::from(3); let hotkey3 = U256::from(4); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); - let netuid3 = NetUid::from(3); + let netuid1 = 1u16; + let netuid2 = 2u16; + let netuid3 = 3u16; let stake = DefaultMinStake::::get() * 10; SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake * 6); SubtensorModule::add_balance_to_coldkey_account(&delegate1, stake * 2); @@ -1610,8 +1610,8 @@ fn test_coldkey_delegations() { let owner = U256::from(1); let coldkey = U256::from(4); let delegate = U256::from(2); - let netuid = NetUid::from(0); // Stake to 0 - let netuid2 = NetUid::from(1); // Stake to 1 + let netuid = 0u16; // Stake to 0 + let netuid2 = 1u16; // Stake to 1 let stake = DefaultMinStake::::get() * 10; let fee = DefaultStakingFee::::get(); @@ -1750,7 +1750,7 @@ fn test_schedule_swap_coldkey_execution() { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); let hotkey = U256::from(3); - let netuid = NetUid::from(1u16); + let netuid = 1u16; let stake_amount = DefaultMinStake::::get() * 10; add_network(netuid, 13, 0); @@ -1954,7 +1954,7 @@ fn test_coldkey_swap_delegate_identity_updated() { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid = 1; let burn_cost = 10; let tempo = 1; @@ -2006,7 +2006,7 @@ fn test_coldkey_swap_no_identity_no_changes() { let old_coldkey = U256::from(1); let new_coldkey = U256::from(2); - let netuid = NetUid::from(1); + let netuid = 1; let burn_cost = 10; let tempo = 1; @@ -2043,7 +2043,7 @@ fn test_coldkey_swap_no_identity_no_changes_newcoldkey_exists() { let old_coldkey = U256::from(3); let new_coldkey = U256::from(4); - let netuid = NetUid::from(1); + let netuid = 1; let burn_cost = 10; let tempo = 1; @@ -2113,7 +2113,7 @@ fn test_coldkey_in_swap_schedule_prevents_funds_usage() { // while a coldkey swap is scheduled. new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let coldkey = U256::from(0); let new_coldkey = U256::from(1); @@ -2368,7 +2368,7 @@ fn test_coldkey_in_swap_schedule_prevents_critical_calls() { // while a coldkey swap is scheduled. new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let coldkey = U256::from(0); let new_coldkey = U256::from(1); diff --git a/pallets/subtensor/src/tests/swap_hotkey.rs b/pallets/subtensor/src/tests/swap_hotkey.rs index ba003b442c..0d6b24d7c0 100644 --- a/pallets/subtensor/src/tests/swap_hotkey.rs +++ b/pallets/subtensor/src/tests/swap_hotkey.rs @@ -69,7 +69,7 @@ fn test_swap_total_hotkey_stake() { let fee = DefaultStakingFee::::get(); //add network - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey, amount); @@ -173,7 +173,7 @@ fn test_swap_subnet_membership() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let mut weight = Weight::zero(); add_network(netuid, 1, 1); @@ -197,7 +197,7 @@ fn test_swap_uids_and_keys() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let uid = 5u16; let mut weight = Weight::zero(); @@ -226,7 +226,7 @@ fn test_swap_prometheus() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let prometheus_info = PrometheusInfo::default(); let mut weight = Weight::zero(); @@ -256,7 +256,7 @@ fn test_swap_axons() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let axon_info = AxonInfo::default(); let mut weight = Weight::zero(); @@ -283,7 +283,7 @@ fn test_swap_certificates() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let certificate = NeuronCertificate::try_from(vec![1, 2, 3]).unwrap(); let mut weight = Weight::zero(); @@ -315,7 +315,7 @@ fn test_swap_weight_commits() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let mut weight_commits: VecDeque<(H256, u64, u64, u64)> = VecDeque::new(); weight_commits.push_back((H256::from_low_u64_be(100), 200, 1, 1)); let mut weight = Weight::zero(); @@ -346,7 +346,7 @@ fn test_swap_loaded_emission() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let server_emission = 1000u64; let validator_emission = 1000u64; let mut weight = Weight::zero(); @@ -386,7 +386,6 @@ fn test_swap_staking_hotkeys() { let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); let mut weight = Weight::zero(); - let netuid = NetUid::from(1); StakingHotkeys::::insert(coldkey, vec![old_hotkey]); Alpha::::insert((old_hotkey, coldkey, netuid), U64F64::from_num(100)); @@ -473,8 +472,8 @@ fn test_swap_hotkey_with_multiple_subnets() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid1 = NetUid::from(0); - let netuid2 = NetUid::from(1); + let netuid1 = 0; + let netuid2 = 1; let mut weight = Weight::zero(); add_network(netuid1, 1, 1); @@ -600,8 +599,8 @@ fn test_swap_hotkey_with_multiple_coldkeys_and_subnets() { let new_hotkey = U256::from(2); let coldkey1 = U256::from(3); let coldkey2 = U256::from(4); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1 = 1; + let netuid2 = 2; let stake = DefaultMinStake::::get() * 10; let mut weight = Weight::zero(); @@ -725,7 +724,7 @@ fn test_swap_hotkey_with_multiple_coldkeys_and_subnets() { #[test] fn test_swap_hotkey_tx_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let old_hotkey = U256::from(1); let new_hotkey_1 = U256::from(2); @@ -783,7 +782,7 @@ fn test_swap_hotkey_tx_rate_limit_exceeded() { #[test] fn test_do_swap_hotkey_err_not_owner() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); @@ -946,7 +945,6 @@ fn test_swap_stake_old_hotkey_not_exist() { let alpha_share = U64F64::from_num(1234); let mut weight = Weight::zero(); - let netuid = NetUid::from(1); // Initialize Stake for old_hotkey Alpha::::insert((old_hotkey, coldkey, netuid), alpha_share); @@ -1036,7 +1034,7 @@ fn test_swap_hotkey_error_cases() { ); // Test new hotkey already registered - IsNetworkMember::::insert(new_hotkey, NetUid::ROOT, true); + IsNetworkMember::::insert(new_hotkey, 0, true); assert_noop!( SubtensorModule::do_swap_hotkey( RuntimeOrigin::signed(coldkey), @@ -1046,7 +1044,7 @@ fn test_swap_hotkey_error_cases() { ), Error::::HotKeyAlreadyRegisteredInSubNet ); - IsNetworkMember::::remove(new_hotkey, NetUid::ROOT); + IsNetworkMember::::remove(new_hotkey, 0); // Test non-associated coldkey assert_noop!( @@ -1079,7 +1077,7 @@ fn test_swap_child_keys() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let children = vec![(100u64, U256::from(4)), (200u64, U256::from(5))]; let mut weight = Weight::zero(); @@ -1108,7 +1106,7 @@ fn test_swap_parent_keys() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let parents = vec![(100u64, U256::from(4)), (200u64, U256::from(5))]; let mut weight = Weight::zero(); @@ -1151,8 +1149,8 @@ fn test_swap_multiple_subnets() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid1 = NetUid::from(0); - let netuid2 = NetUid::from(1); + let netuid1 = 0u16; + let netuid2 = 1u16; let children1 = vec![(100u64, U256::from(4)), (200u64, U256::from(5))]; let children2 = vec![(300u64, U256::from(6))]; let mut weight = Weight::zero(); @@ -1187,7 +1185,7 @@ fn test_swap_complex_parent_child_structure() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = NetUid::from(0u16); + let netuid = 0u16; let parent1 = U256::from(4); let parent2 = U256::from(5); let child1 = U256::from(6); @@ -1251,7 +1249,7 @@ fn test_swap_complex_parent_child_structure() { #[test] fn test_swap_parent_hotkey_childkey_maps() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let parent_old = U256::from(1); let coldkey = U256::from(2); let child = U256::from(3); @@ -1306,7 +1304,7 @@ fn test_swap_parent_hotkey_childkey_maps() { #[test] fn test_swap_child_hotkey_childkey_maps() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let parent = U256::from(1); let coldkey = U256::from(2); let child_old = U256::from(3); @@ -1392,7 +1390,7 @@ fn test_swap_hotkey_swap_rate_limits() { let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); let last_tx_block = 123; diff --git a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs index 7ed66cd8ac..583a8cf448 100644 --- a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs +++ b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs @@ -19,7 +19,7 @@ fn test_swap_owner() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); Owner::::insert(old_hotkey, coldkey); System::set_block_number(System::block_number() + HotkeySwapOnSubnetInterval::get()); @@ -43,7 +43,7 @@ fn test_swap_owned_hotkeys() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); OwnedHotkeys::::insert(coldkey, vec![old_hotkey]); @@ -73,7 +73,7 @@ fn test_swap_total_hotkey_stake() { let fee = DefaultStakingFee::::get(); //add network - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); @@ -129,7 +129,7 @@ fn test_swap_senate_members() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); assert_ok!(SenateMembers::add_member(RuntimeOrigin::root(), old_hotkey)); @@ -156,7 +156,7 @@ fn test_swap_delegates() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); Delegates::::insert(old_hotkey, 100); @@ -181,7 +181,7 @@ fn test_swap_subnet_membership() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -207,7 +207,7 @@ fn test_swap_uids_and_keys() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -239,7 +239,7 @@ fn test_swap_prometheus() { let prometheus_info = PrometheusInfo::default(); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -272,7 +272,7 @@ fn test_swap_axons() { let axon_info = AxonInfo::default(); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -302,7 +302,7 @@ fn test_swap_certificates() { let certificate = NeuronCertificate::try_from(vec![1, 2, 3]).unwrap(); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -338,7 +338,7 @@ fn test_swap_weight_commits() { let mut weight_commits: VecDeque<(H256, u64, u64, u64)> = VecDeque::new(); weight_commits.push_back((H256::from_low_u64_be(100), 200, 1, 1)); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -372,7 +372,7 @@ fn test_swap_loaded_emission() { let server_emission = 1000u64; let validator_emission = 1000u64; - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); IsNetworkMember::::insert(old_hotkey, netuid, true); @@ -630,8 +630,8 @@ fn test_swap_hotkey_with_multiple_coldkeys_and_subnets() { let new_hotkey = U256::from(2); let coldkey1 = U256::from(3); let coldkey2 = U256::from(4); - let netuid1 = NetUid::from(1); - let netuid2 = NetUid::from(2); + let netuid1 = 1; + let netuid2 = 2; let stake = DefaultMinStake::::get() * 10; // Set up initial state @@ -763,7 +763,7 @@ fn test_swap_hotkey_with_multiple_coldkeys_and_subnets() { #[test] fn test_swap_hotkey_tx_rate_limit_exceeded() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let old_hotkey = U256::from(1); let new_hotkey_1 = U256::from(2); @@ -823,7 +823,7 @@ fn test_swap_hotkey_tx_rate_limit_exceeded() { #[test] fn test_do_swap_hotkey_err_not_owner() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let old_hotkey = U256::from(1); let new_hotkey = U256::from(2); @@ -1443,7 +1443,7 @@ fn test_swap_owner_failed_interval_not_passed() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); Owner::::insert(old_hotkey, coldkey); assert_err!( @@ -1465,7 +1465,7 @@ fn test_swap_owner_check_swap_block_set() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); Owner::::insert(old_hotkey, coldkey); let new_block_number = System::block_number() + HotkeySwapOnSubnetInterval::get(); @@ -1491,7 +1491,7 @@ fn test_swap_owner_check_swap_record_clean_up() { let new_hotkey = U256::from(2); let coldkey = U256::from(3); - let netuid = add_dynamic_network(&old_hotkey, &coldkey); + let netuid: u16 = add_dynamic_network(&old_hotkey, &coldkey); SubtensorModule::add_balance_to_coldkey_account(&coldkey, u64::MAX); Owner::::insert(old_hotkey, coldkey); let new_block_number = System::block_number() + HotkeySwapOnSubnetInterval::get(); @@ -1508,7 +1508,7 @@ fn test_swap_owner_check_swap_record_clean_up() { new_block_number ); - step_block((HotkeySwapOnSubnetInterval::get() as u16 + u16::from(netuid)) * 2); + step_block((HotkeySwapOnSubnetInterval::get() as u16 + netuid) * 2); assert!(!LastHotkeySwapOnNetuid::::contains_key( netuid, coldkey )); diff --git a/pallets/subtensor/src/tests/uids.rs b/pallets/subtensor/src/tests/uids.rs index 49233f105c..92a8a64048 100644 --- a/pallets/subtensor/src/tests/uids.rs +++ b/pallets/subtensor/src/tests/uids.rs @@ -18,7 +18,7 @@ use sp_core::U256; fn test_replace_neuron() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( @@ -149,7 +149,7 @@ fn test_replace_neuron() { fn test_bonds_cleared_on_replace() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( @@ -216,8 +216,8 @@ fn test_bonds_cleared_on_replace() { fn test_replace_neuron_multiple_subnets() { new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - let netuid = NetUid::from(1); - let netuid1 = NetUid::from(2); + let netuid: u16 = 1; + let netuid1: u16 = 2; let tempo: u16 = 13; let hotkey_account_id = U256::from(1); let new_hotkey_account_id = U256::from(2); diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index eb189d1ab5..3d240750cf 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -40,7 +40,7 @@ fn test_set_weights_dispatch_info_ok() { new_test_ext(0).execute_with(|| { let dests = vec![1, 1]; let weights = vec![1, 1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let call = RuntimeCall::SubtensorModule(SubtensorCall::set_weights { netuid, @@ -64,7 +64,7 @@ fn test_set_rootweights_validate() { new_test_ext(0).execute_with(|| { let dests = vec![1, 1]; let weights = vec![1, 1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let coldkey = U256::from(0); let hotkey: U256 = U256::from(1); // Add the hotkey field @@ -152,7 +152,7 @@ fn test_commit_weights_dispatch_info_ok() { new_test_ext(0).execute_with(|| { let dests = vec![1, 1]; let weights = vec![1, 1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; let version_key: u64 = 0; let hotkey: U256 = U256::from(1); @@ -180,7 +180,7 @@ fn test_commit_weights_validate() { new_test_ext(0).execute_with(|| { let dests = vec![1, 1]; let weights = vec![1, 1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; let version_key: u64 = 0; let coldkey = U256::from(0); @@ -267,7 +267,7 @@ fn test_reveal_weights_dispatch_info_ok() { new_test_ext(0).execute_with(|| { let dests = vec![1, 1]; let weights = vec![1, 1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; let version_key: u64 = 0; @@ -292,7 +292,7 @@ fn test_set_weights_validate() { // correctly filters the `set_weights` transaction. new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let coldkey = U256::from(0); let hotkey: U256 = U256::from(1); assert_ne!(hotkey, coldkey); @@ -365,7 +365,7 @@ fn test_reveal_weights_validate() { new_test_ext(0).execute_with(|| { let dests = vec![1, 1]; let weights = vec![1, 1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; let version_key: u64 = 0; let coldkey = U256::from(0); @@ -451,6 +451,8 @@ fn test_reveal_weights_validate() { #[test] fn test_set_weights_is_root_error() { new_test_ext(0).execute_with(|| { + let root_netuid: u16 = 0; + let uids = vec![0]; let weights = vec![1]; let version_key: u64 = 0; @@ -459,7 +461,7 @@ fn test_set_weights_is_root_error() { assert_err!( SubtensorModule::set_weights( RuntimeOrigin::signed(hotkey), - NetUid::ROOT, + root_netuid, uids.clone(), weights.clone(), version_key, @@ -475,7 +477,7 @@ fn test_set_weights_is_root_error() { fn test_weights_err_no_validator_permit() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(55); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; add_network(netuid, tempo, 0); SubtensorModule::set_min_allowed_weights(netuid, 0); @@ -520,7 +522,7 @@ fn test_set_stake_threshold_failed() { new_test_ext(0).execute_with(|| { let dests = vec![0]; let weights = vec![1]; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let version_key: u64 = 0; let hotkey = U256::from(0); let coldkey = U256::from(0); @@ -584,8 +586,8 @@ fn test_weights_version_key() { new_test_ext(0).execute_with(|| { let hotkey = U256::from(55); let coldkey = U256::from(66); - let netuid0 = NetUid::from(1); - let netuid1 = NetUid::from(2); + let netuid0: u16 = 1; + let netuid1: u16 = 2; add_network(netuid0, 1, 0); add_network(netuid1, 1, 0); @@ -661,7 +663,7 @@ fn test_weights_version_key() { fn test_weights_err_setting_weights_too_fast() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(55); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; add_network(netuid, tempo, 0); SubtensorModule::set_min_allowed_weights(netuid, 0); @@ -724,11 +726,11 @@ fn test_weights_err_setting_weights_too_fast() { fn test_weights_err_weights_vec_not_equal_size() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(55); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; add_network(netuid, tempo, 0); - register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); + register_ok_neuron(1, hotkey_account_id, U256::from(66), 0); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id) .expect("Not registered."); @@ -737,7 +739,7 @@ fn test_weights_err_weights_vec_not_equal_size() { let weight_values: Vec = vec![1, 2, 3, 4, 5]; // Uneven sizes let result = commit_reveal_set_weights( hotkey_account_id, - 1.into(), + 1, weights_keys.clone(), weight_values.clone(), salt.clone(), @@ -753,7 +755,7 @@ fn test_weights_err_weights_vec_not_equal_size() { fn test_weights_err_has_duplicate_ids() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(666); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; add_network(netuid, tempo, 0); @@ -814,7 +816,7 @@ fn test_weights_err_max_weight_limit() { //TO DO SAM: uncomment when we implement run_to_block fn new_test_ext(0).execute_with(|| { // Add network. - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 100; add_network(netuid, tempo, 0); @@ -876,13 +878,8 @@ fn test_weights_err_max_weight_limit() { // Non self-weight fails. let uids: Vec = vec![1, 2, 3, 4]; let values: Vec = vec![u16::MAX / 4, u16::MAX / 4, u16::MAX / 54, u16::MAX / 4]; - let result = SubtensorModule::set_weights( - RuntimeOrigin::signed(U256::from(0)), - 1.into(), - uids, - values, - 0, - ); + let result = + SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(0)), 1, uids, values, 0); assert_eq!(result, Err(Error::::MaxWeightExceeded.into())); // Self-weight is a success. @@ -890,7 +887,7 @@ fn test_weights_err_max_weight_limit() { let values: Vec = vec![u16::MAX]; // normalizes to u32::MAX assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(0)), - 1.into(), + 1, uids, values, 0 @@ -905,7 +902,7 @@ fn test_no_signature() { new_test_ext(0).execute_with(|| { let uids: Vec = vec![]; let values: Vec = vec![]; - let result = SubtensorModule::set_weights(RuntimeOrigin::none(), 1.into(), uids, values, 0); + let result = SubtensorModule::set_weights(RuntimeOrigin::none(), 1, uids, values, 0); assert_eq!(result, Err(DispatchError::BadOrigin)); }); } @@ -915,27 +912,21 @@ fn test_no_signature() { #[test] fn test_set_weights_err_not_active() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; add_network(netuid, tempo, 0); // Register one neuron. Should have uid 0 - register_ok_neuron(netuid, U256::from(666), U256::from(2), 100000); + register_ok_neuron(1, U256::from(666), U256::from(2), 100000); SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(666)) .expect("Not registered."); let weights_keys: Vec = vec![0]; // Uid 0 is valid. let weight_values: Vec = vec![1]; // This hotkey is NOT registered. - let result = commit_reveal_set_weights( - U256::from(1), - 1.into(), - weights_keys, - weight_values, - salt, - 0, - ); + let result = + commit_reveal_set_weights(U256::from(1), 1, weights_keys, weight_values, salt, 0); assert_eq!( result, Err(Error::::HotKeyNotRegisteredInSubNet.into()) @@ -949,11 +940,11 @@ fn test_set_weights_err_not_active() { fn test_set_weights_err_invalid_uid() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(55); - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; add_network(netuid, tempo, 0); - register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); + register_ok_neuron(1, hotkey_account_id, U256::from(66), 0); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id) .expect("Not registered."); @@ -968,14 +959,8 @@ fn test_set_weights_err_invalid_uid() { ); let weight_keys: Vec = vec![9999]; // Does not exist let weight_values: Vec = vec![88]; // random value - let result = commit_reveal_set_weights( - hotkey_account_id, - netuid, - weight_keys, - weight_values, - salt, - 0, - ); + let result = + commit_reveal_set_weights(hotkey_account_id, 1, weight_keys, weight_values, salt, 0); assert_eq!(result, Err(Error::::UidVecContainInvalidOne.into())); }); } @@ -985,13 +970,13 @@ fn test_set_weights_err_invalid_uid() { #[test] fn test_set_weight_not_enough_values() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; let account_id = U256::from(1); add_network(netuid, tempo, 0); - register_ok_neuron(netuid, account_id, U256::from(2), 100000); + register_ok_neuron(1, account_id, U256::from(2), 100000); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(1)) .expect("Not registered."); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid, true); @@ -1004,7 +989,7 @@ fn test_set_weight_not_enough_values() { 1, ); - register_ok_neuron(netuid, U256::from(3), U256::from(4), 300000); + register_ok_neuron(1, U256::from(3), U256::from(4), 300000); SubtensorModule::set_min_allowed_weights(netuid, 2); // Should fail because we are only setting a single value and its not the self weight. @@ -1012,7 +997,7 @@ fn test_set_weight_not_enough_values() { let weight_values: Vec = vec![88]; // random value. let result = SubtensorModule::set_weights( RuntimeOrigin::signed(account_id), - 1.into(), + 1, weight_keys, weight_values, 0, @@ -1024,7 +1009,7 @@ fn test_set_weight_not_enough_values() { let weight_values: Vec = vec![88]; // random value. assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(account_id), - 1.into(), + 1, weight_keys, weight_values, 0 @@ -1036,7 +1021,7 @@ fn test_set_weight_not_enough_values() { SubtensorModule::set_min_allowed_weights(netuid, 1); assert_ok!(commit_reveal_set_weights( account_id, - 1.into(), + 1, weight_keys, weight_values, salt, @@ -1050,17 +1035,17 @@ fn test_set_weight_not_enough_values() { #[test] fn test_set_weight_too_many_uids() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; add_network(netuid, tempo, 0); - register_ok_neuron(1.into(), U256::from(1), U256::from(2), 100_000); + register_ok_neuron(1, U256::from(1), U256::from(2), 100_000); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(1)) .expect("Not registered."); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid, true); - register_ok_neuron(1.into(), U256::from(3), U256::from(4), 300_000); - SubtensorModule::set_min_allowed_weights(1.into(), 2); + register_ok_neuron(1, U256::from(3), U256::from(4), 300_000); + SubtensorModule::set_min_allowed_weights(1, 2); SubtensorModule::set_max_weight_limit(netuid, u16::MAX); // Should fail because we are setting more weights than there are neurons. @@ -1068,7 +1053,7 @@ fn test_set_weight_too_many_uids() { let weight_values: Vec = vec![88, 102, 303, 1212, 11]; // random value. let result = SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(1)), - 1.into(), + 1, weight_keys, weight_values, 0, @@ -1083,7 +1068,7 @@ fn test_set_weight_too_many_uids() { let weight_values: Vec = vec![10, 10]; // random value. assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(1)), - 1.into(), + 1, weight_keys, weight_values, 0 @@ -1096,12 +1081,12 @@ fn test_set_weight_too_many_uids() { #[test] fn test_set_weights_sum_larger_than_u16_max() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; add_network(netuid, tempo, 0); - register_ok_neuron(1.into(), U256::from(1), U256::from(2), 100_000); + register_ok_neuron(1, U256::from(1), U256::from(2), 100_000); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(1)) .expect("Not registered."); SubtensorModule::set_stake_threshold(0); @@ -1115,8 +1100,8 @@ fn test_set_weights_sum_larger_than_u16_max() { 1, ); - register_ok_neuron(1.into(), U256::from(3), U256::from(4), 300_000); - SubtensorModule::set_min_allowed_weights(1.into(), 2); + register_ok_neuron(1, U256::from(3), U256::from(4), 300_000); + SubtensorModule::set_min_allowed_weights(1, 2); // Shouldn't fail because we are setting the right number of weights. let weight_keys: Vec = vec![0, 1]; @@ -1125,7 +1110,7 @@ fn test_set_weights_sum_larger_than_u16_max() { assert!(weight_values.iter().map(|x| *x as u64).sum::() > (u16::MAX as u64)); let result = - commit_reveal_set_weights(U256::from(1), 1.into(), weight_keys, weight_values, salt, 0); + commit_reveal_set_weights(U256::from(1), 1, weight_keys, weight_values, salt, 0); assert_ok!(result); // Get max-upscaled unnormalized weights. @@ -1141,7 +1126,7 @@ fn test_set_weights_sum_larger_than_u16_max() { #[test] fn test_check_length_allows_singleton() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_allowed: u16 = 1; let min_allowed_weights = max_allowed; @@ -1164,7 +1149,7 @@ fn test_check_length_allows_singleton() { #[test] fn test_check_length_weights_length_exceeds_min_allowed() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let max_allowed: u16 = 3; let min_allowed_weights = max_allowed; @@ -1187,7 +1172,7 @@ fn test_check_length_weights_length_exceeds_min_allowed() { #[test] fn test_check_length_to_few_weights() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let min_allowed_weights = 3; @@ -1195,13 +1180,13 @@ fn test_check_length_to_few_weights() { SubtensorModule::set_target_registrations_per_interval(netuid, 100); SubtensorModule::set_max_registrations_per_block(netuid, 100); // register morw than min allowed - register_ok_neuron(1.into(), U256::from(1), U256::from(1), 300_000); - register_ok_neuron(1.into(), U256::from(2), U256::from(2), 300_001); - register_ok_neuron(1.into(), U256::from(3), U256::from(3), 300_002); - register_ok_neuron(1.into(), U256::from(4), U256::from(4), 300_003); - register_ok_neuron(1.into(), U256::from(5), U256::from(5), 300_004); - register_ok_neuron(1.into(), U256::from(6), U256::from(6), 300_005); - register_ok_neuron(1.into(), U256::from(7), U256::from(7), 300_006); + register_ok_neuron(1, U256::from(1), U256::from(1), 300_000); + register_ok_neuron(1, U256::from(2), U256::from(2), 300_001); + register_ok_neuron(1, U256::from(3), U256::from(3), 300_002); + register_ok_neuron(1, U256::from(4), U256::from(4), 300_003); + register_ok_neuron(1, U256::from(5), U256::from(5), 300_004); + register_ok_neuron(1, U256::from(6), U256::from(6), 300_005); + register_ok_neuron(1, U256::from(7), U256::from(7), 300_006); SubtensorModule::set_min_allowed_weights(netuid, min_allowed_weights); let uids: Vec = Vec::from_iter((0..2).map(|id| id + 1)); @@ -1257,7 +1242,7 @@ fn test_max_weight_limited_allow_self_weights_to_exceed_max_weight_limit() { new_test_ext(0).execute_with(|| { let max_allowed: u16 = 1; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = Vec::from_iter((0..max_allowed).map(|id| id + 1)); let uid: u16 = uids[0]; let weights: Vec = vec![0]; @@ -1279,7 +1264,7 @@ fn test_max_weight_limited_when_weight_limit_is_u16_max() { new_test_ext(0).execute_with(|| { let max_allowed: u16 = 3; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = Vec::from_iter((0..max_allowed).map(|id| id + 1)); let uid: u16 = uids[0]; let weights: Vec = Vec::from_iter((0..max_allowed).map(|_id| u16::MAX)); @@ -1302,7 +1287,7 @@ fn test_max_weight_limited_when_max_weight_is_within_limit() { let max_allowed: u16 = 1; let max_weight_limit = u16::MAX / 5; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = Vec::from_iter((0..max_allowed).map(|id| id + 1)); let uid: u16 = uids[0]; let weights: Vec = Vec::from_iter((0..max_allowed).map(|id| max_weight_limit - id)); @@ -1327,7 +1312,7 @@ fn test_max_weight_limited_when_guard_checks_are_not_triggered() { let max_allowed: u16 = 3; let max_weight_limit = u16::MAX / 5; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = Vec::from_iter((0..max_allowed).map(|id| id + 1)); let uid: u16 = uids[0]; let weights: Vec = Vec::from_iter((0..max_allowed).map(|id| max_weight_limit + id)); @@ -1413,7 +1398,7 @@ fn test_is_self_weight_uid_in_uids() { #[test] fn test_check_len_uids_within_allowed_within_network_pool() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let modality: u16 = 0; @@ -1446,7 +1431,7 @@ fn test_check_len_uids_within_allowed_within_network_pool() { #[test] fn test_check_len_uids_within_allowed_not_within_network_pool() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let tempo: u16 = 13; let modality: u16 = 0; @@ -1479,7 +1464,7 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { #[test] fn test_set_weights_commit_reveal_enabled_error() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 1, 0); register_ok_neuron(netuid, U256::from(1), U256::from(2), 10); @@ -1517,7 +1502,7 @@ fn test_set_weights_commit_reveal_enabled_error() { #[test] fn test_reveal_weights_when_commit_reveal_disabled() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -1577,7 +1562,7 @@ fn test_reveal_weights_when_commit_reveal_disabled() { #[test] fn test_commit_reveal_weights_ok() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -1646,7 +1631,7 @@ fn test_commit_reveal_weights_ok() { #[test] fn test_commit_reveal_tempo_interval() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -1792,7 +1777,7 @@ fn test_commit_reveal_tempo_interval() { #[test] fn test_commit_reveal_hash() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -1884,7 +1869,7 @@ fn test_commit_reveal_hash() { #[test] fn test_commit_reveal_disabled_or_enabled() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -1961,7 +1946,7 @@ fn test_commit_reveal_disabled_or_enabled() { #[test] fn test_toggle_commit_reveal_weights_and_set_weights() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -2044,7 +2029,7 @@ fn test_toggle_commit_reveal_weights_and_set_weights() { #[test] fn test_tempo_change_during_commit_reveal_process() { new_test_ext(0).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -2202,7 +2187,7 @@ fn test_tempo_change_during_commit_reveal_process() { #[test] fn test_commit_reveal_multiple_commits() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let version_key: u64 = 0; @@ -2568,7 +2553,7 @@ fn test_commit_reveal_multiple_commits() { fn commit_reveal_set_weights( hotkey: U256, - netuid: NetUid, + netuid: u16, uids: Vec, weights: Vec, salt: Vec, @@ -2605,7 +2590,7 @@ fn commit_reveal_set_weights( #[test] fn test_expired_commits_handling_in_commit_and_reveal() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: ::AccountId = U256::from(1); let version_key: u64 = 0; let uids: Vec = vec![0, 1]; @@ -2804,7 +2789,7 @@ fn test_expired_commits_handling_in_commit_and_reveal() { #[test] fn test_reveal_at_exact_epoch() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: ::AccountId = U256::from(1); let version_key: u64 = 0; let uids: Vec = vec![0, 1]; @@ -2954,7 +2939,7 @@ fn test_reveal_at_exact_epoch() { #[test] fn test_tempo_and_reveal_period_change_during_commit_reveal_process() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![42; 8]; @@ -3158,7 +3143,7 @@ fn test_tempo_and_reveal_period_change_during_commit_reveal_process() { #[test] fn test_commit_reveal_order_enforcement() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: ::AccountId = U256::from(1); let version_key: u64 = 0; let uids: Vec = vec![0, 1]; @@ -3260,7 +3245,7 @@ fn test_commit_reveal_order_enforcement() { #[test] fn test_reveal_at_exact_block() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: ::AccountId = U256::from(1); let version_key: u64 = 0; let uids: Vec = vec![0, 1]; @@ -3319,7 +3304,7 @@ fn test_reveal_at_exact_block() { // Calculate the block number where the reveal epoch starts let tempo_plus_one = (tempo as u64).saturating_add(1); - let netuid_plus_one = (u16::from(netuid) as u64).saturating_add(1); + let netuid_plus_one = (netuid as u64).saturating_add(1); let reveal_epoch_start_block = reveal_epoch .saturating_mul(tempo_plus_one) .saturating_sub(netuid_plus_one); @@ -3430,7 +3415,7 @@ fn test_reveal_at_exact_block() { #[test] fn test_successful_batch_reveal() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0, 0, 0]; let uids_list: Vec> = vec![vec![0, 1], vec![1, 0], vec![0, 1]]; @@ -3508,7 +3493,7 @@ fn test_successful_batch_reveal() { #[test] fn test_batch_reveal_with_expired_commits() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0, 0, 0]; let uids_list: Vec> = vec![vec![0, 1], vec![1, 0], vec![0, 1]]; @@ -3629,7 +3614,7 @@ fn test_batch_reveal_with_expired_commits() { #[test] fn test_batch_reveal_with_invalid_input_lengths() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let tempo: u16 = 100; @@ -3727,7 +3712,7 @@ fn test_batch_reveal_with_invalid_input_lengths() { #[test] fn test_batch_reveal_with_no_commits() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0]; let uids_list: Vec> = vec![vec![0, 1]]; @@ -3757,7 +3742,7 @@ fn test_batch_reveal_with_no_commits() { #[test] fn test_batch_reveal_before_reveal_period() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0, 0]; let uids_list: Vec> = vec![vec![0, 1], vec![1, 0]]; @@ -3815,7 +3800,7 @@ fn test_batch_reveal_before_reveal_period() { #[test] fn test_batch_reveal_after_commits_expired() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0, 0]; let uids_list: Vec> = vec![vec![0, 1], vec![1, 0]]; @@ -3895,7 +3880,7 @@ fn test_batch_reveal_after_commits_expired() { #[test] fn test_batch_reveal_when_commit_reveal_disabled() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0]; let uids_list: Vec> = vec![vec![0, 1]]; @@ -3925,7 +3910,7 @@ fn test_batch_reveal_when_commit_reveal_disabled() { #[test] fn test_batch_reveal_with_out_of_order_commits() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey = U256::from(1); let version_keys: Vec = vec![0, 0, 0]; let uids_list: Vec> = vec![vec![0, 1], vec![1, 0], vec![0, 1]]; @@ -4037,7 +4022,7 @@ fn test_batch_reveal_with_out_of_order_commits() { fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { new_test_ext(1).execute_with(|| { // ==== Test Configuration ==== - let netuid = NetUid::from(1); + let netuid: u16 = 1; let num_hotkeys: usize = 10; let max_unrevealed_commits: usize = 10; let commits_per_hotkey: usize = 20; @@ -4316,7 +4301,7 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { fn test_get_reveal_blocks() { new_test_ext(1).execute_with(|| { // **1. Define Test Parameters** - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -4455,7 +4440,7 @@ fn test_get_reveal_blocks() { #[test] fn test_commit_weights_rate_limit() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let uids: Vec = vec![0, 1]; let weight_values: Vec = vec![10, 10]; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; @@ -4652,7 +4637,7 @@ fn test_reveal_crv3_commits_success() { new_test_ext(100).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey1: AccountId = U256::from(1); let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; @@ -4808,7 +4793,7 @@ fn test_reveal_crv3_commits_cannot_reveal_after_reveal_epoch() { new_test_ext(100).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey1: AccountId = U256::from(1); let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; @@ -4933,7 +4918,7 @@ fn test_reveal_crv3_commits_cannot_reveal_after_reveal_epoch() { #[test] fn test_do_commit_crv3_weights_success() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let commit_data: Vec = vec![1, 2, 3, 4, 5]; let reveal_round: u64 = 1000; @@ -4967,7 +4952,7 @@ fn test_do_commit_crv3_weights_success() { #[test] fn test_do_commit_crv3_weights_disabled() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let commit_data: Vec = vec![1, 2, 3, 4, 5]; let reveal_round: u64 = 1000; @@ -4995,7 +4980,7 @@ fn test_do_commit_crv3_weights_disabled() { #[test] fn test_do_commit_crv3_weights_hotkey_not_registered() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let unregistered_hotkey: AccountId = U256::from(99); let commit_data: Vec = vec![1, 2, 3, 4, 5]; let reveal_round: u64 = 1000; @@ -5024,7 +5009,7 @@ fn test_do_commit_crv3_weights_hotkey_not_registered() { #[test] fn test_do_commit_crv3_weights_committing_too_fast() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let commit_data_1: Vec = vec![1, 2, 3]; let commit_data_2: Vec = vec![4, 5, 6]; @@ -5093,7 +5078,7 @@ fn test_do_commit_crv3_weights_committing_too_fast() { #[test] fn test_do_commit_crv3_weights_too_many_unrevealed_commits() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey1: AccountId = U256::from(1); let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; @@ -5198,7 +5183,7 @@ fn test_do_commit_crv3_weights_too_many_unrevealed_commits() { #[test] fn test_reveal_crv3_commits_decryption_failure() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5251,7 +5236,7 @@ fn test_reveal_crv3_commits_multiple_commits_some_fail_some_succeed() { new_test_ext(100).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey1: AccountId = U256::from(1); let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; @@ -5375,7 +5360,7 @@ fn test_reveal_crv3_commits_do_set_weights_failure() { new_test_ext(1).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5461,7 +5446,7 @@ fn test_reveal_crv3_commits_payload_decoding_failure() { new_test_ext(1).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5540,7 +5525,7 @@ fn test_reveal_crv3_commits_signature_deserialization_failure() { new_test_ext(1).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5620,7 +5605,7 @@ fn test_reveal_crv3_commits_signature_deserialization_failure() { #[test] fn test_do_commit_crv3_weights_commit_size_exceeds_limit() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5663,7 +5648,7 @@ fn test_do_commit_crv3_weights_commit_size_exceeds_limit() { #[test] fn test_reveal_crv3_commits_with_empty_commit_queue() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; add_network(netuid, 5, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); @@ -5685,7 +5670,7 @@ fn test_reveal_crv3_commits_with_incorrect_identity_message() { new_test_ext(1).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5771,7 +5756,7 @@ fn test_reveal_crv3_commits_with_incorrect_identity_message() { #[test] fn test_multiple_commits_by_same_hotkey_within_limit() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5808,7 +5793,7 @@ fn test_multiple_commits_by_same_hotkey_within_limit() { #[test] fn test_reveal_crv3_commits_removes_past_epoch_commits() { new_test_ext(100).execute_with(|| { - let netuid = NetUid::from(1); + let netuid: u16 = 1; let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; @@ -5875,7 +5860,7 @@ fn test_reveal_crv3_commits_multiple_valid_commits_all_processed() { new_test_ext(100).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let reveal_round: u64 = 1000; // Initialize the network @@ -6064,7 +6049,7 @@ fn test_reveal_crv3_commits_max_neurons() { new_test_ext(100).execute_with(|| { use ark_serialize::CanonicalSerialize; - let netuid = NetUid::from(1); + let netuid: u16 = 1; let reveal_round: u64 = 1000; add_network(netuid, 5, 0); diff --git a/pallets/subtensor/src/utils/evm.rs b/pallets/subtensor/src/utils/evm.rs index 5d4f1ad493..6877739f69 100644 --- a/pallets/subtensor/src/utils/evm.rs +++ b/pallets/subtensor/src/utils/evm.rs @@ -5,7 +5,6 @@ use frame_support::ensure; use frame_system::ensure_signed; use sp_core::{H160, ecdsa::Signature, hashing::keccak_256}; use sp_std::vec::Vec; -use subtensor_runtime_common::NetUid; const MESSAGE_PREFIX: &str = "\x19Ethereum Signed Message:\n"; @@ -43,7 +42,7 @@ impl Pallet { /// * `signature` - A signed message by the `evm_key` containing the `hotkey` and the hashed `block_number`. pub fn do_associate_evm_key( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, hotkey: T::AccountId, evm_key: H160, block_number: u64, @@ -92,7 +91,7 @@ impl Pallet { Ok(()) } - pub fn uid_lookup(netuid: NetUid, evm_key: H160, limit: u16) -> Vec<(u16, u64)> { + pub fn uid_lookup(netuid: u16, evm_key: H160, limit: u16) -> Vec<(u16, u64)> { let mut ret_val = AssociatedEvmAddress::::iter_prefix(netuid) .take(limit as usize) .filter_map(|(uid, (stored_evm_key, block_associated))| { diff --git a/pallets/subtensor/src/utils/identity.rs b/pallets/subtensor/src/utils/identity.rs index 287c45a543..c4b9fdc821 100644 --- a/pallets/subtensor/src/utils/identity.rs +++ b/pallets/subtensor/src/utils/identity.rs @@ -2,7 +2,6 @@ use super::*; use frame_support::ensure; use frame_system::ensure_signed; use sp_std::vec::Vec; -use subtensor_runtime_common::NetUid; impl Pallet { /// Sets the identity for a coldkey. @@ -97,7 +96,7 @@ impl Pallet { /// Returns `Ok(())` if the subnet identity is successfully set, otherwise returns an error. pub fn do_set_subnet_identity( origin: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, subnet_name: Vec, github_repo: Vec, subnet_contact: Vec, diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index cf7c5f1a18..899fa83646 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -8,12 +8,11 @@ use sp_core::Get; use sp_core::U256; use sp_runtime::Saturating; use substrate_fixed::types::{I32F32, U96F32}; -use subtensor_runtime_common::NetUid; impl Pallet { pub fn ensure_subnet_owner_or_root( o: T::RuntimeOrigin, - netuid: NetUid, + netuid: u16, ) -> Result<(), DispatchError> { let coldkey = ensure_signed_or_root(o); match coldkey { @@ -24,7 +23,7 @@ impl Pallet { } } - pub fn ensure_subnet_owner(o: T::RuntimeOrigin, netuid: NetUid) -> Result<(), DispatchError> { + pub fn ensure_subnet_owner(o: T::RuntimeOrigin, netuid: u16) -> Result<(), DispatchError> { let coldkey = ensure_signed(o); match coldkey { Ok(who) if SubnetOwner::::get(netuid) == who => Ok(()), @@ -36,33 +35,30 @@ impl Pallet { // ======================== // ==== Global Setters ==== // ======================== - pub fn set_tempo(netuid: NetUid, tempo: u16) { + pub fn set_tempo(netuid: u16, tempo: u16) { Tempo::::insert(netuid, tempo); Self::deposit_event(Event::TempoSet(netuid, tempo)); } - pub fn set_last_adjustment_block(netuid: NetUid, last_adjustment_block: u64) { + pub fn set_last_adjustment_block(netuid: u16, last_adjustment_block: u64) { LastAdjustmentBlock::::insert(netuid, last_adjustment_block); } - pub fn set_blocks_since_last_step(netuid: NetUid, blocks_since_last_step: u64) { + pub fn set_blocks_since_last_step(netuid: u16, blocks_since_last_step: u64) { BlocksSinceLastStep::::insert(netuid, blocks_since_last_step); } - pub fn set_registrations_this_block(netuid: NetUid, registrations_this_block: u16) { + pub fn set_registrations_this_block(netuid: u16, registrations_this_block: u16) { RegistrationsThisBlock::::insert(netuid, registrations_this_block); } - pub fn set_last_mechanism_step_block(netuid: NetUid, last_mechanism_step_block: u64) { + pub fn set_last_mechanism_step_block(netuid: u16, last_mechanism_step_block: u64) { LastMechansimStepBlock::::insert(netuid, last_mechanism_step_block); } - pub fn set_registrations_this_interval(netuid: NetUid, registrations_this_interval: u16) { + pub fn set_registrations_this_interval(netuid: u16, registrations_this_interval: u16) { RegistrationsThisInterval::::insert(netuid, registrations_this_interval); } - pub fn set_pow_registrations_this_interval( - netuid: NetUid, - pow_registrations_this_interval: u16, - ) { + pub fn set_pow_registrations_this_interval(netuid: u16, pow_registrations_this_interval: u16) { POWRegistrationsThisInterval::::insert(netuid, pow_registrations_this_interval); } pub fn set_burn_registrations_this_interval( - netuid: NetUid, + netuid: u16, burn_registrations_this_interval: u16, ) { BurnRegistrationsThisInterval::::insert(netuid, burn_registrations_this_interval); @@ -83,44 +79,44 @@ impl Pallet { // ============================== // ==== YumaConsensus params ==== // ============================== - pub fn get_rank(netuid: NetUid) -> Vec { + pub fn get_rank(netuid: u16) -> Vec { Rank::::get(netuid) } - pub fn get_trust(netuid: NetUid) -> Vec { + pub fn get_trust(netuid: u16) -> Vec { Trust::::get(netuid) } - pub fn get_active(netuid: NetUid) -> Vec { + pub fn get_active(netuid: u16) -> Vec { Active::::get(netuid) } - pub fn get_emission(netuid: NetUid) -> Vec { + pub fn get_emission(netuid: u16) -> Vec { Emission::::get(netuid) } - pub fn get_consensus(netuid: NetUid) -> Vec { + pub fn get_consensus(netuid: u16) -> Vec { Consensus::::get(netuid) } - pub fn get_incentive(netuid: NetUid) -> Vec { + pub fn get_incentive(netuid: u16) -> Vec { Incentive::::get(netuid) } - pub fn get_dividends(netuid: NetUid) -> Vec { + pub fn get_dividends(netuid: u16) -> Vec { Dividends::::get(netuid) } - pub fn get_last_update(netuid: NetUid) -> Vec { + pub fn get_last_update(netuid: u16) -> Vec { LastUpdate::::get(netuid) } - pub fn get_pruning_score(netuid: NetUid) -> Vec { + pub fn get_pruning_score(netuid: u16) -> Vec { PruningScores::::get(netuid) } - pub fn get_validator_trust(netuid: NetUid) -> Vec { + pub fn get_validator_trust(netuid: u16) -> Vec { ValidatorTrust::::get(netuid) } - pub fn get_validator_permit(netuid: NetUid) -> Vec { + pub fn get_validator_permit(netuid: u16) -> Vec { ValidatorPermit::::get(netuid) } // ================================== // ==== YumaConsensus UID params ==== // ================================== - pub fn set_last_update_for_uid(netuid: NetUid, uid: u16, last_update: u64) { + pub fn set_last_update_for_uid(netuid: u16, uid: u16, last_update: u64) { let mut updated_last_update_vec = Self::get_last_update(netuid); let Some(updated_last_update) = updated_last_update_vec.get_mut(uid as usize) else { return; @@ -128,7 +124,7 @@ impl Pallet { *updated_last_update = last_update; LastUpdate::::insert(netuid, updated_last_update_vec); } - pub fn set_active_for_uid(netuid: NetUid, uid: u16, active: bool) { + pub fn set_active_for_uid(netuid: u16, uid: u16, active: bool) { let mut updated_active_vec = Self::get_active(netuid); let Some(updated_active) = updated_active_vec.get_mut(uid as usize) else { return; @@ -136,7 +132,7 @@ impl Pallet { *updated_active = active; Active::::insert(netuid, updated_active_vec); } - pub fn set_pruning_score_for_uid(netuid: NetUid, uid: u16, pruning_score: u16) { + pub fn set_pruning_score_for_uid(netuid: u16, uid: u16, pruning_score: u16) { log::debug!("netuid = {:?}", netuid); log::debug!( "SubnetworkN::::get( netuid ) = {:?}", @@ -150,7 +146,7 @@ impl Pallet { } }); } - pub fn set_validator_permit_for_uid(netuid: NetUid, uid: u16, validator_permit: bool) { + pub fn set_validator_permit_for_uid(netuid: u16, uid: u16, validator_permit: bool) { let mut updated_validator_permits = Self::get_validator_permit(netuid); let Some(updated_validator_permit) = updated_validator_permits.get_mut(uid as usize) else { return; @@ -163,47 +159,47 @@ impl Pallet { Self::deposit_event(Event::StakeThresholdSet(min_stake)); } - pub fn get_rank_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_rank_for_uid(netuid: u16, uid: u16) -> u16 { let vec = Rank::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_trust_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_trust_for_uid(netuid: u16, uid: u16) -> u16 { let vec = Trust::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_emission_for_uid(netuid: NetUid, uid: u16) -> u64 { + pub fn get_emission_for_uid(netuid: u16, uid: u16) -> u64 { let vec = Emission::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_active_for_uid(netuid: NetUid, uid: u16) -> bool { + pub fn get_active_for_uid(netuid: u16, uid: u16) -> bool { let vec = Active::::get(netuid); vec.get(uid as usize).copied().unwrap_or(false) } - pub fn get_consensus_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_consensus_for_uid(netuid: u16, uid: u16) -> u16 { let vec = Consensus::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_incentive_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_incentive_for_uid(netuid: u16, uid: u16) -> u16 { let vec = Incentive::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_dividends_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_dividends_for_uid(netuid: u16, uid: u16) -> u16 { let vec = Dividends::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_last_update_for_uid(netuid: NetUid, uid: u16) -> u64 { + pub fn get_last_update_for_uid(netuid: u16, uid: u16) -> u64 { let vec = LastUpdate::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_pruning_score_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_pruning_score_for_uid(netuid: u16, uid: u16) -> u16 { let vec = PruningScores::::get(netuid); vec.get(uid as usize).copied().unwrap_or(u16::MAX) } - pub fn get_validator_trust_for_uid(netuid: NetUid, uid: u16) -> u16 { + pub fn get_validator_trust_for_uid(netuid: u16, uid: u16) -> u16 { let vec = ValidatorTrust::::get(netuid); vec.get(uid as usize).copied().unwrap_or(0) } - pub fn get_validator_permit_for_uid(netuid: NetUid, uid: u16) -> bool { + pub fn get_validator_permit_for_uid(netuid: u16, uid: u16) -> bool { let vec = ValidatorPermit::::get(netuid); vec.get(uid as usize).copied().unwrap_or(false) } @@ -214,37 +210,37 @@ impl Pallet { // ============================ // ==== Subnetwork Getters ==== // ============================ - pub fn get_tempo(netuid: NetUid) -> u16 { + pub fn get_tempo(netuid: u16) -> u16 { Tempo::::get(netuid) } - pub fn get_pending_emission(netuid: NetUid) -> u64 { + pub fn get_pending_emission(netuid: u16) -> u64 { PendingEmission::::get(netuid) } - pub fn get_last_adjustment_block(netuid: NetUid) -> u64 { + pub fn get_last_adjustment_block(netuid: u16) -> u64 { LastAdjustmentBlock::::get(netuid) } - pub fn get_blocks_since_last_step(netuid: NetUid) -> u64 { + pub fn get_blocks_since_last_step(netuid: u16) -> u64 { BlocksSinceLastStep::::get(netuid) } - pub fn get_difficulty(netuid: NetUid) -> U256 { + pub fn get_difficulty(netuid: u16) -> U256 { U256::from(Self::get_difficulty_as_u64(netuid)) } - pub fn get_registrations_this_block(netuid: NetUid) -> u16 { + pub fn get_registrations_this_block(netuid: u16) -> u16 { RegistrationsThisBlock::::get(netuid) } - pub fn get_last_mechanism_step_block(netuid: NetUid) -> u64 { + pub fn get_last_mechanism_step_block(netuid: u16) -> u64 { LastMechansimStepBlock::::get(netuid) } - pub fn get_registrations_this_interval(netuid: NetUid) -> u16 { + pub fn get_registrations_this_interval(netuid: u16) -> u16 { RegistrationsThisInterval::::get(netuid) } - pub fn get_pow_registrations_this_interval(netuid: NetUid) -> u16 { + pub fn get_pow_registrations_this_interval(netuid: u16) -> u16 { POWRegistrationsThisInterval::::get(netuid) } - pub fn get_burn_registrations_this_interval(netuid: NetUid) -> u16 { + pub fn get_burn_registrations_this_interval(netuid: u16) -> u16 { BurnRegistrationsThisInterval::::get(netuid) } - pub fn get_neuron_block_at_registration(netuid: NetUid, neuron_uid: u16) -> u64 { + pub fn get_neuron_block_at_registration(netuid: u16, neuron_uid: u16) -> u64 { BlockAtRegistration::::get(netuid, neuron_uid) } @@ -277,10 +273,10 @@ impl Pallet { TotalIssuance::::put(TotalIssuance::::get().saturating_add(amount)); } - pub fn set_subnet_locked_balance(netuid: NetUid, amount: u64) { + pub fn set_subnet_locked_balance(netuid: u16, amount: u64) { SubnetLocked::::insert(netuid, amount); } - pub fn get_subnet_locked_balance(netuid: NetUid) -> u64 { + pub fn get_subnet_locked_balance(netuid: u16) -> u64 { SubnetLocked::::get(netuid) } pub fn get_total_subnet_locked() -> u64 { @@ -356,42 +352,42 @@ impl Pallet { MaxChildkeyTake::::get() } - pub fn get_serving_rate_limit(netuid: NetUid) -> u64 { + pub fn get_serving_rate_limit(netuid: u16) -> u64 { ServingRateLimit::::get(netuid) } - pub fn set_serving_rate_limit(netuid: NetUid, serving_rate_limit: u64) { + pub fn set_serving_rate_limit(netuid: u16, serving_rate_limit: u64) { ServingRateLimit::::insert(netuid, serving_rate_limit); Self::deposit_event(Event::ServingRateLimitSet(netuid, serving_rate_limit)); } - pub fn get_min_difficulty(netuid: NetUid) -> u64 { + pub fn get_min_difficulty(netuid: u16) -> u64 { MinDifficulty::::get(netuid) } - pub fn set_min_difficulty(netuid: NetUid, min_difficulty: u64) { + pub fn set_min_difficulty(netuid: u16, min_difficulty: u64) { MinDifficulty::::insert(netuid, min_difficulty); Self::deposit_event(Event::MinDifficultySet(netuid, min_difficulty)); } - pub fn get_max_difficulty(netuid: NetUid) -> u64 { + pub fn get_max_difficulty(netuid: u16) -> u64 { MaxDifficulty::::get(netuid) } - pub fn set_max_difficulty(netuid: NetUid, max_difficulty: u64) { + pub fn set_max_difficulty(netuid: u16, max_difficulty: u64) { MaxDifficulty::::insert(netuid, max_difficulty); Self::deposit_event(Event::MaxDifficultySet(netuid, max_difficulty)); } - pub fn get_weights_version_key(netuid: NetUid) -> u64 { + pub fn get_weights_version_key(netuid: u16) -> u64 { WeightsVersionKey::::get(netuid) } - pub fn set_weights_version_key(netuid: NetUid, weights_version_key: u64) { + pub fn set_weights_version_key(netuid: u16, weights_version_key: u64) { WeightsVersionKey::::insert(netuid, weights_version_key); Self::deposit_event(Event::WeightsVersionKeySet(netuid, weights_version_key)); } - pub fn get_weights_set_rate_limit(netuid: NetUid) -> u64 { + pub fn get_weights_set_rate_limit(netuid: u16) -> u64 { WeightsSetRateLimit::::get(netuid) } - pub fn set_weights_set_rate_limit(netuid: NetUid, weights_set_rate_limit: u64) { + pub fn set_weights_set_rate_limit(netuid: u16, weights_set_rate_limit: u64) { WeightsSetRateLimit::::insert(netuid, weights_set_rate_limit); Self::deposit_event(Event::WeightsSetRateLimitSet( netuid, @@ -399,126 +395,126 @@ impl Pallet { )); } - pub fn get_adjustment_interval(netuid: NetUid) -> u16 { + pub fn get_adjustment_interval(netuid: u16) -> u16 { AdjustmentInterval::::get(netuid) } - pub fn set_adjustment_interval(netuid: NetUid, adjustment_interval: u16) { + pub fn set_adjustment_interval(netuid: u16, adjustment_interval: u16) { AdjustmentInterval::::insert(netuid, adjustment_interval); Self::deposit_event(Event::AdjustmentIntervalSet(netuid, adjustment_interval)); } - pub fn get_adjustment_alpha(netuid: NetUid) -> u64 { + pub fn get_adjustment_alpha(netuid: u16) -> u64 { AdjustmentAlpha::::get(netuid) } - pub fn set_adjustment_alpha(netuid: NetUid, adjustment_alpha: u64) { + pub fn set_adjustment_alpha(netuid: u16, adjustment_alpha: u64) { AdjustmentAlpha::::insert(netuid, adjustment_alpha); Self::deposit_event(Event::AdjustmentAlphaSet(netuid, adjustment_alpha)); } - pub fn set_validator_prune_len(netuid: NetUid, validator_prune_len: u64) { + pub fn set_validator_prune_len(netuid: u16, validator_prune_len: u64) { ValidatorPruneLen::::insert(netuid, validator_prune_len); Self::deposit_event(Event::ValidatorPruneLenSet(netuid, validator_prune_len)); } - pub fn get_scaling_law_power(netuid: NetUid) -> u16 { + pub fn get_scaling_law_power(netuid: u16) -> u16 { ScalingLawPower::::get(netuid) } - pub fn set_scaling_law_power(netuid: NetUid, scaling_law_power: u16) { + pub fn set_scaling_law_power(netuid: u16, scaling_law_power: u16) { ScalingLawPower::::insert(netuid, scaling_law_power); Self::deposit_event(Event::ScalingLawPowerSet(netuid, scaling_law_power)); } - pub fn get_max_weight_limit(netuid: NetUid) -> u16 { + pub fn get_max_weight_limit(netuid: u16) -> u16 { MaxWeightsLimit::::get(netuid) } - pub fn set_max_weight_limit(netuid: NetUid, max_weight_limit: u16) { + pub fn set_max_weight_limit(netuid: u16, max_weight_limit: u16) { MaxWeightsLimit::::insert(netuid, max_weight_limit); Self::deposit_event(Event::MaxWeightLimitSet(netuid, max_weight_limit)); } - pub fn get_immunity_period(netuid: NetUid) -> u16 { + pub fn get_immunity_period(netuid: u16) -> u16 { ImmunityPeriod::::get(netuid) } - pub fn set_immunity_period(netuid: NetUid, immunity_period: u16) { + pub fn set_immunity_period(netuid: u16, immunity_period: u16) { ImmunityPeriod::::insert(netuid, immunity_period); Self::deposit_event(Event::ImmunityPeriodSet(netuid, immunity_period)); } /// Check if a neuron is in immunity based on the current block - pub fn get_neuron_is_immune(netuid: NetUid, uid: u16) -> bool { + pub fn get_neuron_is_immune(netuid: u16, uid: u16) -> bool { let registered_at = Self::get_neuron_block_at_registration(netuid, uid); let current_block = Self::get_current_block_as_u64(); let immunity_period = Self::get_immunity_period(netuid); current_block.saturating_sub(registered_at) < u64::from(immunity_period) } - pub fn get_min_allowed_weights(netuid: NetUid) -> u16 { + pub fn get_min_allowed_weights(netuid: u16) -> u16 { MinAllowedWeights::::get(netuid) } - pub fn set_min_allowed_weights(netuid: NetUid, min_allowed_weights: u16) { + pub fn set_min_allowed_weights(netuid: u16, min_allowed_weights: u16) { MinAllowedWeights::::insert(netuid, min_allowed_weights); Self::deposit_event(Event::MinAllowedWeightSet(netuid, min_allowed_weights)); } - pub fn get_max_allowed_uids(netuid: NetUid) -> u16 { + pub fn get_max_allowed_uids(netuid: u16) -> u16 { MaxAllowedUids::::get(netuid) } - pub fn set_max_allowed_uids(netuid: NetUid, max_allowed: u16) { + pub fn set_max_allowed_uids(netuid: u16, max_allowed: u16) { MaxAllowedUids::::insert(netuid, max_allowed); Self::deposit_event(Event::MaxAllowedUidsSet(netuid, max_allowed)); } - pub fn get_kappa(netuid: NetUid) -> u16 { + pub fn get_kappa(netuid: u16) -> u16 { Kappa::::get(netuid) } - pub fn set_kappa(netuid: NetUid, kappa: u16) { + pub fn set_kappa(netuid: u16, kappa: u16) { Kappa::::insert(netuid, kappa); Self::deposit_event(Event::KappaSet(netuid, kappa)); } - pub fn get_commit_reveal_weights_enabled(netuid: NetUid) -> bool { + pub fn get_commit_reveal_weights_enabled(netuid: u16) -> bool { CommitRevealWeightsEnabled::::get(netuid) } - pub fn set_commit_reveal_weights_enabled(netuid: NetUid, enabled: bool) { + pub fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool) { CommitRevealWeightsEnabled::::set(netuid, enabled); Self::deposit_event(Event::CommitRevealEnabled(netuid, enabled)); } - pub fn get_rho(netuid: NetUid) -> u16 { + pub fn get_rho(netuid: u16) -> u16 { Rho::::get(netuid) } - pub fn set_rho(netuid: NetUid, rho: u16) { + pub fn set_rho(netuid: u16, rho: u16) { Rho::::insert(netuid, rho); } - pub fn get_activity_cutoff(netuid: NetUid) -> u16 { + pub fn get_activity_cutoff(netuid: u16) -> u16 { ActivityCutoff::::get(netuid) } - pub fn set_activity_cutoff(netuid: NetUid, activity_cutoff: u16) { + pub fn set_activity_cutoff(netuid: u16, activity_cutoff: u16) { ActivityCutoff::::insert(netuid, activity_cutoff); Self::deposit_event(Event::ActivityCutoffSet(netuid, activity_cutoff)); } // Registration Toggle utils - pub fn get_network_registration_allowed(netuid: NetUid) -> bool { + pub fn get_network_registration_allowed(netuid: u16) -> bool { NetworkRegistrationAllowed::::get(netuid) } - pub fn set_network_registration_allowed(netuid: NetUid, registration_allowed: bool) { + pub fn set_network_registration_allowed(netuid: u16, registration_allowed: bool) { NetworkRegistrationAllowed::::insert(netuid, registration_allowed); Self::deposit_event(Event::RegistrationAllowed(netuid, registration_allowed)); } - pub fn get_network_pow_registration_allowed(netuid: NetUid) -> bool { + pub fn get_network_pow_registration_allowed(netuid: u16) -> bool { NetworkPowRegistrationAllowed::::get(netuid) } - pub fn set_network_pow_registration_allowed(netuid: NetUid, registration_allowed: bool) { + pub fn set_network_pow_registration_allowed(netuid: u16, registration_allowed: bool) { NetworkPowRegistrationAllowed::::insert(netuid, registration_allowed); Self::deposit_event(Event::PowRegistrationAllowed(netuid, registration_allowed)); } - pub fn get_target_registrations_per_interval(netuid: NetUid) -> u16 { + pub fn get_target_registrations_per_interval(netuid: u16) -> u16 { TargetRegistrationsPerInterval::::get(netuid) } pub fn set_target_registrations_per_interval( - netuid: NetUid, + netuid: u16, target_registrations_per_interval: u16, ) { TargetRegistrationsPerInterval::::insert(netuid, target_registrations_per_interval); @@ -528,41 +524,41 @@ impl Pallet { )); } - pub fn get_burn_as_u64(netuid: NetUid) -> u64 { + pub fn get_burn_as_u64(netuid: u16) -> u64 { Burn::::get(netuid) } - pub fn set_burn(netuid: NetUid, burn: u64) { + pub fn set_burn(netuid: u16, burn: u64) { Burn::::insert(netuid, burn); } - pub fn get_min_burn_as_u64(netuid: NetUid) -> u64 { + pub fn get_min_burn_as_u64(netuid: u16) -> u64 { MinBurn::::get(netuid) } - pub fn set_min_burn(netuid: NetUid, min_burn: u64) { + pub fn set_min_burn(netuid: u16, min_burn: u64) { MinBurn::::insert(netuid, min_burn); Self::deposit_event(Event::MinBurnSet(netuid, min_burn)); } - pub fn get_max_burn_as_u64(netuid: NetUid) -> u64 { + pub fn get_max_burn_as_u64(netuid: u16) -> u64 { MaxBurn::::get(netuid) } - pub fn set_max_burn(netuid: NetUid, max_burn: u64) { + pub fn set_max_burn(netuid: u16, max_burn: u64) { MaxBurn::::insert(netuid, max_burn); Self::deposit_event(Event::MaxBurnSet(netuid, max_burn)); } - pub fn get_difficulty_as_u64(netuid: NetUid) -> u64 { + pub fn get_difficulty_as_u64(netuid: u16) -> u64 { Difficulty::::get(netuid) } - pub fn set_difficulty(netuid: NetUid, difficulty: u64) { + pub fn set_difficulty(netuid: u16, difficulty: u64) { Difficulty::::insert(netuid, difficulty); Self::deposit_event(Event::DifficultySet(netuid, difficulty)); } - pub fn get_max_allowed_validators(netuid: NetUid) -> u16 { + pub fn get_max_allowed_validators(netuid: u16) -> u16 { MaxAllowedValidators::::get(netuid) } - pub fn set_max_allowed_validators(netuid: NetUid, max_allowed_validators: u16) { + pub fn set_max_allowed_validators(netuid: u16, max_allowed_validators: u16) { MaxAllowedValidators::::insert(netuid, max_allowed_validators); Self::deposit_event(Event::MaxAllowedValidatorsSet( netuid, @@ -570,34 +566,34 @@ impl Pallet { )); } - pub fn get_bonds_moving_average(netuid: NetUid) -> u64 { + pub fn get_bonds_moving_average(netuid: u16) -> u64 { BondsMovingAverage::::get(netuid) } - pub fn set_bonds_moving_average(netuid: NetUid, bonds_moving_average: u64) { + pub fn set_bonds_moving_average(netuid: u16, bonds_moving_average: u64) { BondsMovingAverage::::insert(netuid, bonds_moving_average); Self::deposit_event(Event::BondsMovingAverageSet(netuid, bonds_moving_average)); } - pub fn get_bonds_penalty(netuid: NetUid) -> u16 { + pub fn get_bonds_penalty(netuid: u16) -> u16 { BondsPenalty::::get(netuid) } - pub fn set_bonds_penalty(netuid: NetUid, bonds_penalty: u16) { + pub fn set_bonds_penalty(netuid: u16, bonds_penalty: u16) { BondsPenalty::::insert(netuid, bonds_penalty); Self::deposit_event(Event::BondsPenaltySet(netuid, bonds_penalty)); } - pub fn get_bonds_reset(netuid: NetUid) -> bool { + pub fn get_bonds_reset(netuid: u16) -> bool { BondsResetOn::::get(netuid) } - pub fn set_bonds_reset(netuid: NetUid, bonds_reset: bool) { + pub fn set_bonds_reset(netuid: u16, bonds_reset: bool) { BondsResetOn::::insert(netuid, bonds_reset); Self::deposit_event(Event::BondsResetOnSet(netuid, bonds_reset)); } - pub fn get_max_registrations_per_block(netuid: NetUid) -> u16 { + pub fn get_max_registrations_per_block(netuid: u16) -> u16 { MaxRegistrationsPerBlock::::get(netuid) } - pub fn set_max_registrations_per_block(netuid: NetUid, max_registrations_per_block: u16) { + pub fn set_max_registrations_per_block(netuid: u16, max_registrations_per_block: u16) { MaxRegistrationsPerBlock::::insert(netuid, max_registrations_per_block); Self::deposit_event(Event::MaxRegistrationsPerBlockSet( netuid, @@ -605,7 +601,7 @@ impl Pallet { )); } - pub fn get_subnet_owner(netuid: NetUid) -> T::AccountId { + pub fn get_subnet_owner(netuid: u16) -> T::AccountId { SubnetOwner::::get(netuid) } pub fn get_subnet_owner_cut() -> u16 { @@ -631,14 +627,14 @@ impl Pallet { TotalIssuance::::put(total_issuance); } - pub fn get_rao_recycled(netuid: NetUid) -> u64 { + pub fn get_rao_recycled(netuid: u16) -> u64 { RAORecycledForRegistration::::get(netuid) } - pub fn set_rao_recycled(netuid: NetUid, rao_recycled: u64) { + pub fn set_rao_recycled(netuid: u16, rao_recycled: u64) { RAORecycledForRegistration::::insert(netuid, rao_recycled); Self::deposit_event(Event::RAORecycledForRegistrationSet(netuid, rao_recycled)); } - pub fn increase_rao_recycled(netuid: NetUid, inc_rao_recycled: u64) { + pub fn increase_rao_recycled(netuid: u16, inc_rao_recycled: u64) { let curr_rao_recycled = Self::get_rao_recycled(netuid); let rao_recycled = curr_rao_recycled.saturating_add(inc_rao_recycled); Self::set_rao_recycled(netuid, rao_recycled); @@ -679,17 +675,17 @@ impl Pallet { T::KeySwapCost::get() } - pub fn get_alpha_values(netuid: NetUid) -> (u16, u16) { + pub fn get_alpha_values(netuid: u16) -> (u16, u16) { AlphaValues::::get(netuid) } - pub fn set_alpha_values_32(netuid: NetUid, low: I32F32, high: I32F32) { + pub fn set_alpha_values_32(netuid: u16, low: I32F32, high: I32F32) { let low = (low.saturating_mul(I32F32::saturating_from_num(u16::MAX))).to_num::(); let high = (high.saturating_mul(I32F32::saturating_from_num(u16::MAX))).to_num::(); AlphaValues::::insert(netuid, (low, high)); } - pub fn get_alpha_values_32(netuid: NetUid) -> (I32F32, I32F32) { + pub fn get_alpha_values_32(netuid: u16) -> (I32F32, I32F32) { let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); let converted_low = I32F32::saturating_from_num(alpha_low).safe_div(I32F32::saturating_from_num(u16::MAX)); @@ -699,27 +695,27 @@ impl Pallet { (converted_low, converted_high) } - pub fn set_alpha_sigmoid_steepness(netuid: NetUid, steepness: u16) { + pub fn set_alpha_sigmoid_steepness(netuid: u16, steepness: u16) { AlphaSigmoidSteepness::::insert(netuid, steepness); } - pub fn get_alpha_sigmoid_steepness(netuid: NetUid) -> I32F32 { + pub fn get_alpha_sigmoid_steepness(netuid: u16) -> I32F32 { let alpha = AlphaSigmoidSteepness::::get(netuid); I32F32::saturating_from_num(alpha) } - pub fn set_liquid_alpha_enabled(netuid: NetUid, enabled: bool) { + pub fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { LiquidAlphaOn::::set(netuid, enabled); } - pub fn get_liquid_alpha_enabled(netuid: NetUid) -> bool { + pub fn get_liquid_alpha_enabled(netuid: u16) -> bool { LiquidAlphaOn::::get(netuid) } - pub fn set_yuma3_enabled(netuid: NetUid, enabled: bool) { + pub fn set_yuma3_enabled(netuid: u16, enabled: bool) { Yuma3On::::set(netuid, enabled); } - pub fn get_yuma3_enabled(netuid: NetUid) -> bool { + pub fn get_yuma3_enabled(netuid: u16) -> bool { Yuma3On::::get(netuid) } @@ -764,13 +760,13 @@ impl Pallet { /// /// * Update the SubnetOwnerHotkey storage. /// * Emits a SubnetOwnerHotkeySet event. - pub fn set_subnet_owner_hotkey(netuid: NetUid, hotkey: &T::AccountId) { + pub fn set_subnet_owner_hotkey(netuid: u16, hotkey: &T::AccountId) { SubnetOwnerHotkey::::insert(netuid, hotkey.clone()); Self::deposit_event(Event::SubnetOwnerHotkeySet(netuid, hotkey.clone())); } // Get the uid of the Owner Hotkey for a subnet. - pub fn get_owner_uid(netuid: NetUid) -> Option { + pub fn get_owner_uid(netuid: u16) -> Option { match SubnetOwnerHotkey::::try_get(netuid) { Ok(owner_hotkey) => Uids::::get(netuid, &owner_hotkey), Err(_) => None, diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index eeb5b96ddb..7edaebc98a 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -1,5 +1,3 @@ -use subtensor_runtime_common::NetUid; - use super::*; /// Enum representing different types of transactions @@ -56,7 +54,7 @@ impl Pallet { } } - pub fn get_rate_limit_on_subnet(tx_type: &TransactionType, netuid: NetUid) -> u64 { + pub fn get_rate_limit_on_subnet(tx_type: &TransactionType, netuid: u16) -> u64 { #[allow(clippy::match_single_binding)] match tx_type { TransactionType::SetWeightsVersionKey => (Tempo::::get(netuid) as u64) @@ -84,7 +82,7 @@ impl Pallet { pub fn passes_rate_limit_on_subnet( tx_type: &TransactionType, hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, ) -> bool { let block: u64 = Self::get_current_block_as_u64(); let limit: u64 = Self::get_rate_limit_on_subnet(tx_type, netuid); @@ -97,14 +95,14 @@ impl Pallet { pub fn get_last_transaction_block(key: &T::AccountId, tx_type: &TransactionType) -> u64 { match tx_type { TransactionType::RegisterNetwork => Self::get_network_last_lock_block(), - _ => Self::get_last_transaction_block_on_subnet(key, NetUid::ROOT, tx_type), + _ => Self::get_last_transaction_block_on_subnet(key, 0, tx_type), } } /// Get the block number of the last transaction for a specific hotkey, network, and transaction type pub fn get_last_transaction_block_on_subnet( hotkey: &T::AccountId, - netuid: NetUid, + netuid: u16, tx_type: &TransactionType, ) -> u64 { match tx_type { @@ -123,14 +121,14 @@ impl Pallet { pub fn set_last_transaction_block(key: &T::AccountId, tx_type: &TransactionType, block: u64) { match tx_type { TransactionType::RegisterNetwork => Self::set_network_last_lock_block(block), - _ => Self::set_last_transaction_block_on_subnet(key, NetUid::ROOT, tx_type, block), + _ => Self::set_last_transaction_block_on_subnet(key, 0, tx_type, block), } } /// Set the block number of the last transaction for a specific hotkey, network, and transaction type pub fn set_last_transaction_block_on_subnet( key: &T::AccountId, - netuid: NetUid, + netuid: u16, tx_type: &TransactionType, block: u64, ) { diff --git a/pallets/subtensor/src/utils/try_state.rs b/pallets/subtensor/src/utils/try_state.rs index f5e8d5ffb9..1fb75fd4bb 100644 --- a/pallets/subtensor/src/utils/try_state.rs +++ b/pallets/subtensor/src/utils/try_state.rs @@ -41,7 +41,7 @@ impl Pallet { let total_staked = SubnetTAO::::iter().fold(0u64, |acc, (netuid, stake)| { let acc = acc.saturating_add(stake); - if netuid.is_root() { + if netuid == Self::get_root_netuid() { // root network doesn't have initial pool TAO acc } else { diff --git a/precompiles/src/alpha.rs b/precompiles/src/alpha.rs index ff37244cd0..45aab10bf7 100644 --- a/precompiles/src/alpha.rs +++ b/precompiles/src/alpha.rs @@ -4,7 +4,6 @@ use pallet_evm::PrecompileHandle; use precompile_utils::EvmResult; use sp_core::U256; use substrate_fixed::types::U96F32; -use subtensor_runtime_common::NetUid; use crate::PrecompileExt; @@ -26,45 +25,39 @@ where #[precompile::public("getAlphaPrice(uint16)")] #[precompile::view] fn get_alpha_price(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - let price: U96F32 = pallet_subtensor::Pallet::::get_alpha_price(netuid.into()); + let price: U96F32 = pallet_subtensor::Pallet::::get_alpha_price(netuid); Ok(U256::from(price.saturating_to_num::())) } #[precompile::public("getMovingAlphaPrice(uint16)")] #[precompile::view] fn get_moving_alpha_price(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - let price: U96F32 = pallet_subtensor::Pallet::::get_moving_alpha_price(netuid.into()); + let price: U96F32 = pallet_subtensor::Pallet::::get_moving_alpha_price(netuid); Ok(U256::from(price.saturating_to_num::())) } #[precompile::public("getTaoInPool(uint16)")] #[precompile::view] fn get_tao_in_pool(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::SubnetTAO::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::SubnetTAO::::get(netuid)) } #[precompile::public("getAlphaInPool(uint16)")] #[precompile::view] fn get_alpha_in_pool(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::SubnetAlphaIn::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::SubnetAlphaIn::::get(netuid)) } #[precompile::public("getAlphaOutPool(uint16)")] #[precompile::view] fn get_alpha_out_pool(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::SubnetAlphaOut::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::SubnetAlphaOut::::get(netuid)) } #[precompile::public("getAlphaIssuance(uint16)")] #[precompile::view] fn get_alpha_issuance(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::Pallet::::get_alpha_issuance( - netuid.into(), - )) + Ok(pallet_subtensor::Pallet::::get_alpha_issuance(netuid)) } #[precompile::public("getTaoWeight()")] @@ -81,8 +74,7 @@ where netuid: u16, tao: u64, ) -> EvmResult { - let alpha_option = - pallet_subtensor::Pallet::::sim_swap_tao_for_alpha(netuid.into(), tao); + let alpha_option = pallet_subtensor::Pallet::::sim_swap_tao_for_alpha(netuid, tao); let result = alpha_option.unwrap_or(0); Ok(U256::from(result)) } @@ -94,8 +86,7 @@ where netuid: u16, alpha: u64, ) -> EvmResult { - let tao_option = - pallet_subtensor::Pallet::::sim_swap_alpha_for_tao(netuid.into(), alpha); + let tao_option = pallet_subtensor::Pallet::::sim_swap_alpha_for_tao(netuid, alpha); let result = tao_option.unwrap_or(0); Ok(U256::from(result)) } @@ -103,15 +94,13 @@ where #[precompile::public("getSubnetMechanism(uint16)")] #[precompile::view] fn get_subnet_mechanism(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::SubnetMechanism::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::SubnetMechanism::::get(netuid)) } #[precompile::public("getRootNetuid()")] #[precompile::view] fn get_root_netuid(_handle: &mut impl PrecompileHandle) -> EvmResult { - Ok(NetUid::ROOT.into()) + Ok(pallet_subtensor::Pallet::::get_root_netuid()) } #[precompile::public("getEMAPriceHalvingBlocks(uint16)")] @@ -120,16 +109,12 @@ where _handle: &mut impl PrecompileHandle, netuid: u16, ) -> EvmResult { - Ok(pallet_subtensor::EMAPriceHalvingBlocks::::get( - NetUid::from(netuid), - )) + Ok(pallet_subtensor::EMAPriceHalvingBlocks::::get(netuid)) } #[precompile::public("getSubnetVolume(uint16)")] #[precompile::view] fn get_subnet_volume(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(U256::from(pallet_subtensor::SubnetVolume::::get( - NetUid::from(netuid), - ))) + Ok(U256::from(pallet_subtensor::SubnetVolume::::get(netuid))) } } diff --git a/precompiles/src/metagraph.rs b/precompiles/src/metagraph.rs index 05f7a5bf79..758ce8f8eb 100644 --- a/precompiles/src/metagraph.rs +++ b/precompiles/src/metagraph.rs @@ -5,7 +5,6 @@ use fp_evm::{ExitError, PrecompileFailure, PrecompileHandle}; use pallet_subtensor::AxonInfo as SubtensorModuleAxonInfo; use precompile_utils::{EvmResult, solidity::Codec}; use sp_core::{ByteArray, H256}; -use subtensor_runtime_common::NetUid; use crate::PrecompileExt; @@ -28,15 +27,13 @@ where #[precompile::public("getUidCount(uint16)")] #[precompile::view] fn get_uid_count(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::SubnetworkN::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::SubnetworkN::::get(netuid)) } #[precompile::public("getStake(uint16,uint16)")] #[precompile::view] fn get_stake(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { - let hotkey = pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid.into(), uid) + let hotkey = pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid, uid) .map_err(|_| PrecompileFailure::Error { exit_status: ExitError::InvalidRange, })?; @@ -49,18 +46,14 @@ where #[precompile::public("getRank(uint16,uint16)")] #[precompile::view] fn get_rank(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { - Ok(pallet_subtensor::Pallet::::get_rank_for_uid( - netuid.into(), - uid, - )) + Ok(pallet_subtensor::Pallet::::get_rank_for_uid(netuid, uid)) } #[precompile::public("getTrust(uint16,uint16)")] #[precompile::view] fn get_trust(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_trust_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -68,8 +61,7 @@ where #[precompile::view] fn get_consensus(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_consensus_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -77,8 +69,7 @@ where #[precompile::view] fn get_incentive(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_incentive_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -86,8 +77,7 @@ where #[precompile::view] fn get_dividends(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_dividends_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -95,8 +85,7 @@ where #[precompile::view] fn get_emission(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_emission_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -104,8 +93,7 @@ where #[precompile::view] fn get_vtrust(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_validator_trust_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -117,8 +105,7 @@ where uid: u16, ) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_validator_permit_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -126,8 +113,7 @@ where #[precompile::view] fn get_last_update(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_last_update_for_uid( - netuid.into(), - uid, + netuid, uid, )) } @@ -135,26 +121,25 @@ where #[precompile::view] fn get_is_active(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { Ok(pallet_subtensor::Pallet::::get_active_for_uid( - netuid.into(), - uid, + netuid, uid, )) } #[precompile::public("getAxon(uint16,uint16)")] #[precompile::view] fn get_axon(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { - let hotkey = pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid.into(), uid) + let hotkey = pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid, uid) .map_err(|_| PrecompileFailure::Error { exit_status: ExitError::Other("hotkey not found".into()), })?; - Ok(pallet_subtensor::Pallet::::get_axon_info(netuid.into(), &hotkey).into()) + Ok(pallet_subtensor::Pallet::::get_axon_info(netuid, &hotkey).into()) } #[precompile::public("getHotkey(uint16,uint16)")] #[precompile::view] fn get_hotkey(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { - pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid.into(), uid) + pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid, uid) .map(|acc| H256::from_slice(acc.as_slice())) .map_err(|_| PrecompileFailure::Error { exit_status: ExitError::InvalidRange, @@ -164,7 +149,7 @@ where #[precompile::public("getColdkey(uint16,uint16)")] #[precompile::view] fn get_coldkey(_: &mut impl PrecompileHandle, netuid: u16, uid: u16) -> EvmResult { - let hotkey = pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid.into(), uid) + let hotkey = pallet_subtensor::Pallet::::get_hotkey_for_net_and_uid(netuid, uid) .map_err(|_| PrecompileFailure::Error { exit_status: ExitError::InvalidRange, })?; diff --git a/precompiles/src/neuron.rs b/precompiles/src/neuron.rs index 3e49387bb3..cedb3a56db 100644 --- a/precompiles/src/neuron.rs +++ b/precompiles/src/neuron.rs @@ -44,7 +44,7 @@ where version_key: u64, ) -> EvmResult<()> { let call = pallet_subtensor::Call::::set_weights { - netuid: netuid.into(), + netuid, dests, weights, version_key, @@ -64,7 +64,7 @@ where commit_hash: H256, ) -> EvmResult<()> { let call = pallet_subtensor::Call::::commit_weights { - netuid: netuid.into(), + netuid, commit_hash, }; @@ -85,7 +85,7 @@ where version_key: u64, ) -> EvmResult<()> { let call = pallet_subtensor::Call::::reveal_weights { - netuid: netuid.into(), + netuid, uids, values, salt, @@ -107,10 +107,7 @@ where ) -> EvmResult<()> { let coldkey = handle.caller_account_id::(); let hotkey = R::AccountId::from(hotkey.0); - let call = pallet_subtensor::Call::::burned_register { - netuid: netuid.into(), - hotkey, - }; + let call = pallet_subtensor::Call::::burned_register { netuid, hotkey }; handle.try_dispatch_runtime_call::(call, RawOrigin::Signed(coldkey)) } @@ -130,7 +127,7 @@ where placeholder2: u8, ) -> EvmResult<()> { let call = pallet_subtensor::Call::::serve_axon { - netuid: netuid.into(), + netuid, version, ip, port, @@ -164,7 +161,7 @@ where certificate: UnboundedBytes, ) -> EvmResult<()> { let call = pallet_subtensor::Call::::serve_axon_tls { - netuid: netuid.into(), + netuid, version, ip, port, @@ -193,7 +190,7 @@ where ip_type: u8, ) -> EvmResult<()> { let call = pallet_subtensor::Call::::serve_prometheus { - netuid: netuid.into(), + netuid, version, ip, port, diff --git a/precompiles/src/staking.rs b/precompiles/src/staking.rs index f26506b14c..21f50bc917 100644 --- a/precompiles/src/staking.rs +++ b/precompiles/src/staking.rs @@ -37,7 +37,7 @@ use precompile_utils::EvmResult; use sp_core::{H256, U256}; use sp_runtime::traits::{Dispatchable, StaticLookup, UniqueSaturatedInto}; use sp_std::vec; -use subtensor_runtime_common::{NetUid, ProxyType}; +use subtensor_runtime_common::ProxyType; use crate::{PrecompileExt, PrecompileHandleExt}; @@ -94,7 +94,7 @@ where let netuid = try_u16_from_u256(netuid)?; let call = pallet_subtensor::Call::::add_stake { hotkey, - netuid: netuid.into(), + netuid, amount_staked, }; @@ -114,7 +114,7 @@ where let amount_unstaked = amount_alpha.unique_saturated_into(); let call = pallet_subtensor::Call::::remove_stake { hotkey, - netuid: netuid.into(), + netuid, amount_unstaked, }; @@ -139,8 +139,8 @@ where let call = pallet_subtensor::Call::::move_stake { origin_hotkey, destination_hotkey, - origin_netuid: origin_netuid.into(), - destination_netuid: destination_netuid.into(), + origin_netuid, + destination_netuid, alpha_amount, }; @@ -165,8 +165,8 @@ where let call = pallet_subtensor::Call::::transfer_stake { destination_coldkey, hotkey, - origin_netuid: origin_netuid.into(), - destination_netuid: destination_netuid.into(), + origin_netuid, + destination_netuid, alpha_amount, }; @@ -209,9 +209,7 @@ where let coldkey = R::AccountId::from(coldkey.0); let netuid = try_u16_from_u256(netuid)?; let stake = pallet_subtensor::Pallet::::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey, - &coldkey, - netuid.into(), + &hotkey, &coldkey, netuid, ); Ok(stake.into()) @@ -226,7 +224,7 @@ where ) -> EvmResult> { let hotkey = R::AccountId::from(hotkey.0); let mut coldkeys: Vec = vec![]; - let netuid = NetUid::from(try_u16_from_u256(netuid)?); + let netuid = try_u16_from_u256(netuid)?; for ((coldkey, netuid_in_alpha), _) in pallet_subtensor::Alpha::::iter_prefix((hotkey,)) { if netuid == netuid_in_alpha { @@ -247,8 +245,7 @@ where ) -> EvmResult { let hotkey = R::AccountId::from(hotkey.0); let netuid = try_u16_from_u256(netuid)?; - let stake = - pallet_subtensor::Pallet::::get_stake_for_hotkey_on_subnet(&hotkey, netuid.into()); + let stake = pallet_subtensor::Pallet::::get_stake_for_hotkey_on_subnet(&hotkey, netuid); Ok(stake.into()) } @@ -297,7 +294,7 @@ where let netuid = try_u16_from_u256(netuid)?; let call = pallet_subtensor::Call::::add_stake_limit { hotkey, - netuid: netuid.into(), + netuid, amount_staked, limit_price, allow_partial, @@ -322,7 +319,7 @@ where let limit_price = limit_price_rao.unique_saturated_into(); let call = pallet_subtensor::Call::::remove_stake_limit { hotkey, - netuid: netuid.into(), + netuid, amount_unstaked, limit_price, allow_partial, @@ -388,7 +385,7 @@ where let netuid = try_u16_from_u256(netuid)?; let call = pallet_subtensor::Call::::add_stake { hotkey, - netuid: netuid.into(), + netuid, amount_staked: amount_sub.unique_saturated_into(), }; @@ -412,7 +409,7 @@ where .ok_or(ExitError::OutOfFund)?; let call = pallet_subtensor::Call::::remove_stake { hotkey, - netuid: netuid.into(), + netuid, amount_unstaked, }; @@ -469,9 +466,7 @@ where let coldkey = R::AccountId::from(coldkey.0); let netuid = try_u16_from_u256(netuid)?; let stake = pallet_subtensor::Pallet::::get_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey, - &coldkey, - netuid.into(), + &hotkey, &coldkey, netuid, ); let stake: SubstrateBalance = stake.into(); let stake = ::BalanceConverter::into_evm_balance(stake) diff --git a/precompiles/src/subnet.rs b/precompiles/src/subnet.rs index 7eecb5d095..a793fbdfda 100644 --- a/precompiles/src/subnet.rs +++ b/precompiles/src/subnet.rs @@ -7,7 +7,6 @@ use pallet_evm::{AddressMapping, PrecompileHandle}; use precompile_utils::{EvmResult, prelude::BoundedString}; use sp_core::H256; use sp_runtime::traits::Dispatchable; -use subtensor_runtime_common::NetUid; use crate::{PrecompileExt, PrecompileHandleExt}; @@ -99,9 +98,7 @@ where #[precompile::public("getServingRateLimit(uint16)")] #[precompile::view] fn get_serving_rate_limit(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::ServingRateLimit::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::ServingRateLimit::::get(netuid)) } #[precompile::public("setServingRateLimit(uint16,uint64)")] @@ -112,7 +109,7 @@ where serving_rate_limit: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_serving_rate_limit { - netuid: netuid.into(), + netuid, serving_rate_limit, }; @@ -125,9 +122,7 @@ where #[precompile::public("getMinDifficulty(uint16)")] #[precompile::view] fn get_min_difficulty(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::MinDifficulty::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::MinDifficulty::::get(netuid)) } #[precompile::public("setMinDifficulty(uint16,uint64)")] @@ -138,7 +133,7 @@ where min_difficulty: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_min_difficulty { - netuid: netuid.into(), + netuid, min_difficulty, }; @@ -151,9 +146,7 @@ where #[precompile::public("getMaxDifficulty(uint16)")] #[precompile::view] fn get_max_difficulty(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::MaxDifficulty::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::MaxDifficulty::::get(netuid)) } #[precompile::public("setMaxDifficulty(uint16,uint64)")] @@ -164,7 +157,7 @@ where max_difficulty: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_max_difficulty { - netuid: netuid.into(), + netuid, max_difficulty, }; @@ -177,9 +170,7 @@ where #[precompile::public("getWeightsVersionKey(uint16)")] #[precompile::view] fn get_weights_version_key(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::WeightsVersionKey::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::WeightsVersionKey::::get(netuid)) } #[precompile::public("setWeightsVersionKey(uint16,uint64)")] @@ -190,7 +181,7 @@ where weights_version_key: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_weights_version_key { - netuid: netuid.into(), + netuid, weights_version_key, }; @@ -203,9 +194,7 @@ where #[precompile::public("getWeightsSetRateLimit(uint16)")] #[precompile::view] fn get_weights_set_rate_limit(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::WeightsSetRateLimit::::get( - NetUid::from(netuid), - )) + Ok(pallet_subtensor::WeightsSetRateLimit::::get(netuid)) } #[precompile::public("setWeightsSetRateLimit(uint16,uint64)")] @@ -222,9 +211,7 @@ where #[precompile::public("getAdjustmentAlpha(uint16)")] #[precompile::view] fn get_adjustment_alpha(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::AdjustmentAlpha::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::AdjustmentAlpha::::get(netuid)) } #[precompile::public("setAdjustmentAlpha(uint16,uint64)")] @@ -235,7 +222,7 @@ where adjustment_alpha: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_adjustment_alpha { - netuid: netuid.into(), + netuid, adjustment_alpha, }; @@ -248,9 +235,7 @@ where #[precompile::public("getMaxWeightLimit(uint16)")] #[precompile::view] fn get_max_weight_limit(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::MaxWeightsLimit::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::MaxWeightsLimit::::get(netuid)) } #[precompile::public("setMaxWeightLimit(uint16,uint16)")] @@ -261,7 +246,7 @@ where max_weight_limit: u16, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_max_weight_limit { - netuid: netuid.into(), + netuid, max_weight_limit, }; @@ -274,9 +259,7 @@ where #[precompile::public("getImmunityPeriod(uint16)")] #[precompile::view] fn get_immunity_period(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::ImmunityPeriod::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::ImmunityPeriod::::get(netuid)) } #[precompile::public("setImmunityPeriod(uint16,uint16)")] @@ -287,7 +270,7 @@ where immunity_period: u16, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_immunity_period { - netuid: netuid.into(), + netuid, immunity_period, }; @@ -300,9 +283,7 @@ where #[precompile::public("getMinAllowedWeights(uint16)")] #[precompile::view] fn get_min_allowed_weights(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::MinAllowedWeights::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::MinAllowedWeights::::get(netuid)) } #[precompile::public("setMinAllowedWeights(uint16,uint16)")] @@ -313,7 +294,7 @@ where min_allowed_weights: u16, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_min_allowed_weights { - netuid: netuid.into(), + netuid, min_allowed_weights, }; @@ -326,16 +307,13 @@ where #[precompile::public("getKappa(uint16)")] #[precompile::view] fn get_kappa(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::Kappa::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::Kappa::::get(netuid)) } #[precompile::public("setKappa(uint16,uint16)")] #[precompile::payable] fn set_kappa(handle: &mut impl PrecompileHandle, netuid: u16, kappa: u16) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_kappa { - netuid: netuid.into(), - kappa, - }; + let call = pallet_admin_utils::Call::::sudo_set_kappa { netuid, kappa }; handle.try_dispatch_runtime_call::( call, @@ -346,24 +324,19 @@ where #[precompile::public("getRho(uint16)")] #[precompile::view] fn get_rho(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::Rho::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::Rho::::get(netuid)) } #[precompile::public("getAlphaSigmoidSteepness(uint16)")] #[precompile::view] fn get_alpha_sigmoid_steepness(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::AlphaSigmoidSteepness::::get( - NetUid::from(netuid), - )) + Ok(pallet_subtensor::AlphaSigmoidSteepness::::get(netuid)) } #[precompile::public("setRho(uint16,uint16)")] #[precompile::payable] fn set_rho(handle: &mut impl PrecompileHandle, netuid: u16, rho: u16) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_rho { - netuid: netuid.into(), - rho, - }; + let call = pallet_admin_utils::Call::::sudo_set_rho { netuid, rho }; handle.try_dispatch_runtime_call::( call, @@ -378,10 +351,8 @@ where netuid: u16, steepness: u16, ) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_alpha_sigmoid_steepness { - netuid: netuid.into(), - steepness, - }; + let call = + pallet_admin_utils::Call::::sudo_set_alpha_sigmoid_steepness { netuid, steepness }; handle.try_dispatch_runtime_call::( call, @@ -392,9 +363,7 @@ where #[precompile::public("getActivityCutoff(uint16)")] #[precompile::view] fn get_activity_cutoff(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::ActivityCutoff::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::ActivityCutoff::::get(netuid)) } #[precompile::public("setActivityCutoff(uint16,uint16)")] @@ -405,7 +374,7 @@ where activity_cutoff: u16, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_activity_cutoff { - netuid: netuid.into(), + netuid, activity_cutoff, }; @@ -422,7 +391,7 @@ where netuid: u16, ) -> EvmResult { Ok(pallet_subtensor::NetworkRegistrationAllowed::::get( - NetUid::from(netuid), + netuid, )) } @@ -434,7 +403,7 @@ where registration_allowed: bool, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_network_registration_allowed { - netuid: netuid.into(), + netuid, registration_allowed, }; @@ -451,7 +420,7 @@ where netuid: u16, ) -> EvmResult { Ok(pallet_subtensor::NetworkPowRegistrationAllowed::::get( - NetUid::from(netuid), + netuid, )) } @@ -463,7 +432,7 @@ where registration_allowed: bool, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_network_pow_registration_allowed { - netuid: netuid.into(), + netuid, registration_allowed, }; @@ -476,7 +445,7 @@ where #[precompile::public("getMinBurn(uint16)")] #[precompile::view] fn get_min_burn(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::MinBurn::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::MinBurn::::get(netuid)) } #[precompile::public("setMinBurn(uint16,uint64)")] @@ -493,7 +462,7 @@ where #[precompile::public("getMaxBurn(uint16)")] #[precompile::view] fn get_max_burn(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::MaxBurn::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::MaxBurn::::get(netuid)) } #[precompile::public("setMaxBurn(uint16,uint64)")] @@ -510,7 +479,7 @@ where #[precompile::public("getDifficulty(uint16)")] #[precompile::view] fn get_difficulty(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::Difficulty::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::Difficulty::::get(netuid)) } #[precompile::public("setDifficulty(uint16,uint64)")] @@ -520,10 +489,7 @@ where netuid: u16, difficulty: u64, ) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_difficulty { - netuid: netuid.into(), - difficulty, - }; + let call = pallet_admin_utils::Call::::sudo_set_difficulty { netuid, difficulty }; handle.try_dispatch_runtime_call::( call, @@ -534,9 +500,7 @@ where #[precompile::public("getBondsMovingAverage(uint16)")] #[precompile::view] fn get_bonds_moving_average(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::BondsMovingAverage::::get( - NetUid::from(netuid), - )) + Ok(pallet_subtensor::BondsMovingAverage::::get(netuid)) } #[precompile::public("setBondsMovingAverage(uint16,uint64)")] @@ -547,7 +511,7 @@ where bonds_moving_average: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_bonds_moving_average { - netuid: netuid.into(), + netuid, bonds_moving_average, }; @@ -564,7 +528,7 @@ where netuid: u16, ) -> EvmResult { Ok(pallet_subtensor::CommitRevealWeightsEnabled::::get( - NetUid::from(netuid), + netuid, )) } @@ -576,7 +540,7 @@ where enabled: bool, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_commit_reveal_weights_enabled { - netuid: netuid.into(), + netuid, enabled, }; @@ -589,9 +553,7 @@ where #[precompile::public("getLiquidAlphaEnabled(uint16)")] #[precompile::view] fn get_liquid_alpha_enabled(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::LiquidAlphaOn::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::LiquidAlphaOn::::get(netuid)) } #[precompile::public("setLiquidAlphaEnabled(uint16,bool)")] @@ -601,10 +563,7 @@ where netuid: u16, enabled: bool, ) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_liquid_alpha_enabled { - netuid: netuid.into(), - enabled, - }; + let call = pallet_admin_utils::Call::::sudo_set_liquid_alpha_enabled { netuid, enabled }; handle.try_dispatch_runtime_call::( call, @@ -615,15 +574,13 @@ where #[precompile::public("getYuma3Enabled(uint16)")] #[precompile::view] fn get_yuma3_enabled(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::Yuma3On::::get(NetUid::from(netuid))) + Ok(pallet_subtensor::Yuma3On::::get(netuid)) } #[precompile::public("getBondsResetEnabled(uint16)")] #[precompile::view] fn get_bonds_reset_enabled(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult { - Ok(pallet_subtensor::BondsResetOn::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::BondsResetOn::::get(netuid)) } #[precompile::public("setYuma3Enabled(uint16,bool)")] @@ -633,10 +590,7 @@ where netuid: u16, enabled: bool, ) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_yuma3_enabled { - netuid: netuid.into(), - enabled, - }; + let call = pallet_admin_utils::Call::::sudo_set_yuma3_enabled { netuid, enabled }; handle.try_dispatch_runtime_call::( call, @@ -665,9 +619,7 @@ where #[precompile::public("getAlphaValues(uint16)")] #[precompile::view] fn get_alpha_values(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<(u16, u16)> { - Ok(pallet_subtensor::AlphaValues::::get(NetUid::from( - netuid, - ))) + Ok(pallet_subtensor::AlphaValues::::get(netuid)) } #[precompile::public("setAlphaValues(uint16,uint16,uint16)")] @@ -679,7 +631,7 @@ where alpha_high: u16, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_alpha_values { - netuid: netuid.into(), + netuid, alpha_low, alpha_high, }; @@ -696,9 +648,7 @@ where _: &mut impl PrecompileHandle, netuid: u16, ) -> EvmResult { - Ok(pallet_subtensor::RevealPeriodEpochs::::get( - NetUid::from(netuid), - )) + Ok(pallet_subtensor::RevealPeriodEpochs::::get(netuid)) } #[precompile::public("setCommitRevealWeightsInterval(uint16,uint64)")] @@ -709,7 +659,7 @@ where interval: u64, ) -> EvmResult<()> { let call = pallet_admin_utils::Call::::sudo_set_commit_reveal_weights_interval { - netuid: netuid.into(), + netuid, interval, }; @@ -726,10 +676,7 @@ where netuid: u16, toggle: bool, ) -> EvmResult<()> { - let call = pallet_admin_utils::Call::::sudo_set_toggle_transfer { - netuid: netuid.into(), - toggle, - }; + let call = pallet_admin_utils::Call::::sudo_set_toggle_transfer { netuid, toggle }; handle.try_dispatch_runtime_call::( call, diff --git a/precompiles/src/uid_lookup.rs b/precompiles/src/uid_lookup.rs index be8c803b45..61fb9d6d7f 100644 --- a/precompiles/src/uid_lookup.rs +++ b/precompiles/src/uid_lookup.rs @@ -45,7 +45,7 @@ where limit: u16, ) -> EvmResult> { Ok(pallet_subtensor::Pallet::::uid_lookup( - netuid.into(), + netuid, evm_address.0, limit, )) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 581e3d2252..9e0e158358 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -943,7 +943,7 @@ impl CanRegisterIdentity for AllowIdentityReg { fn can_register(address: &AccountId, identified: &AccountId) -> bool { if address != identified { SubtensorModule::coldkey_owns_hotkey(address, identified) - && SubtensorModule::is_hotkey_registered_on_network(NetUid::ROOT, identified) + && SubtensorModule::is_hotkey_registered_on_network(0, identified) } else { SubtensorModule::is_subnet_owner(address) } @@ -993,12 +993,12 @@ impl Get for MaxCommitFields { pub struct AllowCommitments; impl CanCommit for AllowCommitments { #[cfg(not(feature = "runtime-benchmarks"))] - fn can_commit(netuid: NetUid, address: &AccountId) -> bool { + fn can_commit(netuid: u16, address: &AccountId) -> bool { SubtensorModule::is_hotkey_registered_on_network(netuid, address) } #[cfg(feature = "runtime-benchmarks")] - fn can_commit(_: NetUid, _: &AccountId) -> bool { + fn can_commit(_: u16, _: &AccountId) -> bool { true } } @@ -1006,12 +1006,12 @@ impl CanCommit for AllowCommitments { pub struct ResetBondsOnCommit; impl OnMetadataCommitment for ResetBondsOnCommit { #[cfg(not(feature = "runtime-benchmarks"))] - fn on_metadata_commitment(netuid: NetUid, address: &AccountId) { + fn on_metadata_commitment(netuid: u16, address: &AccountId) { let _ = SubtensorModule::do_reset_bonds(netuid, address); } #[cfg(feature = "runtime-benchmarks")] - fn on_metadata_commitment(_: NetUid, _: &AccountId) {} + fn on_metadata_commitment(_: u16, _: &AccountId) {} } impl pallet_commitments::Config for Runtime { @@ -1030,13 +1030,13 @@ impl pallet_commitments::Config for Runtime { pub struct TempoInterface; impl pallet_commitments::GetTempoInterface for TempoInterface { - fn get_epoch_index(netuid: NetUid, cur_block: u64) -> u64 { + fn get_epoch_index(netuid: u16, cur_block: u64) -> u64 { SubtensorModule::get_epoch_index(netuid, cur_block) } } impl pallet_commitments::GetTempoInterface for Runtime { - fn get_epoch_index(netuid: NetUid, cur_block: u64) -> u64 { + fn get_epoch_index(netuid: u16, cur_block: u64) -> u64 { SubtensorModule::get_epoch_index(netuid, cur_block) } } @@ -2190,31 +2190,31 @@ impl_runtime_apis! { SubtensorModule::get_delegate(delegate_account) } - fn get_delegated(delegatee_account: AccountId32) -> Vec<(DelegateInfo, (Compact, Compact))> { + fn get_delegated(delegatee_account: AccountId32) -> Vec<(DelegateInfo, (Compact, Compact))> { SubtensorModule::get_delegated(delegatee_account) } } impl subtensor_custom_rpc_runtime_api::NeuronInfoRuntimeApi for Runtime { - fn get_neurons_lite(netuid: NetUid) -> Vec> { + fn get_neurons_lite(netuid: u16) -> Vec> { SubtensorModule::get_neurons_lite(netuid) } - fn get_neuron_lite(netuid: NetUid, uid: u16) -> Option> { + fn get_neuron_lite(netuid: u16, uid: u16) -> Option> { SubtensorModule::get_neuron_lite(netuid, uid) } - fn get_neurons(netuid: NetUid) -> Vec> { + fn get_neurons(netuid: u16) -> Vec> { SubtensorModule::get_neurons(netuid) } - fn get_neuron(netuid: NetUid, uid: u16) -> Option> { + fn get_neuron(netuid: u16, uid: u16) -> Option> { SubtensorModule::get_neuron(netuid, uid) } } impl subtensor_custom_rpc_runtime_api::SubnetInfoRuntimeApi for Runtime { - fn get_subnet_info(netuid: NetUid) -> Option> { + fn get_subnet_info(netuid: u16) -> Option> { SubtensorModule::get_subnet_info(netuid) } @@ -2222,7 +2222,7 @@ impl_runtime_apis! { SubtensorModule::get_subnets_info() } - fn get_subnet_info_v2(netuid: NetUid) -> Option> { + fn get_subnet_info_v2(netuid: u16) -> Option> { SubtensorModule::get_subnet_info_v2(netuid) } @@ -2230,19 +2230,19 @@ impl_runtime_apis! { SubtensorModule::get_subnets_info_v2() } - fn get_subnet_hyperparams(netuid: NetUid) -> Option { + fn get_subnet_hyperparams(netuid: u16) -> Option { SubtensorModule::get_subnet_hyperparams(netuid) } - fn get_dynamic_info(netuid: NetUid) -> Option> { + fn get_dynamic_info(netuid: u16) -> Option> { SubtensorModule::get_dynamic_info(netuid) } - fn get_metagraph(netuid: NetUid) -> Option> { + fn get_metagraph(netuid: u16) -> Option> { SubtensorModule::get_metagraph(netuid) } - fn get_subnet_state(netuid: NetUid) -> Option> { + fn get_subnet_state(netuid: u16) -> Option> { SubtensorModule::get_subnet_state(netuid) } @@ -2254,7 +2254,7 @@ impl_runtime_apis! { SubtensorModule::get_all_dynamic_info() } - fn get_selective_metagraph(netuid: NetUid, metagraph_indexes: Vec) -> Option> { + fn get_selective_metagraph(netuid: u16, metagraph_indexes: Vec) -> Option> { SubtensorModule::get_selective_metagraph(netuid, metagraph_indexes) } @@ -2269,11 +2269,11 @@ impl_runtime_apis! { SubtensorModule::get_stake_info_for_coldkeys( coldkey_accounts ) } - fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: NetUid ) -> Option> { + fn get_stake_info_for_hotkey_coldkey_netuid( hotkey_account: AccountId32, coldkey_account: AccountId32, netuid: u16 ) -> Option> { SubtensorModule::get_stake_info_for_hotkey_coldkey_netuid( hotkey_account, coldkey_account, netuid ) } - fn get_stake_fee( origin: Option<(AccountId32, NetUid)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, NetUid)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64 { + fn get_stake_fee( origin: Option<(AccountId32, u16)>, origin_coldkey_account: AccountId32, destination: Option<(AccountId32, u16)>, destination_coldkey_account: AccountId32, amount: u64 ) -> u64 { SubtensorModule::get_stake_fee( origin, origin_coldkey_account, destination, destination_coldkey_account, amount ) } } diff --git a/runtime/tests/pallet_proxy.rs b/runtime/tests/pallet_proxy.rs index 088da291e2..1fcb36dec5 100644 --- a/runtime/tests/pallet_proxy.rs +++ b/runtime/tests/pallet_proxy.rs @@ -6,7 +6,7 @@ use node_subtensor_runtime::{ BalancesCall, BuildStorage, Proxy, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin, SubtensorModule, System, SystemCall, }; -use subtensor_runtime_common::{AccountId, NetUid, ProxyType}; +use subtensor_runtime_common::{AccountId, ProxyType}; const ACCOUNT: [u8; 32] = [1_u8; 32]; const DELEGATE: [u8; 32] = [2_u8; 32]; @@ -60,7 +60,7 @@ fn call_remark() -> RuntimeCall { // owner call fn call_owner_util() -> RuntimeCall { - let netuid = NetUid::from(1); + let netuid = 1; let serving_rate_limit = 2; RuntimeCall::AdminUtils(pallet_admin_utils::Call::sudo_set_serving_rate_limit { netuid, @@ -70,7 +70,7 @@ fn call_owner_util() -> RuntimeCall { // sn owner hotkey call fn call_sn_owner_hotkey() -> RuntimeCall { - let netuid = NetUid::from(1); + let netuid = 1; RuntimeCall::AdminUtils(pallet_admin_utils::Call::sudo_set_sn_owner_hotkey { netuid, hotkey: AccountId::from(ACCOUNT).into(), @@ -112,7 +112,7 @@ fn call_senate() -> RuntimeCall { // staking call fn call_add_stake() -> RuntimeCall { - let netuid = NetUid::from(1); + let netuid = 1; let amount_staked = 100; RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake { hotkey: AccountId::from(DELEGATE), @@ -124,7 +124,7 @@ fn call_add_stake() -> RuntimeCall { // register call, account as hotkey, delegate as coldkey fn call_register() -> RuntimeCall { let block_number: u64 = 1; - let netuid = NetUid::from(2); + let netuid: u16 = 2; // lower diff first SubtensorModule::set_difficulty(netuid, 100);