From 9de3678e3fa413ab33d510462feff0cec427813a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 17:39:13 +0100 Subject: [PATCH 001/137] Remove check_validotar_permit from pallet-subtensor --- pallets/subtensor/src/subnets/weights.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index ed7708448..5ee39f09d 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -739,7 +739,8 @@ impl Pallet { // --- 10. Check that the neuron uid is an allowed validator permitted to set non-self weights. ensure!( - Self::check_validator_permit(netuid, neuron_uid, &uids, &values), + Self::is_self_weight(neuron_uid, &uids, &values) + || Self::get_validator_permit_for_uid(netuid, neuron_uid), Error::::NeuronNoValidatorPermit ); @@ -955,16 +956,6 @@ impl Pallet { false } - /// Returns True if setting self-weight or has validator permit. - 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; - } - // Check if uid has validator permit. - Self::get_validator_permit_for_uid(netuid, uid) - } - /// Returns True if the uids and weights are have a valid length for uid on network. pub fn check_length(netuid: u16, uid: u16, uids: &[u16], weights: &[u16]) -> bool { let subnet_n: usize = Self::get_subnetwork_n(netuid) as usize; From c6f974adbaca5dddcde5182ca2fff44f0998c995 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 17:40:36 +0100 Subject: [PATCH 002/137] Remove check_allowed_register from pallet-subtensor --- pallets/subtensor/src/lib.rs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 2f92fd60e..d1679a945 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1373,30 +1373,6 @@ pub mod pallet { // Blacklist weights transactions for low stake peers. Self::get_stake_for_hotkey_on_subnet(hotkey, netuid) >= Self::get_stake_threshold() } - - /// Helper function to check if register is allowed - pub fn checked_allowed_register(netuid: u16) -> bool { - if netuid == Self::get_root_netuid() { - return false; - } - if !Self::if_subnet_exist(netuid) { - return false; - } - if !Self::get_network_registration_allowed(netuid) { - return false; - } - if Self::get_registrations_this_block(netuid) - >= Self::get_max_registrations_per_block(netuid) - { - return false; - } - if Self::get_registrations_this_interval(netuid) - >= Self::get_target_registrations_per_interval(netuid).saturating_mul(3) - { - return false; - } - true - } } } From ceee1c7443f515d4bf3a7682108664c18728b083 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 18:00:14 +0100 Subject: [PATCH 003/137] Remove decrease_stake_on_hotkey_account from pallet-subtensor --- pallets/subtensor/src/staking/helpers.rs | 13 ------------- pallets/subtensor/src/tests/staking.rs | 13 +++++++++++-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 4a5369ecf..797b2f714 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -161,19 +161,6 @@ impl Pallet { ); } - /// Decreases the stake on the hotkey account under its owning coldkey. - /// - /// # Arguments - /// * `hotkey` - The hotkey account ID. - /// * `decrement` - The amount to be decremented. - pub fn decrease_stake_on_hotkey_account(hotkey: &T::AccountId, decrement: u64) { - Self::decrease_stake_on_coldkey_hotkey_account( - &Self::get_owning_coldkey_for_hotkey(hotkey), - hotkey, - decrement, - ); - } - // Increases the stake on the cold - hot pairing by increment while also incrementing other counters. // This function should be called rather than set_stake under account. // diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index e6675e0cd..d7358366e 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -897,7 +897,11 @@ fn test_remove_stake_from_hotkey_account() { ); // Remove stake - SubtensorModule::decrease_stake_on_hotkey_account(&hotkey_id, amount); + SubtensorModule::decrease_stake_on_coldkey_hotkey_account( + &SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_id), + &hotkey_id, + amount, + ); // The stake on the hotkey account should be 0 assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); @@ -950,7 +954,12 @@ fn test_remove_stake_from_hotkey_account_registered_in_various_networks() { ); // Remove stake - SubtensorModule::decrease_stake_on_hotkey_account(&hotkey_id, amount); + SubtensorModule::decrease_stake_on_coldkey_hotkey_account( + &SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_id), + &hotkey_id, + amount, + ); + // assert_eq!( SubtensorModule::get_stake_for_uid_and_subnetwork(netuid, neuron_uid), From 979d84fc84ed9c039c6dfc98afe15b4cc1fd0493 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 18:17:38 +0100 Subject: [PATCH 004/137] Remove decrease/increase_total_stake from pallet-subtensor --- pallets/subtensor/src/benchmarks.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 12 ------------ pallets/subtensor/src/tests/staking.rs | 19 ++++--------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 6fd1cbf8b..cb6f19e92 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -143,7 +143,7 @@ benchmarks! { Subtensor::::set_target_stakes_per_interval(100); // Set our total stake to 1000 TAO - Subtensor::::increase_total_stake(1_000_000_000_000); + TotalStake::::put(Subtensor::::get_total_stake().saturating_add(1_000_000_000_000)); Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_network_registration_allowed( netuid, true ); diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 797b2f714..63b6524f1 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -29,18 +29,6 @@ impl Pallet { TotalStake::::get() } - // Increases the total amount of stake by the passed amount. - // - pub fn increase_total_stake(increment: u64) { - TotalStake::::put(Self::get_total_stake().saturating_add(increment)); - } - - // Decreases the total amount of stake by the passed amount. - // - pub fn decrease_total_stake(decrement: u64) { - TotalStake::::put(Self::get_total_stake().saturating_sub(decrement)); - } - // Returns the total amount of stake under a hotkey (delegative or otherwise) // pub fn get_total_stake_for_hotkey(hotkey: &T::AccountId) -> u64 { diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index d7358366e..eb1a3df22 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -972,19 +972,6 @@ fn test_remove_stake_from_hotkey_account_registered_in_various_networks() { }); } -// /************************************************************ -// staking::increase_total_stake() tests -// ************************************************************/ -#[test] -fn test_increase_total_stake_ok() { - new_test_ext(1).execute_with(|| { - let increment = 10000; - assert_eq!(SubtensorModule::get_total_stake(), 0); - SubtensorModule::increase_total_stake(increment); - assert_eq!(SubtensorModule::get_total_stake(), increment); - }); -} - // /************************************************************ // staking::decrease_total_stake() tests // ************************************************************/ @@ -994,8 +981,10 @@ fn test_decrease_total_stake_ok() { let initial_total_stake = 10000; let decrement = 5000; - SubtensorModule::increase_total_stake(initial_total_stake); - SubtensorModule::decrease_total_stake(decrement); + TotalStake::::put( + SubtensorModule::get_total_stake().saturating_add(initial_total_stake), + ); + TotalStake::::put(SubtensorModule::get_total_stake().saturating_sub(decrement)); // The total stake remaining should be the difference between the initial stake and the decrement assert_eq!( From d4edf488731740358aeb0357b29e2c5c7b97d123 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 19:15:24 +0100 Subject: [PATCH 005/137] Remove do_set_senate_required_stake_perc from pallet-subtensor --- pallets/subtensor/src/utils/misc.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 4c3fd2ba1..260acbe15 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -659,17 +659,6 @@ impl Pallet { T::SenateMembers::is_member(hotkey) } - pub fn do_set_senate_required_stake_perc( - origin: T::RuntimeOrigin, - required_percent: u64, - ) -> DispatchResult { - ensure_root(origin)?; - - Self::set_senate_required_stake_perc(required_percent); - Self::deposit_event(Event::SenateRequiredStakePercentSet(required_percent)); - Ok(()) - } - pub fn is_subnet_owner(address: &T::AccountId) -> bool { SubnetOwner::::iter_values().any(|owner| *address == owner) } From 0d8e3cd7c0a6ac869f4ff47c76989b14d27418cc Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 20:02:11 +0100 Subject: [PATCH 006/137] Remove get_rao_recycled from pallet-subtensor --- pallets/admin-utils/src/tests/mod.rs | 10 +++++----- pallets/subtensor/src/tests/registration.rs | 11 ++++++++--- pallets/subtensor/src/utils/misc.rs | 6 ++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 9bdf133f5..4b39c60db 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -5,8 +5,7 @@ use frame_support::{ traits::Hooks, }; use frame_system::Config; -use pallet_subtensor::Error as SubtensorError; -use pallet_subtensor::{migrations, Event}; +use pallet_subtensor::{migrations, Error as SubtensorError, Event, RAORecycledForRegistration}; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -746,7 +745,7 @@ fn test_sudo_set_rao_recycled() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_rao_recycled(netuid); + let init_value: u64 = RAORecycledForRegistration::::get(netuid); // Need to run from genesis block run_to_block(1); @@ -767,7 +766,8 @@ fn test_sudo_set_rao_recycled() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_rao_recycled(netuid), init_value); + + assert_eq!(RAORecycledForRegistration::::get(netuid), init_value); // Verify no events emitted matching the expected event assert_eq!( @@ -786,7 +786,7 @@ fn test_sudo_set_rao_recycled() { netuid, to_be_set )); - assert_eq!(SubtensorModule::get_rao_recycled(netuid), to_be_set); + assert_eq!(RAORecycledForRegistration::::get(netuid), to_be_set); // Verify event emitted with correct values assert_eq!( diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 07a456c83..a0e68b38c 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,6 +11,8 @@ use frame_system::Config; use sp_core::U256; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; +use crate::RAORecycledForRegistration; + /******************************************** subscribing::subscribe() tests *********************************************/ @@ -1465,7 +1467,7 @@ fn test_burn_registration_increase_recycled_rao() { netuid, hotkey_account_id )); - assert_eq!(SubtensorModule::get_rao_recycled(netuid), burn_amount); + assert_eq!(RAORecycledForRegistration::::get(netuid), burn_amount); run_to_block(2); @@ -1480,9 +1482,12 @@ fn test_burn_registration_increase_recycled_rao() { netuid2, U256::from(2) )); - assert_eq!(SubtensorModule::get_rao_recycled(netuid2), burn_amount2 * 2); + assert_eq!( + RAORecycledForRegistration::::get(netuid2), + burn_amount2 * 2 + ); // Validate netuid is not affected. - assert_eq!(SubtensorModule::get_rao_recycled(netuid), burn_amount); + assert_eq!(RAORecycledForRegistration::::get(netuid), burn_amount); }); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 260acbe15..9bc81180d 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -638,15 +638,13 @@ impl Pallet { TotalIssuance::::put(total_issuance); } - pub fn get_rao_recycled(netuid: u16) -> u64 { - RAORecycledForRegistration::::get(netuid) - } 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: u16, inc_rao_recycled: u64) { - let curr_rao_recycled = Self::get_rao_recycled(netuid); + let curr_rao_recycled = RAORecycledForRegistration::::get(netuid); let rao_recycled = curr_rao_recycled.saturating_add(inc_rao_recycled); Self::set_rao_recycled(netuid, rao_recycled); } From 506101f4e61c910d342352174ee019ccf80424d3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 21:04:19 +0100 Subject: [PATCH 007/137] Remove get_axon_info from pallet-subtensor --- pallets/subtensor/src/rpc_info/neuron_info.rs | 14 ++++++------- pallets/subtensor/src/subnets/serving.rs | 20 ++----------------- pallets/subtensor/src/tests/registration.rs | 4 ++-- pallets/subtensor/src/tests/serving.rs | 6 +++--- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index be367a566..188818a2a 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -77,9 +77,9 @@ impl Pallet { Err(_) => return None, }; - let axon_info = Self::get_axon_info(netuid, &hotkey.clone()); + let axon_info = Axons::::get(netuid, &hotkey).unwrap_or_default(); - let prometheus_info = Self::get_prometheus_info(netuid, &hotkey.clone()); + let prometheus_info = Self::get_prometheus_info(netuid, &hotkey); let coldkey = Owner::::get(hotkey.clone()).clone(); @@ -160,11 +160,11 @@ impl Pallet { Err(_) => return None, }; - let axon_info = Self::get_axon_info(netuid, &hotkey.clone()); + let axon_info = Axons::::get(netuid, &hotkey).unwrap_or_default(); - let prometheus_info = Self::get_prometheus_info(netuid, &hotkey.clone()); + let prometheus_info = Self::get_prometheus_info(netuid, &hotkey); - let coldkey = Owner::::get(hotkey.clone()).clone(); + let coldkey = Owner::::get(&hotkey).clone(); let active = Self::get_active_for_uid(netuid, uid); let rank = Self::get_rank_for_uid(netuid, uid); @@ -184,8 +184,8 @@ impl Pallet { )]; let neuron = NeuronInfoLite { - hotkey: hotkey.clone(), - coldkey: coldkey.clone(), + hotkey, + coldkey, uid: uid.into(), netuid: netuid.into(), active, diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index 647b328cc..19027526d 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -83,7 +83,8 @@ impl Pallet { ); // Get the previous axon information. - let mut prev_axon = Self::get_axon_info(netuid, &hotkey_id); + let mut prev_axon = Axons::::get(netuid, &hotkey_id).unwrap_or_default(); + let current_block: u64 = Self::get_current_block_as_u64(); ensure!( Self::axon_passes_rate_limit(netuid, &prev_axon, current_block), @@ -246,23 +247,6 @@ impl Pallet { rate_limit == 0 || last_serve == 0 || current_block.saturating_sub(last_serve) >= rate_limit } - pub fn get_axon_info(netuid: u16, hotkey: &T::AccountId) -> AxonInfoOf { - if let Some(axons) = Axons::::get(netuid, hotkey) { - axons - } else { - AxonInfo { - block: 0, - version: 0, - ip: 0, - port: 0, - ip_type: 0, - protocol: 0, - placeholder1: 0, - placeholder2: 0, - } - } - } - pub fn get_prometheus_info(netuid: u16, hotkey: &T::AccountId) -> PrometheusInfoOf { if let Some(prometheus) = Prometheus::::get(netuid, hotkey) { prometheus diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index a0e68b38c..5d42e9fb9 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -3,7 +3,7 @@ use frame_support::traits::Currency; use super::mock::*; -use crate::{AxonInfoOf, Error, SubtensorSignedExtension}; +use crate::{Axons, Error, SubtensorSignedExtension}; use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}; use frame_support::sp_runtime::{transaction_validity::InvalidTransaction, DispatchError}; use frame_support::{assert_err, assert_noop, assert_ok}; @@ -1363,7 +1363,7 @@ fn test_registration_get_neuron_metadata() { // //let neuron_id = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id); // let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey( netuid, &hotkey_account_id ).unwrap(); - let neuron: AxonInfoOf = SubtensorModule::get_axon_info(netuid, &hotkey_account_id); + let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, 0); assert_eq!(neuron.version, 0); assert_eq!(neuron.port, 0); diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index 32b604ba5..e28618f67 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -88,7 +88,7 @@ fn test_serving_ok() { placeholder1, placeholder2 )); - let neuron = SubtensorModule::get_axon_info(netuid, &hotkey_account_id); + let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip); assert_eq!(neuron.version, version); assert_eq!(neuron.port, port); @@ -184,7 +184,7 @@ fn test_serving_set_metadata_update() { placeholder1, placeholder2 )); - let neuron = SubtensorModule::get_axon_info(netuid, &hotkey_account_id); + let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip); assert_eq!(neuron.version, version); assert_eq!(neuron.port, port); @@ -210,7 +210,7 @@ fn test_serving_set_metadata_update() { placeholder12, placeholder22 )); - let neuron = SubtensorModule::get_axon_info(netuid, &hotkey_account_id); + let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip2); assert_eq!(neuron.version, version2); assert_eq!(neuron.port, port2); From 1b8dbd99b6fa1c66b99dbd62b24c56a3fe99e04d Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 29 Nov 2024 21:40:18 +0100 Subject: [PATCH 008/137] Remove get_root_netuid from pallet-subtensor --- pallets/subtensor/src/coinbase/root.rs | 30 +++++++------------ pallets/subtensor/src/staking/set_children.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 4 +-- pallets/subtensor/src/subnets/weights.rs | 4 +-- pallets/subtensor/src/tests/children.rs | 4 +-- pallets/subtensor/src/tests/senate.rs | 2 +- 6 files changed, 19 insertions(+), 27 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 9d53151b4..bcf5ef91c 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -29,16 +29,8 @@ use substrate_fixed::{ }; 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 - } + pub(crate) const ROOT_NETUID: u16 = 0; /// Fetches the total count of subnets. /// @@ -79,7 +71,7 @@ impl Pallet { /// * 'u16': The total number of root network validators /// pub fn get_num_root_validators() -> u16 { - Self::get_subnetwork_n(Self::get_root_netuid()) + Self::get_subnetwork_n(Self::ROOT_NETUID) } /// Fetches the max validators count of root network. @@ -90,7 +82,7 @@ impl Pallet { /// * 'u16': The max validators count of root network. /// pub fn get_max_root_validators() -> u16 { - Self::get_max_allowed_uids(Self::get_root_netuid()) + Self::get_max_allowed_uids(Self::ROOT_NETUID) } /// Returns the emission value for the given subnet. @@ -268,7 +260,7 @@ impl Pallet { // --- 3. Iterate over stored weights and fill the matrix. for (uid_i, weights_i) in as IterableStorageDoubleMap>>::iter_prefix( - Self::get_root_netuid(), + Self::ROOT_NETUID, ) { // --- 4. Iterate over each weight entry in `weights_i` to update the corresponding value in the @@ -325,7 +317,7 @@ impl Pallet { /// pub fn root_epoch(block_number: u64) -> Result<(), &'static str> { // --- 0. The unique ID associated with the root network. - let root_netuid: u16 = Self::get_root_netuid(); + let root_netuid: u16 = Self::ROOT_NETUID; // --- 1. Check if we should update the emission values based on blocks since emission was last set. let blocks_until_next_epoch: u64 = @@ -478,7 +470,7 @@ 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 root_netuid: u16 = Self::ROOT_NETUID; let current_block_number: u64 = Self::get_current_block_as_u64(); ensure!( Self::if_subnet_exist(root_netuid), @@ -615,7 +607,7 @@ impl Pallet { // 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(); + let root_netuid: u16 = Self::ROOT_NETUID; ensure!( Self::if_subnet_exist(root_netuid), Error::::RootNetworkDoesNotExist @@ -677,7 +669,7 @@ impl Pallet { // fn join_senate_if_eligible(hotkey: &T::AccountId) -> Result, Error> { // Get the root network UID. - let root_netuid: u16 = Self::get_root_netuid(); + let root_netuid: u16 = Self::ROOT_NETUID; // --- 1. Check the hotkey is registered in the root network. ensure!( @@ -761,7 +753,7 @@ impl Pallet { ); // Check that this is the root network. - ensure!(netuid == Self::get_root_netuid(), Error::::NotRootSubnet); + ensure!(netuid == Self::ROOT_NETUID, Error::::NotRootSubnet); // Check that the length of uid list and value list are equal for this network. ensure!( @@ -1165,7 +1157,7 @@ impl Pallet { // --- 9. Iterate over stored weights and fill the matrix. for (uid_i, weights_i) in as IterableStorageDoubleMap>>::iter_prefix( - Self::get_root_netuid(), + Self::ROOT_NETUID, ) { // Create a new vector to hold modified weights. @@ -1177,7 +1169,7 @@ impl Pallet { *weight = 0; // Set weight to 0 for the matching subnet_id. } } - Weights::::insert(Self::get_root_netuid(), uid_i, modified_weights); + Weights::::insert(Self::ROOT_NETUID, uid_i, modified_weights); } // --- 10. Remove various network-related parameters. diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index c47dfa0ca..9407e40b6 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -70,7 +70,7 @@ impl Pallet { // Check that this delegation is not on the root network. Child hotkeys are not valid on root. ensure!( - netuid != Self::get_root_netuid(), + netuid != Self::ROOT_NETUID, Error::::RegistrationNotPermittedOnRootSubnet ); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 516fd8cf3..2f87ffd2a 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -50,7 +50,7 @@ impl Pallet { // --- 2. Ensure the passed network is valid. ensure!( - netuid != Self::get_root_netuid(), + netuid != Self::ROOT_NETUID, Error::::RegistrationNotPermittedOnRootSubnet ); ensure!( @@ -235,7 +235,7 @@ impl Pallet { // --- 2. Ensure the passed network is valid. ensure!( - netuid != Self::get_root_netuid(), + netuid != Self::ROOT_NETUID, Error::::RegistrationNotPermittedOnRootSubnet ); ensure!( diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 5ee39f09d..958d4fccc 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -687,7 +687,7 @@ impl Pallet { // --- Check that the netuid is not the root network. ensure!( - netuid != Self::get_root_netuid(), + netuid != Self::ROOT_NETUID, Error::::CanNotSetRootNetworkWeights ); @@ -970,7 +970,7 @@ impl Pallet { // Check self weight. Allowed to set single value for self weight. // Or check that this is the root netuid. - if netuid != Self::get_root_netuid() && Self::is_self_weight(uid, uids, weights) { + if netuid != Self::ROOT_NETUID && Self::is_self_weight(uid, uids, weights) { return true; } // Check if number of weights exceeds min. diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index ea89e4aae..3b6676e41 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -118,7 +118,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: u16 = SubtensorModule::get_root_netuid(); // Root network + let netuid: u16 = SubtensorModule::ROOT_NETUID; // Root network let proportion: u64 = 1000; // Add network and register hotkey @@ -663,7 +663,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: u16 = SubtensorModule::get_root_netuid(); // Root network + let netuid: u16 = SubtensorModule::ROOT_NETUID; // Root network let proportion: u64 = 1000; // Add network and register hotkey diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index 75a7f064a..565f00288 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -662,7 +662,7 @@ fn test_adjust_senate_events() { let hotkey_account_id = U256::from(6); let burn_cost = 1000; let coldkey_account_id = U256::from(667); - let root_netuid = SubtensorModule::get_root_netuid(); + let root_netuid = SubtensorModule::ROOT_NETUID; let max_senate_size: u16 = SenateMaxMembers::get() as u16; let stake_threshold: u64 = 100_000; // Give this much to every senator From 1fbbc300600e2dcda8aead58715f716c0f49fdf8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 2 Dec 2024 15:51:30 +0100 Subject: [PATCH 009/137] Remove get_subnetwork_n from pallet-subtensor --- pallets/admin-utils/src/lib.rs | 2 +- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/epoch/run_epoch.rs | 14 +++---- pallets/subtensor/src/rpc_info/neuron_info.rs | 4 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 +- pallets/subtensor/src/subnets/registration.rs | 6 +-- pallets/subtensor/src/subnets/uids.rs | 7 +--- pallets/subtensor/src/subnets/weights.rs | 4 +- pallets/subtensor/src/tests/difficulty.rs | 3 +- pallets/subtensor/src/tests/epoch.rs | 20 ++++----- pallets/subtensor/src/tests/migration.rs | 2 +- pallets/subtensor/src/tests/registration.rs | 42 +++++++++---------- pallets/subtensor/src/tests/root.rs | 26 +++++------- pallets/subtensor/src/tests/senate.rs | 25 ++++++----- pallets/subtensor/src/tests/staking.rs | 2 +- pallets/subtensor/src/tests/weights.rs | 27 ++++++------ 16 files changed, 90 insertions(+), 100 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index d709c70c5..ab353bc65 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -397,7 +397,7 @@ pub mod pallet { Error::::SubnetDoesNotExist ); ensure!( - pallet_subtensor::Pallet::::get_subnetwork_n(netuid) < max_allowed_uids, + pallet_subtensor::SubnetworkN::::get(netuid) < max_allowed_uids, Error::::MaxAllowedUIdsLessThanCurrentUIds ); pallet_subtensor::Pallet::::set_max_allowed_uids(netuid, max_allowed_uids); diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index bcf5ef91c..82e0cfa30 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -71,7 +71,7 @@ impl Pallet { /// * 'u16': The total number of root network validators /// pub fn get_num_root_validators() -> u16 { - Self::get_subnetwork_n(Self::ROOT_NETUID) + SubnetworkN::::get(Self::ROOT_NETUID) } /// Fetches the max validators count of root network. diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index bd54269c2..7304d29cb 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -91,7 +91,7 @@ impl Pallet { #[allow(clippy::indexing_slicing)] 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); + let n: u16 = SubnetworkN::::get(netuid); log::trace!("n:\n{:?}\n", n); // ====================== @@ -437,7 +437,7 @@ impl Pallet { #[allow(clippy::indexing_slicing)] pub fn epoch(netuid: u16, rao_emission: u64) -> Vec<(T::AccountId, u64, u64)> { // Get subnetwork size. - let n: u16 = Self::get_subnetwork_n(netuid); + let n: u16 = SubnetworkN::::get(netuid); log::trace!("Number of Neurons in Network: {:?}", n); // ====================== @@ -804,7 +804,7 @@ impl Pallet { } pub fn get_block_at_registration(netuid: u16) -> Vec { - let n = Self::get_subnetwork_n(netuid); + let n = SubnetworkN::::get(netuid); let block_at_registration: Vec = (0..n) .map(|neuron_uid| { if Keys::::contains_key(netuid, neuron_uid) { @@ -819,7 +819,7 @@ impl Pallet { /// Output unnormalized sparse weights, input weights are assumed to be row max-upscaled in u16. pub fn get_weights_sparse(netuid: u16) -> Vec> { - let n: usize = Self::get_subnetwork_n(netuid) as usize; + let n: usize = SubnetworkN::::get(netuid) as usize; let mut weights: Vec> = vec![vec![]; n]; for (uid_i, weights_i) in as IterableStorageDoubleMap>>::iter_prefix(netuid) @@ -837,7 +837,7 @@ 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: u16) -> Vec> { - let n: usize = Self::get_subnetwork_n(netuid) as usize; + let n: usize = SubnetworkN::::get(netuid) as usize; let mut weights: Vec> = vec![vec![I32F32::from_num(0.0); n]; n]; for (uid_i, weights_vec) in as IterableStorageDoubleMap>>::iter_prefix(netuid) @@ -860,7 +860,7 @@ impl Pallet { /// Output unnormalized sparse bonds, input bonds are assumed to be column max-upscaled in u16. pub fn get_bonds_sparse(netuid: u16) -> Vec> { - let n: usize = Self::get_subnetwork_n(netuid) as usize; + let n: usize = SubnetworkN::::get(netuid) as usize; let mut bonds: Vec> = vec![vec![]; n]; for (uid_i, bonds_vec) in as IterableStorageDoubleMap>>::iter_prefix(netuid) @@ -878,7 +878,7 @@ 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: u16) -> Vec> { - let n: usize = Self::get_subnetwork_n(netuid) as usize; + let n: usize = SubnetworkN::::get(netuid) as usize; let mut bonds: Vec> = vec![vec![I32F32::from_num(0.0); n]; n]; for (uid_i, bonds_vec) in as IterableStorageDoubleMap>>::iter_prefix(netuid) diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index 188818a2a..6ea10773b 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -59,7 +59,7 @@ impl Pallet { } let mut neurons = Vec::new(); - let n = Self::get_subnetwork_n(netuid); + let n = SubnetworkN::::get(netuid); for uid in 0..n { let neuron = match Self::get_neuron_subnet_exists(netuid, uid) { Some(n) => n, @@ -213,7 +213,7 @@ impl Pallet { } let mut neurons: Vec> = Vec::new(); - let n = Self::get_subnetwork_n(netuid); + let n = SubnetworkN::::get(netuid); for uid in 0..n { let neuron = match Self::get_neuron_lite_subnet_exists(netuid, uid) { Some(n) => n, diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index bdd420821..57ee2c8dd 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -97,7 +97,7 @@ impl Pallet { let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); - let subnetwork_n = Self::get_subnetwork_n(netuid); + let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = Self::get_max_allowed_uids(netuid); let blocks_since_last_step = Self::get_blocks_since_last_step(netuid); let tempo = Self::get_tempo(netuid); @@ -167,7 +167,7 @@ impl Pallet { let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); - let subnetwork_n = Self::get_subnetwork_n(netuid); + let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = Self::get_max_allowed_uids(netuid); let blocks_since_last_step = Self::get_blocks_since_last_step(netuid); let tempo = Self::get_tempo(netuid); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 2f87ffd2a..95e0d33ea 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -116,7 +116,7 @@ impl Pallet { // --- 11. Append neuron or prune it. let subnetwork_uid: u16; - let current_subnetwork_n: u16 = Self::get_subnetwork_n(netuid); + let current_subnetwork_n: u16 = SubnetworkN::::get(netuid); // Possibly there is no neuron slots at all. ensure!( @@ -311,7 +311,7 @@ impl Pallet { // --- 11. Append neuron or prune it. let subnetwork_uid: u16; - let current_subnetwork_n: u16 = Self::get_subnetwork_n(netuid); + let current_subnetwork_n: u16 = SubnetworkN::::get(netuid); // Possibly there is no neuron slots at all. ensure!( @@ -441,7 +441,7 @@ impl Pallet { // This may be unlikely in practice. let mut found_non_immune = false; - let neurons_n = Self::get_subnetwork_n(netuid); + let neurons_n = SubnetworkN::::get(netuid); if neurons_n == 0 { return 0; // If there are no neurons in this network. } diff --git a/pallets/subtensor/src/subnets/uids.rs b/pallets/subtensor/src/subnets/uids.rs index acacc5a36..21e8247f6 100644 --- a/pallets/subtensor/src/subnets/uids.rs +++ b/pallets/subtensor/src/subnets/uids.rs @@ -3,11 +3,6 @@ use frame_support::storage::IterableStorageDoubleMap; use sp_std::vec; impl Pallet { - /// Returns the number of filled slots on a network. - pub fn get_subnetwork_n(netuid: u16) -> u16 { - SubnetworkN::::get(netuid) - } - /// Replace the neuron under this uid. pub fn replace_neuron( netuid: u16, @@ -53,7 +48,7 @@ impl Pallet { /// Appends the uid to the network. 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); + let next_uid = SubnetworkN::::get(netuid); log::debug!( "append_neuron( netuid: {:?} | next_uid: {:?} | new_hotkey: {:?} ) ", netuid, diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 958d4fccc..86deca370 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -958,7 +958,7 @@ impl Pallet { /// Returns True if the uids and weights are have a valid length for uid on network. 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 subnet_n: usize = SubnetworkN::::get(netuid) as usize; let min_allowed_length: usize = Self::get_min_allowed_weights(netuid) as usize; let min_allowed: usize = { if subnet_n < min_allowed_length { @@ -1029,7 +1029,7 @@ 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: u16, uids: &[u16]) -> bool { - let subnetwork_n: u16 = Self::get_subnetwork_n(netuid); + let subnetwork_n = SubnetworkN::::get(netuid); // we should expect at most subnetwork_n uids. uids.len() <= subnetwork_n as usize } diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 59bf3d5e5..b4ecf0eaa 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -3,6 +3,7 @@ use sp_core::U256; use super::mock::*; +use crate::SubnetworkN; #[test] fn test_registration_difficulty_adjustment() { @@ -61,7 +62,7 @@ fn test_registration_difficulty_adjustment() { hotkey2 ); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 3); // All 3 are registered. + assert_eq!(SubnetworkN::::get(netuid), 3); // All 3 are registered. assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 3); // 3 Registrations. assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // 3 Registrations this interval. diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index e483d83d6..e231b6494 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -176,7 +176,7 @@ fn init_run_epochs( stake, ); } - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + assert_eq!(SubnetworkN::::get(netuid), n); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, validators.len() as u16); @@ -552,7 +552,7 @@ fn test_1_graph() { SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake_amount); SubtensorModule::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, stake_amount); SubtensorModule::append_neuron(netuid, &hotkey, 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); run_to_block(1); // run to next block to ensure weights are set on nodes after their registration block assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(U256::from(uid)), @@ -599,7 +599,7 @@ fn test_10_graph() { hotkey, uid, stake_amount, - SubtensorModule::get_subnetwork_n(netuid), + SubnetworkN::::get(netuid), ); SubtensorModule::increase_stake_on_coldkey_hotkey_account( &coldkey, @@ -607,7 +607,7 @@ fn test_10_graph() { stake_amount, ); SubtensorModule::append_neuron(netuid, &hotkey, 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid) - 1, uid); + assert_eq!(SubnetworkN::::get(netuid) - 1, uid); } // Build the graph with 10 items // each with 1 stake and self weights. @@ -618,7 +618,7 @@ fn test_10_graph() { for i in 0..10 { add_node(netuid, U256::from(i), U256::from(i), i as u16, 1) } - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 10); + assert_eq!(SubnetworkN::::get(netuid), 10); run_to_block(1); // run to next block to ensure weights are set on nodes after their registration block for i in 0..10 { assert_ok!(SubtensorModule::set_weights( @@ -991,7 +991,7 @@ fn test_bonds() { SubtensorModule::increase_stake_on_coldkey_hotkey_account( &U256::from(key), &U256::from(key), stakes[key as usize] ); } assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + assert_eq!(SubnetworkN::::get(netuid), n); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, n); @@ -1550,7 +1550,7 @@ fn test_active_stake() { ); } assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + assert_eq!(SubnetworkN::::get(netuid), n); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, n); @@ -1756,7 +1756,7 @@ fn test_outdated_weights() { stake, ); } - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + assert_eq!(SubnetworkN::::get(netuid), n); assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 4); // === Issue validator permits @@ -1942,7 +1942,7 @@ fn test_zero_weights() { stake, ); } - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), n); + assert_eq!(SubnetworkN::::get(netuid), n); // === No weights if sparse { @@ -2157,7 +2157,7 @@ fn test_validator_permits() { stake[key as usize], ); } - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), network_n as u16); + assert_eq!(SubnetworkN::::get(netuid), network_n as u16); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, validators_n as u16); diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index a162fb7c6..0daba9744 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -207,7 +207,7 @@ fn test_total_issuance_global() { netuid, hotkey )); // Execute the burn operation, reducing the total issuance. - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); // Ensure the subnetwork count increases to 1 after burning + assert_eq!(SubnetworkN::::get(netuid), 1); // Ensure the subnetwork count increases to 1 after burning assert_eq!( SubtensorModule::get_total_issuance(), account_balance + lockcost - burn_cost diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 5d42e9fb9..e4d53c825 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,7 +11,7 @@ use frame_system::Config; use sp_core::U256; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; -use crate::RAORecycledForRegistration; +use crate::{RAORecycledForRegistration, SubnetworkN}; /******************************************** subscribing::subscribe() tests @@ -130,7 +130,7 @@ fn test_registration_ok() { )); // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); //check if hotkey is added to the Hotkeys assert_eq!( @@ -438,7 +438,7 @@ fn test_burned_registration_ok() { 10000 - burn_cost ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); //check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -1400,10 +1400,10 @@ fn test_registration_add_network_size() { let coldkey_account_id = U256::from(667); add_network(netuid, 13, 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 0); + assert_eq!(SubnetworkN::::get(netuid), 0); add_network(netuid2, 13, 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 0); + assert_eq!(SubnetworkN::::get(netuid2), 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1414,7 +1414,7 @@ fn test_registration_add_network_size() { hotkey_account_id, coldkey_account_id )); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 1); assert_ok!(SubtensorModule::register( @@ -1435,7 +1435,7 @@ fn test_registration_add_network_size() { hotkey_account_id2, coldkey_account_id )); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 2); + assert_eq!(SubnetworkN::::get(netuid2), 2); assert_eq!(SubtensorModule::get_registrations_this_interval(netuid2), 2); }); } @@ -1454,10 +1454,10 @@ fn test_burn_registration_increase_recycled_rao() { Balances::deposit_creating(&coldkey_account_id, Balance::from(1_000_000_000_000_u64)); add_network(netuid, 13, 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 0); + assert_eq!(SubnetworkN::::get(netuid), 0); add_network(netuid2, 13, 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 0); + assert_eq!(SubnetworkN::::get(netuid2), 0); run_to_block(1); @@ -1548,9 +1548,9 @@ fn test_full_pass_through() { assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid2), 3); // Check that no one has registered yet. - assert_eq!(SubtensorModule::get_subnetwork_n(netuid0), 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid1), 0); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 0); + assert_eq!(SubnetworkN::::get(netuid0), 0); + assert_eq!(SubnetworkN::::get(netuid1), 0); + assert_eq!(SubnetworkN::::get(netuid2), 0); // Registered the keys to all networks. register_ok_neuron(netuid0, hotkey0, coldkey0, 39420842); @@ -1606,9 +1606,9 @@ fn test_full_pass_through() { assert_eq!(SubtensorModule::get_registrations_this_interval(netuid2), 2); // Get the number of uids in each network. - assert_eq!(SubtensorModule::get_subnetwork_n(netuid0), 2); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid1), 2); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 2); + assert_eq!(SubnetworkN::::get(netuid0), 2); + assert_eq!(SubnetworkN::::get(netuid1), 2); + assert_eq!(SubnetworkN::::get(netuid2), 2); // Check the uids exist. assert!(SubtensorModule::is_uid_exist_on_network(netuid0, 0)); @@ -1649,9 +1649,9 @@ fn test_full_pass_through() { ); // Check for replacement. - assert_eq!(SubtensorModule::get_subnetwork_n(netuid0), 2); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid1), 2); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 2); + assert_eq!(SubnetworkN::::get(netuid0), 2); + assert_eq!(SubnetworkN::::get(netuid1), 2); + assert_eq!(SubnetworkN::::get(netuid2), 2); // Register the 3rd hotkey. register_ok_neuron(netuid0, hotkey2, coldkey2, 59420842); @@ -1659,9 +1659,9 @@ fn test_full_pass_through() { register_ok_neuron(netuid2, hotkey2, coldkey2, 451232207); // Check for replacement. - assert_eq!(SubtensorModule::get_subnetwork_n(netuid0), 2); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid1), 2); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 2); + assert_eq!(SubnetworkN::::get(netuid0), 2); + assert_eq!(SubnetworkN::::get(netuid1), 2); + assert_eq!(SubnetworkN::::get(netuid2), 2); // Check uids. // n0 [ h0, h1 ] diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index b6f7fb300..0d777234e 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -1,16 +1,16 @@ #![allow(clippy::indexing_slicing, clippy::unwrap_used)] -use super::mock::*; -use crate::Error; -use crate::{ - migrations, utils::rate_limiting::TransactionType, NetworkRateLimit, SubnetIdentities, - SubnetIdentity, SubnetIdentityOf, -}; use frame_support::{assert_err, assert_ok}; use frame_system::Config; use frame_system::{EventRecord, Phase}; use sp_core::{Get, H256, U256}; +use super::mock::*; +use crate::{ + migrations, utils::rate_limiting::TransactionType, Error, NetworkRateLimit, SubnetIdentities, + SubnetIdentity, SubnetIdentityOf, SubnetworkN, +}; + #[allow(dead_code)] fn record(event: RuntimeEvent) -> EventRecord { EventRecord { @@ -389,10 +389,7 @@ fn test_root_set_weights_out_of_order_netuids() { } log::info!("netuids: {:?}", SubtensorModule::get_all_subnet_netuids()); - log::info!( - "root network count: {:?}", - SubtensorModule::get_subnetwork_n(0) - ); + log::info!("root network count: {:?}", SubnetworkN::::get(0)); let subnets = SubtensorModule::get_all_subnet_netuids(); // Set weights into diagonal matrix. @@ -555,7 +552,7 @@ fn test_network_pruning() { SubtensorModule::set_max_allowed_uids(root_netuid, n as u16 + 1); SubtensorModule::set_tempo(root_netuid, 1); // No validators yet. - assert_eq!(SubtensorModule::get_subnetwork_n(root_netuid), 0); + assert_eq!(SubnetworkN::::get(root_netuid), 0); for i in 0..n { let hot: U256 = U256::from(i); @@ -597,10 +594,7 @@ fn test_network_pruning() { (i as u16) + 1, hot )); - assert_eq!( - SubtensorModule::get_subnetwork_n(root_netuid), - (i as u16) + 1 - ); + assert_eq!(SubnetworkN::::get(root_netuid), (i as u16) + 1); } // Stakes // 0 : 10_000 @@ -690,7 +684,7 @@ fn test_weights_after_network_pruning() { SubtensorModule::set_weights_set_rate_limit(root_netuid, 0_u64); // No validators yet. - assert_eq!(SubtensorModule::get_subnetwork_n(root_netuid), 0); + assert_eq!(SubnetworkN::::get(root_netuid), 0); for i in 0..n { // Register a validator diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index 565f00288..758765cef 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -4,18 +4,17 @@ use super::mock::*; use codec::Encode; use frame_support::{assert_noop, assert_ok}; +use frame_system::pallet_prelude::*; +use frame_system::Config; use frame_system::{EventRecord, Phase}; +use pallet_collective::Event as CollectiveEvent; use sp_core::{bounded_vec, H256, U256}; use sp_runtime::{ traits::{BlakeTwo256, Hash}, BuildStorage, }; -use crate::migrations; -use crate::Error; -use frame_system::pallet_prelude::*; -use frame_system::Config; -use pallet_collective::Event as CollectiveEvent; +use crate::{migrations, Error, SubnetworkN}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -82,7 +81,7 @@ fn test_senate_join_works() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -151,7 +150,7 @@ fn test_senate_vote_works() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -259,7 +258,7 @@ fn test_senate_vote_not_member() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -319,7 +318,7 @@ fn test_senate_leave_works() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -389,7 +388,7 @@ fn test_senate_leave_vote_removal() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -528,7 +527,7 @@ fn test_senate_not_leave_when_stake_removed() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -607,7 +606,7 @@ fn test_senate_join_current_delegate() { (10000 - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), @@ -696,7 +695,7 @@ fn test_adjust_senate_events() { (balance_to_add - burn_cost) ); // funds drained on reg. // Check if neuron has added to the specified network(netuid) - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index eb1a3df22..d33d26155 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -112,7 +112,7 @@ fn test_dividends_with_run_to_block() { ); // Check if all three neurons are registered - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 3); + assert_eq!(SubnetworkN::::get(netuid), 3); // Run a couple of blocks to check if emission works run_to_block(2); diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index cfb3b7122..530c291ac 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -1,10 +1,5 @@ #![allow(clippy::indexing_slicing)] -use super::mock::*; -use crate::{ - coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, - MAX_CRV3_COMMIT_SIZE_BYTES, -}; use ark_serialize::CanonicalDeserialize; use frame_support::{ assert_err, assert_ok, @@ -32,6 +27,12 @@ use w3f_bls::EngineBLS; use pallet_drand::types::Pulse; use sp_core::Encode; +use super::mock::*; +use crate::{ + coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, SubnetworkN, + MAX_CRV3_COMMIT_SIZE_BYTES, +}; + /*************************** pub fn set_weights() tests *****************************/ @@ -721,7 +722,7 @@ fn test_weights_err_has_duplicate_ids() { SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(3)) .expect("Not registered."); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 4); + assert_eq!(SubnetworkN::::get(netuid), 4); let weights_keys: Vec = vec![1, 1, 1]; // Contains duplicates let weight_values: Vec = vec![1, 2, 3]; @@ -759,7 +760,7 @@ fn test_weights_err_max_weight_limit() { let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(0)) .expect("Not registered."); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid, true); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); + assert_eq!(SubnetworkN::::get(netuid), 1); assert!(SubtensorModule::is_hotkey_registered_on_network( netuid, &U256::from(0) @@ -772,7 +773,7 @@ fn test_weights_err_max_weight_limit() { netuid, &U256::from(1) )); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 2); + assert_eq!(SubnetworkN::::get(netuid), 2); step_block(1); println!("+Registering: net:{:?}, cold:{:?}, hot:{:?}", netuid, 2, 2); @@ -781,7 +782,7 @@ fn test_weights_err_max_weight_limit() { netuid, &U256::from(2) )); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 3); + assert_eq!(SubnetworkN::::get(netuid), 3); step_block(1); println!("+Registering: net:{:?}, cold:{:?}, hot:{:?}", netuid, 3, 3); @@ -790,7 +791,7 @@ fn test_weights_err_max_weight_limit() { netuid, &U256::from(3) )); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 4); + assert_eq!(SubnetworkN::::get(netuid), 4); step_block(1); println!("+Registering: net:{:?}, cold:{:?}, hot:{:?}", netuid, 4, 4); @@ -799,7 +800,7 @@ fn test_weights_err_max_weight_limit() { netuid, &U256::from(4) )); - assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 5); + assert_eq!(SubnetworkN::::get(netuid), 5); step_block(1); // Non self-weight fails. @@ -1296,7 +1297,7 @@ fn test_check_len_uids_within_allowed_within_network_pool() { register_ok_neuron(netuid, U256::from(1), U256::from(1), 0); register_ok_neuron(netuid, U256::from(3), U256::from(3), 65555); register_ok_neuron(netuid, U256::from(5), U256::from(5), 75555); - let max_allowed: u16 = SubtensorModule::get_subnetwork_n(netuid); + let max_allowed: u16 = SubnetworkN::::get(netuid); SubtensorModule::set_max_allowed_uids(netuid, max_allowed); SubtensorModule::set_max_registrations_per_block(netuid, max_registrations_per_block); @@ -1329,7 +1330,7 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { register_ok_neuron(netuid, U256::from(1), U256::from(1), 0); register_ok_neuron(netuid, U256::from(3), U256::from(3), 65555); register_ok_neuron(netuid, U256::from(5), U256::from(5), 75555); - let max_allowed: u16 = SubtensorModule::get_subnetwork_n(netuid); + let max_allowed: u16 = SubnetworkN::::get(netuid); SubtensorModule::set_max_allowed_uids(netuid, max_allowed); SubtensorModule::set_max_registrations_per_block(netuid, max_registrations_per_block); From 37de1372ae36a39c36a26bfc24018c457a93f15e Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 2 Dec 2024 16:41:49 +0100 Subject: [PATCH 010/137] Remove check_len_uids_within_allowed from pallet-subtensor --- pallets/subtensor/src/subnets/weights.rs | 9 +-------- pallets/subtensor/src/tests/weights.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 86deca370..f0fba4090 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -705,7 +705,7 @@ impl Pallet { // --- 4. Check to see if the number of uids is within the max allowed uids for this network. ensure!( - Self::check_len_uids_within_allowed(netuid, &uids), + uids.len() <= SubnetworkN::::get(netuid) as usize, Error::::UidsLengthExceedUidsInSubNet ); @@ -1027,13 +1027,6 @@ impl Pallet { true } - /// Returns False is the number of uids exceeds the allowed number of uids for this network. - pub fn check_len_uids_within_allowed(netuid: u16, uids: &[u16]) -> bool { - let subnetwork_n = SubnetworkN::::get(netuid); - // we should expect at most subnetwork_n uids. - uids.len() <= subnetwork_n as usize - } - 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); diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index 530c291ac..71b667f4c 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -1304,10 +1304,8 @@ fn test_check_len_uids_within_allowed_within_network_pool() { let uids: Vec = Vec::from_iter(0..max_allowed); - let expected = true; - let result = SubtensorModule::check_len_uids_within_allowed(netuid, &uids); - assert_eq!( - expected, result, + assert!( + uids.len() <= SubnetworkN::::get(netuid) as usize, "netuid network length and uids length incompatible" ); }); @@ -1337,10 +1335,8 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { let uids: Vec = Vec::from_iter(0..(max_allowed + 1)); - let expected = false; - let result = SubtensorModule::check_len_uids_within_allowed(netuid, &uids); - assert_eq!( - expected, result, + assert!( + uids.len() > SubnetworkN::::get(netuid) as usize, "Failed to detect incompatible uids for network" ); }); From 7b1130522c6cbc13de6aea0755eaaf4a02b46213 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 2 Dec 2024 16:53:24 +0100 Subject: [PATCH 011/137] Remove get_active from pallet-subtensor --- pallets/subtensor/src/staking/helpers.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 63b6524f1..25b77776c 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -221,7 +221,7 @@ impl Pallet { /// /// * `coldkey` - A reference to the AccountId of the coldkey involved in the staking. /// * `hotkey` - A reference to the AccountId of the hotkey associated with the coldkey. - pub fn empty_stake_on_coldkey_hotkey_account( + fn empty_stake_on_coldkey_hotkey_account( coldkey: &T::AccountId, hotkey: &T::AccountId, ) -> u64 { diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9bc81180d..8eafea209 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -75,9 +75,6 @@ impl Pallet { pub fn get_trust(netuid: u16) -> Vec { Trust::::get(netuid) } - pub fn get_active(netuid: u16) -> Vec { - Active::::get(netuid) - } pub fn get_emission(netuid: u16) -> Vec { Emission::::get(netuid) } @@ -115,7 +112,7 @@ impl Pallet { LastUpdate::::insert(netuid, updated_last_update_vec); } pub fn set_active_for_uid(netuid: u16, uid: u16, active: bool) { - let mut updated_active_vec = Self::get_active(netuid); + let mut updated_active_vec = Active::::get(netuid); let Some(updated_active) = updated_active_vec.get_mut(uid as usize) else { return; }; From f132d771b626cb1a87840a7e7fa9408560297115 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 2 Dec 2024 17:29:55 +0100 Subject: [PATCH 012/137] Remove get_adjustment_alpha from pallet-subtensor --- pallets/admin-utils/src/tests/mod.rs | 17 ++++++++++------- pallets/subtensor/src/coinbase/block_step.rs | 8 +++++--- pallets/subtensor/src/epoch/run_epoch.rs | 6 +++--- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/tests/epoch.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 6 ------ 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 4b39c60db..c8d1506f5 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -5,7 +5,10 @@ use frame_support::{ traits::Hooks, }; use frame_system::Config; -use pallet_subtensor::{migrations, Error as SubtensorError, Event, RAORecycledForRegistration}; +use pallet_subtensor::{ + migrations, ActivityCutoff, AdjustmentAlpha, Error as SubtensorError, Event, + RAORecycledForRegistration, +}; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -236,7 +239,7 @@ fn test_sudo_set_adjustment_alpha() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_adjustment_alpha(netuid); + let init_value: u64 = AdjustmentAlpha::::get(netuid); assert_eq!( AdminUtils::sudo_set_adjustment_alpha( <::RuntimeOrigin>::signed(U256::from(1)), @@ -253,13 +256,13 @@ fn test_sudo_set_adjustment_alpha() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_adjustment_alpha(netuid), init_value); + assert_eq!(AdjustmentAlpha::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_adjustment_alpha( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_adjustment_alpha(netuid), to_be_set); + assert_eq!(AdjustmentAlpha::::get(netuid), to_be_set); }); } @@ -544,7 +547,7 @@ fn test_sudo_set_activity_cutoff() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_activity_cutoff(netuid); + let init_value: u16 = ActivityCutoff::::get(netuid); assert_eq!( AdminUtils::sudo_set_activity_cutoff( <::RuntimeOrigin>::signed(U256::from(1)), @@ -561,13 +564,13 @@ fn test_sudo_set_activity_cutoff() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_activity_cutoff(netuid), init_value); + assert_eq!(ActivityCutoff::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_activity_cutoff( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_activity_cutoff(netuid), to_be_set); + assert_eq!(ActivityCutoff::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 22addb3ba..b7b496466 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -1,7 +1,9 @@ -use super::*; use frame_support::storage::IterableStorageMap; use substrate_fixed::types::I110F18; +use super::*; +use crate::AdjustmentAlpha; + impl Pallet { /// Executes the necessary operations for each block. pub fn block_step() -> Result<(), &'static str> { @@ -188,7 +190,7 @@ impl Pallet { .saturating_div(I110F18::from_num( target_registrations_per_interval.saturating_add(target_registrations_per_interval), )); - let alpha: I110F18 = I110F18::from_num(Self::get_adjustment_alpha(netuid)) + let alpha: I110F18 = I110F18::from_num(AdjustmentAlpha::::get(netuid)) .saturating_div(I110F18::from_num(u64::MAX)); let next_value: I110F18 = alpha .saturating_mul(I110F18::from_num(current_difficulty)) @@ -222,7 +224,7 @@ impl Pallet { .saturating_div(I110F18::from_num( target_registrations_per_interval.saturating_add(target_registrations_per_interval), )); - let alpha: I110F18 = I110F18::from_num(Self::get_adjustment_alpha(netuid)) + let alpha: I110F18 = I110F18::from_num(AdjustmentAlpha::::get(netuid)) .saturating_div(I110F18::from_num(u64::MAX)); let next_value: I110F18 = alpha .saturating_mul(I110F18::from_num(current_burn)) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 7304d29cb..cbe21602b 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -1,5 +1,5 @@ use super::*; -use crate::epoch::math::*; +use crate::{epoch::math::*, ActivityCutoff}; use frame_support::IterableStorageDoubleMap; use sp_std::vec; use substrate_fixed::types::{I32F32, I64F64, I96F32}; @@ -103,7 +103,7 @@ impl Pallet { log::trace!("current_block:\n{:?}\n", current_block); // Get activity cutoff. - let activity_cutoff: u64 = Self::get_activity_cutoff(netuid) as u64; + let activity_cutoff = ActivityCutoff::::get(netuid) as u64; log::trace!("activity_cutoff:\n{:?}\n", activity_cutoff); // Last update vector. @@ -449,7 +449,7 @@ impl Pallet { log::trace!("current_block: {:?}", current_block); // Get activity cutoff. - let activity_cutoff: u64 = Self::get_activity_cutoff(netuid) as u64; + let activity_cutoff = ActivityCutoff::::get(netuid) as u64; log::trace!("activity_cutoff: {:?}", activity_cutoff); // Last update vector. diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 57ee2c8dd..f6c26d0f5 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -241,7 +241,7 @@ impl Pallet { let weights_version = Self::get_weights_version_key(netuid); let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); let adjustment_interval = Self::get_adjustment_interval(netuid); - let activity_cutoff = Self::get_activity_cutoff(netuid); + let activity_cutoff = ActivityCutoff::::get(netuid); let registration_allowed = Self::get_network_registration_allowed(netuid); let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); let min_burn = Self::get_min_burn_as_u64(netuid); @@ -250,7 +250,7 @@ impl Pallet { let max_regs_per_block = Self::get_max_registrations_per_block(netuid); let serving_rate_limit = Self::get_serving_rate_limit(netuid); let max_validators = Self::get_max_allowed_validators(netuid); - let adjustment_alpha = Self::get_adjustment_alpha(netuid); + let adjustment_alpha = AdjustmentAlpha::::get(netuid); let difficulty = Self::get_difficulty_as_u64(netuid); let commit_reveal_periods = Self::get_reveal_period(netuid); let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index e231b6494..8a9ae6886 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -1596,7 +1596,7 @@ fn test_active_stake() { assert_eq!(*i, I32F32::from_num(65_535)); // floor(0.5*(2^16-1))/(2^16-1), then max-upscale to 65_535 } } - let activity_cutoff: u64 = SubtensorModule::get_activity_cutoff(netuid) as u64; + let activity_cutoff = ActivityCutoff::::get(netuid) as u64; run_to_block(activity_cutoff + 2); // run to block where validator (uid 0, 1) weights become outdated // === Update uid 0 weights diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 8eafea209..ad2a4fc11 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -432,9 +432,6 @@ impl Pallet { Self::deposit_event(Event::AdjustmentIntervalSet(netuid, adjustment_interval)); } - pub fn get_adjustment_alpha(netuid: u16) -> u64 { - AdjustmentAlpha::::get(netuid) - } pub fn set_adjustment_alpha(netuid: u16, adjustment_alpha: u64) { AdjustmentAlpha::::insert(netuid, adjustment_alpha); Self::deposit_event(Event::AdjustmentAlphaSet(netuid, adjustment_alpha)); @@ -513,9 +510,6 @@ impl Pallet { Rho::::insert(netuid, rho); } - pub fn get_activity_cutoff(netuid: u16) -> u16 { - ActivityCutoff::::get(netuid) - } pub fn set_activity_cutoff(netuid: u16, activity_cutoff: u16) { ActivityCutoff::::insert(netuid, activity_cutoff); Self::deposit_event(Event::ActivityCutoffSet(netuid, activity_cutoff)); From cf429305a50dcc77df536bb26c2092a284caeb5b Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 2 Dec 2024 17:37:15 +0100 Subject: [PATCH 013/137] Remove get_adjustment_interval from pallet-subtensor --- pallets/admin-utils/src/tests/mod.rs | 8 ++++---- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/tests/difficulty.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 3 --- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index c8d1506f5..9823b00c1 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -7,7 +7,7 @@ use frame_support::{ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, Error as SubtensorError, Event, - RAORecycledForRegistration, + RAORecycledForRegistration, AdjustmentInterval, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -206,7 +206,7 @@ fn test_sudo_set_adjustment_interval() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_adjustment_interval(netuid); + let init_value: u16 = AdjustmentInterval::::get(netuid); assert_eq!( AdminUtils::sudo_set_adjustment_interval( <::RuntimeOrigin>::signed(U256::from(1)), @@ -223,13 +223,13 @@ fn test_sudo_set_adjustment_interval() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_adjustment_interval(netuid), init_value); + assert_eq!(AdjustmentInterval::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_adjustment_interval( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_adjustment_interval(netuid), to_be_set); + assert_eq!(AdjustmentInterval::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index b7b496466..8e2d9b34e 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -26,7 +26,7 @@ impl Pallet { 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); + let adjustment_interval: u16 = AdjustmentInterval::::get(netuid); let current_block: u64 = Self::get_current_block_as_u64(); log::debug!("netuid: {:?} last_adjustment_block: {:?} adjustment_interval: {:?} current_block: {:?}", netuid, diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index f6c26d0f5..2cb9d1c09 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -240,7 +240,7 @@ impl Pallet { let max_difficulty = Self::get_max_difficulty(netuid); let weights_version = Self::get_weights_version_key(netuid); let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); - let adjustment_interval = Self::get_adjustment_interval(netuid); + let adjustment_interval = AdjustmentInterval::::get(netuid); let activity_cutoff = ActivityCutoff::::get(netuid); let registration_allowed = Self::get_network_registration_allowed(netuid); let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index b4ecf0eaa..13bff43d6 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -3,7 +3,7 @@ use sp_core::U256; use super::mock::*; -use crate::SubnetworkN; +use crate::{SubnetworkN, AdjustmentInterval}; #[test] fn test_registration_difficulty_adjustment() { @@ -30,7 +30,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::set_max_allowed_uids(netuid, 3); SubtensorModule::set_network_registration_allowed(netuid, true); assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 20000); // Check set difficutly. - assert_eq!(SubtensorModule::get_adjustment_interval(netuid), 1); // Check set adjustment interval. + assert_eq!(AdjustmentInterval::::get(netuid), 1); // Check set adjustment interval. assert_eq!( SubtensorModule::get_target_registrations_per_interval(netuid), 1 @@ -79,7 +79,7 @@ fn test_registration_difficulty_adjustment() { // Lets change the adjustment interval SubtensorModule::set_adjustment_interval(netuid, 3); - assert_eq!(SubtensorModule::get_adjustment_interval(netuid), 3); // Check set adjustment interval. + assert_eq!(AdjustmentInterval::::get(netuid), 3); // Check set adjustment interval. SubtensorModule::set_target_registrations_per_interval(netuid, 3); assert_eq!( diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index ad2a4fc11..0f7b6d9ad 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -424,9 +424,6 @@ impl Pallet { )); } - pub fn get_adjustment_interval(netuid: u16) -> u16 { - AdjustmentInterval::::get(netuid) - } pub fn set_adjustment_interval(netuid: u16, adjustment_interval: u16) { AdjustmentInterval::::insert(netuid, adjustment_interval); Self::deposit_event(Event::AdjustmentIntervalSet(netuid, adjustment_interval)); From 69d4e33e35992d3b4c9139c5ca1ae7617539ea51 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 2 Dec 2024 17:49:09 +0100 Subject: [PATCH 014/137] Remove get_all_staked_hotkeys from pallet-subtensor --- pallets/subtensor/src/tests/swap_coldkey.rs | 30 ++++++++++----------- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 2f1a71366..db342838a 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -6,7 +6,7 @@ use frame_system::{Config, RawOrigin}; use super::mock::*; use crate::*; -use crate::{Call, ColdkeySwapScheduleDuration, Error}; +// use crate::{Call, ColdkeySwapScheduleDuration, Error}; use frame_support::error::BadOrigin; use frame_support::traits::schedule::v3::Named as ScheduleNamed; use frame_support::traits::schedule::DispatchTime; @@ -1100,7 +1100,7 @@ fn test_coldkey_swap_total() { vec![hotkey1, hotkey2, hotkey3] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&coldkey), + StakingHotkeys::::get(&coldkey), vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&coldkey), 600); @@ -1124,15 +1124,15 @@ fn test_coldkey_swap_total() { vec![delegate3] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&delegate1), + StakingHotkeys::::get(&delegate1), vec![delegate1, hotkey1] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&delegate2), + StakingHotkeys::::get(&delegate2), vec![delegate2, hotkey2] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&delegate3), + StakingHotkeys::::get(&delegate3), vec![delegate3, hotkey3] ); @@ -1141,15 +1141,15 @@ fn test_coldkey_swap_total() { assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator3), vec![]); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&nominator1), + StakingHotkeys::::get(&nominator1), vec![hotkey1, delegate1] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&nominator2), + StakingHotkeys::::get(&nominator2), vec![hotkey2, delegate2] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&nominator3), + StakingHotkeys::::get(&nominator3), vec![hotkey3, delegate3] ); @@ -1173,7 +1173,7 @@ fn test_coldkey_swap_total() { vec![hotkey1, hotkey2, hotkey3] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&new_coldkey), + StakingHotkeys::::get(&new_coldkey), vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); assert_eq!( @@ -1200,15 +1200,15 @@ fn test_coldkey_swap_total() { vec![delegate3] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&delegate1), + StakingHotkeys::::get(&delegate1), vec![delegate1, hotkey1] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&delegate2), + StakingHotkeys::::get(&delegate2), vec![delegate2, hotkey2] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&delegate3), + StakingHotkeys::::get(&delegate3), vec![delegate3, hotkey3] ); @@ -1217,15 +1217,15 @@ fn test_coldkey_swap_total() { assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator3), vec![]); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&nominator1), + StakingHotkeys::::get(&nominator1), vec![hotkey1, delegate1] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&nominator2), + StakingHotkeys::::get(&nominator2), vec![hotkey2, delegate2] ); assert_eq!( - SubtensorModule::get_all_staked_hotkeys(&nominator3), + StakingHotkeys::::get(&nominator3), vec![hotkey3, delegate3] ); }); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0f7b6d9ad..4bb908cf9 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -618,9 +618,6 @@ impl Pallet { pub fn get_owned_hotkeys(coldkey: &T::AccountId) -> Vec { OwnedHotkeys::::get(coldkey) } - pub fn get_all_staked_hotkeys(coldkey: &T::AccountId) -> Vec { - StakingHotkeys::::get(coldkey) - } pub fn set_total_issuance(total_issuance: u64) { TotalIssuance::::put(total_issuance); From 198ce865fb4f34bb83b8454783366096c12230ca Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 16:01:53 +0100 Subject: [PATCH 015/137] Remove get_alpha_values from pallet-subtensor --- pallets/admin-utils/src/tests/mod.rs | 7 +++---- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/tests/epoch.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 ---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 9823b00c1..69ee34fda 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -6,8 +6,8 @@ use frame_support::{ }; use frame_system::Config; use pallet_subtensor::{ - migrations, ActivityCutoff, AdjustmentAlpha, Error as SubtensorError, Event, - RAORecycledForRegistration, AdjustmentInterval, + migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, + Error as SubtensorError, Event, RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -1234,8 +1234,7 @@ fn test_sudo_get_set_alpha() { alpha_low, alpha_high )); - let (grabbed_alpha_low, grabbed_alpha_high): (u16, u16) = - SubtensorModule::get_alpha_values(netuid); + let (grabbed_alpha_low, grabbed_alpha_high): (u16, u16) = AlphaValues::::get(netuid); log::info!( "alpha_low: {:?} alpha_high: {:?}", diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 2cb9d1c09..2b5a28fe5 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -255,7 +255,7 @@ impl Pallet { let commit_reveal_periods = Self::get_reveal_period(netuid); let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); - let (alpha_low, alpha_high): (u16, u16) = Self::get_alpha_values(netuid); + let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); Some(SubnetHyperparams { rho: rho.into(), diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 8a9ae6886..8a8b595ab 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2579,7 +2579,7 @@ fn test_get_set_alpha() { alpha_high )); let (grabbed_alpha_low, grabbed_alpha_high): (u16, u16) = - SubtensorModule::get_alpha_values(netuid); + AlphaValues::::get(netuid); log::info!( "alpha_low: {:?} alpha_high: {:?}", diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 4bb908cf9..0d3d9ced1 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -658,10 +658,6 @@ impl Pallet { T::KeySwapCost::get() } - pub fn get_alpha_values(netuid: u16) -> (u16, u16) { - AlphaValues::::get(netuid) - } - pub fn get_alpha_values_32(netuid: u16) -> (I32F32, I32F32) { let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); let converted_low = I32F32::from_num(alpha_low).saturating_div(I32F32::from_num(u16::MAX)); From 3b953e3a21efcd54504b3d720fe43354ebcad390 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 16:09:17 +0100 Subject: [PATCH 016/137] Remove get_blocks_since_last_step from pallet-subtensor --- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/tests/epoch.rs | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 1b69c1972..99960738e 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -173,7 +173,7 @@ impl Pallet { // No epoch, increase blocks since last step and continue Self::set_blocks_since_last_step( *netuid, - Self::get_blocks_since_last_step(*netuid).saturating_add(1), + BlocksSinceLastStep::::get(*netuid).saturating_add(1), ); log::debug!("Tempo not reached for subnet: {:?}", *netuid); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 2b5a28fe5..1d8c30be9 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -99,7 +99,7 @@ impl Pallet { let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = Self::get_max_allowed_uids(netuid); - let blocks_since_last_step = Self::get_blocks_since_last_step(netuid); + let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); @@ -169,7 +169,7 @@ impl Pallet { let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = Self::get_max_allowed_uids(netuid); - let blocks_since_last_step = Self::get_blocks_since_last_step(netuid); + let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 8a8b595ab..f7ae868b4 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2698,11 +2698,11 @@ fn test_blocks_since_last_step() { let tempo: u16 = 7200; add_network(netuid, tempo, 0); - let original_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid); + let original_blocks: u64 = BlocksSinceLastStep::::get(netuid); step_block(5); - let new_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid); + let new_blocks: u64 = BlocksSinceLastStep::::get(netuid); assert!(new_blocks > original_blocks); assert_eq!(new_blocks, 5); @@ -2715,7 +2715,7 @@ fn test_blocks_since_last_step() { + 10; step_block(blocks_to_step); - let post_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid); + let post_blocks: u64 = BlocksSinceLastStep::::get(netuid); assert_eq!(post_blocks, 10); @@ -2727,13 +2727,13 @@ fn test_blocks_since_last_step() { + 20; step_block(blocks_to_step); - let new_post_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid); + let new_post_blocks: u64 = BlocksSinceLastStep::::get(netuid); assert_eq!(new_post_blocks, 20); step_block(7); - assert_eq!(SubtensorModule::get_blocks_since_last_step(netuid), 27); + assert_eq!(BlocksSinceLastStep::::get(netuid), 27); }); } From 6610ba8a6d95b797e7cef0654eaaf12176842007 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 16:19:59 +0100 Subject: [PATCH 017/137] Remove get_bonds_moving_average from pallet-subtensor --- pallets/admin-utils/src/tests/mod.rs | 11 ++++------- pallets/subtensor/src/epoch/run_epoch.rs | 4 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 69ee34fda..66fb2173e 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -7,7 +7,7 @@ use frame_support::{ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, - Error as SubtensorError, Event, RAORecycledForRegistration, + BondsMovingAverage, Error as SubtensorError, Event, RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -712,7 +712,7 @@ fn test_sudo_set_bonds_moving_average() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_bonds_moving_average(netuid); + let init_value = BondsMovingAverage::::get(netuid); assert_eq!( AdminUtils::sudo_set_bonds_moving_average( <::RuntimeOrigin>::signed(U256::from(1)), @@ -729,16 +729,13 @@ fn test_sudo_set_bonds_moving_average() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!( - SubtensorModule::get_bonds_moving_average(netuid), - init_value - ); + assert_eq!(BondsMovingAverage::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_bonds_moving_average( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_bonds_moving_average(netuid), to_be_set); + assert_eq!(BondsMovingAverage::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index cbe21602b..0f398c564 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -1081,7 +1081,7 @@ impl Pallet { netuid: u16, ) -> Vec> { // 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)) + let bonds_moving_average: I64F64 = I64F64::from_num(BondsMovingAverage::::get(netuid)) .saturating_div(I64F64::from_num(1_000_000)); // Calculate the alpha value for the EMA calculation. @@ -1114,7 +1114,7 @@ impl Pallet { netuid: u16, ) -> Vec> { // 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)) + let bonds_moving_average: I64F64 = I64F64::from_num(BondsMovingAverage::::get(netuid)) .saturating_div(I64F64::from_num(1_000_000)); // Calculate the alpha value for the EMA calculation. diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 1d8c30be9..b22bbd18c 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -246,7 +246,7 @@ impl Pallet { let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); let min_burn = Self::get_min_burn_as_u64(netuid); let max_burn = Self::get_max_burn_as_u64(netuid); - let bonds_moving_avg = Self::get_bonds_moving_average(netuid); + let bonds_moving_avg = BondsMovingAverage::::get(netuid); let max_regs_per_block = Self::get_max_registrations_per_block(netuid); let serving_rate_limit = Self::get_serving_rate_limit(netuid); let max_validators = Self::get_max_allowed_validators(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0d3d9ced1..0a3d40268 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -585,9 +585,6 @@ impl Pallet { )); } - pub fn get_bonds_moving_average(netuid: u16) -> u64 { - BondsMovingAverage::::get(netuid) - } 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)); From 6d612bca6d35384175e4c94eb00f5281c45bea90 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 16:31:28 +0100 Subject: [PATCH 018/137] Remove get_burn_as_u64 from pallet-subtensor --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/subnets/registration.rs | 4 ++-- pallets/subtensor/src/tests/registration.rs | 13 +++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 8e2d9b34e..b1ffb5f84 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -41,7 +41,7 @@ impl Pallet { log::debug!("interval reached."); // --- 4. Get the current counters for this network w.r.t burn and difficulty values. - let current_burn: u64 = Self::get_burn_as_u64(netuid); + let current_burn: u64 = Burn::::get(netuid); let current_difficulty: u64 = Self::get_difficulty_as_u64(netuid); let registrations_this_interval: u16 = Self::get_registrations_this_interval(netuid); diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index b22bbd18c..54ceacd51 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -103,7 +103,7 @@ impl Pallet { let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); - let burn: Compact = Self::get_burn_as_u64(netuid).into(); + let burn: Compact = Burn::::get(netuid).into(); // DEPRECATED let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); // DEPRECATED for ( _netuid_, con_req) in < NetworkConnect as IterableStorageDoubleMap >::iter_prefix(netuid) { @@ -173,7 +173,7 @@ impl Pallet { let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); let emission_values = Self::get_emission_value(netuid); - let burn: Compact = Self::get_burn_as_u64(netuid).into(); + let burn: Compact = Burn::::get(netuid).into(); let identity: Option = SubnetIdentities::::get(netuid); // DEPRECATED diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 95e0d33ea..b84d644c2 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -92,7 +92,7 @@ impl Pallet { // --- 7. Ensure the callers coldkey has enough stake to perform the transaction. let current_block_number: u64 = Self::get_current_block_as_u64(); - let registration_cost = Self::get_burn_as_u64(netuid); + let registration_cost = Burn::::get(netuid); ensure!( Self::can_remove_balance_from_coldkey_account(&coldkey, registration_cost), Error::::NotEnoughBalanceToStake @@ -146,7 +146,7 @@ impl Pallet { BurnRegistrationsThisInterval::::mutate(netuid, |val| val.saturating_inc()); RegistrationsThisInterval::::mutate(netuid, |val| val.saturating_inc()); RegistrationsThisBlock::::mutate(netuid, |val| val.saturating_inc()); - Self::increase_rao_recycled(netuid, Self::get_burn_as_u64(netuid)); + Self::increase_rao_recycled(netuid, Burn::::get(netuid)); // --- 15. Deposit successful event. log::debug!( diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index e4d53c825..6d5f0a688 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -2,8 +2,6 @@ use frame_support::traits::Currency; -use super::mock::*; -use crate::{Axons, Error, SubtensorSignedExtension}; use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}; use frame_support::sp_runtime::{transaction_validity::InvalidTransaction, DispatchError}; use frame_support::{assert_err, assert_noop, assert_ok}; @@ -11,7 +9,10 @@ use frame_system::Config; use sp_core::U256; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; -use crate::{RAORecycledForRegistration, SubnetworkN}; +use super::mock::*; +use crate::{ + Axons, Burn, Error, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, +}; /******************************************** subscribing::subscribe() tests @@ -528,7 +529,7 @@ fn test_burn_adjustment() { step_block(1); // Check the adjusted burn. - assert_eq!(SubtensorModule::get_burn_as_u64(netuid), 1500); + assert_eq!(Burn::::get(netuid), 1500); }); } @@ -1461,7 +1462,7 @@ fn test_burn_registration_increase_recycled_rao() { run_to_block(1); - let burn_amount = SubtensorModule::get_burn_as_u64(netuid); + let burn_amount = Burn::::get(netuid); assert_ok!(SubtensorModule::burned_register( <::RuntimeOrigin>::signed(hotkey_account_id), netuid, @@ -1471,7 +1472,7 @@ fn test_burn_registration_increase_recycled_rao() { run_to_block(2); - let burn_amount2 = SubtensorModule::get_burn_as_u64(netuid2); + let burn_amount2 = Burn::::get(netuid2); assert_ok!(SubtensorModule::burned_register( <::RuntimeOrigin>::signed(hotkey_account_id), netuid2, From 38dd6849b3cb453de5b91cf62384cac47026eb0f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 16:38:04 +0100 Subject: [PATCH 019/137] Remove get_burn_registrations_this_interval from pallet-subtensor --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index b1ffb5f84..31d206054 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -48,7 +48,7 @@ impl Pallet { let pow_registrations_this_interval: u16 = Self::get_pow_registrations_this_interval(netuid); let burn_registrations_this_interval: u16 = - Self::get_burn_registrations_this_interval(netuid); + BurnRegistrationsThisInterval::::get(netuid); let target_registrations_this_interval: u16 = Self::get_target_registrations_per_interval(netuid); // --- 5. Adjust burn + pow diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0a3d40268..67eb74101 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -266,9 +266,6 @@ impl Pallet { pub fn get_pow_registrations_this_interval(netuid: u16) -> u16 { POWRegistrationsThisInterval::::get(netuid) } - pub fn get_burn_registrations_this_interval(netuid: u16) -> u16 { - BurnRegistrationsThisInterval::::get(netuid) - } pub fn get_neuron_block_at_registration(netuid: u16, neuron_uid: u16) -> u64 { BlockAtRegistration::::get(netuid, neuron_uid) } From d2625aff90d0f86afc7fc33def2d4fff524bb027 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 18:00:20 +0100 Subject: [PATCH 020/137] Remove get_childkey_take from pallet-subtensor --- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/staking/set_children.rs | 16 ---------------- pallets/subtensor/src/tests/children.rs | 12 ++++++------ 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 99960738e..25937c748 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -358,7 +358,7 @@ impl Pallet { ) { // --- 1. First, calculate the hotkey's share of the emission. let childkey_take_proportion: I96F32 = - I96F32::from_num(Self::get_childkey_take(hotkey, netuid)) + I96F32::from_num(ChildkeyTake::::get(hotkey, netuid)) .saturating_div(I96F32::from_num(u16::MAX)); let mut total_childkey_take: u64 = 0; diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index 9407e40b6..f084bb2ea 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -354,20 +354,4 @@ impl Pallet { ); Ok(()) } - - /// Gets the childkey take for a given hotkey. - /// - /// This function retrieves the current childkey take value for a specified hotkey. - /// If no specific take value has been set, it returns the default childkey take. - /// - /// # Arguments: - /// * `hotkey` (&T::AccountId): - /// - The hotkey for which to retrieve the childkey take. - /// - /// # Returns: - /// * `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: u16) -> u16 { - ChildkeyTake::::get(hotkey, netuid) - } } diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 3b6676e41..15238421e 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -876,7 +876,7 @@ fn test_childkey_take_functionality() { )); // Verify childkey take was set correctly - let stored_take = SubtensorModule::get_childkey_take(&hotkey, netuid); + let stored_take = ChildkeyTake::::get(&hotkey, netuid); log::info!("Stored take: {}", stored_take); assert_eq!(stored_take, new_take); @@ -1001,7 +1001,7 @@ fn test_childkey_take_rate_limiting() { log_rate_limit_info(); // Verify the final take was set - let stored_take = SubtensorModule::get_childkey_take(&hotkey, netuid); + let stored_take = ChildkeyTake::::get(&hotkey, netuid); assert_eq!(stored_take, 700); }); } @@ -1039,7 +1039,7 @@ fn test_multiple_networks_childkey_take() { )); // Verify the childkey take was set correctly - let stored_take = SubtensorModule::get_childkey_take(&hotkey, netuid); + let stored_take = ChildkeyTake::::get(&hotkey, netuid); assert_eq!( stored_take, take_value, "Childkey take not set correctly for network {}", @@ -1053,8 +1053,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); - let take_j = SubtensorModule::get_childkey_take(&hotkey, j); + let take_i = ChildkeyTake::::get(&hotkey, i); + let take_j = ChildkeyTake::::get(&hotkey, j); assert_ne!( take_i, take_j, "Childkey take values should be different for networks {} and {}", @@ -1080,7 +1080,7 @@ fn test_multiple_networks_childkey_take() { )); // Verify the new take value - let new_take = SubtensorModule::get_childkey_take(&hotkey, 1); + let new_take = ChildkeyTake::::get(&hotkey, 1); assert_eq!(new_take, 1100, "Childkey take not updated after rate limit"); }); } From f05bfa507106f54d765f2e6954cb6e764adf8176 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 3 Dec 2024 18:11:19 +0100 Subject: [PATCH 021/137] Remove get_children from pallet-subtensor --- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/staking/set_children.rs | 17 ------- pallets/subtensor/src/tests/children.rs | 48 +++++++++---------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 0f398c564..d0c8ae68b 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -40,7 +40,7 @@ impl Pallet { // Retrieve lists of parents and children from storage, based on the hotkey and network ID. let parents: Vec<(u64, T::AccountId)> = Self::get_parents(hotkey, netuid); - let children: Vec<(u64, T::AccountId)> = Self::get_children(hotkey, netuid); + let children: Vec<(u64, T::AccountId)> = ChildKeys::::get(hotkey, netuid); // Iterate over children to calculate the total stake allocated to them. for (proportion, _) in children { diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index f084bb2ea..b4d615f2e 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -236,23 +236,6 @@ impl Pallet { ); } - /* Retrieves the list of children for a given hotkey and network. - /// - /// # Arguments - /// * `hotkey` - The hotkey whose children are to be retrieved. - /// * `netuid` - The network identifier. - /// - /// # Returns - /// * `Vec<(u64, T::AccountId)>` - A vector of tuples containing the proportion and child account ID. - /// - /// # Example - /// ``` - /// let children = SubtensorModule::get_children(&hotkey, netuid); - */ - pub fn get_children(hotkey: &T::AccountId, netuid: u16) -> Vec<(u64, T::AccountId)> { - ChildKeys::::get(hotkey, netuid) - } - /* Retrieves the list of parents for a given child and network. /// /// # Arguments diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 15238421e..aef2168b8 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -24,7 +24,7 @@ fn test_do_set_child_singular_success() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); // Verify child assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); }); } @@ -201,7 +201,7 @@ fn test_do_set_child_singular_new_children_assignment() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); // Verify child assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); // Verify parent assignment @@ -234,7 +234,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { mock_set_children(&coldkey, &hotkey, netuid, &[(min_proportion, child)]); // Verify child assignment with minimum proportion - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(min_proportion, child)]); step_rate_limit(&TransactionType::SetChildren, netuid); @@ -244,7 +244,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { mock_set_children(&coldkey, &hotkey, netuid, &[(max_proportion, child)]); // Verify child assignment with maximum proportion - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(max_proportion, child)]); }); } @@ -281,7 +281,7 @@ fn test_do_set_child_singular_multiple_children() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion1, child2)]); // Verify children assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion2, child2)]); // Verify parent assignment for both children @@ -419,7 +419,7 @@ fn test_do_revoke_child_singular_success() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); // Verify child assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); step_rate_limit(&TransactionType::SetChildren, netuid); @@ -428,7 +428,7 @@ fn test_do_revoke_child_singular_success() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify child removal - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert!(children.is_empty()); // Verify parent removal @@ -549,7 +549,7 @@ fn test_do_schedule_children_multiple_success() { ); // Verify children assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion1, child1), (proportion2, child2)]); // Verify parent assignment for both children @@ -761,7 +761,7 @@ fn test_do_schedule_children_multiple_proportion_edge_cases() { ); // Verify children assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!( children, vec![(min_proportion, child1), (max_proportion, child2)] @@ -811,7 +811,7 @@ fn test_do_schedule_children_multiple_overwrite_existing() { ); // Verify final children assignment - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!( children, vec![(proportion * 2, child2), (proportion * 3, child3)] @@ -1106,7 +1106,7 @@ fn test_do_schedule_children_multiple_empty_list() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify children assignment is empty - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert!(children.is_empty()); }); } @@ -1148,7 +1148,7 @@ fn test_do_revoke_children_multiple_success() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify children removal - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert!(children.is_empty()); // Verify parent removal for both children @@ -1264,7 +1264,7 @@ fn test_do_revoke_children_multiple_partial_revocation() { ); // Verify children removal - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion, child1), (proportion, child2)]); // Verify parents. @@ -1307,7 +1307,7 @@ fn test_do_revoke_children_multiple_non_existent_children() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify all children are removed - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert!(children.is_empty()); // Verify parent removal for the existing child @@ -1337,7 +1337,7 @@ fn test_do_revoke_children_multiple_empty_list() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify no changes in children - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert!(children.is_empty()); }); } @@ -1390,7 +1390,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { ); // Verify remaining children - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(proportion1, child1), (proportion3, child3)]); // Verify parent removal for child2 @@ -1403,7 +1403,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify all children are removed - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert!(children.is_empty()); // Verify parent removal for all children @@ -2345,7 +2345,7 @@ fn test_dynamic_parent_child_relationships() { // Expected total stake: 580,000 + 2,000,000 = 2,580,000 // Additional checks for parent-child relationships - let parent_children: Vec<(u64, U256)> = SubtensorModule::get_children(&parent, netuid); + let parent_children: Vec<(u64, U256)> = ChildKeys::::get(&parent, netuid); assert_eq!( parent_children, vec![(u64::MAX / 4, child1), (u64::MAX / 3, child2)], @@ -2705,7 +2705,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { log::info!("After setting parent's children:"); log::info!( "Parent's children: {:?}", - SubtensorModule::get_children(&parent, netuid) + ChildKeys::::get(&parent, netuid) ); log::info!( "Child1's parents: {:?}", @@ -2737,7 +2737,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { log::info!("After setting child1's children:"); log::info!( "Child1's children: {:?}", - SubtensorModule::get_children(&child1, netuid) + ChildKeys::::get(&child1, netuid) ); log::info!( "Grandchild's parents: {:?}", @@ -2776,7 +2776,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { log::info!("Final parent-child relationships:"); log::info!( "Parent's children: {:?}", - SubtensorModule::get_children(&parent, netuid) + ChildKeys::::get(&parent, netuid) ); log::info!( "Child1's parents: {:?}", @@ -2788,7 +2788,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { ); log::info!( "Child1's children: {:?}", - SubtensorModule::get_children(&child1, netuid) + ChildKeys::::get(&child1, netuid) ); log::info!( "Grandchild's parents: {:?}", @@ -2797,7 +2797,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { // Check if the parent-child relationships are correct assert_eq!( - SubtensorModule::get_children(&parent, netuid), + ChildKeys::::get(&parent, netuid), vec![(u64::MAX / 2, child1), (u64::MAX / 2, child2)], "Parent should have both children" ); @@ -2812,7 +2812,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { "Child2 should have parent as its parent" ); assert_eq!( - SubtensorModule::get_children(&child1, netuid), + ChildKeys::::get(&child1, netuid), vec![(u64::MAX, grandchild)], "Child1 should have grandchild as its child" ); From 46ab5a447f85ebcb000ac3f12e2a05f4e99a7de1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 5 Dec 2024 16:11:35 +0100 Subject: [PATCH 022/137] Remove get_coldkey_for_hotkey from pallet-subtensor --- pallets/subtensor/src/rpc_info/delegate_info.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index a877a9730..591f34e48 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -156,8 +156,17 @@ impl Pallet { total_delegated } - // Helper function to get the coldkey associated with a hotkey - pub fn get_coldkey_for_hotkey(hotkey: &T::AccountId) -> T::AccountId { - Owner::::get(hotkey) + // Helper function to get total delegated stake for a hotkey + pub fn get_total_hotkey_delegated_stake(hotkey: &T::AccountId) -> u64 { + let mut total_delegated = 0u64; + + // Iterate through all delegators for this hotkey + for (delegator, stake) in Stake::::iter_prefix(hotkey) { + if delegator != Owner::::get(hotkey) { + total_delegated = total_delegated.saturating_add(stake); + } + } + + total_delegated } } From acbcfa8889435ae0f8051154eb9f16cd848bebf6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 5 Dec 2024 17:28:39 +0100 Subject: [PATCH 023/137] Remove get_commit_reveal_weights_enabled from pallet-subtensor --- pallets/admin-utils/src/tests/mod.rs | 10 ++++------ pallets/subtensor/src/macros/dispatches.rs | 6 ++---- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/weights.rs | 10 +++++----- pallets/subtensor/src/utils/misc.rs | 3 --- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 66fb2173e..78910ff41 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -7,7 +7,8 @@ use frame_support::{ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, - BondsMovingAverage, Error as SubtensorError, Event, RAORecycledForRegistration, + BondsMovingAverage, CommitRevealWeightsEnabled, Error as SubtensorError, Event, + RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -1123,7 +1124,7 @@ fn test_sudo_set_commit_reveal_weights_enabled() { add_network(netuid, 10); let to_be_set: bool = true; - let init_value: bool = SubtensorModule::get_commit_reveal_weights_enabled(netuid); + let init_value: bool = CommitRevealWeightsEnabled::::get(netuid); assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_enabled( <::RuntimeOrigin>::root(), @@ -1132,10 +1133,7 @@ fn test_sudo_set_commit_reveal_weights_enabled() { )); assert!(init_value != to_be_set); - assert_eq!( - SubtensorModule::get_commit_reveal_weights_enabled(netuid), - to_be_set - ); + assert_eq!(CommitRevealWeightsEnabled::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index b62ef4f8c..4d58f3b6d 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -86,10 +86,8 @@ mod dispatches { weights: Vec, version_key: u64, ) -> DispatchResult { - if Self::get_commit_reveal_weights_enabled(netuid) { - Err(Error::::CommitRevealEnabled.into()) - } else { - Self::do_set_weights(origin, netuid, dests, weights, version_key) + if !CommitRevealWeightsEnabled::::get(netuid) { + return Self::do_set_weights(origin, netuid, dests, weights, version_key); } } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 54ceacd51..f9c2d3426 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -253,7 +253,7 @@ impl Pallet { let adjustment_alpha = AdjustmentAlpha::::get(netuid); let difficulty = Self::get_difficulty_as_u64(netuid); let commit_reveal_periods = Self::get_reveal_period(netuid); - let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); + let commit_reveal_weights_enabled = CommitRevealWeightsEnabled::::get(netuid); let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index f0fba4090..a8440b9cb 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -49,7 +49,7 @@ impl Pallet { // 2. Ensure commit-reveal is enabled. ensure!( - Self::get_commit_reveal_weights_enabled(netuid), + CommitRevealWeightsEnabled::::get(netuid), Error::::CommitRevealDisabled ); @@ -346,7 +346,7 @@ impl Pallet { // --- 2. Ensure commit-reveal is enabled for the network. ensure!( - Self::get_commit_reveal_weights_enabled(netuid), + CommitRevealWeightsEnabled::::get(netuid), Error::::CommitRevealDisabled ); @@ -500,7 +500,7 @@ impl Pallet { // --- 3. Ensure commit-reveal is enabled for the network. ensure!( - Self::get_commit_reveal_weights_enabled(netuid), + CommitRevealWeightsEnabled::::get(netuid), Error::::CommitRevealDisabled ); @@ -730,7 +730,7 @@ impl Pallet { // --- 9. Ensure the uid is not setting weights faster than the weights_set_rate_limit. let neuron_uid = Self::get_uid_for_net_and_hotkey(netuid, &hotkey)?; let current_block: u64 = Self::get_current_block_as_u64(); - if !Self::get_commit_reveal_weights_enabled(netuid) { + if !CommitRevealWeightsEnabled::::get(netuid) { ensure!( Self::check_rate_limit(netuid, neuron_uid, current_block), Error::::SettingWeightsTooFast @@ -778,7 +778,7 @@ impl Pallet { Weights::::insert(netuid, neuron_uid, zipped_weights); // --- 18. Set the activity for the weights on this network. - if !Self::get_commit_reveal_weights_enabled(netuid) { + if !CommitRevealWeightsEnabled::::get(netuid) { Self::set_last_update_for_uid(netuid, neuron_uid, current_block); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 67eb74101..f430c82a6 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -490,9 +490,6 @@ impl Pallet { Kappa::::insert(netuid, kappa); Self::deposit_event(Event::KappaSet(netuid, kappa)); } - pub fn get_commit_reveal_weights_enabled(netuid: u16) -> bool { - CommitRevealWeightsEnabled::::get(netuid) - } pub fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool) { CommitRevealWeightsEnabled::::set(netuid, enabled); } From 7348c2441b3b6efff4c2d588d8c97f0cf6d72502 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 5 Dec 2024 22:49:34 +0100 Subject: [PATCH 024/137] Fix rebase --- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/macros/dispatches.rs | 8 +++++--- pallets/subtensor/src/subnets/weights.rs | 4 ++-- pallets/subtensor/src/tests/children.rs | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 25937c748..6abc27901 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -95,7 +95,7 @@ impl Pallet { // --- 4.1 Check to see if the subnet should run its epoch. if Self::should_run_epoch(*netuid, current_block) { // --- 4.2 Reveal weights from the n-2nd epoch. - if Self::get_commit_reveal_weights_enabled(*netuid) { + if CommitRevealWeightsEnabled::::get(*netuid) { if let Err(e) = Self::reveal_crv3_commits(*netuid) { log::warn!( "Failed to reveal commits for subnet {} due to error: {:?}", diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 4d58f3b6d..3263cd741 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -86,9 +86,11 @@ mod dispatches { weights: Vec, version_key: u64, ) -> DispatchResult { - if !CommitRevealWeightsEnabled::::get(netuid) { - return Self::do_set_weights(origin, netuid, dests, weights, version_key); - } + ensure!( + !CommitRevealWeightsEnabled::::get(netuid), + Error::::CommitRevealEnabled + ); + Self::do_set_weights(origin, netuid, dests, weights, version_key) } /// --- Allows a hotkey to set weights for multiple netuids as a batch. diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index a8440b9cb..d2c59f273 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -242,7 +242,7 @@ impl Pallet { // 2. Ensure commit-reveal is enabled. ensure!( - Self::get_commit_reveal_weights_enabled(netuid), + CommitRevealWeightsEnabled::::get(netuid), Error::::CommitRevealDisabled ); @@ -851,7 +851,7 @@ impl Pallet { .map(|((&netuid, w), &version_key)| { let origin_cloned = origin.clone(); - if Self::get_commit_reveal_weights_enabled(netuid.into()) { + if CommitRevealWeightsEnabled::::get::(netuid.into()) { return Err(Error::::CommitRevealEnabled.into()); } diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index aef2168b8..36577dca5 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -3604,7 +3604,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { ); // Verify first children assignment remains - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(100, child)]); // Try again after rate limit period has passed @@ -3626,7 +3626,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { mock_set_children(&coldkey, &hotkey, netuid, &[(100, child2)]); // Verify children assignment has changed - let children = SubtensorModule::get_children(&hotkey, netuid); + let children = ChildKeys::::get(&hotkey, netuid); assert_eq!(children, vec![(100, child2)]); }); } @@ -3736,14 +3736,14 @@ fn test_do_set_child_cooldown_period() { )); // Ensure the childkeys are not yet applied - let children_before = SubtensorModule::get_children(&parent, netuid); + let children_before = ChildKeys::::get(&parent, netuid); assert_eq!(children_before, vec![]); wait_and_set_pending_children(netuid); TotalHotkeyStake::::insert(parent, parent_total_stake_original); // Verify child assignment - let children_after = SubtensorModule::get_children(&parent, netuid); + let children_after = ChildKeys::::get(&parent, netuid); assert_eq!(children_after, vec![(proportion, child)]); }); } From 23ad81fc6f822a7a26700897524463345645a093 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 18:11:36 +0100 Subject: [PATCH 025/137] Remove get_consensus method from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index f430c82a6..26f79cb77 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -1,6 +1,6 @@ use super::*; use crate::{ - system::{ensure_root, ensure_signed_or_root, pallet_prelude::BlockNumberFor}, + system::{ensure_signed_or_root, pallet_prelude::BlockNumberFor}, Error, }; use sp_core::Get; @@ -78,9 +78,6 @@ impl Pallet { pub fn get_emission(netuid: u16) -> Vec { Emission::::get(netuid) } - pub fn get_consensus(netuid: u16) -> Vec { - Consensus::::get(netuid) - } pub fn get_incentive(netuid: u16) -> Vec { Incentive::::get(netuid) } From ec4c017be400341b90e8b136f7c9ed1ee6ea3168 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:12:46 +0100 Subject: [PATCH 026/137] Remove get_default_childkey_take method from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/children.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 36577dca5..2f1943e2a 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -850,7 +850,7 @@ fn test_childkey_take_functionality() { register_ok_neuron(netuid, hotkey, coldkey, 0); // Test default and max childkey take - let default_take = SubtensorModule::get_default_childkey_take(); + let default_take = MinChildkeyTake::::get(); let min_take = SubtensorModule::get_min_childkey_take(); log::info!("Default take: {}, Max take: {}", default_take, min_take); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 26f79cb77..18d43405e 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -347,11 +347,6 @@ impl Pallet { // Default to maximum MaxDelegateTake::::get() } - // get_default_childkey_take - pub fn get_default_childkey_take() -> u16 { - // Default to maximum - MinChildkeyTake::::get() - } pub fn get_tx_childkey_take_rate_limit() -> u64 { TxChildkeyTakeRateLimit::::get() } From c3ed86de36e1535395f2124bda826123dadb3149 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:21:47 +0100 Subject: [PATCH 027/137] Remove get_default_delegate_take from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 8 ++++---- pallets/subtensor/src/macros/dispatches.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 78910ff41..9106eae53 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -8,7 +8,7 @@ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, BondsMovingAverage, CommitRevealWeightsEnabled, Error as SubtensorError, Event, - RAORecycledForRegistration, + MaxDelegateTake, RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -22,7 +22,7 @@ mod mock; fn test_sudo_set_default_take() { new_test_ext().execute_with(|| { let to_be_set: u16 = 10; - let init_value: u16 = SubtensorModule::get_default_delegate_take(); + let init_value: u16 = MaxDelegateTake::::get(); assert_eq!( AdminUtils::sudo_set_default_take( <::RuntimeOrigin>::signed(U256::from(0)), @@ -30,12 +30,12 @@ fn test_sudo_set_default_take() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_default_delegate_take(), init_value); + assert_eq!(MaxDelegateTake::::get(), init_value); assert_ok!(AdminUtils::sudo_set_default_take( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_default_delegate_take(), to_be_set); + assert_eq!(MaxDelegateTake::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 3263cd741..e19b7b6c0 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -454,7 +454,7 @@ mod dispatches { .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)), DispatchClass::Normal, Pays::No))] pub fn become_delegate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { - Self::do_become_delegate(origin, hotkey, Self::get_default_delegate_take()) + Self::do_become_delegate(origin, hotkey, MaxDelegateTake::::get()) } /// --- Allows delegates to decrease its take value. diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 18d43405e..05fcf05e7 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -343,10 +343,6 @@ impl Pallet { pub fn get_max_delegate_take() -> u16 { MaxDelegateTake::::get() } - pub fn get_default_delegate_take() -> u16 { - // Default to maximum - MaxDelegateTake::::get() - } pub fn get_tx_childkey_take_rate_limit() -> u64 { TxChildkeyTakeRateLimit::::get() } From 509f439cd956dfb59f738032532e491bf163f253 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:29:04 +0100 Subject: [PATCH 028/137] Remove get_difficulty_as_u64 from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 8 +++--- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 ++-- pallets/subtensor/src/subnets/registration.rs | 4 +-- pallets/subtensor/src/tests/difficulty.rs | 28 +++++++++---------- pallets/subtensor/src/tests/registration.rs | 10 +++---- pallets/subtensor/src/utils/misc.rs | 7 ----- 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 9106eae53..f07d5b05c 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -8,7 +8,7 @@ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, BondsMovingAverage, CommitRevealWeightsEnabled, Error as SubtensorError, Event, - MaxDelegateTake, RAORecycledForRegistration, + MaxDelegateTake, RAORecycledForRegistration, Difficulty, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -620,7 +620,7 @@ fn test_sudo_set_difficulty() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_difficulty_as_u64(netuid); + let init_value: u64 = Difficulty::::get(netuid); assert_eq!( AdminUtils::sudo_set_difficulty( <::RuntimeOrigin>::signed(U256::from(1)), @@ -637,13 +637,13 @@ fn test_sudo_set_difficulty() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), init_value); + assert_eq!(Difficulty::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_difficulty( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), to_be_set); + assert_eq!(Difficulty::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 31d206054..e2cc265d1 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -42,7 +42,7 @@ impl Pallet { // --- 4. Get the current counters for this network w.r.t burn and difficulty values. let current_burn: u64 = Burn::::get(netuid); - let current_difficulty: u64 = Self::get_difficulty_as_u64(netuid); + let current_difficulty: u64 = Difficulty::::get(netuid); let registrations_this_interval: u16 = Self::get_registrations_this_interval(netuid); let pow_registrations_this_interval: u16 = diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index f9c2d3426..c2da14ee2 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -91,7 +91,7 @@ impl Pallet { let rho = Self::get_rho(netuid); let kappa = Self::get_kappa(netuid); - let difficulty: Compact = Self::get_difficulty_as_u64(netuid).into(); + let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = Self::get_immunity_period(netuid); let max_allowed_validators = Self::get_max_allowed_validators(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); @@ -161,7 +161,7 @@ impl Pallet { let rho = Self::get_rho(netuid); let kappa = Self::get_kappa(netuid); - let difficulty: Compact = Self::get_difficulty_as_u64(netuid).into(); + let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = Self::get_immunity_period(netuid); let max_allowed_validators = Self::get_max_allowed_validators(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); @@ -251,7 +251,7 @@ impl Pallet { let serving_rate_limit = Self::get_serving_rate_limit(netuid); let max_validators = Self::get_max_allowed_validators(netuid); let adjustment_alpha = AdjustmentAlpha::::get(netuid); - let difficulty = Self::get_difficulty_as_u64(netuid); + let difficulty = Difficulty::::get(netuid); let commit_reveal_periods = Self::get_reveal_period(netuid); let commit_reveal_weights_enabled = CommitRevealWeightsEnabled::::get(netuid); let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index b84d644c2..95efbb02d 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -282,7 +282,7 @@ impl Pallet { ); // --- 8. Ensure the supplied work passes the difficulty. - let difficulty: U256 = Self::get_difficulty(netuid); + let difficulty = Difficulty::::get(netuid).into(); let work_hash: H256 = Self::vec_to_hash(work.clone()); ensure!( Self::hash_meets_difficulty(&work_hash, difficulty), @@ -602,7 +602,7 @@ impl Pallet { start_nonce: u64, hotkey: &T::AccountId, ) -> (u64, Vec) { - let difficulty: U256 = Self::get_difficulty(netuid); + let difficulty = Difficulty::::get(netuid).into(); let mut nonce: u64 = start_nonce; let mut work: H256 = Self::create_seal_hash(block_number, nonce, hotkey); while !Self::hash_meets_difficulty(&work, difficulty) { diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 13bff43d6..271cbe0ce 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -3,7 +3,7 @@ use sp_core::U256; use super::mock::*; -use crate::{SubnetworkN, AdjustmentInterval}; +use crate::{SubnetworkN, Difficulty, AdjustmentInterval}; #[test] fn test_registration_difficulty_adjustment() { @@ -14,7 +14,7 @@ fn test_registration_difficulty_adjustment() { let modality: u16 = 1; add_network(netuid, tempo, modality); SubtensorModule::set_min_difficulty(netuid, 10000); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); // Check initial difficulty. + assert_eq!(Difficulty::::get(netuid), 10000); // Check initial difficulty. assert_eq!(SubtensorModule::get_last_adjustment_block(netuid), 0); // Last adjustment block starts at 0. assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // No registrations this block. SubtensorModule::set_adjustment_alpha(netuid, 58000); @@ -29,7 +29,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::set_max_registrations_per_block(netuid, 3); SubtensorModule::set_max_allowed_uids(netuid, 3); SubtensorModule::set_network_registration_allowed(netuid, true); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 20000); // Check set difficutly. + assert_eq!(Difficulty::::get(netuid), 20000); // Check set difficutly. assert_eq!(AdjustmentInterval::::get(netuid), 1); // Check set adjustment interval. assert_eq!( SubtensorModule::get_target_registrations_per_interval(netuid), @@ -67,14 +67,14 @@ fn test_registration_difficulty_adjustment() { assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // 3 Registrations this interval. // Fast forward 1 block. - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 20000); // Difficulty is unchanged. + assert_eq!(Difficulty::::get(netuid), 20000); // Difficulty is unchanged. step_block(1); assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // Registrations have been erased. // TODO: are we OK with this change? assert_eq!(SubtensorModule::get_last_adjustment_block(netuid), 2); // We just adjusted on the first block. - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 40000); // Difficulty is increased ( 20000 * ( 3 + 1 ) / ( 1 + 1 ) ) = 80_000 + assert_eq!(Difficulty::::get(netuid), 40000); // Difficulty is increased ( 20000 * ( 3 + 1 ) / ( 1 + 1 ) ) = 80_000 assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 0); // Registrations this interval has been wiped. // Lets change the adjustment interval @@ -123,29 +123,29 @@ fn test_registration_difficulty_adjustment() { // We have 6 registrations this adjustment interval. step_block(1); // Step assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 6); // Registrations this interval = 6 - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 40000); // Difficulty unchanged. + assert_eq!(Difficulty::::get(netuid), 40000); // Difficulty unchanged. step_block(1); // Step - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 60_000); // Difficulty changed ( 40000 ) * ( 6 + 3 / 3 + 3 ) = 40000 * 1.5 = 60_000 + assert_eq!(Difficulty::::get(netuid), 60_000); // Difficulty changed ( 40000 ) * ( 6 + 3 / 3 + 3 ) = 40000 * 1.5 = 60_000 assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 0); // Registrations this interval drops to 0. // Test min value. SubtensorModule::set_min_difficulty(netuid, 1); SubtensorModule::set_difficulty(netuid, 4); assert_eq!(SubtensorModule::get_min_difficulty(netuid), 1); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 4); + assert_eq!(Difficulty::::get(netuid), 4); SubtensorModule::set_adjustment_interval(netuid, 1); step_block(1); // Step - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 2); // Difficulty dropped 4 * ( 0 + 1 ) / (1 + 1) = 1/2 = 2 + assert_eq!(Difficulty::::get(netuid), 2); // Difficulty dropped 4 * ( 0 + 1 ) / (1 + 1) = 1/2 = 2 step_block(1); // Step - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 1); // Difficulty dropped 2 * ( 0 + 1 ) / (1 + 1) = 1/2 = 1 + assert_eq!(Difficulty::::get(netuid), 1); // Difficulty dropped 2 * ( 0 + 1 ) / (1 + 1) = 1/2 = 1 step_block(1); // Step - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 1); // Difficulty dropped 2 * ( 0 + 1 ) / (1 + 1) = 1/2 = max(0.5, 1) + assert_eq!(Difficulty::::get(netuid), 1); // Difficulty dropped 2 * ( 0 + 1 ) / (1 + 1) = 1/2 = max(0.5, 1) // Test max value. SubtensorModule::set_max_difficulty(netuid, 10000); SubtensorModule::set_difficulty(netuid, 5000); assert_eq!(SubtensorModule::get_max_difficulty(netuid), 10000); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 5000); + assert_eq!(Difficulty::::get(netuid), 5000); SubtensorModule::set_max_registrations_per_block(netuid, 4); register_ok_neuron(netuid, hotkey0 + 3, coldkey0 + 3, 294208420); register_ok_neuron(netuid, hotkey1 + 3, coldkey1 + 3, 824123920); @@ -157,12 +157,12 @@ fn test_registration_difficulty_adjustment() { 3 ); step_block(1); // Step - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 5833); // Difficulty increased 5000 * ( 4 + 3 ) / (3 + 3) = 1.16 * 5000 = 5833 + assert_eq!(Difficulty::::get(netuid), 5833); // Difficulty increased 5000 * ( 4 + 3 ) / (3 + 3) = 1.16 * 5000 = 5833 register_ok_neuron(netuid, hotkey0 + 4, coldkey0 + 4, 124208420); register_ok_neuron(netuid, hotkey1 + 4, coldkey1 + 4, 314123920); register_ok_neuron(netuid, hotkey2 + 4, coldkey2 + 4, 834123920); step_block(1); // Step - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 5833); // Difficulty unchanged + assert_eq!(Difficulty::::get(netuid), 5833); // Difficulty unchanged }); } diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 6d5f0a688..18970cb6f 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,7 +11,7 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ - Axons, Burn, Error, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, + Axons, Burn, Difficulty, Error, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, }; /******************************************** @@ -49,9 +49,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).as_u64(), 10000); - }); + new_test_ext(1).execute_with(|| assert_eq!(Difficulty::::get(1), 10000)); } #[test] @@ -726,7 +724,7 @@ fn test_registration_too_many_registrations_per_block() { 345923888, &U256::from(10), ); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); + assert_eq!(Difficulty::::get(netuid), 10000); // Subscribe and check extrinsic output assert_ok!(SubtensorModule::register( @@ -921,7 +919,7 @@ fn test_registration_too_many_registrations_per_interval() { 153453, &U256::from(9), ); - assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); + assert_eq!(Difficulty::::get(netuid), 10000); // Subscribe and check extrinsic output // Try 10 registrations, this is less than the max per block, but more than the max per interval diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 05fcf05e7..688a3fd4c 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -4,7 +4,6 @@ use crate::{ Error, }; use sp_core::Get; -use sp_core::U256; use sp_runtime::Saturating; use substrate_fixed::types::I32F32; @@ -248,9 +247,6 @@ impl Pallet { pub fn get_blocks_since_last_step(netuid: u16) -> u64 { BlocksSinceLastStep::::get(netuid) } - pub fn get_difficulty(netuid: u16) -> U256 { - U256::from(Self::get_difficulty_as_u64(netuid)) - } pub fn get_registrations_this_block(netuid: u16) -> u16 { RegistrationsThisBlock::::get(netuid) } @@ -548,9 +544,6 @@ impl Pallet { Self::deposit_event(Event::MaxBurnSet(netuid, max_burn)); } - pub fn get_difficulty_as_u64(netuid: u16) -> u64 { - Difficulty::::get(netuid) - } pub fn set_difficulty(netuid: u16, difficulty: u64) { Difficulty::::insert(netuid, difficulty); Self::deposit_event(Event::DifficultySet(netuid, difficulty)); From 1e2a13960484862b2bf33865e664908fa259f490 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:44:34 +0100 Subject: [PATCH 029/137] Remove get_dividends from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 688a3fd4c..83700c510 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -80,9 +80,6 @@ impl Pallet { pub fn get_incentive(netuid: u16) -> Vec { Incentive::::get(netuid) } - pub fn get_dividends(netuid: u16) -> Vec { - Dividends::::get(netuid) - } pub fn get_last_update(netuid: u16) -> Vec { LastUpdate::::get(netuid) } From e73eccf9c42220822fd2a3c77f8230369cb64041 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:48:36 +0100 Subject: [PATCH 030/137] Remove get_emission from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 83700c510..1fb10f49f 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -74,9 +74,6 @@ impl Pallet { pub fn get_trust(netuid: u16) -> Vec { Trust::::get(netuid) } - pub fn get_emission(netuid: u16) -> Vec { - Emission::::get(netuid) - } pub fn get_incentive(netuid: u16) -> Vec { Incentive::::get(netuid) } From e5320184fdd8ebc1fe88993c48d7fe9ea41595ec Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:54:08 +0100 Subject: [PATCH 031/137] Remove get_emission_value from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/tests/registration.rs | 9 +++++---- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 82e0cfa30..416c7bb9f 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1281,7 +1281,7 @@ impl Pallet { netuids.sort_by(|a, b| { use sp_std::cmp::Ordering; - match Self::get_emission_value(*b).cmp(&Self::get_emission_value(*a)) { + match EmissionValues::::get(*b).cmp(&EmissionValues::::get(*a)) { Ordering::Equal => { if Self::get_network_registered_block(*b) < Self::get_network_registered_block(*a) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index c2da14ee2..5ef6f1357 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -102,7 +102,7 @@ impl Pallet { let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); - let emission_values = Self::get_emission_value(netuid); + let emission_values = EmissionValues::::get(netuid); let burn: Compact = Burn::::get(netuid).into(); // DEPRECATED let network_connect: Vec<[u16; 2]> = Vec::<[u16; 2]>::new(); @@ -172,7 +172,7 @@ impl Pallet { let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); - let emission_values = Self::get_emission_value(netuid); + let emission_values = EmissionValues::::get(netuid); let burn: Compact = Burn::::get(netuid).into(); let identity: Option = SubnetIdentities::::get(netuid); diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 18970cb6f..2d57ffa7d 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,7 +11,8 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ - Axons, Burn, Difficulty, Error, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, + Axons, Burn, EmissionValues, Difficulty, Error, RAORecycledForRegistration, SubnetworkN, + SubtensorSignedExtension, }; /******************************************** @@ -1524,9 +1525,9 @@ fn test_full_pass_through() { assert_eq!(SubtensorModule::get_tempo(netuid2), tempo2); // Check their emission value. - assert_eq!(SubtensorModule::get_emission_value(netuid0), 0); - assert_eq!(SubtensorModule::get_emission_value(netuid1), 0); - assert_eq!(SubtensorModule::get_emission_value(netuid2), 0); + assert_eq!(EmissionValues::::get(netuid0), 0); + assert_eq!(EmissionValues::::get(netuid1), 0); + assert_eq!(EmissionValues::::get(netuid2), 0); // Set their max allowed uids. SubtensorModule::set_max_allowed_uids(netuid0, 2); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 1fb10f49f..5f48fcee6 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -229,9 +229,6 @@ impl Pallet { pub fn get_tempo(netuid: u16) -> u16 { Tempo::::get(netuid) } - pub fn get_emission_value(netuid: u16) -> u64 { - EmissionValues::::get(netuid) - } pub fn get_pending_emission(netuid: u16) -> u64 { PendingEmission::::get(netuid) } From ceeadf7b109c62ce493ef9645e99df8b11ecd684 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 19:55:43 +0100 Subject: [PATCH 032/137] Remove get_float_rho from pallet-subtensor::Pallet --- pallets/subtensor/src/epoch/run_epoch.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index d0c8ae68b..f86d524c8 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -796,9 +796,6 @@ impl Pallet { .collect() } - pub fn get_float_rho(netuid: u16) -> I32F32 { - I32F32::from_num(Self::get_rho(netuid)) - } pub fn get_float_kappa(netuid: u16) -> I32F32 { I32F32::from_num(Self::get_kappa(netuid)).saturating_div(I32F32::from_num(u16::MAX)) } From 448376f8479fcfb0c8e84c0d46e1f8be604fdc99 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 20:19:45 +0100 Subject: [PATCH 033/137] Remove get_hotkey_emission_tempo from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/tests/coinbase.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 8 -------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 6abc27901..87368f3c6 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -183,7 +183,7 @@ impl Pallet { // The hotkey takes a proportion of the emission, the remainder is drained through to the nominators. // We keep track of the last stake increase event for accounting purposes. // hotkeys --> nominators. - let emission_tempo: u64 = Self::get_hotkey_emission_tempo(); + let emission_tempo: u64 = HotkeyEmissionTempo::::get(); for (hotkey, hotkey_emission) in PendingdHotkeyEmission::::iter() { // Check for zeros. // remove zero values. diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 2a87da3be..55ab19520 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -5,7 +5,7 @@ use frame_support::assert_ok; use sp_core::U256; use substrate_fixed::types::I64F64; -use crate::TargetStakesPerInterval; +use crate::{HotkeyEmissionTempo, TargetStakesPerInterval}; // Test the ability to hash all sorts of hotkeys. #[test] @@ -145,7 +145,7 @@ fn test_coinbase_basic() { fn test_set_and_get_hotkey_emission_tempo() { new_test_ext(1).execute_with(|| { // Get the default hotkey emission tempo - let default_tempo = SubtensorModule::get_hotkey_emission_tempo(); + let default_tempo = HotkeyEmissionTempo::::get(); assert_eq!(default_tempo, 0); // default is 0 in mock.rs // Set a new hotkey emission tempo @@ -153,7 +153,7 @@ fn test_set_and_get_hotkey_emission_tempo() { SubtensorModule::set_hotkey_emission_tempo(new_tempo); // Get the updated hotkey emission tempo - let updated_tempo = SubtensorModule::get_hotkey_emission_tempo(); + let updated_tempo = HotkeyEmissionTempo::::get(); assert_eq!(updated_tempo, new_tempo); }); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 5f48fcee6..653337f60 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -638,14 +638,6 @@ impl Pallet { LiquidAlphaOn::::get(netuid) } - /// Gets the current hotkey emission tempo. - /// - /// # Returns - /// * `u64` - The current emission tempo value. - pub fn get_hotkey_emission_tempo() -> u64 { - HotkeyEmissionTempo::::get() - } - /// Sets the hotkey emission tempo. /// /// # Arguments From 3baa6c22df9631a8d0cc5fa9f8f776da16e8aa12 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 20:33:15 +0100 Subject: [PATCH 034/137] Remove get_hotkey_take from pallet-subtensor::Pallet --- pallets/subtensor/src/staking/helpers.rs | 11 -------- pallets/subtensor/src/tests/staking.rs | 34 ++++++++++++------------ 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 25b77776c..0e3656665 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -85,17 +85,6 @@ impl Pallet { Owner::::get(hotkey) } - /// Returns the hotkey take. - /// - /// # Arguments - /// * `hotkey` - The hotkey account ID. - /// - /// # Returns - /// The take value of the hotkey. - pub fn get_hotkey_take(hotkey: &T::AccountId) -> u16 { - Delegates::::get(hotkey) - } - /// Returns true if the hotkey account has been created. /// /// # Arguments diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index d33d26155..c9efe0abd 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1691,7 +1691,7 @@ fn test_delegate_take_can_be_decreased() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1737,7 +1737,7 @@ fn test_can_set_min_take_ok() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -1766,7 +1766,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1780,7 +1780,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { Err(Error::::DelegateTakeTooLow.into()) ); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -1809,7 +1809,7 @@ fn test_delegate_take_can_be_increased() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1821,7 +1821,7 @@ fn test_delegate_take_can_be_increased() { hotkey0, u16::MAX / 8 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 8); + assert_eq!(Delegates::::get(&hotkey0), u16::MAX / 8); }); } @@ -1848,7 +1848,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1862,7 +1862,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { Err(Error::::DelegateTakeTooLow.into()) ); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -1891,7 +1891,7 @@ fn test_delegate_take_can_be_increased_to_limit() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1904,7 +1904,7 @@ fn test_delegate_take_can_be_increased_to_limit() { InitialDefaultDelegateTake::get() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), InitialDefaultDelegateTake::get() ); }); @@ -1925,7 +1925,7 @@ fn test_delegate_take_can_not_be_set_beyond_limit() { let netuid = 1; add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - let before = SubtensorModule::get_hotkey_take(&hotkey0); + let before = Delegates::::get(&hotkey0); // Coldkey / hotkey 0 attempt to become delegates with take above maximum // (Disable this check if InitialDefaultDelegateTake is u16::MAX) @@ -1939,7 +1939,7 @@ fn test_delegate_take_can_not_be_set_beyond_limit() { Err(Error::::DelegateTakeTooHigh.into()) ); } - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), before); + assert_eq!(Delegates::::get(&hotkey0), before); }); } @@ -1966,7 +1966,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1983,7 +1983,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { ); } assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -2012,7 +2012,7 @@ fn test_rate_limits_enforced_on_increase_take() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -2026,7 +2026,7 @@ fn test_rate_limits_enforced_on_increase_take() { Err(Error::::DelegateTxRateLimitExceeded.into()) ); assert_eq!( - SubtensorModule::get_hotkey_take(&hotkey0), + Delegates::::get(&hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -2038,7 +2038,7 @@ fn test_rate_limits_enforced_on_increase_take() { hotkey0, u16::MAX / 8 )); - assert_eq!(SubtensorModule::get_hotkey_take(&hotkey0), u16::MAX / 8); + assert_eq!(Delegates::::get(&hotkey0), u16::MAX / 8); }); } From cbc10afc63a8943b9c9b8cf337df8f393d9be3df Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 20:50:35 +0100 Subject: [PATCH 035/137] Fix rebase --- runtime/src/precompiles/metagraph.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/precompiles/metagraph.rs b/runtime/src/precompiles/metagraph.rs index 28bf664b8..969b6c97c 100644 --- a/runtime/src/precompiles/metagraph.rs +++ b/runtime/src/precompiles/metagraph.rs @@ -268,7 +268,7 @@ impl MetagraphPrecompile { exit_status: ExitError::Other(sp_version::Cow::Borrowed(NO_HOTKEY)), })?; - let axon = pallet_subtensor::Pallet::::get_axon_info(netuid, &hotkey); + let axon = pallet_subtensor::Axons::::get(netuid, &hotkey).unwrap_or_default(); let mut block_result = [0_u8; 32]; U256::to_big_endian(&U256::from(axon.block), &mut block_result); From 54fb99aca4bfcc62429975f3311b4c814b79ad65 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 21:00:13 +0100 Subject: [PATCH 036/137] Remove get_immunity_period from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 10 +++++----- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/tests/registration.rs | 8 ++++---- pallets/subtensor/src/utils/misc.rs | 5 +---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index f07d5b05c..1b9225149 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -7,8 +7,8 @@ use frame_support::{ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, - BondsMovingAverage, CommitRevealWeightsEnabled, Error as SubtensorError, Event, - MaxDelegateTake, RAORecycledForRegistration, Difficulty, + BondsMovingAverage, CommitRevealWeightsEnabled, Difficulty, Error as SubtensorError, Event, + ImmunityPeriod, MaxDelegateTake, RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -346,7 +346,7 @@ fn test_sudo_set_immunity_period() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_immunity_period(netuid); + let init_value: u16 = ImmunityPeriod::::get(netuid); assert_eq!( AdminUtils::sudo_set_immunity_period( <::RuntimeOrigin>::signed(U256::from(1)), @@ -363,13 +363,13 @@ fn test_sudo_set_immunity_period() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_immunity_period(netuid), init_value); + assert_eq!(ImmunityPeriod::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_immunity_period( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_immunity_period(netuid), to_be_set); + assert_eq!(ImmunityPeriod::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 5ef6f1357..a345c77a0 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -92,7 +92,7 @@ impl Pallet { let rho = Self::get_rho(netuid); let kappa = Self::get_kappa(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); - let immunity_period = Self::get_immunity_period(netuid); + let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = Self::get_max_allowed_validators(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); @@ -162,7 +162,7 @@ impl Pallet { let rho = Self::get_rho(netuid); let kappa = Self::get_kappa(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); - let immunity_period = Self::get_immunity_period(netuid); + let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = Self::get_max_allowed_validators(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); @@ -232,7 +232,7 @@ impl Pallet { let rho = Self::get_rho(netuid); let kappa = Self::get_kappa(netuid); - let immunity_period = Self::get_immunity_period(netuid); + let immunity_period = ImmunityPeriod::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); let tempo = Self::get_tempo(netuid); diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 2d57ffa7d..e6d716f5e 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,8 +11,8 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ - Axons, Burn, EmissionValues, Difficulty, Error, RAORecycledForRegistration, SubnetworkN, - SubtensorSignedExtension, + Axons, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, RAORecycledForRegistration, + SubnetworkN, SubtensorSignedExtension, }; /******************************************** @@ -1222,7 +1222,7 @@ fn test_registration_get_uid_to_prune_all_in_immunity_period() { SubtensorModule::set_immunity_period(netuid, 2); assert_eq!(SubtensorModule::get_pruning_score_for_uid(netuid, 0), 100); assert_eq!(SubtensorModule::get_pruning_score_for_uid(netuid, 1), 110); - assert_eq!(SubtensorModule::get_immunity_period(netuid), 2); + assert_eq!(ImmunityPeriod::::get(netuid), 2); assert_eq!(SubtensorModule::get_current_block_as_u64(), 0); assert_eq!( SubtensorModule::get_neuron_block_at_registration(netuid, 0), @@ -1246,7 +1246,7 @@ fn test_registration_get_uid_to_prune_none_in_immunity_period() { SubtensorModule::set_immunity_period(netuid, 2); assert_eq!(SubtensorModule::get_pruning_score_for_uid(netuid, 0), 100); assert_eq!(SubtensorModule::get_pruning_score_for_uid(netuid, 1), 110); - assert_eq!(SubtensorModule::get_immunity_period(netuid), 2); + assert_eq!(ImmunityPeriod::::get(netuid), 2); assert_eq!(SubtensorModule::get_current_block_as_u64(), 0); assert_eq!( SubtensorModule::get_neuron_block_at_registration(netuid, 0), diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 653337f60..05d58963f 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -427,9 +427,6 @@ impl Pallet { Self::deposit_event(Event::MaxWeightLimitSet(netuid, max_weight_limit)); } - pub fn get_immunity_period(netuid: u16) -> u16 { - ImmunityPeriod::::get(netuid) - } pub fn set_immunity_period(netuid: u16, immunity_period: u16) { ImmunityPeriod::::insert(netuid, immunity_period); Self::deposit_event(Event::ImmunityPeriodSet(netuid, immunity_period)); @@ -438,7 +435,7 @@ impl Pallet { 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); + let immunity_period = ImmunityPeriod::::get(netuid); current_block.saturating_sub(registered_at) < u64::from(immunity_period) } From 48e8d1379a2f7f5dd349edf983b581fd12d36109 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 21:09:15 +0100 Subject: [PATCH 037/137] Remove get_incentive from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 05d58963f..02a569be2 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -74,9 +74,6 @@ impl Pallet { pub fn get_trust(netuid: u16) -> Vec { Trust::::get(netuid) } - pub fn get_incentive(netuid: u16) -> Vec { - Incentive::::get(netuid) - } pub fn get_last_update(netuid: u16) -> Vec { LastUpdate::::get(netuid) } From 949df4ca7729501fa608a043ac33ca8dfebf48fa Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 21:14:36 +0100 Subject: [PATCH 038/137] Remove get_kappa from pallet-subtensor::Pallet --- pallets/admin-utils/src/benchmarking.rs | 3 +++ pallets/admin-utils/src/tests/mod.rs | 8 ++++---- pallets/subtensor/src/benchmarks.rs | 2 +- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 3 --- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index 5ab4e1421..d609985b6 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -5,8 +5,11 @@ extern crate alloc; use alloc::vec::Vec; +extern crate alloc; + #[allow(unused)] use crate::Pallet as AdminUtils; +use alloc::vec::Vec; use frame_benchmarking::v1::account; use frame_benchmarking::v2::*; use frame_support::BoundedVec; diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 1b9225149..c4b4c91da 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -8,7 +8,7 @@ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, BondsMovingAverage, CommitRevealWeightsEnabled, Difficulty, Error as SubtensorError, Event, - ImmunityPeriod, MaxDelegateTake, RAORecycledForRegistration, + ImmunityPeriod, Kappa, MaxDelegateTake, RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -482,7 +482,7 @@ fn test_sudo_set_kappa() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_kappa(netuid); + let init_value: u16 = Kappa::::get(netuid); assert_eq!( AdminUtils::sudo_set_kappa( <::RuntimeOrigin>::signed(U256::from(1)), @@ -499,13 +499,13 @@ fn test_sudo_set_kappa() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_kappa(netuid), init_value); + assert_eq!(Kappa::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_kappa( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_kappa(netuid), to_be_set); + assert_eq!(Kappa::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index cb6f19e92..d361c4786 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -159,7 +159,7 @@ benchmarks! { Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), wallet_bal); assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); - assert_ok!(Subtensor::::do_become_delegate(RawOrigin::Signed(coldkey.clone()).into(), hotkey.clone(), Subtensor::::get_default_delegate_take())); + assert_ok!(Subtensor::::do_become_delegate(RawOrigin::Signed(coldkey.clone()).into(), hotkey.clone(), MaxDelegateTake::::get())); // Stake 10% of our current total staked TAO let u64_staked_amt = 100_000_000_000; diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index f86d524c8..4d1bb9b3f 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -797,7 +797,7 @@ impl Pallet { } pub fn get_float_kappa(netuid: u16) -> I32F32 { - I32F32::from_num(Self::get_kappa(netuid)).saturating_div(I32F32::from_num(u16::MAX)) + I32F32::from_num(Kappa::::get(netuid)).saturating_div(I32F32::from_num(u16::MAX)) } pub fn get_block_at_registration(netuid: u16) -> Vec { diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index a345c77a0..f292de4b8 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -90,7 +90,7 @@ impl Pallet { } let rho = Self::get_rho(netuid); - let kappa = Self::get_kappa(netuid); + let kappa = Kappa::::get(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = Self::get_max_allowed_validators(netuid); @@ -160,7 +160,7 @@ impl Pallet { } let rho = Self::get_rho(netuid); - let kappa = Self::get_kappa(netuid); + let kappa = Kappa::::get(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = Self::get_max_allowed_validators(netuid); @@ -231,7 +231,7 @@ impl Pallet { } let rho = Self::get_rho(netuid); - let kappa = Self::get_kappa(netuid); + let kappa = Kappa::::get(netuid); let immunity_period = ImmunityPeriod::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 02a569be2..9f759bbd5 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -452,9 +452,6 @@ impl Pallet { Self::deposit_event(Event::MaxAllowedUidsSet(netuid, max_allowed)); } - pub fn get_kappa(netuid: u16) -> u16 { - Kappa::::get(netuid) - } pub fn set_kappa(netuid: u16, kappa: u16) { Kappa::::insert(netuid, kappa); Self::deposit_event(Event::KappaSet(netuid, kappa)); From 88a582ea50e2850fa44238a0fe84d2f49e4dc549 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 22:08:46 +0100 Subject: [PATCH 039/137] Remove get_last_adjustment_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/tests/difficulty.rs | 8 ++++---- pallets/subtensor/src/utils/misc.rs | 7 +------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index e2cc265d1..d6c96a301 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -25,7 +25,7 @@ impl Pallet { // --- 1. Iterate through each network. for (netuid, _) in as IterableStorageMap>::iter() { // --- 2. Pull counters for network difficulty. - let last_adjustment_block: u64 = Self::get_last_adjustment_block(netuid); + let last_adjustment_block: u64 = LastAdjustmentBlock::::get(netuid); let adjustment_interval: u16 = AdjustmentInterval::::get(netuid); let current_block: u64 = Self::get_current_block_as_u64(); log::debug!("netuid: {:?} last_adjustment_block: {:?} adjustment_interval: {:?} current_block: {:?}", diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 271cbe0ce..dda3fb88b 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -3,7 +3,7 @@ use sp_core::U256; use super::mock::*; -use crate::{SubnetworkN, Difficulty, AdjustmentInterval}; +use crate::{AdjustmentInterval, Difficulty, LastAdjustmentBlock, SubnetworkN}; #[test] fn test_registration_difficulty_adjustment() { @@ -15,7 +15,7 @@ fn test_registration_difficulty_adjustment() { add_network(netuid, tempo, modality); SubtensorModule::set_min_difficulty(netuid, 10000); assert_eq!(Difficulty::::get(netuid), 10000); // Check initial difficulty. - assert_eq!(SubtensorModule::get_last_adjustment_block(netuid), 0); // Last adjustment block starts at 0. + assert_eq!(LastAdjustmentBlock::::get(netuid), 0); // Last adjustment block starts at 0. assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // No registrations this block. SubtensorModule::set_adjustment_alpha(netuid, 58000); SubtensorModule::set_target_registrations_per_interval(netuid, 2); @@ -72,7 +72,7 @@ fn test_registration_difficulty_adjustment() { assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // Registrations have been erased. // TODO: are we OK with this change? - assert_eq!(SubtensorModule::get_last_adjustment_block(netuid), 2); // We just adjusted on the first block. + assert_eq!(LastAdjustmentBlock::::get(netuid), 2); // We just adjusted on the first block. assert_eq!(Difficulty::::get(netuid), 40000); // Difficulty is increased ( 20000 * ( 3 + 1 ) / ( 1 + 1 ) ) = 80_000 assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 0); // Registrations this interval has been wiped. @@ -109,7 +109,7 @@ fn test_registration_difficulty_adjustment() { step_block(1); // Step // TODO: are we OK with this change? - assert_eq!(SubtensorModule::get_last_adjustment_block(netuid), 2); // Still previous adjustment block. + assert_eq!(LastAdjustmentBlock::::get(netuid), 2); // Still previous adjustment block. assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // Registrations have been erased. assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // Registrations this interval = 3 diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9f759bbd5..c46a244e4 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -229,12 +229,7 @@ impl Pallet { pub fn get_pending_emission(netuid: u16) -> u64 { PendingEmission::::get(netuid) } - pub fn get_last_adjustment_block(netuid: u16) -> u64 { - LastAdjustmentBlock::::get(netuid) - } - pub fn get_blocks_since_last_step(netuid: u16) -> u64 { - BlocksSinceLastStep::::get(netuid) - } + pub fn get_registrations_this_block(netuid: u16) -> u16 { RegistrationsThisBlock::::get(netuid) } From 1970826fea58dc91908d615001100a4d00a5ca9f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 22:11:04 +0100 Subject: [PATCH 040/137] Remove get_last_mechanism_step_block from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index c46a244e4..7b0ed0285 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -233,9 +233,7 @@ impl Pallet { pub fn get_registrations_this_block(netuid: u16) -> u16 { RegistrationsThisBlock::::get(netuid) } - pub fn get_last_mechanism_step_block(netuid: u16) -> u64 { - LastMechansimStepBlock::::get(netuid) - } + pub fn get_registrations_this_interval(netuid: u16) -> u16 { RegistrationsThisInterval::::get(netuid) } From b000afa0dc8894e495f7985a175ddd84331f90ee Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 11 Dec 2024 22:32:40 +0100 Subject: [PATCH 041/137] Remove get_last_tx_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- .../subtensor/src/staking/become_delegate.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 5 +- pallets/subtensor/src/subnets/weights.rs | 2 +- pallets/subtensor/src/swap/swap_hotkey.rs | 2 +- pallets/subtensor/src/tests/children.rs | 68 +++++++++---------- pallets/subtensor/src/tests/epoch.rs | 3 +- pallets/subtensor/src/tests/registration.rs | 2 +- pallets/subtensor/src/tests/serving.rs | 6 +- pallets/subtensor/src/tests/staking.rs | 34 +++++----- pallets/subtensor/src/tests/swap_coldkey.rs | 28 ++++---- pallets/subtensor/src/utils/rate_limiting.rs | 4 +- 12 files changed, 76 insertions(+), 82 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 416c7bb9f..1fc74d226 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -30,7 +30,7 @@ use substrate_fixed::{ impl Pallet { /// The root network is a special case and has a fixed UID of 0. - pub(crate) const ROOT_NETUID: u16 = 0; + pub(crate) const ROOT_NETUID: u16 = 0; /// Fetches the total count of subnets. /// diff --git a/pallets/subtensor/src/staking/become_delegate.rs b/pallets/subtensor/src/staking/become_delegate.rs index fd600453f..9be107ec7 100644 --- a/pallets/subtensor/src/staking/become_delegate.rs +++ b/pallets/subtensor/src/staking/become_delegate.rs @@ -54,7 +54,7 @@ impl Pallet { // --- 5. Ensure we don't exceed tx rate limit let block: u64 = Self::get_current_block_as_u64(); ensure!( - !Self::exceeds_tx_rate_limit(Self::get_last_tx_block(&coldkey), block), + !Self::exceeds_tx_rate_limit(LastTxBlock::::get(&coldkey), block), Error::::DelegateTxRateLimitExceeded ); diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 0e3656665..95a8925b8 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -210,10 +210,7 @@ impl Pallet { /// /// * `coldkey` - A reference to the AccountId of the coldkey involved in the staking. /// * `hotkey` - A reference to the AccountId of the hotkey associated with the coldkey. - fn empty_stake_on_coldkey_hotkey_account( - coldkey: &T::AccountId, - hotkey: &T::AccountId, - ) -> u64 { + fn empty_stake_on_coldkey_hotkey_account(coldkey: &T::AccountId, hotkey: &T::AccountId) -> u64 { let current_stake: u64 = Stake::::get(hotkey, coldkey); TotalColdkeyStake::::mutate(coldkey, |old| *old = old.saturating_sub(current_stake)); TotalHotkeyStake::::mutate(hotkey, |stake| *stake = stake.saturating_sub(current_stake)); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index d2c59f273..53d2c596e 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -705,7 +705,7 @@ impl Pallet { // --- 4. Check to see if the number of uids is within the max allowed uids for this network. ensure!( - uids.len() <= SubnetworkN::::get(netuid) as usize, + uids.len() <= SubnetworkN::::get(netuid) as usize, Error::::UidsLengthExceedUidsInSubNet ); diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index b16c180c4..5f62ce163 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -56,7 +56,7 @@ impl Pallet { // 8. Ensure the transaction rate limit is not exceeded ensure!( - !Self::exceeds_tx_rate_limit(Self::get_last_tx_block(&coldkey), block), + !Self::exceeds_tx_rate_limit(LastTxBlock::::get(&coldkey), block), Error::::HotKeySetTxRateLimitExceeded ); diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 2f1943e2a..5b82ba2de 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -24,7 +24,7 @@ fn test_do_set_child_singular_success() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); // Verify child assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); }); } @@ -201,7 +201,7 @@ fn test_do_set_child_singular_new_children_assignment() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); // Verify child assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); // Verify parent assignment @@ -234,7 +234,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { mock_set_children(&coldkey, &hotkey, netuid, &[(min_proportion, child)]); // Verify child assignment with minimum proportion - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(min_proportion, child)]); step_rate_limit(&TransactionType::SetChildren, netuid); @@ -244,7 +244,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { mock_set_children(&coldkey, &hotkey, netuid, &[(max_proportion, child)]); // Verify child assignment with maximum proportion - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(max_proportion, child)]); }); } @@ -281,7 +281,7 @@ fn test_do_set_child_singular_multiple_children() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion1, child2)]); // Verify children assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion2, child2)]); // Verify parent assignment for both children @@ -419,7 +419,7 @@ fn test_do_revoke_child_singular_success() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); // Verify child assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); step_rate_limit(&TransactionType::SetChildren, netuid); @@ -428,7 +428,7 @@ fn test_do_revoke_child_singular_success() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify child removal - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert!(children.is_empty()); // Verify parent removal @@ -549,7 +549,7 @@ fn test_do_schedule_children_multiple_success() { ); // Verify children assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion1, child1), (proportion2, child2)]); // Verify parent assignment for both children @@ -761,7 +761,7 @@ fn test_do_schedule_children_multiple_proportion_edge_cases() { ); // Verify children assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!( children, vec![(min_proportion, child1), (max_proportion, child2)] @@ -811,7 +811,7 @@ fn test_do_schedule_children_multiple_overwrite_existing() { ); // Verify final children assignment - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!( children, vec![(proportion * 2, child2), (proportion * 3, child3)] @@ -876,7 +876,7 @@ fn test_childkey_take_functionality() { )); // Verify childkey take was set correctly - let stored_take = ChildkeyTake::::get(&hotkey, netuid); + let stored_take = ChildkeyTake::::get(hotkey, netuid); log::info!("Stored take: {}", stored_take); assert_eq!(stored_take, new_take); @@ -1001,7 +1001,7 @@ fn test_childkey_take_rate_limiting() { log_rate_limit_info(); // Verify the final take was set - let stored_take = ChildkeyTake::::get(&hotkey, netuid); + let stored_take = ChildkeyTake::::get(hotkey, netuid); assert_eq!(stored_take, 700); }); } @@ -1039,7 +1039,7 @@ fn test_multiple_networks_childkey_take() { )); // Verify the childkey take was set correctly - let stored_take = ChildkeyTake::::get(&hotkey, netuid); + let stored_take = ChildkeyTake::::get(hotkey, netuid); assert_eq!( stored_take, take_value, "Childkey take not set correctly for network {}", @@ -1053,8 +1053,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 = ChildkeyTake::::get(&hotkey, i); - let take_j = ChildkeyTake::::get(&hotkey, j); + let take_i = ChildkeyTake::::get(hotkey, i); + let take_j = ChildkeyTake::::get(hotkey, j); assert_ne!( take_i, take_j, "Childkey take values should be different for networks {} and {}", @@ -1080,7 +1080,7 @@ fn test_multiple_networks_childkey_take() { )); // Verify the new take value - let new_take = ChildkeyTake::::get(&hotkey, 1); + let new_take = ChildkeyTake::::get(hotkey, 1); assert_eq!(new_take, 1100, "Childkey take not updated after rate limit"); }); } @@ -1106,7 +1106,7 @@ fn test_do_schedule_children_multiple_empty_list() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify children assignment is empty - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert!(children.is_empty()); }); } @@ -1148,7 +1148,7 @@ fn test_do_revoke_children_multiple_success() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify children removal - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert!(children.is_empty()); // Verify parent removal for both children @@ -1264,7 +1264,7 @@ fn test_do_revoke_children_multiple_partial_revocation() { ); // Verify children removal - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion, child1), (proportion, child2)]); // Verify parents. @@ -1307,7 +1307,7 @@ fn test_do_revoke_children_multiple_non_existent_children() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify all children are removed - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert!(children.is_empty()); // Verify parent removal for the existing child @@ -1337,7 +1337,7 @@ fn test_do_revoke_children_multiple_empty_list() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify no changes in children - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert!(children.is_empty()); }); } @@ -1390,7 +1390,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { ); // Verify remaining children - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion1, child1), (proportion3, child3)]); // Verify parent removal for child2 @@ -1403,7 +1403,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { mock_set_children(&coldkey, &hotkey, netuid, &[]); // Verify all children are removed - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert!(children.is_empty()); // Verify parent removal for all children @@ -2345,7 +2345,7 @@ fn test_dynamic_parent_child_relationships() { // Expected total stake: 580,000 + 2,000,000 = 2,580,000 // Additional checks for parent-child relationships - let parent_children: Vec<(u64, U256)> = ChildKeys::::get(&parent, netuid); + let parent_children: Vec<(u64, U256)> = ChildKeys::::get(parent, netuid); assert_eq!( parent_children, vec![(u64::MAX / 4, child1), (u64::MAX / 3, child2)], @@ -2705,7 +2705,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { log::info!("After setting parent's children:"); log::info!( "Parent's children: {:?}", - ChildKeys::::get(&parent, netuid) + ChildKeys::::get(parent, netuid) ); log::info!( "Child1's parents: {:?}", @@ -2737,7 +2737,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { log::info!("After setting child1's children:"); log::info!( "Child1's children: {:?}", - ChildKeys::::get(&child1, netuid) + ChildKeys::::get(child1, netuid) ); log::info!( "Grandchild's parents: {:?}", @@ -2776,7 +2776,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { log::info!("Final parent-child relationships:"); log::info!( "Parent's children: {:?}", - ChildKeys::::get(&parent, netuid) + ChildKeys::::get(parent, netuid) ); log::info!( "Child1's parents: {:?}", @@ -2788,7 +2788,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { ); log::info!( "Child1's children: {:?}", - ChildKeys::::get(&child1, netuid) + ChildKeys::::get(child1, netuid) ); log::info!( "Grandchild's parents: {:?}", @@ -2797,7 +2797,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { // Check if the parent-child relationships are correct assert_eq!( - ChildKeys::::get(&parent, netuid), + ChildKeys::::get(parent, netuid), vec![(u64::MAX / 2, child1), (u64::MAX / 2, child2)], "Parent should have both children" ); @@ -2812,7 +2812,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { "Child2 should have parent as its parent" ); assert_eq!( - ChildKeys::::get(&child1, netuid), + ChildKeys::::get(child1, netuid), vec![(u64::MAX, grandchild)], "Child1 should have grandchild as its child" ); @@ -3604,7 +3604,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { ); // Verify first children assignment remains - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(100, child)]); // Try again after rate limit period has passed @@ -3626,7 +3626,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { mock_set_children(&coldkey, &hotkey, netuid, &[(100, child2)]); // Verify children assignment has changed - let children = ChildKeys::::get(&hotkey, netuid); + let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(100, child2)]); }); } @@ -3736,14 +3736,14 @@ fn test_do_set_child_cooldown_period() { )); // Ensure the childkeys are not yet applied - let children_before = ChildKeys::::get(&parent, netuid); + let children_before = ChildKeys::::get(parent, netuid); assert_eq!(children_before, vec![]); wait_and_set_pending_children(netuid); TotalHotkeyStake::::insert(parent, parent_total_stake_original); // Verify child assignment - let children_after = ChildKeys::::get(&parent, netuid); + let children_after = ChildKeys::::get(parent, netuid); assert_eq!(children_after, vec![(proportion, child)]); }); } diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index f7ae868b4..f6698c944 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -2578,8 +2578,7 @@ fn test_get_set_alpha() { alpha_low, alpha_high )); - let (grabbed_alpha_low, grabbed_alpha_high): (u16, u16) = - AlphaValues::::get(netuid); + let (grabbed_alpha_low, grabbed_alpha_high): (u16, u16) = AlphaValues::::get(netuid); log::info!( "alpha_low: {:?} alpha_high: {:?}", diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index e6d716f5e..d5b618ff2 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -1363,7 +1363,7 @@ fn test_registration_get_neuron_metadata() { // //let neuron_id = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id); // let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey( netuid, &hotkey_account_id ).unwrap(); - let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); + let neuron = Axons::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, 0); assert_eq!(neuron.version, 0); assert_eq!(neuron.port, 0); diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index e28618f67..01fcd8522 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -88,7 +88,7 @@ fn test_serving_ok() { placeholder1, placeholder2 )); - let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); + let neuron = Axons::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip); assert_eq!(neuron.version, version); assert_eq!(neuron.port, port); @@ -184,7 +184,7 @@ fn test_serving_set_metadata_update() { placeholder1, placeholder2 )); - let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); + let neuron = Axons::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip); assert_eq!(neuron.version, version); assert_eq!(neuron.port, port); @@ -210,7 +210,7 @@ fn test_serving_set_metadata_update() { placeholder12, placeholder22 )); - let neuron = Axons::::get(netuid, &hotkey_account_id).unwrap_or_default(); + let neuron = Axons::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip2); assert_eq!(neuron.version, version2); assert_eq!(neuron.port, port2); diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index c9efe0abd..83f1874be 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1691,7 +1691,7 @@ fn test_delegate_take_can_be_decreased() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1737,7 +1737,7 @@ fn test_can_set_min_take_ok() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -1766,7 +1766,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1780,7 +1780,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { Err(Error::::DelegateTakeTooLow.into()) ); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -1809,7 +1809,7 @@ fn test_delegate_take_can_be_increased() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1821,7 +1821,7 @@ fn test_delegate_take_can_be_increased() { hotkey0, u16::MAX / 8 )); - assert_eq!(Delegates::::get(&hotkey0), u16::MAX / 8); + assert_eq!(Delegates::::get(hotkey0), u16::MAX / 8); }); } @@ -1848,7 +1848,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1862,7 +1862,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { Err(Error::::DelegateTakeTooLow.into()) ); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -1891,7 +1891,7 @@ fn test_delegate_take_can_be_increased_to_limit() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1904,7 +1904,7 @@ fn test_delegate_take_can_be_increased_to_limit() { InitialDefaultDelegateTake::get() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), InitialDefaultDelegateTake::get() ); }); @@ -1925,7 +1925,7 @@ fn test_delegate_take_can_not_be_set_beyond_limit() { let netuid = 1; add_network(netuid, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); - let before = Delegates::::get(&hotkey0); + let before = Delegates::::get(hotkey0); // Coldkey / hotkey 0 attempt to become delegates with take above maximum // (Disable this check if InitialDefaultDelegateTake is u16::MAX) @@ -1939,7 +1939,7 @@ fn test_delegate_take_can_not_be_set_beyond_limit() { Err(Error::::DelegateTakeTooHigh.into()) ); } - assert_eq!(Delegates::::get(&hotkey0), before); + assert_eq!(Delegates::::get(hotkey0), before); }); } @@ -1966,7 +1966,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -1983,7 +1983,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { ); } assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); }); @@ -2012,7 +2012,7 @@ fn test_rate_limits_enforced_on_increase_take() { SubtensorModule::get_min_delegate_take() )); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -2026,7 +2026,7 @@ fn test_rate_limits_enforced_on_increase_take() { Err(Error::::DelegateTxRateLimitExceeded.into()) ); assert_eq!( - Delegates::::get(&hotkey0), + Delegates::::get(hotkey0), SubtensorModule::get_min_delegate_take() ); @@ -2038,7 +2038,7 @@ fn test_rate_limits_enforced_on_increase_take() { hotkey0, u16::MAX / 8 )); - assert_eq!(Delegates::::get(&hotkey0), u16::MAX / 8); + assert_eq!(Delegates::::get(hotkey0), u16::MAX / 8); }); } diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index db342838a..d33f53ff3 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -1100,7 +1100,7 @@ fn test_coldkey_swap_total() { vec![hotkey1, hotkey2, hotkey3] ); assert_eq!( - StakingHotkeys::::get(&coldkey), + StakingHotkeys::::get(coldkey), vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&coldkey), 600); @@ -1124,15 +1124,15 @@ fn test_coldkey_swap_total() { vec![delegate3] ); assert_eq!( - StakingHotkeys::::get(&delegate1), + StakingHotkeys::::get(delegate1), vec![delegate1, hotkey1] ); assert_eq!( - StakingHotkeys::::get(&delegate2), + StakingHotkeys::::get(delegate2), vec![delegate2, hotkey2] ); assert_eq!( - StakingHotkeys::::get(&delegate3), + StakingHotkeys::::get(delegate3), vec![delegate3, hotkey3] ); @@ -1141,15 +1141,15 @@ fn test_coldkey_swap_total() { assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator3), vec![]); assert_eq!( - StakingHotkeys::::get(&nominator1), + StakingHotkeys::::get(nominator1), vec![hotkey1, delegate1] ); assert_eq!( - StakingHotkeys::::get(&nominator2), + StakingHotkeys::::get(nominator2), vec![hotkey2, delegate2] ); assert_eq!( - StakingHotkeys::::get(&nominator3), + StakingHotkeys::::get(nominator3), vec![hotkey3, delegate3] ); @@ -1173,7 +1173,7 @@ fn test_coldkey_swap_total() { vec![hotkey1, hotkey2, hotkey3] ); assert_eq!( - StakingHotkeys::::get(&new_coldkey), + StakingHotkeys::::get(new_coldkey), vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); assert_eq!( @@ -1200,15 +1200,15 @@ fn test_coldkey_swap_total() { vec![delegate3] ); assert_eq!( - StakingHotkeys::::get(&delegate1), + StakingHotkeys::::get(delegate1), vec![delegate1, hotkey1] ); assert_eq!( - StakingHotkeys::::get(&delegate2), + StakingHotkeys::::get(delegate2), vec![delegate2, hotkey2] ); assert_eq!( - StakingHotkeys::::get(&delegate3), + StakingHotkeys::::get(delegate3), vec![delegate3, hotkey3] ); @@ -1217,15 +1217,15 @@ fn test_coldkey_swap_total() { assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator3), vec![]); assert_eq!( - StakingHotkeys::::get(&nominator1), + StakingHotkeys::::get(nominator1), vec![hotkey1, delegate1] ); assert_eq!( - StakingHotkeys::::get(&nominator2), + StakingHotkeys::::get(nominator2), vec![hotkey2, delegate2] ); assert_eq!( - StakingHotkeys::::get(&nominator3), + StakingHotkeys::::get(nominator3), vec![hotkey3, delegate3] ); }); diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index 8b30f9665..f5ad0d05a 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -129,9 +129,7 @@ impl Pallet { pub fn set_last_tx_block(key: &T::AccountId, block: u64) { LastTxBlock::::insert(key, block) } - pub fn get_last_tx_block(key: &T::AccountId) -> u64 { - LastTxBlock::::get(key) - } + pub fn set_last_tx_block_delegate_take(key: &T::AccountId, block: u64) { LastTxBlockDelegateTake::::insert(key, block) } From 9c2638d7325378da21c730277acbec527b295380 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 14:04:29 +0100 Subject: [PATCH 042/137] Remove get_last_tx_block_childkey_take from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/rate_limiting.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index f5ad0d05a..0c0afa47d 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -136,9 +136,6 @@ impl Pallet { pub fn get_last_tx_block_delegate_take(key: &T::AccountId) -> u64 { LastTxBlockDelegateTake::::get(key) } - pub fn get_last_tx_block_childkey_take(key: &T::AccountId) -> u64 { - LastTxBlockChildKeyTake::::get(key) - } pub fn exceeds_tx_rate_limit(prev_tx_block: u64, current_block: u64) -> bool { let rate_limit: u64 = Self::get_tx_rate_limit(); if rate_limit == 0 || prev_tx_block == 0 { From 57a8a7fb2ae693a7b9bf9a22e9751bb3b7e1ab58 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 14:20:29 +0100 Subject: [PATCH 043/137] Remove get_last_tx_block_delegate_take from pallet-subtensor::Pallet --- pallets/subtensor/src/staking/increase_take.rs | 2 +- pallets/subtensor/src/utils/rate_limiting.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/staking/increase_take.rs b/pallets/subtensor/src/staking/increase_take.rs index 021818447..444d16223 100644 --- a/pallets/subtensor/src/staking/increase_take.rs +++ b/pallets/subtensor/src/staking/increase_take.rs @@ -61,7 +61,7 @@ impl Pallet { let block: u64 = Self::get_current_block_as_u64(); ensure!( !Self::exceeds_tx_delegate_take_rate_limit( - Self::get_last_tx_block_delegate_take(&coldkey), + LastTxBlockDelegateTake::::get(&coldkey), block ), Error::::DelegateTxRateLimitExceeded diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index 0c0afa47d..9f0669874 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -133,9 +133,7 @@ impl Pallet { pub fn set_last_tx_block_delegate_take(key: &T::AccountId, block: u64) { LastTxBlockDelegateTake::::insert(key, block) } - pub fn get_last_tx_block_delegate_take(key: &T::AccountId) -> u64 { - LastTxBlockDelegateTake::::get(key) - } + pub fn exceeds_tx_rate_limit(prev_tx_block: u64, current_block: u64) -> bool { let rate_limit: u64 = Self::get_tx_rate_limit(); if rate_limit == 0 || prev_tx_block == 0 { From 7b8ec77c678cbf0292fe77b468803fb9161acbb9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 14:33:36 +0100 Subject: [PATCH 044/137] Remove get_last_update from pallet-subtensor::Pallet --- pallets/subtensor/src/epoch/run_epoch.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 4d1bb9b3f..4c699d87e 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -107,7 +107,7 @@ impl Pallet { log::trace!("activity_cutoff:\n{:?}\n", activity_cutoff); // Last update vector. - let last_update: Vec = Self::get_last_update(netuid); + let last_update: Vec = LastUpdate::::get(netuid); log::trace!("Last update:\n{:?}\n", &last_update); // Inactive mask. @@ -453,7 +453,7 @@ impl Pallet { log::trace!("activity_cutoff: {:?}", activity_cutoff); // Last update vector. - let last_update: Vec = Self::get_last_update(netuid); + let last_update: Vec = LastUpdate::::get(netuid); log::trace!("Last update: {:?}", &last_update); // Inactive mask. diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 7b0ed0285..ddbece79a 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -74,9 +74,7 @@ impl Pallet { pub fn get_trust(netuid: u16) -> Vec { Trust::::get(netuid) } - pub fn get_last_update(netuid: u16) -> Vec { - LastUpdate::::get(netuid) - } + pub fn get_pruning_score(netuid: u16) -> Vec { PruningScores::::get(netuid) } @@ -91,7 +89,7 @@ impl Pallet { // ==== YumaConsensus UID params ==== // ================================== 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 mut updated_last_update_vec = LastUpdate::::get(netuid); let Some(updated_last_update) = updated_last_update_vec.get_mut(uid as usize) else { return; }; From dceea2885e570b11b4c4c0717c018bff4cd8f5fb Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 14:41:53 +0100 Subject: [PATCH 045/137] Remove get_liquid_alpha_enabled from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 ---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index c4b4c91da..e050b4aa2 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -8,7 +8,7 @@ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, BondsMovingAverage, CommitRevealWeightsEnabled, Difficulty, Error as SubtensorError, Event, - ImmunityPeriod, Kappa, MaxDelegateTake, RAORecycledForRegistration, + ImmunityPeriod, Kappa, LiquidAlphaOn, MaxDelegateTake, RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -1166,7 +1166,7 @@ fn test_sudo_set_liquid_alpha_enabled() { new_test_ext().execute_with(|| { let netuid: u16 = 1; let enabled: bool = true; - assert_eq!(!enabled, SubtensorModule::get_liquid_alpha_enabled(netuid)); + assert_eq!(!enabled, LiquidAlphaOn::::get(netuid)); assert_ok!(AdminUtils::sudo_set_liquid_alpha_enabled( <::RuntimeOrigin>::root(), @@ -1174,7 +1174,7 @@ fn test_sudo_set_liquid_alpha_enabled() { enabled )); - assert_eq!(enabled, SubtensorModule::get_liquid_alpha_enabled(netuid)); + assert_eq!(enabled, LiquidAlphaOn::::get(netuid)); }); } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 4c699d87e..cfb4fd060 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -1275,7 +1275,7 @@ impl Pallet { // --- 3. Ensure liquid alpha is enabled ensure!( - Self::get_liquid_alpha_enabled(netuid), + LiquidAlphaOn::::get(netuid), Error::::LiquidAlphaDisabled ); diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index f292de4b8..aad1cb3ca 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -254,7 +254,7 @@ impl Pallet { let difficulty = Difficulty::::get(netuid); let commit_reveal_periods = Self::get_reveal_period(netuid); let commit_reveal_weights_enabled = CommitRevealWeightsEnabled::::get(netuid); - let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); + let liquid_alpha_enabled = LiquidAlphaOn::::get(netuid); let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); Some(SubnetHyperparams { diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index ddbece79a..73a26952a 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -616,10 +616,6 @@ impl Pallet { LiquidAlphaOn::::set(netuid, enabled); } - pub fn get_liquid_alpha_enabled(netuid: u16) -> bool { - LiquidAlphaOn::::get(netuid) - } - /// Sets the hotkey emission tempo. /// /// # Arguments From d802ffea1da2a1bdd2642c1c8e31d5ac675a366b Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 14:54:44 +0100 Subject: [PATCH 046/137] Remove get_lock_reduction_interval from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 9 +++++---- pallets/subtensor/src/coinbase/root.rs | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index e050b4aa2..f7e5921df 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -8,7 +8,8 @@ use frame_system::Config; use pallet_subtensor::{ migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, BondsMovingAverage, CommitRevealWeightsEnabled, Difficulty, Error as SubtensorError, Event, - ImmunityPeriod, Kappa, LiquidAlphaOn, MaxDelegateTake, RAORecycledForRegistration, + ImmunityPeriod, Kappa, LiquidAlphaOn, MaxDelegateTake, NetworkLockReductionInterval, + RAORecycledForRegistration, }; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -834,7 +835,7 @@ fn test_sudo_set_network_lock_reduction_interval() { let to_be_set: u64 = 7200; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_lock_reduction_interval(); + let init_value: u64 = NetworkLockReductionInterval::::get(); assert_eq!( AdminUtils::sudo_set_lock_reduction_interval( <::RuntimeOrigin>::signed(U256::from(1)), @@ -842,12 +843,12 @@ fn test_sudo_set_network_lock_reduction_interval() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_lock_reduction_interval(), init_value); + assert_eq!(NetworkLockReductionInterval::::get(), init_value); assert_ok!(AdminUtils::sudo_set_lock_reduction_interval( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_lock_reduction_interval(), to_be_set); + assert_eq!(NetworkLockReductionInterval::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 1fc74d226..43790468f 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1235,7 +1235,7 @@ impl Pallet { let min_lock = Self::get_network_min_lock(); let last_lock_block = Self::get_network_last_lock_block(); let current_block = Self::get_current_block_as_u64(); - let lock_reduction_interval = Self::get_lock_reduction_interval(); + let lock_reduction_interval = NetworkLockReductionInterval::::get(); let mult = if last_lock_block == 0 { 1 } else { 2 }; let mut lock_cost = last_lock.saturating_mul(mult).saturating_sub( @@ -1336,7 +1336,4 @@ impl Pallet { NetworkLockReductionInterval::::set(interval); Self::deposit_event(Event::NetworkLockCostReductionIntervalSet(interval)); } - pub fn get_lock_reduction_interval() -> u64 { - NetworkLockReductionInterval::::get() - } } From 37f8fcf076180125ad9f166cc523158c4a4ec89d Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 15:09:33 +0100 Subject: [PATCH 047/137] Remove get_max_allowed_uids from pallet-subtensor::Pallet --- pallets/admin-utils/src/lib.rs | 3 +-- pallets/admin-utils/src/tests/mod.rs | 18 +++++++----------- pallets/subtensor/src/benchmarks.rs | 16 ++++++++-------- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/subnets/registration.rs | 8 ++++---- pallets/subtensor/src/tests/difficulty.rs | 4 ++-- pallets/subtensor/src/tests/epoch.rs | 13 +++++-------- pallets/subtensor/src/tests/registration.rs | 10 +++++----- pallets/subtensor/src/utils/misc.rs | 3 --- 10 files changed, 35 insertions(+), 46 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index ab353bc65..4f525c81f 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -643,8 +643,7 @@ pub mod pallet { Error::::SubnetDoesNotExist ); ensure!( - max_allowed_validators - <= pallet_subtensor::Pallet::::get_max_allowed_uids(netuid), + max_allowed_validators <= pallet_subtensor::MaxAllowedUids::::get(netuid), Error::::MaxValidatorsLargerThanMaxUIds ); diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index f7e5921df..11d0f4370 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -5,12 +5,8 @@ use frame_support::{ traits::Hooks, }; use frame_system::Config; -use pallet_subtensor::{ - migrations, ActivityCutoff, AdjustmentAlpha, AdjustmentInterval, AlphaValues, - BondsMovingAverage, CommitRevealWeightsEnabled, Difficulty, Error as SubtensorError, Event, - ImmunityPeriod, Kappa, LiquidAlphaOn, MaxDelegateTake, NetworkLockReductionInterval, - RAORecycledForRegistration, -}; +use pallet_subtensor::Error as SubtensorError; +use pallet_subtensor::*; use sp_consensus_grandpa::AuthorityId as GrandpaId; use sp_core::{ed25519, Pair, U256}; @@ -413,7 +409,7 @@ fn test_sudo_set_max_allowed_uids() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_max_allowed_uids(netuid); + let init_value: u16 = MaxAllowedUids::::get(netuid); assert_eq!( AdminUtils::sudo_set_max_allowed_uids( <::RuntimeOrigin>::signed(U256::from(0)), @@ -430,13 +426,13 @@ fn test_sudo_set_max_allowed_uids() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), init_value); + assert_eq!(MaxAllowedUids::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_max_allowed_uids( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), to_be_set); + assert_eq!(MaxAllowedUids::::get(netuid), to_be_set); }); } @@ -446,7 +442,7 @@ fn test_sudo_set_and_decrease_max_allowed_uids() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_max_allowed_uids(netuid); + let init_value: u16 = MaxAllowedUids::::get(netuid); assert_eq!( AdminUtils::sudo_set_max_allowed_uids( <::RuntimeOrigin>::signed(U256::from(0)), @@ -463,7 +459,7 @@ fn test_sudo_set_and_decrease_max_allowed_uids() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), init_value); + assert_eq!(MaxAllowedUids::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_max_allowed_uids( <::RuntimeOrigin>::root(), netuid, diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index d361c4786..f2798cdbb 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -91,7 +91,7 @@ benchmarks! { Subtensor::::set_max_allowed_uids( netuid, 4096 ); Subtensor::::set_network_registration_allowed( netuid, true); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); @@ -119,7 +119,7 @@ benchmarks! { Subtensor::::set_network_registration_allowed( netuid, true ); Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); @@ -149,7 +149,7 @@ benchmarks! { Subtensor::::set_network_registration_allowed( netuid, true ); Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); @@ -187,7 +187,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); Subtensor::::set_burn(netuid, 1); let amount_to_be_staked = 1000000u32.into(); @@ -213,7 +213,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); Subtensor::::set_burn(netuid, 1); let amount_to_be_staked = 1000000u32.into(); @@ -236,7 +236,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); let seed : u32 = 1; let block_number: u64 = Subtensor::::get_current_block_as_u64(); @@ -277,7 +277,7 @@ benchmarks! { Subtensor::::set_network_registration_allowed( netuid, true); Subtensor::::set_max_allowed_uids( netuid, 4096 ); - assert_eq!(Subtensor::::get_max_allowed_uids(netuid), 4096); + assert_eq!(MaxAllowedUids::::get(netuid), 4096); let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); @@ -332,7 +332,7 @@ benchmarks! { // assert_ok!(Subtensor::::burned_register(RawOrigin::Signed(coldkey.clone()).into(), netuid, old_hotkey.clone())); // assert_ok!(Subtensor::::become_delegate(RawOrigin::Signed(coldkey.clone()).into(), old_hotkey.clone())); - // let max_uids = Subtensor::::get_max_allowed_uids(netuid) as u32; + // let max_uids = MaxAllowedUids::::get(netuid) as u32; // for i in 0..max_uids - 1 { // let coldkey: T::AccountId = account("Axon", 0, i); // let hotkey: T::AccountId = account("Hotkey", 0, i); diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 43790468f..58dbb1177 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -82,7 +82,7 @@ impl Pallet { /// * 'u16': The max validators count of root network. /// pub fn get_max_root_validators() -> u16 { - Self::get_max_allowed_uids(Self::ROOT_NETUID) + MaxAllowedUids::::get(Self::ROOT_NETUID) } /// Returns the emission value for the given subnet. diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index aad1cb3ca..efde764d6 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -98,7 +98,7 @@ impl Pallet { let max_weights_limit = Self::get_max_weight_limit(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); - let max_allowed_uids = Self::get_max_allowed_uids(netuid); + let max_allowed_uids = MaxAllowedUids::::get(netuid); let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); @@ -168,7 +168,7 @@ impl Pallet { let max_weights_limit = Self::get_max_weight_limit(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); - let max_allowed_uids = Self::get_max_allowed_uids(netuid); + let max_allowed_uids = MaxAllowedUids::::get(netuid); let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); let tempo = Self::get_tempo(netuid); let network_modality = >::get(netuid); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 95efbb02d..209fb80c3 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -120,11 +120,11 @@ impl Pallet { // Possibly there is no neuron slots at all. ensure!( - Self::get_max_allowed_uids(netuid) != 0, + MaxAllowedUids::::get(netuid) != 0, Error::::NoNeuronIdAvailable ); - if current_subnetwork_n < Self::get_max_allowed_uids(netuid) { + if current_subnetwork_n < MaxAllowedUids::::get(netuid) { // --- 12.1.1 No replacement required, the uid appends the subnetwork. // We increment the subnetwork count here but not below. subnetwork_uid = current_subnetwork_n; @@ -315,11 +315,11 @@ impl Pallet { // Possibly there is no neuron slots at all. ensure!( - Self::get_max_allowed_uids(netuid) != 0, + MaxAllowedUids::::get(netuid) != 0, Error::::NoNeuronIdAvailable ); - if current_subnetwork_n < Self::get_max_allowed_uids(netuid) { + if current_subnetwork_n < MaxAllowedUids::::get(netuid) { // --- 11.1.1 No replacement required, the uid appends the subnetwork. // We increment the subnetwork count here but not below. subnetwork_uid = current_subnetwork_n; diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index dda3fb88b..d332199e8 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -3,7 +3,7 @@ use sp_core::U256; use super::mock::*; -use crate::{AdjustmentInterval, Difficulty, LastAdjustmentBlock, SubnetworkN}; +use crate::{AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, SubnetworkN}; #[test] fn test_registration_difficulty_adjustment() { @@ -36,7 +36,7 @@ fn test_registration_difficulty_adjustment() { 1 ); // Check set adjustment interval. assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid), 3); // Check set registrations per block. - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), 3); // Check set registrations per block. + assert_eq!(MaxAllowedUids::::get(netuid), 3); // Check set registrations per block. assert!(SubtensorModule::get_network_registration_allowed(netuid)); // Check set registration allowed // Lets register 3 neurons... diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index f6698c944..f3e0c429b 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -976,7 +976,7 @@ fn test_bonds() { let block_number = System::block_number(); add_network(netuid, tempo, 0); SubtensorModule::set_max_allowed_uids( netuid, n ); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(MaxAllowedUids::::get(netuid), n); SubtensorModule::set_max_registrations_per_block( netuid, n ); SubtensorModule::set_target_registrations_per_interval(netuid, n); SubtensorModule::set_weights_set_rate_limit( netuid, 0 ); @@ -990,7 +990,7 @@ fn test_bonds() { assert_ok!(SubtensorModule::register(<::RuntimeOrigin>::signed(U256::from(key)), netuid, block_number, nonce, work, U256::from(key), U256::from(key))); SubtensorModule::increase_stake_on_coldkey_hotkey_account( &U256::from(key), &U256::from(key), stakes[key as usize] ); } - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(MaxAllowedUids::::get(netuid), n); assert_eq!(SubnetworkN::::get(netuid), n); // === Issue validator permits @@ -1519,7 +1519,7 @@ fn test_active_stake() { let stake: u64 = 1; add_network(netuid, tempo, 0); SubtensorModule::set_max_allowed_uids(netuid, n); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(MaxAllowedUids::::get(netuid), n); SubtensorModule::set_max_registrations_per_block(netuid, n); SubtensorModule::set_target_registrations_per_interval(netuid, n); SubtensorModule::set_min_allowed_weights(netuid, 0); @@ -1549,7 +1549,7 @@ fn test_active_stake() { stake, ); } - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid), n); + assert_eq!(MaxAllowedUids::::get(netuid), n); assert_eq!(SubnetworkN::::get(netuid), n); // === Issue validator permits @@ -2119,10 +2119,7 @@ fn test_validator_permits() { let block_number: u64 = 0; add_network(netuid, tempo, 0); SubtensorModule::set_max_allowed_uids(netuid, network_n as u16); - assert_eq!( - SubtensorModule::get_max_allowed_uids(netuid), - network_n as u16 - ); + assert_eq!(MaxAllowedUids::::get(netuid), network_n as u16); SubtensorModule::set_max_registrations_per_block(netuid, network_n as u16); SubtensorModule::set_target_registrations_per_interval( netuid, diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index d5b618ff2..ec75ad216 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,8 +11,8 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ - Axons, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, RAORecycledForRegistration, - SubnetworkN, SubtensorSignedExtension, + Axons, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, MaxAllowedUids, + RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, }; /******************************************** @@ -1535,9 +1535,9 @@ fn test_full_pass_through() { SubtensorModule::set_max_allowed_uids(netuid2, 2); // Check their max allowed. - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid0), 2); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid0), 2); - assert_eq!(SubtensorModule::get_max_allowed_uids(netuid0), 2); + assert_eq!(MaxAllowedUids::::get(netuid0), 2); + assert_eq!(MaxAllowedUids::::get(netuid0), 2); + assert_eq!(MaxAllowedUids::::get(netuid0), 2); // Set the max registration per block. SubtensorModule::set_max_registrations_per_block(netuid0, 3); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 73a26952a..de9cc2ac7 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -435,9 +435,6 @@ impl Pallet { Self::deposit_event(Event::MinAllowedWeightSet(netuid, min_allowed_weights)); } - pub fn get_max_allowed_uids(netuid: u16) -> u16 { - MaxAllowedUids::::get(netuid) - } pub fn set_max_allowed_uids(netuid: u16, max_allowed: u16) { MaxAllowedUids::::insert(netuid, max_allowed); Self::deposit_event(Event::MaxAllowedUidsSet(netuid, max_allowed)); From c891a840aae9376b5249f4e1a0800fa46f40d029 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 15:21:31 +0100 Subject: [PATCH 048/137] Remove get_max_allowed_validators from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 12 +++--------- pallets/subtensor/src/epoch/run_epoch.rs | 4 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/tests/epoch.rs | 10 +++++----- pallets/subtensor/src/utils/misc.rs | 3 --- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 11d0f4370..2426d5427 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -650,7 +650,7 @@ fn test_sudo_set_max_allowed_validators() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_max_allowed_validators(netuid); + let init_value: u16 = MaxAllowedValidators::::get(netuid); assert_eq!( AdminUtils::sudo_set_max_allowed_validators( <::RuntimeOrigin>::signed(U256::from(1)), @@ -667,19 +667,13 @@ fn test_sudo_set_max_allowed_validators() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!( - SubtensorModule::get_max_allowed_validators(netuid), - init_value - ); + assert_eq!(MaxAllowedValidators::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_max_allowed_validators( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!( - SubtensorModule::get_max_allowed_validators(netuid), - to_be_set - ); + assert_eq!(MaxAllowedValidators::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index cfb4fd060..49b2b05df 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -167,7 +167,7 @@ impl Pallet { let validator_forbids: Vec = validator_permits.iter().map(|&b| !b).collect(); // Get max allowed validators. - let max_allowed_validators: u16 = Self::get_max_allowed_validators(netuid); + let max_allowed_validators: u16 = MaxAllowedValidators::::get(netuid); log::trace!("max_allowed_validators: {:?}", max_allowed_validators); // Get new validator permits. @@ -503,7 +503,7 @@ impl Pallet { let validator_forbids: Vec = validator_permits.iter().map(|&b| !b).collect(); // Get max allowed validators. - let max_allowed_validators: u16 = Self::get_max_allowed_validators(netuid); + let max_allowed_validators: u16 = MaxAllowedValidators::::get(netuid); log::trace!("max_allowed_validators: {:?}", max_allowed_validators); // Get new validator permits. diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index efde764d6..0d007418d 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -93,7 +93,7 @@ impl Pallet { let kappa = Kappa::::get(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); - let max_allowed_validators = Self::get_max_allowed_validators(netuid); + let max_allowed_validators = MaxAllowedValidators::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); @@ -163,7 +163,7 @@ impl Pallet { let kappa = Kappa::::get(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); - let max_allowed_validators = Self::get_max_allowed_validators(netuid); + let max_allowed_validators = MaxAllowedValidators::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); let max_weights_limit = Self::get_max_weight_limit(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); @@ -249,7 +249,7 @@ impl Pallet { let bonds_moving_avg = BondsMovingAverage::::get(netuid); let max_regs_per_block = Self::get_max_registrations_per_block(netuid); let serving_rate_limit = Self::get_serving_rate_limit(netuid); - let max_validators = Self::get_max_allowed_validators(netuid); + let max_validators = MaxAllowedValidators::::get(netuid); let adjustment_alpha = AdjustmentAlpha::::get(netuid); let difficulty = Difficulty::::get(netuid); let commit_reveal_periods = Self::get_reveal_period(netuid); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index f3e0c429b..3cbfe0cf8 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -181,7 +181,7 @@ fn init_run_epochs( // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, validators.len() as u16); assert_eq!( - SubtensorModule::get_max_allowed_validators(netuid), + MaxAllowedValidators::::get(netuid), validators.len() as u16 ); SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators @@ -995,7 +995,7 @@ fn test_bonds() { // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, n); - assert_eq!( SubtensorModule::get_max_allowed_validators(netuid), n); + assert_eq!( MaxAllowedValidators::::get(netuid), n); SubtensorModule::epoch( netuid, 1_000_000_000 ); // run first epoch to set allowed validators next_block(); // run to next block to ensure weights are set on nodes after their registration block @@ -1554,7 +1554,7 @@ fn test_active_stake() { // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, n); - assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), n); + assert_eq!(MaxAllowedValidators::::get(netuid), n); SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators next_block(); // run to next block to ensure weights are set on nodes after their registration block @@ -1761,7 +1761,7 @@ fn test_outdated_weights() { // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, n); - assert_eq!(SubtensorModule::get_max_allowed_validators(netuid), n); + assert_eq!(MaxAllowedValidators::::get(netuid), n); SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 4); block_number = next_block(); // run to next block to ensure weights are set on nodes after their registration block @@ -2159,7 +2159,7 @@ fn test_validator_permits() { // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, validators_n as u16); assert_eq!( - SubtensorModule::get_max_allowed_validators(netuid), + MaxAllowedValidators::::get(netuid), validators_n as u16 ); SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index de9cc2ac7..652e4241a 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -519,9 +519,6 @@ impl Pallet { Self::deposit_event(Event::DifficultySet(netuid, difficulty)); } - pub fn get_max_allowed_validators(netuid: u16) -> u16 { - MaxAllowedValidators::::get(netuid) - } pub fn set_max_allowed_validators(netuid: u16, max_allowed_validators: u16) { MaxAllowedValidators::::insert(netuid, max_allowed_validators); Self::deposit_event(Event::MaxAllowedValidatorsSet( From c5a331614d69e7f1ea596b8e8a2abf1a63235a98 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 15:29:21 +0100 Subject: [PATCH 049/137] Remove get_max_burn_as_u64 from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 4 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index d6c96a301..f5148fa03 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -233,8 +233,8 @@ impl Pallet { .saturating_sub(alpha) .saturating_mul(updated_burn), ); - if next_value >= I110F18::from_num(Self::get_max_burn_as_u64(netuid)) { - Self::get_max_burn_as_u64(netuid) + if next_value >= I110F18::from_num(MaxBurn::::get(netuid)) { + MaxBurn::::get(netuid) } else if next_value <= I110F18::from_num(Self::get_min_burn_as_u64(netuid)) { return Self::get_min_burn_as_u64(netuid); } else { diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 0d007418d..06afb9351 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -245,7 +245,7 @@ impl Pallet { let registration_allowed = Self::get_network_registration_allowed(netuid); let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); let min_burn = Self::get_min_burn_as_u64(netuid); - let max_burn = Self::get_max_burn_as_u64(netuid); + let max_burn = MaxBurn::::get(netuid); let bonds_moving_avg = BondsMovingAverage::::get(netuid); let max_regs_per_block = Self::get_max_registrations_per_block(netuid); let serving_rate_limit = Self::get_serving_rate_limit(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 652e4241a..eebe068fb 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -506,9 +506,6 @@ impl Pallet { Self::deposit_event(Event::MinBurnSet(netuid, min_burn)); } - pub fn get_max_burn_as_u64(netuid: u16) -> u64 { - MaxBurn::::get(netuid) - } pub fn set_max_burn(netuid: u16, max_burn: u64) { MaxBurn::::insert(netuid, max_burn); Self::deposit_event(Event::MaxBurnSet(netuid, max_burn)); From 565069e905dc83dcb1f3d0d43b7c99239a71317e Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 15:37:46 +0100 Subject: [PATCH 050/137] Remove get_max_childkey_take from pallet-subtensor::Pallet --- pallets/subtensor/src/staking/set_children.rs | 2 +- pallets/subtensor/src/tests/children.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index b4d615f2e..8b8da0cf9 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -294,7 +294,7 @@ impl Pallet { // Ensure the take value is valid ensure!( - take <= Self::get_max_childkey_take(), + take <= MaxChildkeyTake::::get(), Error::::InvalidChildkeyTake ); diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 5b82ba2de..4d00b6afc 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -867,7 +867,7 @@ fn test_childkey_take_functionality() { ); // Test setting childkey take - let new_take: u16 = SubtensorModule::get_max_childkey_take() / 2; // 50% of max_take + let new_take: u16 = MaxChildkeyTake::::get() / 2; // 50% of max_take assert_ok!(SubtensorModule::set_childkey_take( RuntimeOrigin::signed(coldkey), hotkey, @@ -881,7 +881,7 @@ fn test_childkey_take_functionality() { assert_eq!(stored_take, new_take); // Test setting childkey take outside of allowed range - let invalid_take: u16 = SubtensorModule::get_max_childkey_take() + 1; + let invalid_take: u16 = MaxChildkeyTake::::get() + 1; assert_noop!( SubtensorModule::set_childkey_take( RuntimeOrigin::signed(coldkey), diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index eebe068fb..2fd1e9921 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -337,10 +337,6 @@ impl Pallet { MinChildkeyTake::::get() } - pub fn get_max_childkey_take() -> u16 { - MaxChildkeyTake::::get() - } - pub fn get_serving_rate_limit(netuid: u16) -> u64 { ServingRateLimit::::get(netuid) } From fcfd3c8a4d9e76c4f7a7dad5799ef415b569dfea Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 15:47:35 +0100 Subject: [PATCH 051/137] Remove get_max_delegate_take from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 2fd1e9921..bd0bb755b 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -315,9 +315,7 @@ impl Pallet { pub fn get_min_delegate_take() -> u16 { MinDelegateTake::::get() } - pub fn get_max_delegate_take() -> u16 { - MaxDelegateTake::::get() - } + pub fn get_tx_childkey_take_rate_limit() -> u64 { TxChildkeyTakeRateLimit::::get() } From b12725ea135896dc94aacaf1f92a8c43c5661d70 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 15:54:27 +0100 Subject: [PATCH 052/137] Remove get_max_difficulty from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/block_step.rs | 4 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/tests/difficulty.rs | 6 ++++-- pallets/subtensor/src/utils/misc.rs | 3 --- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 2426d5427..9b9bc3f98 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -99,7 +99,7 @@ fn test_sudo_set_max_difficulty() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_max_difficulty(netuid); + let init_value: u64 = MaxDifficulty::::get(netuid); assert_eq!( AdminUtils::sudo_set_max_difficulty( <::RuntimeOrigin>::signed(U256::from(1)), @@ -116,13 +116,13 @@ fn test_sudo_set_max_difficulty() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_max_difficulty(netuid), init_value); + assert_eq!(MaxDifficulty::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_max_difficulty( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_max_difficulty(netuid), to_be_set); + assert_eq!(MaxDifficulty::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index f5148fa03..312614f63 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -199,8 +199,8 @@ impl Pallet { .saturating_sub(alpha) .saturating_mul(updated_difficulty), ); - if next_value >= I110F18::from_num(Self::get_max_difficulty(netuid)) { - Self::get_max_difficulty(netuid) + if next_value >= I110F18::from_num(MaxDifficulty::::get(netuid)) { + MaxDifficulty::::get(netuid) } else if next_value <= I110F18::from_num(Self::get_min_difficulty(netuid)) { return Self::get_min_difficulty(netuid); } else { diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 06afb9351..39cfba7fd 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -237,7 +237,7 @@ impl Pallet { let max_weights_limit = Self::get_max_weight_limit(netuid); let tempo = Self::get_tempo(netuid); let min_difficulty = Self::get_min_difficulty(netuid); - let max_difficulty = Self::get_max_difficulty(netuid); + let max_difficulty = MaxDifficulty::::get(netuid); let weights_version = Self::get_weights_version_key(netuid); let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); let adjustment_interval = AdjustmentInterval::::get(netuid); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index d332199e8..cd0082293 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -3,7 +3,9 @@ use sp_core::U256; use super::mock::*; -use crate::{AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, SubnetworkN}; +use crate::{ + AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, SubnetworkN, +}; #[test] fn test_registration_difficulty_adjustment() { @@ -144,7 +146,7 @@ fn test_registration_difficulty_adjustment() { // Test max value. SubtensorModule::set_max_difficulty(netuid, 10000); SubtensorModule::set_difficulty(netuid, 5000); - assert_eq!(SubtensorModule::get_max_difficulty(netuid), 10000); + assert_eq!(MaxDifficulty::::get(netuid), 10000); assert_eq!(Difficulty::::get(netuid), 5000); SubtensorModule::set_max_registrations_per_block(netuid, 4); register_ok_neuron(netuid, hotkey0 + 3, coldkey0 + 3, 294208420); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index bd0bb755b..786fd2170 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -351,9 +351,6 @@ impl Pallet { Self::deposit_event(Event::MinDifficultySet(netuid, min_difficulty)); } - pub fn get_max_difficulty(netuid: u16) -> u64 { - MaxDifficulty::::get(netuid) - } pub fn set_max_difficulty(netuid: u16, max_difficulty: u64) { MaxDifficulty::::insert(netuid, max_difficulty); Self::deposit_event(Event::MaxDifficultySet(netuid, max_difficulty)); From 6837bda9f103360ac24e224ef618dac3c6d85a71 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 16:03:22 +0100 Subject: [PATCH 053/137] Remove get_max_registrations_per_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 6 ++---- pallets/subtensor/src/tests/difficulty.rs | 5 +++-- pallets/subtensor/src/tests/epoch.rs | 2 +- pallets/subtensor/src/tests/registration.rs | 12 ++++++------ pallets/subtensor/src/utils/misc.rs | 3 --- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 58dbb1177..9995b6dc2 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -488,7 +488,7 @@ impl Pallet { // --- 2. Ensure that the number of registrations in this block doesn't exceed the allowed limit. ensure!( Self::get_registrations_this_block(root_netuid) - < Self::get_max_registrations_per_block(root_netuid), + < MaxRegistrationsPerBlock::::get(root_netuid), Error::::TooManyRegistrationsThisBlock ); diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 39cfba7fd..15f6d35dd 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -247,7 +247,7 @@ impl Pallet { let min_burn = Self::get_min_burn_as_u64(netuid); let max_burn = MaxBurn::::get(netuid); let bonds_moving_avg = BondsMovingAverage::::get(netuid); - let max_regs_per_block = Self::get_max_registrations_per_block(netuid); + let max_regs_per_block = MaxRegistrationsPerBlock::::get(netuid); let serving_rate_limit = Self::get_serving_rate_limit(netuid); let max_validators = MaxAllowedValidators::::get(netuid); let adjustment_alpha = AdjustmentAlpha::::get(netuid); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 209fb80c3..e390f751a 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -66,8 +66,7 @@ impl Pallet { // --- 4. Ensure we are not exceeding the max allowed registrations per block. ensure!( - Self::get_registrations_this_block(netuid) - < Self::get_max_registrations_per_block(netuid), + Self::get_registrations_this_block(netuid) < MaxRegistrationsPerBlock::::get(netuid), Error::::TooManyRegistrationsThisBlock ); @@ -251,8 +250,7 @@ impl Pallet { // --- 4. Ensure we are not exceeding the max allowed registrations per block. ensure!( - Self::get_registrations_this_block(netuid) - < Self::get_max_registrations_per_block(netuid), + Self::get_registrations_this_block(netuid) < MaxRegistrationsPerBlock::::get(netuid), Error::::TooManyRegistrationsThisBlock ); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index cd0082293..74539481d 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -4,7 +4,8 @@ use sp_core::U256; use super::mock::*; use crate::{ - AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, SubnetworkN, + AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, + MaxRegistrationsPerBlock, SubnetworkN, }; #[test] @@ -37,7 +38,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::get_target_registrations_per_interval(netuid), 1 ); // Check set adjustment interval. - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid), 3); // Check set registrations per block. + assert_eq!(MaxRegistrationsPerBlock::::get(netuid), 3); // Check set registrations per block. assert_eq!(MaxAllowedUids::::get(netuid), 3); // Check set registrations per block. assert!(SubtensorModule::get_network_registration_allowed(netuid)); // Check set registration allowed diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 3cbfe0cf8..63c07ac17 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -1828,7 +1828,7 @@ fn test_outdated_weights() { &U256::from(new_key), ); assert_eq!(System::block_number(), block_number); - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid), n); + assert_eq!(MaxRegistrationsPerBlock::::get(netuid), n); assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(new_key)), diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index ec75ad216..84a66177f 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -12,7 +12,7 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ Axons, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, MaxAllowedUids, - RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, + MaxRegistrationsPerBlock, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, }; /******************************************** @@ -656,7 +656,7 @@ fn test_registration_too_many_registrations_per_block() { add_network(netuid, tempo, 0); SubtensorModule::set_max_registrations_per_block(netuid, 10); SubtensorModule::set_target_registrations_per_interval(netuid, 10); - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid), 10); + assert_eq!(MaxRegistrationsPerBlock::::get(netuid), 10); let block_number: u64 = 0; let (nonce0, work0): (u64, Vec) = SubtensorModule::create_work_for_block_number( @@ -851,7 +851,7 @@ fn test_registration_too_many_registrations_per_interval() { let tempo: u16 = 13; add_network(netuid, tempo, 0); SubtensorModule::set_max_registrations_per_block(netuid, 11); - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid), 11); + assert_eq!(MaxRegistrationsPerBlock::::get(netuid), 11); SubtensorModule::set_target_registrations_per_interval(netuid, 3); assert_eq!( SubtensorModule::get_target_registrations_per_interval(netuid), @@ -1543,9 +1543,9 @@ fn test_full_pass_through() { SubtensorModule::set_max_registrations_per_block(netuid0, 3); SubtensorModule::set_max_registrations_per_block(netuid1, 3); SubtensorModule::set_max_registrations_per_block(netuid2, 3); - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid0), 3); - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid1), 3); - assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid2), 3); + assert_eq!(MaxRegistrationsPerBlock::::get(netuid0), 3); + assert_eq!(MaxRegistrationsPerBlock::::get(netuid1), 3); + assert_eq!(MaxRegistrationsPerBlock::::get(netuid2), 3); // Check that no one has registered yet. assert_eq!(SubnetworkN::::get(netuid0), 0); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 786fd2170..96be77604 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -520,9 +520,6 @@ impl Pallet { Self::deposit_event(Event::BondsMovingAverageSet(netuid, bonds_moving_average)); } - pub fn get_max_registrations_per_block(netuid: u16) -> u16 { - MaxRegistrationsPerBlock::::get(netuid) - } 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( From 8d746c16e7e570b6ff9e4197f72ee07b891df0d2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 16:10:52 +0100 Subject: [PATCH 054/137] Remove get_max_root_validators from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 9995b6dc2..2b3fb5244 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -74,17 +74,6 @@ impl Pallet { SubnetworkN::::get(Self::ROOT_NETUID) } - /// Fetches the max validators count of root network. - /// - /// This function retrieves the max validators count of root network. - /// - /// # Returns: - /// * 'u16': The max validators count of root network. - /// - pub fn get_max_root_validators() -> u16 { - MaxAllowedUids::::get(Self::ROOT_NETUID) - } - /// Returns the emission value for the given subnet. /// /// This function retrieves the emission value for the given subnet. @@ -516,7 +505,7 @@ impl Pallet { // --- 8. Check if the root net is below its allowed size. // max allowed is senate size. - if current_num_root_validators < Self::get_max_root_validators() { + if current_num_root_validators < MaxAllowedUids::::get(Self::ROOT_NETUID) { // --- 12.1.1 We can append to the subnetwork as it's not full. subnetwork_uid = current_num_root_validators; From 931a22c513c9616f75a412c647d243a4bbb41453 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 16:28:24 +0100 Subject: [PATCH 055/137] Remove get_max_subnets from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/root.rs | 15 ++------------- pallets/subtensor/src/tests/root.rs | 8 ++++---- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 9b9bc3f98..f52b29bcf 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -801,7 +801,7 @@ fn test_sudo_set_subnet_limit() { let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_max_subnets(); + let init_value: u16 = SubnetLimit::::get(); assert_eq!( AdminUtils::sudo_set_subnet_limit( <::RuntimeOrigin>::signed(U256::from(1)), @@ -809,12 +809,12 @@ fn test_sudo_set_subnet_limit() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_max_subnets(), init_value); + assert_eq!(SubnetLimit::::get(), init_value); assert_ok!(AdminUtils::sudo_set_subnet_limit( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_max_subnets(), to_be_set); + assert_eq!(SubnetLimit::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 2b3fb5244..7b6df27f8 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -43,17 +43,6 @@ impl Pallet { TotalNetworks::::get() } - /// Fetches the max number of subnet - /// - /// This function retrieves the max number of subnet. - /// - /// # Returns: - /// * 'u16': The max number of subnet - /// - pub fn get_max_subnets() -> u16 { - SubnetLimit::::get() - } - /// Sets the max number of subnet /// /// This function sets the max number of subnet. @@ -916,9 +905,9 @@ impl Pallet { log::debug!( "subnet count: {:?}\nmax subnets: {:?}", Self::get_num_subnets(), - Self::get_max_subnets() + SubnetLimit::::get() ); - if Self::get_num_subnets().saturating_sub(1) < Self::get_max_subnets() { + if Self::get_num_subnets().saturating_sub(1) < SubnetLimit::::get() { // We subtract one because we don't want root subnet to count towards total let mut next_available_netuid = 0; loop { diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 0d777234e..c105d21bd 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -8,7 +8,7 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, Error, NetworkRateLimit, SubnetIdentities, - SubnetIdentity, SubnetIdentityOf, SubnetworkN, + SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, }; #[allow(dead_code)] @@ -226,7 +226,7 @@ fn test_root_set_weights() { )); } - log::info!("subnet limit: {:?}", SubtensorModule::get_max_subnets()); + log::info!("subnet limit: {:?}", SubnetLimit::::get()); log::info!( "current subnet count: {:?}", SubtensorModule::get_num_subnets() @@ -369,7 +369,7 @@ fn test_root_set_weights_out_of_order_netuids() { )); } - log::info!("subnet limit: {:?}", SubtensorModule::get_max_subnets()); + log::info!("subnet limit: {:?}", SubnetLimit::::get()); log::info!( "current subnet count: {:?}", SubtensorModule::get_num_subnets() @@ -735,7 +735,7 @@ fn test_weights_after_network_pruning() { "Root network weights before extra network registration: {:?}", SubtensorModule::get_root_weights() ); - log::info!("Max subnets: {:?}", SubtensorModule::get_max_subnets()); + log::info!("Max subnets: {:?}", SubnetLimit::::get()); let i = (n as u16) + 1; // let _hot: U256 = U256::from(i); let cold: U256 = U256::from(i); From 4c74cf8433ee62fee65420b0ac3db9bf14dd0e51 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 16:35:21 +0100 Subject: [PATCH 056/137] Remove get_max_weight_limit from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/subnets/weights.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index f52b29bcf..1ca556576 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -291,7 +291,7 @@ fn test_sudo_set_max_weight_limit() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_max_weight_limit(netuid); + let init_value: u16 = MaxWeightsLimit::::get(netuid); assert_eq!( AdminUtils::sudo_set_max_weight_limit( <::RuntimeOrigin>::signed(U256::from(1)), @@ -308,13 +308,13 @@ fn test_sudo_set_max_weight_limit() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_max_weight_limit(netuid), init_value); + assert_eq!(MaxWeightsLimit::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_max_weight_limit( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_max_weight_limit(netuid), to_be_set); + assert_eq!(MaxWeightsLimit::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 15f6d35dd..337d86d40 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -95,7 +95,7 @@ impl Pallet { let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = MaxAllowedValidators::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); - let max_weights_limit = Self::get_max_weight_limit(netuid); + let max_weights_limit = MaxWeightsLimit::::get(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = MaxAllowedUids::::get(netuid); @@ -165,7 +165,7 @@ impl Pallet { let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = MaxAllowedValidators::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); - let max_weights_limit = Self::get_max_weight_limit(netuid); + let max_weights_limit = MaxWeightsLimit::::get(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = MaxAllowedUids::::get(netuid); @@ -234,7 +234,7 @@ impl Pallet { let kappa = Kappa::::get(netuid); let immunity_period = ImmunityPeriod::::get(netuid); let min_allowed_weights = Self::get_min_allowed_weights(netuid); - let max_weights_limit = Self::get_max_weight_limit(netuid); + let max_weights_limit = MaxWeightsLimit::::get(netuid); let tempo = Self::get_tempo(netuid); let min_difficulty = Self::get_min_difficulty(netuid); let max_difficulty = MaxDifficulty::::get(netuid); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 53d2c596e..aba5ac4a4 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -1004,7 +1004,7 @@ impl Pallet { } // If the max weight limit it u16 max, return true. - let max_weight_limit: u16 = Self::get_max_weight_limit(netuid); + let max_weight_limit: u16 = MaxWeightsLimit::::get(netuid); if max_weight_limit == u16::MAX { return true; } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 96be77604..a9e0219c3 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -398,9 +398,6 @@ impl Pallet { Self::deposit_event(Event::ScalingLawPowerSet(netuid, scaling_law_power)); } - pub fn get_max_weight_limit(netuid: u16) -> u16 { - MaxWeightsLimit::::get(netuid) - } 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)); From 5fd1e819a37ca9bfe4a573631bdccf4f647b6acb Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 16:42:09 +0100 Subject: [PATCH 057/137] Remove get_min_allowed_weights from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/subnets/weights.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 1ca556576..d240c5110 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -376,7 +376,7 @@ fn test_sudo_set_min_allowed_weights() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_min_allowed_weights(netuid); + let init_value: u16 = MinAllowedWeights::::get(netuid); assert_eq!( AdminUtils::sudo_set_min_allowed_weights( <::RuntimeOrigin>::signed(U256::from(1)), @@ -393,13 +393,13 @@ fn test_sudo_set_min_allowed_weights() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), init_value); + assert_eq!(MinAllowedWeights::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_min_allowed_weights( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_min_allowed_weights(netuid), to_be_set); + assert_eq!(MinAllowedWeights::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 337d86d40..5df32766f 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -94,7 +94,7 @@ impl Pallet { let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = MaxAllowedValidators::::get(netuid); - let min_allowed_weights = Self::get_min_allowed_weights(netuid); + let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); @@ -164,7 +164,7 @@ impl Pallet { let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); let max_allowed_validators = MaxAllowedValidators::::get(netuid); - let min_allowed_weights = Self::get_min_allowed_weights(netuid); + let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); let scaling_law_power = Self::get_scaling_law_power(netuid); let subnetwork_n = SubnetworkN::::get(netuid); @@ -233,7 +233,7 @@ impl Pallet { let rho = Self::get_rho(netuid); let kappa = Kappa::::get(netuid); let immunity_period = ImmunityPeriod::::get(netuid); - let min_allowed_weights = Self::get_min_allowed_weights(netuid); + let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); let tempo = Self::get_tempo(netuid); let min_difficulty = Self::get_min_difficulty(netuid); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index aba5ac4a4..e041ff764 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -959,7 +959,7 @@ impl Pallet { /// Returns True if the uids and weights are have a valid length for uid on network. pub fn check_length(netuid: u16, uid: u16, uids: &[u16], weights: &[u16]) -> bool { let subnet_n: usize = SubnetworkN::::get(netuid) as usize; - let min_allowed_length: usize = Self::get_min_allowed_weights(netuid) as usize; + let min_allowed_length: usize = MinAllowedWeights::::get(netuid) as usize; let min_allowed: usize = { if subnet_n < min_allowed_length { subnet_n diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index a9e0219c3..c064a759f 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -415,9 +415,6 @@ impl Pallet { current_block.saturating_sub(registered_at) < u64::from(immunity_period) } - pub fn get_min_allowed_weights(netuid: u16) -> u16 { - MinAllowedWeights::::get(netuid) - } 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)); From 15570f090155ff66770ba0a4ce3c36d3d4468b0f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 16:59:17 +0100 Subject: [PATCH 058/137] Remove duplicated import in admin-utils benchmarking --- pallets/admin-utils/src/benchmarking.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index d609985b6..13d4a08ea 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -5,8 +5,6 @@ extern crate alloc; use alloc::vec::Vec; -extern crate alloc; - #[allow(unused)] use crate::Pallet as AdminUtils; use alloc::vec::Vec; From 52ddda6dbcd4661e9840d2c20e127d0dfa979c3f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 17:09:11 +0100 Subject: [PATCH 059/137] Remove get_min_burn_as_u64 from pallet-subtensor::Pallet --- pallets/admin-utils/src/benchmarking.rs | 1 - pallets/subtensor/src/coinbase/block_step.rs | 4 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index 13d4a08ea..5ab4e1421 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -7,7 +7,6 @@ use alloc::vec::Vec; #[allow(unused)] use crate::Pallet as AdminUtils; -use alloc::vec::Vec; use frame_benchmarking::v1::account; use frame_benchmarking::v2::*; use frame_support::BoundedVec; diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 312614f63..1429aa8db 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -235,8 +235,8 @@ impl Pallet { ); if next_value >= I110F18::from_num(MaxBurn::::get(netuid)) { MaxBurn::::get(netuid) - } else if next_value <= I110F18::from_num(Self::get_min_burn_as_u64(netuid)) { - return Self::get_min_burn_as_u64(netuid); + } else if next_value <= I110F18::from_num(MinBurn::::get(netuid)) { + return MinBurn::::get(netuid); } else { return next_value.to_num::(); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 5df32766f..e75bdecd8 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -244,7 +244,7 @@ impl Pallet { let activity_cutoff = ActivityCutoff::::get(netuid); let registration_allowed = Self::get_network_registration_allowed(netuid); let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); - let min_burn = Self::get_min_burn_as_u64(netuid); + let min_burn = MinBurn::::get(netuid); let max_burn = MaxBurn::::get(netuid); let bonds_moving_avg = BondsMovingAverage::::get(netuid); let max_regs_per_block = MaxRegistrationsPerBlock::::get(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index c064a759f..8df1bba77 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -483,9 +483,6 @@ impl Pallet { Burn::::insert(netuid, burn); } - pub fn get_min_burn_as_u64(netuid: u16) -> u64 { - MinBurn::::get(netuid) - } pub fn set_min_burn(netuid: u16, min_burn: u64) { MinBurn::::insert(netuid, min_burn); Self::deposit_event(Event::MinBurnSet(netuid, min_burn)); From c57915add02894dc6ce17475bab310064a58f490 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 17:15:37 +0100 Subject: [PATCH 060/137] Remove get_min_childkey_take from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/children.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 4d00b6afc..9240239a4 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -851,7 +851,7 @@ fn test_childkey_take_functionality() { // Test default and max childkey take let default_take = MinChildkeyTake::::get(); - let min_take = SubtensorModule::get_min_childkey_take(); + let min_take = MinChildkeyTake::::get(); log::info!("Default take: {}, Max take: {}", default_take, min_take); // Check if default take and max take are the same diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 8df1bba77..cc87007a7 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -331,9 +331,6 @@ impl Pallet { MaxChildkeyTake::::put(take); Self::deposit_event(Event::MaxChildKeyTakeSet(take)); } - pub fn get_min_childkey_take() -> u16 { - MinChildkeyTake::::get() - } pub fn get_serving_rate_limit(netuid: u16) -> u64 { ServingRateLimit::::get(netuid) From 5b1511746989436e85a14da2aedb04353762d704 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 13 Dec 2024 17:25:28 +0100 Subject: [PATCH 061/137] Remove get_min_delegate_take from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 ++-- pallets/subtensor/src/tests/staking.rs | 44 +++++++++++++------------- pallets/subtensor/src/utils/misc.rs | 3 -- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index d240c5110..0e8e0af7f 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -1091,7 +1091,7 @@ fn test_sudo_set_tx_delegate_take_rate_limit() { fn test_sudo_set_min_delegate_take() { new_test_ext().execute_with(|| { let to_be_set = u16::MAX / 100; - let init_value = SubtensorModule::get_min_delegate_take(); + let init_value = MinDelegateTake::::get(); assert_eq!( AdminUtils::sudo_set_min_delegate_take( <::RuntimeOrigin>::signed(U256::from(1)), @@ -1099,12 +1099,12 @@ fn test_sudo_set_min_delegate_take() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_min_delegate_take(), init_value); + assert_eq!(MinDelegateTake::::get(), init_value); assert_ok!(AdminUtils::sudo_set_min_delegate_take( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_min_delegate_take(), to_be_set); + assert_eq!(MinDelegateTake::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 83f1874be..edf7115eb 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1386,7 +1386,7 @@ fn test_clear_small_nominations() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold1), hot1, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1); @@ -1395,7 +1395,7 @@ fn test_clear_small_nominations() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(cold2), hot2, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2); @@ -1688,11 +1688,11 @@ fn test_delegate_take_can_be_decreased() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); // Coldkey / hotkey 0 decreases take to 5%. This should fail as the minimum take is 9% @@ -1734,11 +1734,11 @@ fn test_can_set_min_take_ok() { assert_ok!(SubtensorModule::do_decrease_take( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); }); } @@ -1763,11 +1763,11 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); // Coldkey / hotkey 0 tries to increase take to 12.5% @@ -1781,7 +1781,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { ); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); }); } @@ -1806,11 +1806,11 @@ fn test_delegate_take_can_be_increased() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); @@ -1845,11 +1845,11 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); // Coldkey / hotkey 0 tries to decrease take to 5% @@ -1863,7 +1863,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { ); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); }); } @@ -1888,11 +1888,11 @@ fn test_delegate_take_can_be_increased_to_limit() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); @@ -1963,11 +1963,11 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); // Coldkey / hotkey 0 tries to increase take to InitialDefaultDelegateTake+1 @@ -1984,7 +1984,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { } assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); }); } @@ -2009,11 +2009,11 @@ fn test_rate_limits_enforced_on_increase_take() { assert_ok!(SubtensorModule::do_become_delegate( <::RuntimeOrigin>::signed(coldkey0), hotkey0, - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() )); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); // Coldkey / hotkey 0 increases take to 12.5% @@ -2027,7 +2027,7 @@ fn test_rate_limits_enforced_on_increase_take() { ); assert_eq!( Delegates::::get(hotkey0), - SubtensorModule::get_min_delegate_take() + MinDelegateTake::::get() ); step_block(1 + InitialTxDelegateTakeRateLimit::get() as u16); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index cc87007a7..8b5e27c17 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -312,9 +312,6 @@ impl Pallet { MaxDelegateTake::::put(take); Self::deposit_event(Event::MaxDelegateTakeSet(take)); } - pub fn get_min_delegate_take() -> u16 { - MinDelegateTake::::get() - } pub fn get_tx_childkey_take_rate_limit() -> u64 { TxChildkeyTakeRateLimit::::get() From d19dc9affa75609b69d64b22304b8bf87583078e Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 16:04:45 +0100 Subject: [PATCH 062/137] Remove get_min_difficulty from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/block_step.rs | 4 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/tests/difficulty.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 3 --- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 0e8e0af7f..8f0372ba3 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -66,7 +66,7 @@ fn test_sudo_set_min_difficulty() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_min_difficulty(netuid); + let init_value: u64 = MinDifficulty::::get(netuid); assert_eq!( AdminUtils::sudo_set_min_difficulty( <::RuntimeOrigin>::signed(U256::from(1)), @@ -83,13 +83,13 @@ fn test_sudo_set_min_difficulty() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_min_difficulty(netuid), init_value); + assert_eq!(MinDifficulty::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_min_difficulty( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_min_difficulty(netuid), to_be_set); + assert_eq!(MinDifficulty::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 1429aa8db..d37cc42e5 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -201,8 +201,8 @@ impl Pallet { ); if next_value >= I110F18::from_num(MaxDifficulty::::get(netuid)) { MaxDifficulty::::get(netuid) - } else if next_value <= I110F18::from_num(Self::get_min_difficulty(netuid)) { - return Self::get_min_difficulty(netuid); + } else if next_value <= I110F18::from_num(MinDifficulty::::get(netuid)) { + return MinDifficulty::::get(netuid); } else { return next_value.to_num::(); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index e75bdecd8..e0c4f75f6 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -236,7 +236,7 @@ impl Pallet { let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); let tempo = Self::get_tempo(netuid); - let min_difficulty = Self::get_min_difficulty(netuid); + let min_difficulty = MinDifficulty::::get(netuid); let max_difficulty = MaxDifficulty::::get(netuid); let weights_version = Self::get_weights_version_key(netuid); let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 74539481d..2e36e4bd1 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -5,7 +5,7 @@ use sp_core::U256; use super::mock::*; use crate::{ AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, - MaxRegistrationsPerBlock, SubnetworkN, + MaxRegistrationsPerBlock, MinDifficulty, SubnetworkN, }; #[test] @@ -134,7 +134,7 @@ fn test_registration_difficulty_adjustment() { // Test min value. SubtensorModule::set_min_difficulty(netuid, 1); SubtensorModule::set_difficulty(netuid, 4); - assert_eq!(SubtensorModule::get_min_difficulty(netuid), 1); + assert_eq!(MinDifficulty::::get(netuid), 1); assert_eq!(Difficulty::::get(netuid), 4); SubtensorModule::set_adjustment_interval(netuid, 1); step_block(1); // Step diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 8b5e27c17..9b53769a5 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -337,9 +337,6 @@ impl Pallet { Self::deposit_event(Event::ServingRateLimitSet(netuid, serving_rate_limit)); } - pub fn get_min_difficulty(netuid: u16) -> u64 { - MinDifficulty::::get(netuid) - } pub fn set_min_difficulty(netuid: u16, min_difficulty: u64) { MinDifficulty::::insert(netuid, min_difficulty); Self::deposit_event(Event::MinDifficultySet(netuid, min_difficulty)); From f89320c5f2b52ff618ab2e5f10a70939edc5fb6f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 16:11:11 +0100 Subject: [PATCH 063/137] Remove get_network_immunity_period from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 7b6df27f8..38cc43eb6 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1246,7 +1246,7 @@ impl Pallet { // Even if we don't have a root subnet, this still works for netuid in NetworksAdded::::iter_keys_from(NetworksAdded::::hashed_key_for(0)) { if current_block.saturating_sub(Self::get_network_registered_block(netuid)) - < Self::get_network_immunity_period() + < NetworkImmunityPeriod::::get() { continue; } @@ -1284,9 +1284,7 @@ impl Pallet { pub fn get_network_registered_block(netuid: u16) -> u64 { NetworkRegisteredAt::::get(netuid) } - pub fn get_network_immunity_period() -> u64 { - NetworkImmunityPeriod::::get() - } + pub fn set_network_immunity_period(net_immunity_period: u64) { NetworkImmunityPeriod::::set(net_immunity_period); Self::deposit_event(Event::NetworkImmunityPeriodSet(net_immunity_period)); From 397d61879121494c77344a208b2281b640aa5c5a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 16:25:18 +0100 Subject: [PATCH 064/137] Remove get_network_last_lock from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 38cc43eb6..b450fb0f9 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1209,7 +1209,7 @@ impl Pallet { /// - The lock cost for the network. /// pub fn get_network_lock_cost() -> u64 { - let last_lock = Self::get_network_last_lock(); + let last_lock = NetworkLastLockCost::::get(); let min_lock = Self::get_network_min_lock(); let last_lock_block = Self::get_network_last_lock_block(); let current_block = Self::get_current_block_as_u64(); @@ -1299,9 +1299,7 @@ impl Pallet { pub fn set_network_last_lock(net_last_lock: u64) { NetworkLastLockCost::::set(net_last_lock); } - pub fn get_network_last_lock() -> u64 { - NetworkLastLockCost::::get() - } + pub fn get_network_last_lock_block() -> u64 { NetworkLastRegistered::::get() } From 14e175518628343d65846873fcd703418d5558eb Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 16:45:10 +0100 Subject: [PATCH 065/137] Remove get_network_last_lock_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 5 +---- pallets/subtensor/src/utils/rate_limiting.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index b450fb0f9..a18e58e02 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1211,7 +1211,7 @@ impl Pallet { pub fn get_network_lock_cost() -> u64 { let last_lock = NetworkLastLockCost::::get(); let min_lock = Self::get_network_min_lock(); - let last_lock_block = Self::get_network_last_lock_block(); + let last_lock_block = NetworkLastRegistered::::get(); let current_block = Self::get_current_block_as_u64(); let lock_reduction_interval = NetworkLockReductionInterval::::get(); let mult = if last_lock_block == 0 { 1 } else { 2 }; @@ -1300,9 +1300,6 @@ impl Pallet { NetworkLastLockCost::::set(net_last_lock); } - pub fn get_network_last_lock_block() -> u64 { - NetworkLastRegistered::::get() - } pub fn set_network_last_lock_block(block: u64) { NetworkLastRegistered::::set(block); } diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index 9f0669874..299f4ebd2 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -82,7 +82,7 @@ impl Pallet { /// Get the block number of the last transaction for a specific key, and transaction type pub fn get_last_transaction_block(key: &T::AccountId, tx_type: &TransactionType) -> u64 { match tx_type { - TransactionType::RegisterNetwork => Self::get_network_last_lock_block(), + TransactionType::RegisterNetwork => NetworkLastRegistered::::get(), _ => Self::get_last_transaction_block_on_subnet(key, 0, tx_type), } } @@ -94,7 +94,7 @@ impl Pallet { tx_type: &TransactionType, ) -> u64 { match tx_type { - TransactionType::RegisterNetwork => Self::get_network_last_lock_block(), + TransactionType::RegisterNetwork => NetworkLastRegistered::::get(), _ => { let tx_as_u16: u16 = (*tx_type).into(); TransactionKeyLastBlock::::get((hotkey, netuid, tx_as_u16)) From 188eee6e35e6c57c26415b8ac27f7b029caffd8a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 16:52:36 +0100 Subject: [PATCH 066/137] Remove get_network_max_stake from pallet-subtensor::Pallet --- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/tests/children.rs | 37 +++++++----------------- pallets/subtensor/src/utils/misc.rs | 13 --------- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 49b2b05df..755a80524 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -77,7 +77,7 @@ impl Pallet { .saturating_add(stake_from_parents); // get the max stake for the network - let max_stake = Self::get_network_max_stake(netuid); + let max_stake = NetworkMaxStake::::get(netuid); // Return the finalized stake value for the hotkey, but capped at the max stake. finalized_stake = finalized_stake.min(max_stake); diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 9240239a4..84bc78c9e 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -1424,7 +1424,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { fn test_get_network_max_stake() { new_test_ext(1).execute_with(|| { let netuid: u16 = 1; - let default_max_stake = SubtensorModule::get_network_max_stake(netuid); + let default_max_stake = NetworkMaxStake::::get(netuid); // Check that the default value is set correctly assert_eq!(default_max_stake, u64::MAX); @@ -1434,10 +1434,7 @@ fn test_get_network_max_stake() { SubtensorModule::set_network_max_stake(netuid, new_max_stake); // Check that the new value is retrieved correctly - assert_eq!( - SubtensorModule::get_network_max_stake(netuid), - new_max_stake - ); + assert_eq!(NetworkMaxStake::::get(netuid), new_max_stake); }); } @@ -1452,21 +1449,15 @@ fn test_get_network_max_stake() { fn test_set_network_max_stake() { new_test_ext(1).execute_with(|| { let netuid: u16 = 1; - let initial_max_stake = SubtensorModule::get_network_max_stake(netuid); + let initial_max_stake = NetworkMaxStake::::get(netuid); // Set a new max stake value let new_max_stake: u64 = 500_000; SubtensorModule::set_network_max_stake(netuid, new_max_stake); // Check that the new value is set correctly - assert_eq!( - SubtensorModule::get_network_max_stake(netuid), - new_max_stake - ); - assert_ne!( - SubtensorModule::get_network_max_stake(netuid), - initial_max_stake - ); + assert_eq!(NetworkMaxStake::::get(netuid), new_max_stake); + assert_ne!(NetworkMaxStake::::get(netuid), initial_max_stake); // Check that the event is emitted System::assert_last_event(Event::NetworkMaxStakeSet(netuid, new_max_stake).into()); @@ -1492,11 +1483,11 @@ fn test_set_network_max_stake_multiple_networks() { SubtensorModule::set_network_max_stake(netuid2, max_stake2); // Check that the values are set correctly for each network - assert_eq!(SubtensorModule::get_network_max_stake(netuid1), max_stake1); - assert_eq!(SubtensorModule::get_network_max_stake(netuid2), max_stake2); + assert_eq!(NetworkMaxStake::::get(netuid1), max_stake1); + assert_eq!(NetworkMaxStake::::get(netuid2), max_stake2); assert_ne!( - SubtensorModule::get_network_max_stake(netuid1), - SubtensorModule::get_network_max_stake(netuid2) + NetworkMaxStake::::get(netuid1), + NetworkMaxStake::::get(netuid2) ); }); } @@ -1522,14 +1513,8 @@ fn test_set_network_max_stake_update() { SubtensorModule::set_network_max_stake(netuid, updated_max_stake); // Check that the value is updated correctly - assert_eq!( - SubtensorModule::get_network_max_stake(netuid), - updated_max_stake - ); - assert_ne!( - SubtensorModule::get_network_max_stake(netuid), - initial_max_stake - ); + assert_eq!(NetworkMaxStake::::get(netuid), updated_max_stake); + assert_ne!(NetworkMaxStake::::get(netuid), initial_max_stake); // Check that the event is emitted for the update System::assert_last_event(Event::NetworkMaxStakeSet(netuid, updated_max_stake).into()); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9b53769a5..5109415d7 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -590,19 +590,6 @@ impl Pallet { PendingdHotkeyEmission::::get(hotkey) } - /// Retrieves the maximum stake allowed for a given network. - /// - /// # Arguments - /// - /// * `netuid` - The unique identifier of the network. - /// - /// # Returns - /// - /// * `u64` - The maximum stake allowed for the specified network. - pub fn get_network_max_stake(netuid: u16) -> u64 { - NetworkMaxStake::::get(netuid) - } - /// Sets the maximum stake allowed for a given network. /// /// # Arguments From 27881c1402808b3b15f4c2a5e8a72a7e8a1bcc77 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 16:59:19 +0100 Subject: [PATCH 067/137] Remove get_network_min_lock from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index a18e58e02..94f40cd45 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1210,7 +1210,7 @@ impl Pallet { /// pub fn get_network_lock_cost() -> u64 { let last_lock = NetworkLastLockCost::::get(); - let min_lock = Self::get_network_min_lock(); + let min_lock = NetworkMinLockCost::::get(); let last_lock_block = NetworkLastRegistered::::get(); let current_block = Self::get_current_block_as_u64(); let lock_reduction_interval = NetworkLockReductionInterval::::get(); @@ -1293,9 +1293,7 @@ impl Pallet { NetworkMinLockCost::::set(net_min_lock); Self::deposit_event(Event::NetworkMinLockCostSet(net_min_lock)); } - pub fn get_network_min_lock() -> u64 { - NetworkMinLockCost::::get() - } + pub fn set_network_last_lock(net_last_lock: u64) { NetworkLastLockCost::::set(net_last_lock); } From 6a6db4de40835a8d2ae2469b619e731c9299732f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 17:05:47 +0100 Subject: [PATCH 068/137] Remove get_network_pow_registration_allowed from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/subnets/registration.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 8f0372ba3..70a6dbed1 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -849,7 +849,7 @@ fn test_sudo_set_network_pow_registration_allowed() { let to_be_set: bool = true; add_network(netuid, 10); - let init_value: bool = SubtensorModule::get_network_pow_registration_allowed(netuid); + let init_value: bool = NetworkPowRegistrationAllowed::::get(netuid); assert_eq!( AdminUtils::sudo_set_network_pow_registration_allowed( <::RuntimeOrigin>::signed(U256::from(1)), @@ -859,7 +859,7 @@ fn test_sudo_set_network_pow_registration_allowed() { Err(DispatchError::BadOrigin) ); assert_eq!( - SubtensorModule::get_network_pow_registration_allowed(netuid), + NetworkPowRegistrationAllowed::::get(netuid), init_value ); assert_ok!(AdminUtils::sudo_set_network_pow_registration_allowed( @@ -868,7 +868,7 @@ fn test_sudo_set_network_pow_registration_allowed() { to_be_set )); assert_eq!( - SubtensorModule::get_network_pow_registration_allowed(netuid), + NetworkPowRegistrationAllowed::::get(netuid), to_be_set ); }); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index e390f751a..7fad22ecf 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -244,7 +244,7 @@ impl Pallet { // --- 3. Ensure the passed network allows registrations. ensure!( - Self::get_network_pow_registration_allowed(netuid), + NetworkPowRegistrationAllowed::::get(netuid), Error::::SubNetRegistrationDisabled ); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 5109415d7..ea6169f28 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -445,9 +445,6 @@ impl Pallet { Self::deposit_event(Event::RegistrationAllowed(netuid, registration_allowed)); } - pub fn get_network_pow_registration_allowed(netuid: u16) -> bool { - NetworkPowRegistrationAllowed::::get(netuid) - } 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)); From 4c94a08d52d4fa7b358299c371bb43396fc56a3c Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 17:44:19 +0100 Subject: [PATCH 069/137] Remove get_network_registered_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 94f40cd45..d93359dc3 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1245,7 +1245,7 @@ impl Pallet { // Even if we don't have a root subnet, this still works for netuid in NetworksAdded::::iter_keys_from(NetworksAdded::::hashed_key_for(0)) { - if current_block.saturating_sub(Self::get_network_registered_block(netuid)) + if current_block.saturating_sub(NetworkRegisteredAt::::get(netuid)) < NetworkImmunityPeriod::::get() { continue; @@ -1261,9 +1261,7 @@ impl Pallet { match EmissionValues::::get(*b).cmp(&EmissionValues::::get(*a)) { Ordering::Equal => { - if Self::get_network_registered_block(*b) - < Self::get_network_registered_block(*a) - { + if NetworkRegisteredAt::::get(*b) < NetworkRegisteredAt::::get(*a) { Ordering::Less } else { Ordering::Equal @@ -1281,10 +1279,6 @@ impl Pallet { } } - pub fn get_network_registered_block(netuid: u16) -> u64 { - NetworkRegisteredAt::::get(netuid) - } - pub fn set_network_immunity_period(net_immunity_period: u64) { NetworkImmunityPeriod::::set(net_immunity_period); Self::deposit_event(Event::NetworkImmunityPeriodSet(net_immunity_period)); From 37ca8f1e4da3b01b27a768a0b4b57518deb068ec Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 18:11:32 +0100 Subject: [PATCH 070/137] Remove get_network_registration_allowed from pallet-subtensor::Pallet --- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 2 +- pallets/subtensor/src/tests/difficulty.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 4 ---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index e0c4f75f6..142b153ad 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -242,7 +242,7 @@ impl Pallet { let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); let adjustment_interval = AdjustmentInterval::::get(netuid); let activity_cutoff = ActivityCutoff::::get(netuid); - let registration_allowed = Self::get_network_registration_allowed(netuid); + let registration_allowed = NetworkRegistrationAllowed::::get(netuid); let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); let min_burn = MinBurn::::get(netuid); let max_burn = MaxBurn::::get(netuid); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 7fad22ecf..dcfaefcc6 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -60,7 +60,7 @@ impl Pallet { // --- 3. Ensure the passed network allows registrations. ensure!( - Self::get_network_registration_allowed(netuid), + NetworkRegistrationAllowed::::get(netuid), Error::::SubNetRegistrationDisabled ); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 2e36e4bd1..67a8e5a28 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -5,7 +5,7 @@ use sp_core::U256; use super::mock::*; use crate::{ AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, - MaxRegistrationsPerBlock, MinDifficulty, SubnetworkN, + MaxRegistrationsPerBlock, MinDifficulty, NetworkRegistrationAllowed, SubnetworkN, }; #[test] @@ -23,7 +23,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::set_adjustment_alpha(netuid, 58000); SubtensorModule::set_target_registrations_per_interval(netuid, 2); SubtensorModule::set_adjustment_interval(netuid, 100); - assert!(SubtensorModule::get_network_registration_allowed(netuid)); // Default registration allowed. + assert!(NetworkRegistrationAllowed::::get(netuid)); // Default registration allowed. // Set values and check. SubtensorModule::set_difficulty(netuid, 20000); @@ -40,7 +40,7 @@ fn test_registration_difficulty_adjustment() { ); // Check set adjustment interval. assert_eq!(MaxRegistrationsPerBlock::::get(netuid), 3); // Check set registrations per block. assert_eq!(MaxAllowedUids::::get(netuid), 3); // Check set registrations per block. - assert!(SubtensorModule::get_network_registration_allowed(netuid)); // Check set registration allowed + assert!(NetworkRegistrationAllowed::::get(netuid)); // Check set registration allowed // Lets register 3 neurons... let hotkey0 = U256::from(0); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index ea6169f28..1ff05705d 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -436,10 +436,6 @@ impl Pallet { Self::deposit_event(Event::ActivityCutoffSet(netuid, activity_cutoff)); } - // Registration Toggle utils - pub fn get_network_registration_allowed(netuid: u16) -> bool { - NetworkRegistrationAllowed::::get(netuid) - } pub fn set_network_registration_allowed(netuid: u16, registration_allowed: bool) { NetworkRegistrationAllowed::::insert(netuid, registration_allowed); Self::deposit_event(Event::RegistrationAllowed(netuid, registration_allowed)); From cfa3e17001185e5d4385a678933c110ea454a436 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 18:18:41 +0100 Subject: [PATCH 071/137] Remove get_neuron_block_at_registration from pallet-subtensor::Pallet --- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 3 +-- pallets/subtensor/src/tests/registration.rs | 15 +++++---------- pallets/subtensor/src/utils/misc.rs | 5 +---- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 755a80524..74c1d922a 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -805,7 +805,7 @@ impl Pallet { let block_at_registration: Vec = (0..n) .map(|neuron_uid| { if Keys::::contains_key(netuid, neuron_uid) { - Self::get_neuron_block_at_registration(netuid, neuron_uid) + BlockAtRegistration::::get(netuid, neuron_uid) } else { 0 } diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index dcfaefcc6..5ec65d556 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -446,8 +446,7 @@ impl Pallet { for neuron_uid in 0..neurons_n { let pruning_score: u16 = Self::get_pruning_score_for_uid(netuid, neuron_uid); - let block_at_registration: u64 = - Self::get_neuron_block_at_registration(netuid, neuron_uid); + let block_at_registration: u64 = BlockAtRegistration::::get(netuid, neuron_uid); let is_immune = Self::get_neuron_is_immune(netuid, neuron_uid); if is_immune { diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 84a66177f..efa0ff6cf 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,8 +11,9 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ - Axons, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, MaxAllowedUids, - MaxRegistrationsPerBlock, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, + Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, + MaxAllowedUids, MaxRegistrationsPerBlock, RAORecycledForRegistration, SubnetworkN, + SubtensorSignedExtension, }; /******************************************** @@ -1224,10 +1225,7 @@ fn test_registration_get_uid_to_prune_all_in_immunity_period() { assert_eq!(SubtensorModule::get_pruning_score_for_uid(netuid, 1), 110); assert_eq!(ImmunityPeriod::::get(netuid), 2); assert_eq!(SubtensorModule::get_current_block_as_u64(), 0); - assert_eq!( - SubtensorModule::get_neuron_block_at_registration(netuid, 0), - 0 - ); + assert_eq!(BlockAtRegistration::::get(netuid, 0), 0); assert_eq!(SubtensorModule::get_neuron_to_prune(0), 0); }); } @@ -1248,10 +1246,7 @@ fn test_registration_get_uid_to_prune_none_in_immunity_period() { assert_eq!(SubtensorModule::get_pruning_score_for_uid(netuid, 1), 110); assert_eq!(ImmunityPeriod::::get(netuid), 2); assert_eq!(SubtensorModule::get_current_block_as_u64(), 0); - assert_eq!( - SubtensorModule::get_neuron_block_at_registration(netuid, 0), - 0 - ); + assert_eq!(BlockAtRegistration::::get(netuid, 0), 0); step_block(3); assert_eq!(SubtensorModule::get_current_block_as_u64(), 3); assert_eq!(SubtensorModule::get_neuron_to_prune(0), 0); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 1ff05705d..1733ffdbe 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -238,9 +238,6 @@ impl Pallet { pub fn get_pow_registrations_this_interval(netuid: u16) -> u16 { POWRegistrationsThisInterval::::get(netuid) } - pub fn get_neuron_block_at_registration(netuid: u16, neuron_uid: u16) -> u64 { - BlockAtRegistration::::get(netuid, neuron_uid) - } // ======================== // ===== Take checks ====== @@ -400,7 +397,7 @@ impl Pallet { } /// Check if a neuron is in immunity based on the current block pub fn get_neuron_is_immune(netuid: u16, uid: u16) -> bool { - let registered_at = Self::get_neuron_block_at_registration(netuid, uid); + let registered_at = BlockAtRegistration::::get(netuid, uid); let current_block = Self::get_current_block_as_u64(); let immunity_period = ImmunityPeriod::::get(netuid); current_block.saturating_sub(registered_at) < u64::from(immunity_period) From 9de07da02b060812908c0eb060797ab1b00e2b32 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 18:26:36 +0100 Subject: [PATCH 072/137] Remove get_nominator_min_required_stake from pallet-subtensor::Pallet --- pallets/admin-utils/src/lib.rs | 2 +- pallets/admin-utils/src/tests/mod.rs | 13 +++++-------- pallets/subtensor/src/staking/helpers.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 ---- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 4f525c81f..3257835b0 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -916,7 +916,7 @@ pub mod pallet { min_stake: u64, ) -> DispatchResult { ensure_root(origin)?; - let prev_min_stake = pallet_subtensor::Pallet::::get_nominator_min_required_stake(); + let prev_min_stake = pallet_subtensor::NominatorMinRequiredStake::::get(); log::trace!("Setting minimum stake to: {}", min_stake); pallet_subtensor::Pallet::::set_nominator_min_required_stake(min_stake); if min_stake > prev_min_stake { diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 70a6dbed1..03c0519c8 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -880,7 +880,7 @@ mod sudo_set_nominator_min_required_stake { #[test] fn can_only_be_called_by_admin() { new_test_ext().execute_with(|| { - let to_be_set: u64 = SubtensorModule::get_nominator_min_required_stake() + 5_u64; + let to_be_set: u64 = NominatorMinRequiredStake::::get() + 5_u64; assert_eq!( AdminUtils::sudo_set_nominator_min_required_stake( <::RuntimeOrigin>::signed(U256::from(0)), @@ -898,28 +898,25 @@ mod sudo_set_nominator_min_required_stake { <::RuntimeOrigin>::root(), 10u64 )); - assert_eq!(SubtensorModule::get_nominator_min_required_stake(), 10u64); + assert_eq!(NominatorMinRequiredStake::::get(), 10u64); assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake( <::RuntimeOrigin>::root(), 5u64 )); - assert_eq!(SubtensorModule::get_nominator_min_required_stake(), 5u64); + assert_eq!(NominatorMinRequiredStake::::get(), 5u64); }); } #[test] fn sets_a_higher_value() { new_test_ext().execute_with(|| { - let to_be_set: u64 = SubtensorModule::get_nominator_min_required_stake() + 5_u64; + let to_be_set: u64 = NominatorMinRequiredStake::::get() + 5_u64; assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!( - SubtensorModule::get_nominator_min_required_stake(), - to_be_set - ); + assert_eq!(NominatorMinRequiredStake::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 95a8925b8..855991a7f 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -237,7 +237,7 @@ impl Pallet { // Verify if the account is a nominator account by checking ownership of the hotkey by the coldkey. if !Self::coldkey_owns_hotkey(coldkey, hotkey) { // If the stake is below the minimum required, it's considered a small nomination and needs to be cleared. - if stake < Self::get_nominator_min_required_stake() { + if stake < NominatorMinRequiredStake::::get() { // Remove the stake from the nominator account. (this is a more forceful unstake operation which ) // Actually deletes the staking account. let cleared_stake = Self::empty_stake_on_coldkey_hotkey_account(coldkey, hotkey); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 1733ffdbe..51f9a7931 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -542,10 +542,6 @@ impl Pallet { SubnetOwner::::iter_values().any(|owner| *address == owner) } - pub fn get_nominator_min_required_stake() -> u64 { - NominatorMinRequiredStake::::get() - } - pub fn set_nominator_min_required_stake(min_stake: u64) { NominatorMinRequiredStake::::put(min_stake); } From 7402aa09d23d614aee065fbf758baa61e2e4d07a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 18:41:18 +0100 Subject: [PATCH 073/137] Remove get_num_subnets from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 23 ++++++----------------- pallets/subtensor/src/tests/root.rs | 12 +++--------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index d93359dc3..9c6e225bd 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -32,17 +32,6 @@ impl Pallet { /// The root network is a special case and has a fixed UID of 0. pub(crate) const ROOT_NETUID: u16 = 0; - /// Fetches the total count of subnets. - /// - /// This function retrieves the total number of subnets present on the chain. - /// - /// # Returns: - /// * 'u16': The total number of subnets. - /// - pub fn get_num_subnets() -> u16 { - TotalNetworks::::get() - } - /// Sets the max number of subnet /// /// This function sets the max number of subnet. @@ -224,8 +213,8 @@ impl Pallet { 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: usize = Self::get_num_subnets() as usize; + log::debug!("subnet size before cast: {:?}", TotalNetworks::::get()); + let k: usize = TotalNetworks::::get() as usize; log::debug!("n: {:?} k: {:?}", n, k); // --- 2. Initialize a 2D vector with zeros to store the weights. The dimensions are determined @@ -363,9 +352,9 @@ impl Pallet { // --- 9. Calculates the trust of networks. Trust is a sum of all stake with weights > 0. // Trust will have shape k, a score for each subnet. log::debug!("Subnets:\n{:?}\n", Self::get_all_subnet_netuids()); - log::debug!("N Subnets:\n{:?}\n", Self::get_num_subnets()); + log::debug!("N Subnets:\n{:?}\n", TotalNetworks::::get()); - let total_networks = Self::get_num_subnets(); + let total_networks = TotalNetworks::::get(); let mut trust = vec![I64F64::from_num(0); total_networks as usize]; let mut total_stake: I64F64 = I64F64::from_num(0); for (weights, hotkey_stake) in weights.iter().zip(stake_i64) { @@ -904,10 +893,10 @@ impl Pallet { let netuid_to_register: u16 = { log::debug!( "subnet count: {:?}\nmax subnets: {:?}", - Self::get_num_subnets(), + TotalNetworks::::get(), SubnetLimit::::get() ); - if Self::get_num_subnets().saturating_sub(1) < SubnetLimit::::get() { + if TotalNetworks::::get().saturating_sub(1) < SubnetLimit::::get() { // We subtract one because we don't want root subnet to count towards total let mut next_available_netuid = 0; loop { diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index c105d21bd..3fb13acb0 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -8,7 +8,7 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, Error, NetworkRateLimit, SubnetIdentities, - SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, + SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, TotalNetworks, }; #[allow(dead_code)] @@ -227,10 +227,7 @@ fn test_root_set_weights() { } log::info!("subnet limit: {:?}", SubnetLimit::::get()); - log::info!( - "current subnet count: {:?}", - SubtensorModule::get_num_subnets() - ); + log::info!("current subnet count: {:?}", TotalNetworks::::get()); // Lets create n networks for netuid in 1..n { @@ -370,10 +367,7 @@ fn test_root_set_weights_out_of_order_netuids() { } log::info!("subnet limit: {:?}", SubnetLimit::::get()); - log::info!( - "current subnet count: {:?}", - SubtensorModule::get_num_subnets() - ); + log::info!("current subnet count: {:?}", TotalNetworks::::get()); // Lets create n networks for netuid in 1..n { From 5467691736d7a8abb64ed9deb69597a8385aa0e9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 19:16:50 +0100 Subject: [PATCH 074/137] Remove get_owned_hotkeys from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/swap_coldkey.rs | 50 +++++++-------------- pallets/subtensor/src/utils/misc.rs | 4 -- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index d33f53ff3..735e03eb8 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -685,10 +685,10 @@ fn test_swap_stake_for_coldkey() { // Verify ownership transfer assert_eq!( - SubtensorModule::get_owned_hotkeys(&new_coldkey), + OwnedHotkeys::::get(new_coldkey), vec![hotkey1, hotkey2] ); - assert_eq!(SubtensorModule::get_owned_hotkeys(&old_coldkey), vec![]); + assert_eq!(OwnedHotkeys::::get(old_coldkey), vec![]); // Verify stake transfer assert_eq!(Stake::::get(hotkey2, new_coldkey), stake_amount2); @@ -1096,7 +1096,7 @@ fn test_coldkey_swap_total() { )); assert_eq!( - SubtensorModule::get_owned_hotkeys(&coldkey), + OwnedHotkeys::::get(coldkey), vec![hotkey1, hotkey2, hotkey3] ); assert_eq!( @@ -1111,18 +1111,9 @@ fn test_coldkey_swap_total() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate2), 300); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate3), 300); - assert_eq!( - SubtensorModule::get_owned_hotkeys(&delegate1), - vec![delegate1] - ); - assert_eq!( - SubtensorModule::get_owned_hotkeys(&delegate2), - vec![delegate2] - ); - assert_eq!( - SubtensorModule::get_owned_hotkeys(&delegate3), - vec![delegate3] - ); + assert_eq!(OwnedHotkeys::::get(delegate1), vec![delegate1]); + assert_eq!(OwnedHotkeys::::get(delegate2), vec![delegate2]); + assert_eq!(OwnedHotkeys::::get(delegate3), vec![delegate3]); assert_eq!( StakingHotkeys::::get(delegate1), vec![delegate1, hotkey1] @@ -1136,9 +1127,9 @@ fn test_coldkey_swap_total() { vec![delegate3, hotkey3] ); - assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator1), vec![]); - assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator2), vec![]); - assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator3), vec![]); + assert_eq!(OwnedHotkeys::::get(nominator1), vec![]); + assert_eq!(OwnedHotkeys::::get(nominator2), vec![]); + assert_eq!(OwnedHotkeys::::get(nominator3), vec![]); assert_eq!( StakingHotkeys::::get(nominator1), @@ -1169,7 +1160,7 @@ fn test_coldkey_swap_total() { // Check everything is swapped. assert_eq!( - SubtensorModule::get_owned_hotkeys(&new_coldkey), + OwnedHotkeys::::get(new_coldkey), vec![hotkey1, hotkey2, hotkey3] ); assert_eq!( @@ -1187,18 +1178,9 @@ fn test_coldkey_swap_total() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate2), 300); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate3), 300); - assert_eq!( - SubtensorModule::get_owned_hotkeys(&delegate1), - vec![delegate1] - ); - assert_eq!( - SubtensorModule::get_owned_hotkeys(&delegate2), - vec![delegate2] - ); - assert_eq!( - SubtensorModule::get_owned_hotkeys(&delegate3), - vec![delegate3] - ); + assert_eq!(OwnedHotkeys::::get(delegate1), vec![delegate1]); + assert_eq!(OwnedHotkeys::::get(delegate2), vec![delegate2]); + assert_eq!(OwnedHotkeys::::get(delegate3), vec![delegate3]); assert_eq!( StakingHotkeys::::get(delegate1), vec![delegate1, hotkey1] @@ -1212,9 +1194,9 @@ fn test_coldkey_swap_total() { vec![delegate3, hotkey3] ); - assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator1), vec![]); - assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator2), vec![]); - assert_eq!(SubtensorModule::get_owned_hotkeys(&nominator3), vec![]); + assert_eq!(OwnedHotkeys::::get(nominator1), vec![]); + assert_eq!(OwnedHotkeys::::get(nominator2), vec![]); + assert_eq!(OwnedHotkeys::::get(nominator3), vec![]); assert_eq!( StakingHotkeys::::get(nominator1), diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 51f9a7931..684077633 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -511,10 +511,6 @@ impl Pallet { Self::deposit_event(Event::SubnetOwnerCutSet(subnet_owner_cut)); } - pub fn get_owned_hotkeys(coldkey: &T::AccountId) -> Vec { - OwnedHotkeys::::get(coldkey) - } - pub fn set_total_issuance(total_issuance: u64) { TotalIssuance::::put(total_issuance); } From 18bda25f5b27e4d779ff30cf5248b3ba6a38a96e Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 19:26:05 +0100 Subject: [PATCH 075/137] Remove get_owning_coldkey_for_hotkey from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 4 +- pallets/subtensor/src/coinbase/root.rs | 2 +- .../subtensor/src/rpc_info/delegate_info.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 17 +------ pallets/subtensor/src/tests/registration.rs | 16 +++---- pallets/subtensor/src/tests/senate.rs | 44 +++++-------------- pallets/subtensor/src/tests/staking.rs | 13 +++--- 7 files changed, 25 insertions(+), 73 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 03c0519c8..b198ae80c 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -943,7 +943,7 @@ mod sudo_set_nominator_min_required_stake { hot1, u16::MAX / 10 )); - assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1); + assert_eq!(Owner::::get(hot1), cold1); // Register hot2. register_ok_neuron(netuid, hot2, cold2, 0); @@ -952,7 +952,7 @@ mod sudo_set_nominator_min_required_stake { hot2, u16::MAX / 10 )); - assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2); + assert_eq!(Owner::::get(hot2), cold2); // Add stake cold1 --> hot1 (non delegation.) SubtensorModule::add_balance_to_coldkey_account(&cold1, 5); diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 9c6e225bd..b12cc9c73 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -709,7 +709,7 @@ impl Pallet { // Check that the signer coldkey owns the hotkey ensure!( - Self::get_owning_coldkey_for_hotkey(&hotkey) == coldkey, + Owner::::get(&hotkey) == coldkey, Error::::NonAssociatedColdKey ); diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index 591f34e48..be068bf68 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -57,7 +57,7 @@ impl Pallet { } } - let owner = Self::get_owning_coldkey_for_hotkey(&delegate.clone()); + let owner = Owner::::get(&delegate.clone()); let take: Compact = >::get(delegate.clone()).into(); let total_stake: U64F64 = Self::get_total_stake_for_hotkey(&delegate.clone()).into(); diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 855991a7f..1e223d4f8 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -74,17 +74,6 @@ impl Pallet { } } - /// Returns the coldkey owning this hotkey. This function should only be called for active accounts. - /// - /// # Arguments - /// * `hotkey` - The hotkey account ID. - /// - /// # Returns - /// The coldkey account ID that owns the hotkey. - pub fn get_owning_coldkey_for_hotkey(hotkey: &T::AccountId) -> T::AccountId { - Owner::::get(hotkey) - } - /// Returns true if the hotkey account has been created. /// /// # Arguments @@ -131,11 +120,7 @@ impl Pallet { /// * `hotkey` - The hotkey account ID. /// * `increment` - The amount to be incremented. pub fn increase_stake_on_hotkey_account(hotkey: &T::AccountId, increment: u64) { - Self::increase_stake_on_coldkey_hotkey_account( - &Self::get_owning_coldkey_for_hotkey(hotkey), - hotkey, - increment, - ); + Self::increase_stake_on_coldkey_hotkey_account(&Owner::::get(hotkey), hotkey, increment); } // Increases the stake on the cold - hot pairing by increment while also incrementing other counters. diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index efa0ff6cf..f4b6bd5ac 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -12,7 +12,7 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, - MaxAllowedUids, MaxRegistrationsPerBlock, RAORecycledForRegistration, SubnetworkN, + MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, SubnetworkN, SubtensorSignedExtension, }; @@ -134,10 +134,7 @@ fn test_registration_ok() { assert_eq!(SubnetworkN::::get(netuid), 1); //check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Check if the neuron has added to the Keys let neuron_uid = @@ -441,10 +438,7 @@ fn test_burned_registration_ok() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); //check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Check if the neuron has added to the Keys let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id).unwrap(); @@ -2005,11 +1999,11 @@ fn test_registration_disabled() { // new_hotkey // )); // assert_ne!( -// SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), +// Owner::::get(&hotkey_account_id), // coldkey_account_id // ); // assert_eq!( -// SubtensorModule::get_owning_coldkey_for_hotkey(&new_hotkey), +// Owner::::get(&new_hotkey), // coldkey_account_id // ); // }); diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index 758765cef..a0a2f81c6 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -14,7 +14,7 @@ use sp_runtime::{ BuildStorage, }; -use crate::{migrations, Error, SubnetworkN}; +use crate::{migrations, Error, Owner, SubnetworkN}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -83,10 +83,7 @@ fn test_senate_join_works() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Lets make this new key a delegate with a 10% take. assert_ok!(SubtensorModule::do_become_delegate( @@ -152,10 +149,7 @@ fn test_senate_vote_works() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Lets make this new key a delegate with a 10% take. assert_ok!(SubtensorModule::do_become_delegate( @@ -260,10 +254,7 @@ fn test_senate_vote_not_member() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); let proposal = make_proposal(42); let proposal_len: u32 = proposal.using_encoded(|p| p.len() as u32); @@ -320,10 +311,7 @@ fn test_senate_leave_works() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Lets make this new key a delegate with a 10% take. assert_ok!(SubtensorModule::do_become_delegate( @@ -390,10 +378,7 @@ fn test_senate_leave_vote_removal() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Lets make this new key a delegate with a 10% take. assert_ok!(SubtensorModule::do_become_delegate( @@ -529,10 +514,7 @@ fn test_senate_not_leave_when_stake_removed() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Lets make this new key a delegate with a 10% take. assert_ok!(SubtensorModule::do_become_delegate( @@ -608,10 +590,7 @@ fn test_senate_join_current_delegate() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Register in the root network assert_ok!(SubtensorModule::root_register( @@ -697,10 +676,7 @@ fn test_adjust_senate_events() { // Check if neuron has added to the specified network(netuid) assert_eq!(SubnetworkN::::get(netuid), 1); // Check if hotkey is added to the Hotkeys - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_account_id), - coldkey_account_id - ); + assert_eq!(Owner::::get(hotkey_account_id), coldkey_account_id); // Should *NOT* be a member of the senate assert!(!Senate::is_member(&hotkey_account_id)); @@ -725,7 +701,7 @@ fn test_adjust_senate_events() { )); // Check if this hotkey is added to the Hotkeys assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&new_hotkey_account_id), + Owner::::get(new_hotkey_account_id), coldkey_account_id ); // Add/delegate enough stake to join the senate diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index edf7115eb..688800b4f 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -898,7 +898,7 @@ fn test_remove_stake_from_hotkey_account() { // Remove stake SubtensorModule::decrease_stake_on_coldkey_hotkey_account( - &SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_id), + &Owner::::get(hotkey_id), &hotkey_id, amount, ); @@ -955,7 +955,7 @@ fn test_remove_stake_from_hotkey_account_registered_in_various_networks() { // Remove stake SubtensorModule::decrease_stake_on_coldkey_hotkey_account( - &SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_id), + &Owner::::get(hotkey_id), &hotkey_id, amount, ); @@ -1055,10 +1055,7 @@ fn test_hotkey_belongs_to_coldkey_ok() { let start_nonce: u64 = 0; add_network(netuid, tempo, 0); register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); - assert_eq!( - SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_id), - coldkey_id - ); + assert_eq!(Owner::::get(hotkey_id), coldkey_id); }); } // /************************************************************ @@ -1388,7 +1385,7 @@ fn test_clear_small_nominations() { hot1, MinDelegateTake::::get() )); - assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot1), cold1); + assert_eq!(Owner::::get(hot1), cold1); // Register hot2. register_ok_neuron(netuid, hot2, cold2, 0); @@ -1397,7 +1394,7 @@ fn test_clear_small_nominations() { hot2, MinDelegateTake::::get() )); - assert_eq!(SubtensorModule::get_owning_coldkey_for_hotkey(&hot2), cold2); + assert_eq!(Owner::::get(hot2), cold2); // Add stake cold1 --> hot1 (non delegation.) SubtensorModule::add_balance_to_coldkey_account(&cold1, 5); From dc73d14ecbca70313bf35e1355b870be72cd7f6c Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 20:06:52 +0100 Subject: [PATCH 076/137] Remove get_parents from pallet-subtensor::Pallet --- .../subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/epoch/run_epoch.rs | 2 +- pallets/subtensor/src/staking/set_children.rs | 17 ----- pallets/subtensor/src/tests/children.rs | 74 +++++++++---------- 4 files changed, 39 insertions(+), 56 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 87368f3c6..e0ad44ffc 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -372,7 +372,7 @@ impl Pallet { if total_hotkey_stake != 0 { // --- 4. If the total stake is not zero, iterate over each parent to determine their contribution to the hotkey's stake, // and calculate their share of the emission accordingly. - for (proportion, parent) in Self::get_parents(hotkey, netuid) { + for (proportion, parent) in ParentKeys::::get(hotkey, netuid) { // --- 4.1 Retrieve the parent's stake. This is the raw stake value including nominators. let parent_stake: u64 = Self::get_total_stake_for_hotkey(&parent); diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 74c1d922a..128fe120f 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -39,7 +39,7 @@ impl Pallet { let mut stake_from_parents: u64 = 0; // Retrieve lists of parents and children from storage, based on the hotkey and network ID. - let parents: Vec<(u64, T::AccountId)> = Self::get_parents(hotkey, netuid); + let parents: Vec<(u64, T::AccountId)> = ParentKeys::::get(hotkey, netuid); let children: Vec<(u64, T::AccountId)> = ChildKeys::::get(hotkey, netuid); // Iterate over children to calculate the total stake allocated to them. diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index 8b8da0cf9..2c6fcf6f7 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -236,23 +236,6 @@ impl Pallet { ); } - /* Retrieves the list of parents for a given child and network. - /// - /// # Arguments - /// * `child` - The child whose parents are to be retrieved. - /// * `netuid` - The network identifier. - /// - /// # Returns - /// * `Vec<(u64, T::AccountId)>` - A vector of tuples containing the proportion and parent account ID. - /// - /// # Example - /// ``` - /// let parents = SubtensorModule::get_parents(&child, netuid); - */ - pub fn get_parents(child: &T::AccountId, netuid: u16) -> Vec<(u64, T::AccountId)> { - ParentKeys::::get(child, netuid) - } - /// Sets the childkey take for a given hotkey. /// /// This function allows a coldkey to set the childkey take for a given hotkey. diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 84bc78c9e..01f1af07b 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -168,11 +168,11 @@ fn test_do_set_child_singular_old_children_cleanup() { mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, new_child)]); // Verify old child is removed - let old_child_parents = SubtensorModule::get_parents(&old_child, netuid); + let old_child_parents = ParentKeys::::get(old_child, netuid); assert!(old_child_parents.is_empty()); // Verify new child assignment - let new_child_parents = SubtensorModule::get_parents(&new_child, netuid); + let new_child_parents = ParentKeys::::get(new_child, netuid); assert_eq!(new_child_parents, vec![(proportion, hotkey)]); }); } @@ -205,7 +205,7 @@ fn test_do_set_child_singular_new_children_assignment() { assert_eq!(children, vec![(proportion, child)]); // Verify parent assignment - let parents = SubtensorModule::get_parents(&child, netuid); + let parents = ParentKeys::::get(child, netuid); assert_eq!(parents, vec![(proportion, hotkey)]); }); } @@ -285,10 +285,10 @@ fn test_do_set_child_singular_multiple_children() { assert_eq!(children, vec![(proportion2, child2)]); // Verify parent assignment for both children - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert!(parents1.is_empty()); // Old child should be removed - let parents2 = SubtensorModule::get_parents(&child2, netuid); + let parents2 = ParentKeys::::get(child2, netuid); assert_eq!(parents2, vec![(proportion2, hotkey)]); }); } @@ -432,7 +432,7 @@ fn test_do_revoke_child_singular_success() { assert!(children.is_empty()); // Verify parent removal - let parents = SubtensorModule::get_parents(&child, netuid); + let parents = ParentKeys::::get(child, netuid); assert!(parents.is_empty()); }); } @@ -553,10 +553,10 @@ fn test_do_schedule_children_multiple_success() { assert_eq!(children, vec![(proportion1, child1), (proportion2, child2)]); // Verify parent assignment for both children - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert_eq!(parents1, vec![(proportion1, hotkey)]); - let parents2 = SubtensorModule::get_parents(&child2, netuid); + let parents2 = ParentKeys::::get(child2, netuid); assert_eq!(parents2, vec![(proportion2, hotkey)]); }); } @@ -719,14 +719,14 @@ fn test_do_schedule_children_multiple_old_children_cleanup() { ); // Verify old child is removed - let old_child_parents = SubtensorModule::get_parents(&old_child, netuid); + let old_child_parents = ParentKeys::::get(old_child, netuid); assert!(old_child_parents.is_empty()); // Verify new children assignment - let new_child1_parents = SubtensorModule::get_parents(&new_child1, netuid); + let new_child1_parents = ParentKeys::::get(new_child1, netuid); assert_eq!(new_child1_parents, vec![(proportion, hotkey)]); - let new_child2_parents = SubtensorModule::get_parents(&new_child2, netuid); + let new_child2_parents = ParentKeys::::get(new_child2, netuid); assert_eq!(new_child2_parents, vec![(proportion, hotkey)]); }); } @@ -818,13 +818,13 @@ fn test_do_schedule_children_multiple_overwrite_existing() { ); // Verify parent assignment for all children - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert!(parents1.is_empty()); - let parents2 = SubtensorModule::get_parents(&child2, netuid); + let parents2 = ParentKeys::::get(child2, netuid); assert_eq!(parents2, vec![(proportion * 2, hotkey)]); - let parents3 = SubtensorModule::get_parents(&child3, netuid); + let parents3 = ParentKeys::::get(child3, netuid); assert_eq!(parents3, vec![(proportion * 3, hotkey)]); }); } @@ -1152,10 +1152,10 @@ fn test_do_revoke_children_multiple_success() { assert!(children.is_empty()); // Verify parent removal for both children - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert!(parents1.is_empty()); - let parents2 = SubtensorModule::get_parents(&child2, netuid); + let parents2 = ParentKeys::::get(child2, netuid); assert!(parents2.is_empty()); }); } @@ -1268,11 +1268,11 @@ fn test_do_revoke_children_multiple_partial_revocation() { assert_eq!(children, vec![(proportion, child1), (proportion, child2)]); // Verify parents. - let parents1 = SubtensorModule::get_parents(&child3, netuid); + let parents1 = ParentKeys::::get(child3, netuid); assert!(parents1.is_empty()); - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert_eq!(parents1, vec![(proportion, hotkey)]); - let parents2 = SubtensorModule::get_parents(&child2, netuid); + let parents2 = ParentKeys::::get(child2, netuid); assert_eq!(parents2, vec![(proportion, hotkey)]); }); } @@ -1311,7 +1311,7 @@ fn test_do_revoke_children_multiple_non_existent_children() { assert!(children.is_empty()); // Verify parent removal for the existing child - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert!(parents1.is_empty()); }); } @@ -1394,7 +1394,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { assert_eq!(children, vec![(proportion1, child1), (proportion3, child3)]); // Verify parent removal for child2 - let parents2 = SubtensorModule::get_parents(&child2, netuid); + let parents2 = ParentKeys::::get(child2, netuid); assert!(parents2.is_empty()); step_rate_limit(&TransactionType::SetChildren, netuid); @@ -1407,9 +1407,9 @@ fn test_do_revoke_children_multiple_complex_scenario() { assert!(children.is_empty()); // Verify parent removal for all children - let parents1 = SubtensorModule::get_parents(&child1, netuid); + let parents1 = ParentKeys::::get(child1, netuid); assert!(parents1.is_empty()); - let parents3 = SubtensorModule::get_parents(&child3, netuid); + let parents3 = ParentKeys::::get(child3, netuid); assert!(parents3.is_empty()); }); } @@ -1657,7 +1657,7 @@ fn test_get_parents_chain() { // Test get_parents for each hotkey for i in 1..num_keys { - let parents = SubtensorModule::get_parents(&hotkeys[i], netuid); + let parents = ParentKeys::::get(hotkeys[i], netuid); log::info!( "Testing get_parents for hotkey {}: {:?}", hotkeys[i], @@ -1678,7 +1678,7 @@ fn test_get_parents_chain() { } // Test get_parents for the root (should be empty) - let root_parents = SubtensorModule::get_parents(&hotkeys[0], netuid); + let root_parents = ParentKeys::::get(hotkeys[0], netuid); log::info!( "Testing get_parents for root hotkey {}: {:?}", hotkeys[0], @@ -1714,7 +1714,7 @@ fn test_get_parents_chain() { proportion / 2 ); - let last_hotkey_parents = SubtensorModule::get_parents(&last_hotkey, netuid); + let last_hotkey_parents = ParentKeys::::get(last_hotkey, netuid); log::info!( "Testing get_parents for last hotkey {} with multiple parents: {:?}", last_hotkey, @@ -2340,7 +2340,7 @@ fn test_dynamic_parent_child_relationships() { // child1: 1/4 of parent's stake // child2: 1/3 of parent's stake - let child1_parents: Vec<(u64, U256)> = SubtensorModule::get_parents(&child1, netuid); + let child1_parents: Vec<(u64, U256)> = ParentKeys::::get(child1, netuid); assert_eq!( child1_parents, vec![(u64::MAX / 4, parent)], @@ -2349,7 +2349,7 @@ fn test_dynamic_parent_child_relationships() { // Child1-parent relationship: // parent: 1/4 of child1's stake - let child2_parents: Vec<(u64, U256)> = SubtensorModule::get_parents(&child2, netuid); + let child2_parents: Vec<(u64, U256)> = ParentKeys::::get(child2, netuid); assert_eq!( child2_parents, vec![(u64::MAX / 3, parent)], @@ -2694,11 +2694,11 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { ); log::info!( "Child1's parents: {:?}", - SubtensorModule::get_parents(&child1, netuid) + ParentKeys::::get(child1, netuid) ); log::info!( "Child2's parents: {:?}", - SubtensorModule::get_parents(&child2, netuid) + ParentKeys::::get(child2, netuid) ); let parent_stake_1 = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); @@ -2726,7 +2726,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { ); log::info!( "Grandchild's parents: {:?}", - SubtensorModule::get_parents(&grandchild, netuid) + ParentKeys::::get(grandchild, netuid) ); let parent_stake_2 = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); @@ -2765,11 +2765,11 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { ); log::info!( "Child1's parents: {:?}", - SubtensorModule::get_parents(&child1, netuid) + ParentKeys::::get(child1, netuid) ); log::info!( "Child2's parents: {:?}", - SubtensorModule::get_parents(&child2, netuid) + ParentKeys::::get(child2, netuid) ); log::info!( "Child1's children: {:?}", @@ -2777,7 +2777,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { ); log::info!( "Grandchild's parents: {:?}", - SubtensorModule::get_parents(&grandchild, netuid) + ParentKeys::::get(grandchild, netuid) ); // Check if the parent-child relationships are correct @@ -2787,12 +2787,12 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { "Parent should have both children" ); assert_eq!( - SubtensorModule::get_parents(&child1, netuid), + ParentKeys::::get(child1, netuid), vec![(u64::MAX / 2, parent)], "Child1 should have parent as its parent" ); assert_eq!( - SubtensorModule::get_parents(&child2, netuid), + ParentKeys::::get(child2, netuid), vec![(u64::MAX / 2, parent)], "Child2 should have parent as its parent" ); @@ -2802,7 +2802,7 @@ fn test_get_stake_for_hotkey_on_subnet_complex_hierarchy() { "Child1 should have grandchild as its child" ); assert_eq!( - SubtensorModule::get_parents(&grandchild, netuid), + ParentKeys::::get(grandchild, netuid), vec![(u64::MAX, child1)], "Grandchild should have child1 as its parent" ); From 3ed0df6e194c74e3e22450d950048945acf0a0a2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 20:19:54 +0100 Subject: [PATCH 077/137] Remove get_pending_emission from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/coinbase.rs | 70 ++++++++++++------------- pallets/subtensor/src/tests/root.rs | 42 +++++++-------- pallets/subtensor/src/utils/misc.rs | 3 -- 3 files changed, 53 insertions(+), 62 deletions(-) diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 55ab19520..9fb4251f5 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -5,7 +5,7 @@ use frame_support::assert_ok; use sp_core::U256; use substrate_fixed::types::I64F64; -use crate::{HotkeyEmissionTempo, TargetStakesPerInterval}; +use crate::{HotkeyEmissionTempo, PendingEmission, TargetStakesPerInterval}; // Test the ability to hash all sorts of hotkeys. #[test] @@ -74,7 +74,7 @@ fn test_coinbase_basic() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 1000); // Subnet has no pending emission. - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); // Step block next_block(); @@ -86,13 +86,13 @@ fn test_coinbase_basic() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 1000); // Subnet has no pending emission of 1 ( from coinbase ) - assert_eq!(SubtensorModule::get_pending_emission(netuid), 1); + assert_eq!(PendingEmission::::get(netuid), 1); // Step block releases next_block(); // Subnet pending has been drained. - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); // Hotkey pending immediately drained. assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); @@ -110,7 +110,7 @@ fn test_coinbase_basic() { next_block(); // Subnet pending increased by 1 - assert_eq!(SubtensorModule::get_pending_emission(netuid), 1); + assert_eq!(PendingEmission::::get(netuid), 1); // Hotkey pending not increased (still on subnet) assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); @@ -125,7 +125,7 @@ fn test_coinbase_basic() { next_block(); // Subnet pending has been drained. - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); // Hotkey pending drained. assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); @@ -325,7 +325,7 @@ fn test_coinbase_nominator_drainage_overflow() { SubtensorModule::get_total_stake_for_hotkey(&hotkey), initial_stake * 2 ); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -335,14 +335,14 @@ fn test_coinbase_nominator_drainage_overflow() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), to_emit); + assert_eq!(PendingEmission::::get(netuid), to_emit); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -474,7 +474,7 @@ fn test_coinbase_nominator_drainage_no_deltas() { assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -484,14 +484,14 @@ fn test_coinbase_nominator_drainage_no_deltas() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 10); + assert_eq!(PendingEmission::::get(netuid), 10); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -624,7 +624,7 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200 + 123 ); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -634,14 +634,14 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 10); + assert_eq!(PendingEmission::::get(netuid), 10); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -782,7 +782,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200 - 12 ); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -792,14 +792,14 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 10); + assert_eq!(PendingEmission::::get(netuid), 10); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -945,7 +945,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -955,14 +955,14 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 10); + assert_eq!(PendingEmission::::get(netuid), 10); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -1127,7 +1127,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { SubtensorModule::get_total_stake_for_hotkey(&hotkey), u64::try_from(200 + net_change).unwrap() ); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -1137,14 +1137,14 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 10); + assert_eq!(PendingEmission::::get(netuid), 10); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -1329,7 +1329,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { SubtensorModule::get_total_stake_for_hotkey(&hotkey), u64::try_from(600 + net_change).unwrap() ); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -1339,14 +1339,14 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { // 7. Simulate blocks and check emissions next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), to_emit); + assert_eq!(PendingEmission::::get(netuid), to_emit); log::debug!( "After first block, pending emission: {}", - SubtensorModule::get_pending_emission(netuid) + PendingEmission::::get(netuid) ); next_block(); - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); log::debug!("After second block, pending emission drained"); @@ -1478,7 +1478,7 @@ fn test_emission_with_registration_disabled_subnet() { assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); // Verify initial emission state is zero - assert_eq!(SubtensorModule::get_pending_emission(netuid), 0); + assert_eq!(PendingEmission::::get(netuid), 0); assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); // Advance chain by 100 blocks diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 3fb13acb0..25d50fc43 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -7,8 +7,8 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ - migrations, utils::rate_limiting::TransactionType, Error, NetworkRateLimit, SubnetIdentities, - SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, TotalNetworks, + migrations, utils::rate_limiting::TransactionType, Error, NetworkRateLimit, PendingEmission, + SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, TotalNetworks, }; #[allow(dead_code)] @@ -307,24 +307,18 @@ fn test_root_set_weights() { log::debug!( "check pending emission for netuid {} has pending {}", netuid, - SubtensorModule::get_pending_emission(netuid as u16) - ); - assert_eq!( - SubtensorModule::get_pending_emission(netuid as u16), - 199_999_998 + PendingEmission::::get(netuid as u16) ); + assert_eq!(PendingEmission::::get(netuid as u16), 199_999_998); } step_block(1); for netuid in 1..n { log::debug!( "check pending emission for netuid {} has pending {}", netuid, - SubtensorModule::get_pending_emission(netuid as u16) - ); - assert_eq!( - SubtensorModule::get_pending_emission(netuid as u16), - 299_999_997 + PendingEmission::::get(netuid as u16) ); + assert_eq!(PendingEmission::::get(netuid as u16), 299_999_997); } let step = SubtensorModule::blocks_until_next_epoch( 10, @@ -332,7 +326,7 @@ fn test_root_set_weights() { SubtensorModule::get_current_block_as_u64(), ); step_block(step as u16); - assert_eq!(SubtensorModule::get_pending_emission(10), 0); + assert_eq!(PendingEmission::::get(10), 0); }); } @@ -424,9 +418,9 @@ fn test_root_set_weights_out_of_order_netuids() { log::debug!( "check pending emission for netuid {} has pending {}", netuid, - SubtensorModule::get_pending_emission(*netuid) + PendingEmission::::get(*netuid) ); - assert_eq!(SubtensorModule::get_pending_emission(*netuid), 199_999_998); + assert_eq!(PendingEmission::::get(*netuid), 199_999_998); } step_block(1); for netuid in subnets.iter() { @@ -437,9 +431,9 @@ fn test_root_set_weights_out_of_order_netuids() { log::debug!( "check pending emission for netuid {} has pending {}", netuid, - SubtensorModule::get_pending_emission(*netuid) + PendingEmission::::get(*netuid) ); - assert_eq!(SubtensorModule::get_pending_emission(*netuid), 299_999_997); + assert_eq!(PendingEmission::::get(*netuid), 299_999_997); } let step = SubtensorModule::blocks_until_next_epoch( 9, @@ -447,7 +441,7 @@ fn test_root_set_weights_out_of_order_netuids() { SubtensorModule::get_current_block_as_u64(), ); step_block(step as u16); - assert_eq!(SubtensorModule::get_pending_emission(9), 0); + assert_eq!(PendingEmission::::get(9), 0); }); } @@ -611,12 +605,12 @@ fn test_network_pruning() { assert_eq!(SubtensorModule::get_subnet_emission_value(4), 50_857_187); assert_eq!(SubtensorModule::get_subnet_emission_value(5), 3_530_356); step_block(1); - assert_eq!(SubtensorModule::get_pending_emission(0), 0); // root network gets no pending emission. - assert_eq!(SubtensorModule::get_pending_emission(1), 249_435_914); - assert_eq!(SubtensorModule::get_pending_emission(2), 0); // This has been drained. - assert_eq!(SubtensorModule::get_pending_emission(3), 129_362_980); - assert_eq!(SubtensorModule::get_pending_emission(4), 0); // This network has been drained. - assert_eq!(SubtensorModule::get_pending_emission(5), 3_530_356); + assert_eq!(PendingEmission::::get(0), 0); // root network gets no pending emission. + assert_eq!(PendingEmission::::get(1), 249_435_914); + assert_eq!(PendingEmission::::get(2), 0); // This has been drained. + assert_eq!(PendingEmission::::get(3), 129_362_980); + assert_eq!(PendingEmission::::get(4), 0); // This network has been drained. + assert_eq!(PendingEmission::::get(5), 3_530_356); step_block(1); }); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 684077633..a07dd9e08 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -224,9 +224,6 @@ impl Pallet { pub fn get_tempo(netuid: u16) -> u16 { Tempo::::get(netuid) } - pub fn get_pending_emission(netuid: u16) -> u64 { - PendingEmission::::get(netuid) - } pub fn get_registrations_this_block(netuid: u16) -> u16 { RegistrationsThisBlock::::get(netuid) From c80ae381f76d20fb08498b8567628d8fc4b51cba Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 20:30:52 +0100 Subject: [PATCH 078/137] Remove get_pending_hotkey_emission from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/children.rs | 6 ++-- pallets/subtensor/src/tests/coinbase.rs | 46 +++++++++++++------------ pallets/subtensor/src/utils/misc.rs | 4 --- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 01f1af07b..552add3cc 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -2120,9 +2120,9 @@ fn test_parent_child_chain_emission() { } // Log PendingEmission Tuple for a, b, c - let pending_emission_a = SubtensorModule::get_pending_hotkey_emission(&hotkey_a); - let pending_emission_b = SubtensorModule::get_pending_hotkey_emission(&hotkey_b); - let pending_emission_c = SubtensorModule::get_pending_hotkey_emission(&hotkey_c); + let pending_emission_a = PendingdHotkeyEmission::::get(hotkey_a); + let pending_emission_b = PendingdHotkeyEmission::::get(hotkey_b); + let pending_emission_c = PendingdHotkeyEmission::::get(hotkey_c); log::info!("Pending Emission for A: {:?}", pending_emission_a); log::info!("Pending Emission for B: {:?}", pending_emission_b); diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 9fb4251f5..8ba9e4c1d 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -5,7 +5,9 @@ use frame_support::assert_ok; use sp_core::U256; use substrate_fixed::types::I64F64; -use crate::{HotkeyEmissionTempo, PendingEmission, TargetStakesPerInterval}; +use crate::{ + HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, TargetStakesPerInterval, +}; // Test the ability to hash all sorts of hotkeys. #[test] @@ -68,7 +70,7 @@ fn test_coinbase_basic() { assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 1); // Hotkey has no pending emission - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has same stake assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 1000); @@ -80,7 +82,7 @@ fn test_coinbase_basic() { next_block(); // Hotkey has no pending emission - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has same stake assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 1000); @@ -95,7 +97,7 @@ fn test_coinbase_basic() { assert_eq!(PendingEmission::::get(netuid), 0); // Hotkey pending immediately drained. - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has NEW stake assert_eq!( @@ -113,7 +115,7 @@ fn test_coinbase_basic() { assert_eq!(PendingEmission::::get(netuid), 1); // Hotkey pending not increased (still on subnet) - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has same stake assert_eq!( @@ -128,7 +130,7 @@ fn test_coinbase_basic() { assert_eq!(PendingEmission::::get(netuid), 0); // Hotkey pending drained. - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has 2 new TAO. assert_eq!( @@ -320,7 +322,7 @@ fn test_coinbase_nominator_drainage_overflow() { let to_emit = 20_000e9 as u64; SubtensorModule::set_emission_values(&[netuid], vec![to_emit]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), to_emit); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), initial_stake * 2 @@ -343,7 +345,7 @@ fn test_coinbase_nominator_drainage_overflow() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -472,7 +474,7 @@ fn test_coinbase_nominator_drainage_no_deltas() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); assert_eq!(PendingEmission::::get(netuid), 0); @@ -492,7 +494,7 @@ fn test_coinbase_nominator_drainage_no_deltas() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -619,7 +621,7 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200 + 123 @@ -642,7 +644,7 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -777,7 +779,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200 - 12 @@ -800,7 +802,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -943,7 +945,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); assert_eq!(PendingEmission::::get(netuid), 0); @@ -963,7 +965,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -1122,7 +1124,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), u64::try_from(200 + net_change).unwrap() @@ -1145,7 +1147,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -1324,7 +1326,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { let to_emit = 10_000e9 as u64; SubtensorModule::set_emission_values(&[netuid], vec![to_emit]).unwrap(); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), to_emit); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), u64::try_from(600 + net_change).unwrap() @@ -1347,7 +1349,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { next_block(); assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); log::debug!("After second block, pending emission drained"); // 8. Check final stakes @@ -1479,14 +1481,14 @@ fn test_emission_with_registration_disabled_subnet() { // Verify initial emission state is zero assert_eq!(PendingEmission::::get(netuid), 0); - assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0); + assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Advance chain by 100 blocks step_block(100); // Verify no emissions were distributed after 100 blocks assert_eq!( - SubtensorModule::get_pending_hotkey_emission(&hotkey), + PendingdHotkeyEmission::::get(hotkey), 0, "Hotkey pending emission should remain zero" ); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index a07dd9e08..98f93e095 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -565,10 +565,6 @@ impl Pallet { Self::deposit_event(Event::HotkeyEmissionTempoSet(emission_tempo)); } - pub fn get_pending_hotkey_emission(hotkey: &T::AccountId) -> u64 { - PendingdHotkeyEmission::::get(hotkey) - } - /// Sets the maximum stake allowed for a given network. /// /// # Arguments From 5447afd3d402a13c909796dff7e8e9067b52fcbd Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 20:37:52 +0100 Subject: [PATCH 079/137] Remove get_pow_registrations_this_interval from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index d37cc42e5..627211cc8 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -46,7 +46,7 @@ impl Pallet { let registrations_this_interval: u16 = Self::get_registrations_this_interval(netuid); let pow_registrations_this_interval: u16 = - Self::get_pow_registrations_this_interval(netuid); + POWRegistrationsThisInterval::::get(netuid); let burn_registrations_this_interval: u16 = BurnRegistrationsThisInterval::::get(netuid); let target_registrations_this_interval: u16 = diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 98f93e095..c1ccbdcdb 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -232,9 +232,6 @@ impl Pallet { pub fn get_registrations_this_interval(netuid: u16) -> u16 { RegistrationsThisInterval::::get(netuid) } - pub fn get_pow_registrations_this_interval(netuid: u16) -> u16 { - POWRegistrationsThisInterval::::get(netuid) - } // ======================== // ===== Take checks ====== From 0d503cd9a681fcc877150b60cf20270d0e898a36 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 16 Dec 2024 21:15:57 +0100 Subject: [PATCH 080/137] Remove get_prometheus and get_pruning_score from pallet-subtensor::Pallet --- pallets/subtensor/src/rpc_info/neuron_info.rs | 4 ++-- pallets/subtensor/src/subnets/serving.rs | 16 +--------------- pallets/subtensor/src/tests/serving.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index 6ea10773b..8cbb66ab2 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -79,7 +79,7 @@ impl Pallet { let axon_info = Axons::::get(netuid, &hotkey).unwrap_or_default(); - let prometheus_info = Self::get_prometheus_info(netuid, &hotkey); + let prometheus_info = Prometheus::::get(netuid, &hotkey).unwrap_or_default(); let coldkey = Owner::::get(hotkey.clone()).clone(); @@ -162,7 +162,7 @@ impl Pallet { let axon_info = Axons::::get(netuid, &hotkey).unwrap_or_default(); - let prometheus_info = Self::get_prometheus_info(netuid, &hotkey); + let prometheus_info = Prometheus::::get(netuid, &hotkey).unwrap_or_default(); let coldkey = Owner::::get(&hotkey).clone(); diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index 19027526d..e95d22dfc 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -191,7 +191,7 @@ impl Pallet { ); // We get the previous axon info assoicated with this ( netuid, uid ) - let mut prev_prometheus = Self::get_prometheus_info(netuid, &hotkey_id); + let mut prev_prometheus = Prometheus::::get(netuid, &hotkey_id).unwrap_or_default(); let current_block: u64 = Self::get_current_block_as_u64(); ensure!( Self::prometheus_passes_rate_limit(netuid, &prev_prometheus, current_block), @@ -247,20 +247,6 @@ impl Pallet { rate_limit == 0 || last_serve == 0 || current_block.saturating_sub(last_serve) >= rate_limit } - pub fn get_prometheus_info(netuid: u16, hotkey: &T::AccountId) -> PrometheusInfoOf { - if let Some(prometheus) = Prometheus::::get(netuid, hotkey) { - prometheus - } else { - PrometheusInfo { - block: 0, - version: 0, - ip: 0, - port: 0, - ip_type: 0, - } - } - } - pub fn is_valid_ip_type(ip_type: u8) -> bool { let allowed_values = [4, 6]; allowed_values.contains(&ip_type) diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index 01fcd8522..6074e57ed 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -384,7 +384,7 @@ fn test_prometheus_serving_ok() { port, ip_type )); - let neuron = SubtensorModule::get_prometheus_info(netuid, &hotkey_account_id); + let neuron = Prometheus::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip); assert_eq!(neuron.version, version); assert_eq!(neuron.port, port); @@ -413,7 +413,7 @@ fn test_prometheus_serving_set_metadata_update() { port, ip_type )); - let neuron = SubtensorModule::get_prometheus_info(netuid, &hotkey_account_id); + let neuron = Prometheus::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip); assert_eq!(neuron.version, version); assert_eq!(neuron.port, port); @@ -430,7 +430,7 @@ fn test_prometheus_serving_set_metadata_update() { port2, ip_type2 )); - let neuron = SubtensorModule::get_prometheus_info(netuid, &hotkey_account_id); + let neuron = Prometheus::::get(netuid, hotkey_account_id).unwrap_or_default(); assert_eq!(neuron.ip, ip2); assert_eq!(neuron.version, version2); assert_eq!(neuron.port, port2); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index c1ccbdcdb..745e3bfa3 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -75,9 +75,6 @@ impl Pallet { Trust::::get(netuid) } - pub fn get_pruning_score(netuid: u16) -> Vec { - PruningScores::::get(netuid) - } pub fn get_validator_trust(netuid: u16) -> Vec { ValidatorTrust::::get(netuid) } From 4fc7683db5e74ed7194164f71702da4be35dffbf Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 13:46:15 +0100 Subject: [PATCH 081/137] Remove get_rank from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 745e3bfa3..7c324338a 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -68,9 +68,6 @@ impl Pallet { // ============================== // ==== YumaConsensus params ==== // ============================== - pub fn get_rank(netuid: u16) -> Vec { - Rank::::get(netuid) - } pub fn get_trust(netuid: u16) -> Vec { Trust::::get(netuid) } From d20c519e8adceedd7ccd3d39f94f28b25909e8b6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 14:04:55 +0100 Subject: [PATCH 082/137] Remove get_registrations_this_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 4 ++-- pallets/subtensor/src/tests/difficulty.rs | 15 ++++++------ pallets/subtensor/src/tests/epoch.rs | 10 ++++---- pallets/subtensor/src/tests/registration.rs | 24 +++++++++---------- pallets/subtensor/src/utils/misc.rs | 4 ---- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index b12cc9c73..4426930bd 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -454,7 +454,7 @@ impl Pallet { // --- 2. Ensure that the number of registrations in this block doesn't exceed the allowed limit. ensure!( - Self::get_registrations_this_block(root_netuid) + RegistrationsThisBlock::::get(root_netuid) < MaxRegistrationsPerBlock::::get(root_netuid), Error::::TooManyRegistrationsThisBlock ); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 5ec65d556..727677b15 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -66,7 +66,7 @@ impl Pallet { // --- 4. Ensure we are not exceeding the max allowed registrations per block. ensure!( - Self::get_registrations_this_block(netuid) < MaxRegistrationsPerBlock::::get(netuid), + RegistrationsThisBlock::::get(netuid) < MaxRegistrationsPerBlock::::get(netuid), Error::::TooManyRegistrationsThisBlock ); @@ -250,7 +250,7 @@ impl Pallet { // --- 4. Ensure we are not exceeding the max allowed registrations per block. ensure!( - Self::get_registrations_this_block(netuid) < MaxRegistrationsPerBlock::::get(netuid), + RegistrationsThisBlock::::get(netuid) < MaxRegistrationsPerBlock::::get(netuid), Error::::TooManyRegistrationsThisBlock ); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 67a8e5a28..2001ec301 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -5,7 +5,8 @@ use sp_core::U256; use super::mock::*; use crate::{ AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, - MaxRegistrationsPerBlock, MinDifficulty, NetworkRegistrationAllowed, SubnetworkN, + MaxRegistrationsPerBlock, MinDifficulty, NetworkRegistrationAllowed, RegistrationsThisBlock, + SubnetworkN, }; #[test] @@ -19,7 +20,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::set_min_difficulty(netuid, 10000); assert_eq!(Difficulty::::get(netuid), 10000); // Check initial difficulty. assert_eq!(LastAdjustmentBlock::::get(netuid), 0); // Last adjustment block starts at 0. - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // No registrations this block. + assert_eq!(RegistrationsThisBlock::::get(netuid), 0); // No registrations this block. SubtensorModule::set_adjustment_alpha(netuid, 58000); SubtensorModule::set_target_registrations_per_interval(netuid, 2); SubtensorModule::set_adjustment_interval(netuid, 100); @@ -66,13 +67,13 @@ fn test_registration_difficulty_adjustment() { ); assert_eq!(SubnetworkN::::get(netuid), 3); // All 3 are registered. - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 3); // 3 Registrations. + assert_eq!(RegistrationsThisBlock::::get(netuid), 3); // 3 Registrations. assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // 3 Registrations this interval. // Fast forward 1 block. assert_eq!(Difficulty::::get(netuid), 20000); // Difficulty is unchanged. step_block(1); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // Registrations have been erased. + assert_eq!(RegistrationsThisBlock::::get(netuid), 0); // Registrations have been erased. // TODO: are we OK with this change? assert_eq!(LastAdjustmentBlock::::get(netuid), 2); // We just adjusted on the first block. @@ -106,7 +107,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::get_hotkey_for_net_and_uid(netuid, 2).unwrap(), hotkey2 + 1 ); // replace 2 - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 3); // Registrations have been erased. + assert_eq!(RegistrationsThisBlock::::get(netuid), 3); // Registrations have been erased. assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // Registrations this interval = 3 step_block(1); // Step @@ -114,14 +115,14 @@ fn test_registration_difficulty_adjustment() { // TODO: are we OK with this change? assert_eq!(LastAdjustmentBlock::::get(netuid), 2); // Still previous adjustment block. - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // Registrations have been erased. + assert_eq!(RegistrationsThisBlock::::get(netuid), 0); // Registrations have been erased. assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // Registrations this interval = 3 // Register 3 more. register_ok_neuron(netuid, hotkey0 + 2, coldkey0 + 2, 394208420); register_ok_neuron(netuid, hotkey1 + 2, coldkey1 + 2, 124123920); register_ok_neuron(netuid, hotkey2 + 2, coldkey2 + 2, 218131230); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 3); // Registrations have been erased. + assert_eq!(RegistrationsThisBlock::::get(netuid), 3); // Registrations have been erased. // We have 6 registrations this adjustment interval. step_block(1); // Step diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 63c07ac17..655907cce 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -1730,7 +1730,7 @@ fn test_outdated_weights() { SubtensorModule::set_target_registrations_per_interval(netuid, n); SubtensorModule::set_min_allowed_weights(netuid, 0); SubtensorModule::set_max_weight_limit(netuid, u16::MAX); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); + assert_eq!(RegistrationsThisBlock::::get(netuid), 0); // === Register [validator1, validator2, server1, server2] for key in 0..n as u64 { @@ -1757,15 +1757,15 @@ fn test_outdated_weights() { ); } assert_eq!(SubnetworkN::::get(netuid), n); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 4); + assert_eq!(RegistrationsThisBlock::::get(netuid), 4); // === Issue validator permits SubtensorModule::set_max_allowed_validators(netuid, n); assert_eq!(MaxAllowedValidators::::get(netuid), n); SubtensorModule::epoch(netuid, 1_000_000_000); // run first epoch to set allowed validators - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 4); + assert_eq!(RegistrationsThisBlock::::get(netuid), 4); block_number = next_block(); // run to next block to ensure weights are set on nodes after their registration block - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); + assert_eq!(RegistrationsThisBlock::::get(netuid), 0); // === Set weights [val1->srv1: 2/3, val1->srv2: 1/3, val2->srv1: 2/3, val2->srv2: 1/3, srv1->srv1: 1, srv2->srv2: 1] for uid in 0..(n / 2) as u64 { @@ -1829,7 +1829,7 @@ fn test_outdated_weights() { ); assert_eq!(System::block_number(), block_number); assert_eq!(MaxRegistrationsPerBlock::::get(netuid), n); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); + assert_eq!(RegistrationsThisBlock::::get(netuid), 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(new_key)), netuid, diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index f4b6bd5ac..c7345f0a9 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -12,8 +12,8 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, - MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, SubnetworkN, - SubtensorSignedExtension, + MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, + RegistrationsThisBlock, SubnetworkN, SubtensorSignedExtension, }; /******************************************** @@ -732,7 +732,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(0), U256::from(0) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 1); + assert_eq!(RegistrationsThisBlock::::get(netuid), 1); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(1)), netuid, @@ -742,7 +742,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(1), U256::from(1) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 2); + assert_eq!(RegistrationsThisBlock::::get(netuid), 2); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(2)), netuid, @@ -752,7 +752,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(2), U256::from(2) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 3); + assert_eq!(RegistrationsThisBlock::::get(netuid), 3); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(3)), netuid, @@ -762,7 +762,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(3), U256::from(3) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 4); + assert_eq!(RegistrationsThisBlock::::get(netuid), 4); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(4)), netuid, @@ -772,7 +772,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(4), U256::from(4) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 5); + assert_eq!(RegistrationsThisBlock::::get(netuid), 5); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(5)), netuid, @@ -782,7 +782,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(5), U256::from(5) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 6); + assert_eq!(RegistrationsThisBlock::::get(netuid), 6); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(6)), netuid, @@ -792,7 +792,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(6), U256::from(6) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 7); + assert_eq!(RegistrationsThisBlock::::get(netuid), 7); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(7)), netuid, @@ -802,7 +802,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(7), U256::from(7) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 8); + assert_eq!(RegistrationsThisBlock::::get(netuid), 8); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(8)), netuid, @@ -812,7 +812,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(8), U256::from(8) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 9); + assert_eq!(RegistrationsThisBlock::::get(netuid), 9); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(9)), netuid, @@ -822,7 +822,7 @@ fn test_registration_too_many_registrations_per_block() { U256::from(9), U256::from(9) )); - assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 10); + assert_eq!(RegistrationsThisBlock::::get(netuid), 10); let result = SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(10)), netuid, diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 7c324338a..65b2d0495 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -219,10 +219,6 @@ impl Pallet { Tempo::::get(netuid) } - pub fn get_registrations_this_block(netuid: u16) -> u16 { - RegistrationsThisBlock::::get(netuid) - } - pub fn get_registrations_this_interval(netuid: u16) -> u16 { RegistrationsThisInterval::::get(netuid) } From a7a56fc5fa98a61d27f98c48a473ba79a9537e72 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 14:20:56 +0100 Subject: [PATCH 083/137] Remove get_registrations_this_interval from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 3 +- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/lib.rs | 3 +- pallets/subtensor/src/subnets/registration.rs | 4 +- pallets/subtensor/src/tests/difficulty.rs | 16 +++---- pallets/subtensor/src/tests/registration.rs | 46 +++++++++---------- pallets/subtensor/src/utils/misc.rs | 4 -- 7 files changed, 36 insertions(+), 42 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 627211cc8..379a79af4 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -43,8 +43,7 @@ impl Pallet { // --- 4. Get the current counters for this network w.r.t burn and difficulty values. let current_burn: u64 = Burn::::get(netuid); let current_difficulty: u64 = Difficulty::::get(netuid); - let registrations_this_interval: u16 = - Self::get_registrations_this_interval(netuid); + let registrations_this_interval: u16 = RegistrationsThisInterval::::get(netuid); let pow_registrations_this_interval: u16 = POWRegistrationsThisInterval::::get(netuid); let burn_registrations_this_interval: u16 = diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 4426930bd..43c44d441 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -461,7 +461,7 @@ impl Pallet { // --- 3. Ensure that the number of registrations in this interval doesn't exceed thrice the target limit. ensure!( - Self::get_registrations_this_interval(root_netuid) + RegistrationsThisInterval::::get(root_netuid) < Self::get_target_registrations_per_interval(root_netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index d1679a945..c52f89f1e 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1559,8 +1559,7 @@ where ..Default::default() }), Some(Call::register { netuid, .. } | Call::burned_register { netuid, .. }) => { - let registrations_this_interval = - Pallet::::get_registrations_this_interval(*netuid); + let registrations_this_interval = RegistrationsThisInterval::::get(*netuid); let max_registrations_per_interval = Pallet::::get_target_registrations_per_interval(*netuid); if registrations_this_interval >= (max_registrations_per_interval.saturating_mul(3)) diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 727677b15..4602694b0 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -72,7 +72,7 @@ impl Pallet { // --- 4. Ensure we are not exceeding the max allowed registrations per interval. ensure!( - Self::get_registrations_this_interval(netuid) + RegistrationsThisInterval::::get(netuid) < Self::get_target_registrations_per_interval(netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); @@ -256,7 +256,7 @@ impl Pallet { // --- 5. Ensure we are not exceeding the max allowed registrations per interval. ensure!( - Self::get_registrations_this_interval(netuid) + RegistrationsThisInterval::::get(netuid) < Self::get_target_registrations_per_interval(netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 2001ec301..e9e744dd7 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -6,7 +6,7 @@ use super::mock::*; use crate::{ AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, MaxRegistrationsPerBlock, MinDifficulty, NetworkRegistrationAllowed, RegistrationsThisBlock, - SubnetworkN, + RegistrationsThisInterval, SubnetworkN, }; #[test] @@ -68,7 +68,7 @@ fn test_registration_difficulty_adjustment() { assert_eq!(SubnetworkN::::get(netuid), 3); // All 3 are registered. assert_eq!(RegistrationsThisBlock::::get(netuid), 3); // 3 Registrations. - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // 3 Registrations this interval. + assert_eq!(RegistrationsThisInterval::::get(netuid), 3); // 3 Registrations this interval. // Fast forward 1 block. assert_eq!(Difficulty::::get(netuid), 20000); // Difficulty is unchanged. @@ -79,7 +79,7 @@ fn test_registration_difficulty_adjustment() { assert_eq!(LastAdjustmentBlock::::get(netuid), 2); // We just adjusted on the first block. assert_eq!(Difficulty::::get(netuid), 40000); // Difficulty is increased ( 20000 * ( 3 + 1 ) / ( 1 + 1 ) ) = 80_000 - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 0); // Registrations this interval has been wiped. + assert_eq!(RegistrationsThisInterval::::get(netuid), 0); // Registrations this interval has been wiped. // Lets change the adjustment interval SubtensorModule::set_adjustment_interval(netuid, 3); @@ -108,7 +108,7 @@ fn test_registration_difficulty_adjustment() { hotkey2 + 1 ); // replace 2 assert_eq!(RegistrationsThisBlock::::get(netuid), 3); // Registrations have been erased. - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // Registrations this interval = 3 + assert_eq!(RegistrationsThisInterval::::get(netuid), 3); // Registrations this interval = 3 step_block(1); // Step @@ -116,7 +116,7 @@ fn test_registration_difficulty_adjustment() { assert_eq!(LastAdjustmentBlock::::get(netuid), 2); // Still previous adjustment block. assert_eq!(RegistrationsThisBlock::::get(netuid), 0); // Registrations have been erased. - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); // Registrations this interval = 3 + assert_eq!(RegistrationsThisInterval::::get(netuid), 3); // Registrations this interval = 3 // Register 3 more. register_ok_neuron(netuid, hotkey0 + 2, coldkey0 + 2, 394208420); @@ -126,11 +126,11 @@ fn test_registration_difficulty_adjustment() { // We have 6 registrations this adjustment interval. step_block(1); // Step - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 6); // Registrations this interval = 6 + assert_eq!(RegistrationsThisInterval::::get(netuid), 6); // Registrations this interval = 6 assert_eq!(Difficulty::::get(netuid), 40000); // Difficulty unchanged. step_block(1); // Step assert_eq!(Difficulty::::get(netuid), 60_000); // Difficulty changed ( 40000 ) * ( 6 + 3 / 3 + 3 ) = 40000 * 1.5 = 60_000 - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 0); // Registrations this interval drops to 0. + assert_eq!(RegistrationsThisInterval::::get(netuid), 0); // Registrations this interval drops to 0. // Test min value. SubtensorModule::set_min_difficulty(netuid, 1); @@ -155,7 +155,7 @@ fn test_registration_difficulty_adjustment() { register_ok_neuron(netuid, hotkey1 + 3, coldkey1 + 3, 824123920); register_ok_neuron(netuid, hotkey2 + 3, coldkey2 + 3, 324123920); register_ok_neuron(netuid, hotkey2 + 4, coldkey2 + 4, 524123920); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 4); + assert_eq!(RegistrationsThisInterval::::get(netuid), 4); assert_eq!( SubtensorModule::get_target_registrations_per_interval(netuid), 3 diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index c7345f0a9..e5c67ff33 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -13,7 +13,7 @@ use super::mock::*; use crate::{ Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, - RegistrationsThisBlock, SubnetworkN, SubtensorSignedExtension, + RegistrationsThisBlock, RegistrationsThisInterval, SubnetworkN, SubtensorSignedExtension, }; /******************************************** @@ -234,7 +234,7 @@ fn test_registration_under_limit() { coldkey_account_id )); - let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); + let current_registrants = RegistrationsThisInterval::::get(netuid); let target_registrants = SubtensorModule::get_target_registrations_per_interval(netuid); assert!(current_registrants <= target_registrants); }); @@ -276,7 +276,7 @@ fn test_registration_rate_limit_exceeded() { // Expectation: The transaction should be rejected assert_err!(result, InvalidTransaction::Custom(5)); - let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); + let current_registrants = RegistrationsThisInterval::::get(netuid); assert!(current_registrants <= max_registrants); }); } @@ -324,7 +324,7 @@ fn test_burned_registration_under_limit() { hotkey_account_id, )); - let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); + let current_registrants = RegistrationsThisInterval::::get(netuid); assert!(current_registrants <= max_registrants); }); } @@ -358,7 +358,7 @@ fn test_burned_registration_rate_limit_exceeded() { // Expectation: The transaction should be rejected assert_err!(burned_register_result, InvalidTransaction::Custom(5)); - let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); + let current_registrants = RegistrationsThisInterval::::get(netuid); assert!(current_registrants <= max_registrants); }); } @@ -406,7 +406,7 @@ fn test_burned_registration_rate_allows_burn_adjustment() { hotkey_account_id )); - let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); + let current_registrants = RegistrationsThisInterval::::get(netuid); assert!(current_registrants > target_registrants); // Should be able to register more than the target }); } @@ -928,7 +928,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(0), U256::from(0) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 1); + assert_eq!(RegistrationsThisInterval::::get(netuid), 1); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(1)), netuid, @@ -938,7 +938,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(1), U256::from(1) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 2); + assert_eq!(RegistrationsThisInterval::::get(netuid), 2); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(2)), netuid, @@ -948,7 +948,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(2), U256::from(2) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 3); + assert_eq!(RegistrationsThisInterval::::get(netuid), 3); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(3)), netuid, @@ -958,7 +958,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(3), U256::from(3) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 4); + assert_eq!(RegistrationsThisInterval::::get(netuid), 4); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(4)), netuid, @@ -968,7 +968,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(4), U256::from(4) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 5); + assert_eq!(RegistrationsThisInterval::::get(netuid), 5); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(5)), netuid, @@ -978,7 +978,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(5), U256::from(5) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 6); + assert_eq!(RegistrationsThisInterval::::get(netuid), 6); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(6)), netuid, @@ -988,7 +988,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(6), U256::from(6) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 7); + assert_eq!(RegistrationsThisInterval::::get(netuid), 7); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(7)), netuid, @@ -998,7 +998,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(7), U256::from(7) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 8); + assert_eq!(RegistrationsThisInterval::::get(netuid), 8); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(8)), netuid, @@ -1008,7 +1008,7 @@ fn test_registration_too_many_registrations_per_interval() { U256::from(8), U256::from(8) )); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 9); + assert_eq!(RegistrationsThisInterval::::get(netuid), 9); let result = SubtensorModule::register( <::RuntimeOrigin>::signed(U256::from(9)), netuid, @@ -1404,7 +1404,7 @@ fn test_registration_add_network_size() { coldkey_account_id )); assert_eq!(SubnetworkN::::get(netuid), 1); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid), 1); + assert_eq!(RegistrationsThisInterval::::get(netuid), 1); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id1), @@ -1425,7 +1425,7 @@ fn test_registration_add_network_size() { coldkey_account_id )); assert_eq!(SubnetworkN::::get(netuid2), 2); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid2), 2); + assert_eq!(RegistrationsThisInterval::::get(netuid2), 2); }); } @@ -1590,9 +1590,9 @@ fn test_full_pass_through() { // assert!( !SubtensorModule::get_registered_networks_for_hotkey( &hotkey2 ).contains( &netuid2 ) ); // Check the number of registrations. - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid0), 2); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid1), 2); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid2), 2); + assert_eq!(RegistrationsThisInterval::::get(netuid0), 2); + assert_eq!(RegistrationsThisInterval::::get(netuid1), 2); + assert_eq!(RegistrationsThisInterval::::get(netuid2), 2); // Get the number of uids in each network. assert_eq!(SubnetworkN::::get(netuid0), 2); @@ -1694,9 +1694,9 @@ fn test_full_pass_through() { // assert!( SubtensorModule::get_registered_networks_for_hotkey( &hotkey2 ).contains( &netuid2 ) ); // Check the registration counters. - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid0), 3); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid1), 3); - assert_eq!(SubtensorModule::get_registrations_this_interval(netuid2), 3); + assert_eq!(RegistrationsThisInterval::::get(netuid0), 3); + assert_eq!(RegistrationsThisInterval::::get(netuid1), 3); + assert_eq!(RegistrationsThisInterval::::get(netuid2), 3); // Check the hotkeys are expected. assert_eq!( diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 65b2d0495..2606d0ce0 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -219,10 +219,6 @@ impl Pallet { Tempo::::get(netuid) } - pub fn get_registrations_this_interval(netuid: u16) -> u16 { - RegistrationsThisInterval::::get(netuid) - } - // ======================== // ===== Take checks ====== // ======================== From ac7062db55741c0d09e06a18b8d75fc92184a875 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 15:21:57 +0100 Subject: [PATCH 084/137] Remove get_reveal_period from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 4 ++-- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/weights.rs | 9 +++------ pallets/subtensor/src/tests/weights.rs | 6 +++--- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index b198ae80c..69b26bc2f 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -1408,7 +1408,7 @@ fn sudo_set_commit_reveal_weights_interval() { add_network(netuid, 10); let to_be_set = 55; - let init_value = SubtensorModule::get_reveal_period(netuid); + let init_value = RevealPeriodEpochs::::get(netuid); assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval( <::RuntimeOrigin>::root(), @@ -1417,7 +1417,7 @@ fn sudo_set_commit_reveal_weights_interval() { )); assert!(init_value != to_be_set); - assert_eq!(SubtensorModule::get_reveal_period(netuid), to_be_set); + assert_eq!(RevealPeriodEpochs::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index e0ad44ffc..bef08a1e0 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -223,7 +223,7 @@ impl Pallet { // Weights revealed must have been committed during epoch `cur_epoch - reveal_period`. let reveal_epoch = - cur_epoch.saturating_sub(Self::get_reveal_period(netuid).saturating_sub(1)); + cur_epoch.saturating_sub(RevealPeriodEpochs::::get(netuid).saturating_sub(1)); // Clean expired commits for (epoch, _) in CRV3WeightCommits::::iter_prefix(netuid) { diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 142b153ad..fa1021d02 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -252,7 +252,7 @@ impl Pallet { let max_validators = MaxAllowedValidators::::get(netuid); let adjustment_alpha = AdjustmentAlpha::::get(netuid); let difficulty = Difficulty::::get(netuid); - let commit_reveal_periods = Self::get_reveal_period(netuid); + let commit_reveal_periods = RevealPeriodEpochs::::get(netuid); let commit_reveal_weights_enabled = CommitRevealWeightsEnabled::::get(netuid); let liquid_alpha_enabled = LiquidAlphaOn::::get(netuid); let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index e041ff764..9b1422a28 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -1031,7 +1031,7 @@ impl Pallet { 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); - let reveal_period: u64 = Self::get_reveal_period(netuid); + let reveal_period: u64 = RevealPeriodEpochs::::get(netuid); // Reveal is allowed only in the exact epoch `commit_epoch + reveal_period` current_epoch == commit_epoch.saturating_add(reveal_period) @@ -1050,13 +1050,13 @@ impl Pallet { 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); - let reveal_period: u64 = Self::get_reveal_period(netuid); + let reveal_period: u64 = RevealPeriodEpochs::::get(netuid); current_epoch > commit_epoch.saturating_add(reveal_period) } pub fn get_reveal_blocks(netuid: u16, commit_block: u64) -> (u64, u64) { - let reveal_period: u64 = Self::get_reveal_period(netuid); + let reveal_period: u64 = RevealPeriodEpochs::::get(netuid); let tempo: u64 = Self::get_tempo(netuid) as u64; let tempo_plus_one: u64 = tempo.saturating_add(1); let netuid_plus_one: u64 = (netuid as u64).saturating_add(1); @@ -1075,7 +1075,4 @@ impl Pallet { pub fn set_reveal_period(netuid: u16, reveal_period: u64) { RevealPeriodEpochs::::insert(netuid, reveal_period); } - pub fn get_reveal_period(netuid: u16) -> u64 { - RevealPeriodEpochs::::get(netuid) - } } diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index 71b667f4c..0f18265b6 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -29,8 +29,8 @@ use sp_core::Encode; use super::mock::*; use crate::{ - coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, SubnetworkN, - MAX_CRV3_COMMIT_SIZE_BYTES, + coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, + RevealPeriodEpochs, SubnetworkN, MAX_CRV3_COMMIT_SIZE_BYTES, }; /*************************** @@ -3942,7 +3942,7 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { Error::::NoWeightsCommitFound ); - assert_eq!(SubtensorModule::get_reveal_period(netuid), 10); + assert_eq!(RevealPeriodEpochs::::get(netuid), 10); assert_eq!(SubtensorModule::get_tempo(netuid), 200); }) } From 48f1242026ee2fc9a40d0c5ba6848b36ae375ea8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 16:12:28 +0100 Subject: [PATCH 085/137] Remove get_rho from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 69b26bc2f..ec9da2366 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -512,7 +512,7 @@ fn test_sudo_set_rho() { let netuid: u16 = 1; let to_be_set: u16 = 10; add_network(netuid, 10); - let init_value: u16 = SubtensorModule::get_rho(netuid); + let init_value: u16 = Rho::::get(netuid); assert_eq!( AdminUtils::sudo_set_rho( <::RuntimeOrigin>::signed(U256::from(1)), @@ -529,13 +529,13 @@ fn test_sudo_set_rho() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_rho(netuid), init_value); + assert_eq!(Rho::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_rho( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_rho(netuid), to_be_set); + assert_eq!(Rho::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 43c44d441..f72d279a0 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -388,7 +388,7 @@ impl Pallet { let shifted_trust = trust_score.saturating_sub(I64F64::from_num(Self::get_float_kappa(0))); // Range( -kappa, 1 - kappa ) let temperatured_trust = - shifted_trust.saturating_mul(I64F64::from_num(Self::get_rho(0))); // Range( -rho * kappa, rho ( 1 - kappa ) ) + shifted_trust.saturating_mul(I64F64::from_num(Rho::::get(0))); // Range( -rho * kappa, rho ( 1 - kappa ) ) let exponentiated_trust: I64F64 = substrate_fixed::transcendental::exp(temperatured_trust.saturating_neg()) .expect("temperatured_trust is on range( -rho * kappa, rho ( 1 - kappa ) )"); diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index fa1021d02..0ccf414d6 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -89,7 +89,7 @@ impl Pallet { return None; } - let rho = Self::get_rho(netuid); + let rho = Rho::::get(netuid); let kappa = Kappa::::get(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); @@ -159,7 +159,7 @@ impl Pallet { return None; } - let rho = Self::get_rho(netuid); + let rho = Rho::::get(netuid); let kappa = Kappa::::get(netuid); let difficulty: Compact = Difficulty::::get(netuid).into(); let immunity_period = ImmunityPeriod::::get(netuid); @@ -230,7 +230,7 @@ impl Pallet { return None; } - let rho = Self::get_rho(netuid); + let rho = Rho::::get(netuid); let kappa = Kappa::::get(netuid); let immunity_period = ImmunityPeriod::::get(netuid); let min_allowed_weights = MinAllowedWeights::::get(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 2606d0ce0..3b1433a54 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -401,9 +401,6 @@ impl Pallet { CommitRevealWeightsEnabled::::set(netuid, enabled); } - pub fn get_rho(netuid: u16) -> u16 { - Rho::::get(netuid) - } pub fn set_rho(netuid: u16, rho: u16) { Rho::::insert(netuid, rho); } From 5b6231636b1d33985573625c0345d485dbc379bd Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 16:35:22 +0100 Subject: [PATCH 086/137] Remove get_scaling_law_power from pallet-subtensor::Pallet --- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 0ccf414d6..0f6c7b85e 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -96,7 +96,7 @@ impl Pallet { let max_allowed_validators = MaxAllowedValidators::::get(netuid); let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); - let scaling_law_power = Self::get_scaling_law_power(netuid); + let scaling_law_power = ScalingLawPower::::get(netuid); let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = MaxAllowedUids::::get(netuid); let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); @@ -166,7 +166,7 @@ impl Pallet { let max_allowed_validators = MaxAllowedValidators::::get(netuid); let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); - let scaling_law_power = Self::get_scaling_law_power(netuid); + let scaling_law_power = ScalingLawPower::::get(netuid); let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = MaxAllowedUids::::get(netuid); let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 3b1433a54..e2c1f7f75 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -358,9 +358,6 @@ impl Pallet { Self::deposit_event(Event::ValidatorPruneLenSet(netuid, validator_prune_len)); } - pub fn get_scaling_law_power(netuid: u16) -> u16 { - ScalingLawPower::::get(netuid) - } 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)); From 3bba475a1f2e1c69c6f29f563c48b010fbaf9316 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 16:42:55 +0100 Subject: [PATCH 087/137] Remove get_serving_rate_limit from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/serving.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 3 --- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index ec9da2366..3f24deb78 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -41,7 +41,7 @@ fn test_sudo_set_serving_rate_limit() { new_test_ext().execute_with(|| { let netuid: u16 = 3; let to_be_set: u64 = 10; - let init_value: u64 = SubtensorModule::get_serving_rate_limit(netuid); + let init_value: u64 = ServingRateLimit::::get(netuid); assert_eq!( AdminUtils::sudo_set_serving_rate_limit( <::RuntimeOrigin>::signed(U256::from(1)), @@ -50,13 +50,13 @@ fn test_sudo_set_serving_rate_limit() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_serving_rate_limit(netuid), init_value); + assert_eq!(ServingRateLimit::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_serving_rate_limit( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_serving_rate_limit(netuid), to_be_set); + assert_eq!(ServingRateLimit::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 0f6c7b85e..92710f3b0 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -248,7 +248,7 @@ impl Pallet { let max_burn = MaxBurn::::get(netuid); let bonds_moving_avg = BondsMovingAverage::::get(netuid); let max_regs_per_block = MaxRegistrationsPerBlock::::get(netuid); - let serving_rate_limit = Self::get_serving_rate_limit(netuid); + let serving_rate_limit = ServingRateLimit::::get(netuid); let max_validators = MaxAllowedValidators::::get(netuid); let adjustment_alpha = AdjustmentAlpha::::get(netuid); let difficulty = Difficulty::::get(netuid); diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index e95d22dfc..03343d61c 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -232,7 +232,7 @@ impl Pallet { prev_axon_info: &AxonInfoOf, current_block: u64, ) -> bool { - let rate_limit: u64 = Self::get_serving_rate_limit(netuid); + let rate_limit: u64 = ServingRateLimit::::get(netuid); let last_serve = prev_axon_info.block; rate_limit == 0 || last_serve == 0 || current_block.saturating_sub(last_serve) >= rate_limit } @@ -242,7 +242,7 @@ impl Pallet { prev_prometheus_info: &PrometheusInfoOf, current_block: u64, ) -> bool { - let rate_limit: u64 = Self::get_serving_rate_limit(netuid); + let rate_limit: u64 = ServingRateLimit::::get(netuid); let last_serve = prev_prometheus_info.block; rate_limit == 0 || last_serve == 0 || current_block.saturating_sub(last_serve) >= rate_limit } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index e2c1f7f75..9b9514393 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -306,9 +306,6 @@ impl Pallet { Self::deposit_event(Event::MaxChildKeyTakeSet(take)); } - pub fn get_serving_rate_limit(netuid: u16) -> u64 { - ServingRateLimit::::get(netuid) - } 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)); From 4bc37978f1b13717769848bb4a669cdcc45b6718 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 19:36:56 +0100 Subject: [PATCH 088/137] Remove get_stake_for_coldkey_and_hotkey from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 60 ++------- .../migrate_fix_pending_emission.rs | 35 ++--- .../subtensor/src/rpc_info/delegate_info.rs | 3 +- pallets/subtensor/src/staking/helpers.rs | 8 +- pallets/subtensor/src/staking/remove_stake.rs | 2 +- pallets/subtensor/src/tests/children.rs | 26 ++-- pallets/subtensor/src/tests/coinbase.rs | 127 +++++++----------- pallets/subtensor/src/tests/migration.rs | 23 +--- pallets/subtensor/src/tests/senate.rs | 17 +-- pallets/subtensor/src/tests/staking.rs | 102 +++----------- pallets/subtensor/src/tests/uids.rs | 48 ++----- 11 files changed, 124 insertions(+), 327 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 3f24deb78..186831031 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -961,10 +961,7 @@ mod sudo_set_nominator_min_required_stake { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); assert_eq!(Balances::free_balance(cold1), 4); // Add stake cold2 --> hot1 (is delegation.) @@ -974,10 +971,7 @@ mod sudo_set_nominator_min_required_stake { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold2), 1); assert_eq!(Balances::free_balance(cold2), 4); // Add stake cold1 --> hot2 (non delegation.) @@ -987,10 +981,7 @@ mod sudo_set_nominator_min_required_stake { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold1), 1); assert_eq!(Balances::free_balance(cold1), 8); // Add stake cold2 --> hot2 (is delegation.) @@ -1000,10 +991,7 @@ mod sudo_set_nominator_min_required_stake { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold2), 1); assert_eq!(Balances::free_balance(cold2), 8); // Set min stake to 0 (noop) @@ -1011,44 +999,20 @@ mod sudo_set_nominator_min_required_stake { <::RuntimeOrigin>::root(), 0u64 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 1); + assert_eq!(Stake::::get(hot1, cold2), 1); + assert_eq!(Stake::::get(hot2, cold2), 1); // Set min nomination to 10: should clear (cold2, hot1) and (cold1, hot2). assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake( <::RuntimeOrigin>::root(), 10u64 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 0); + assert_eq!(Stake::::get(hot1, cold2), 0); + assert_eq!(Stake::::get(hot2, cold2), 1); // Balances have been added back into accounts. assert_eq!(Balances::free_balance(cold1), 9); diff --git a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs index b5e833aeb..46f7c5373 100644 --- a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs +++ b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs @@ -204,10 +204,7 @@ impl Pallet { assert!(StakingHotkeys::::get(migration_ck_acct).contains(taostats_old_hk_acct)); - assert_eq!( - Self::get_stake_for_coldkey_and_hotkey(null_account, taostats_old_hk_acct), - 0 - ); + assert_eq!(Stake::::get(taostats_old_hk_acct, null_account), 0); // Check the total hotkey stake is the same assert_eq!( @@ -217,7 +214,7 @@ impl Pallet { ); let new_null_stake_taostats = - Self::get_stake_for_coldkey_and_hotkey(migration_ck_acct, taostats_old_hk_acct); + Stake::::get(taostats_old_hk_acct, migration_ck_acct); assert_eq!( new_null_stake_taostats, @@ -257,10 +254,7 @@ impl Pallet { assert!(StakingHotkeys::::get(migration_ck_acct).contains(datura_old_hk_acct)); - assert_eq!( - Self::get_stake_for_coldkey_and_hotkey(null_account, datura_old_hk_acct), - 0 - ); + assert_eq!(Stake::::get(datura_old_hk_acct, null_account), 0); // Check the total hotkey stake is the same assert_eq!( @@ -269,8 +263,7 @@ impl Pallet { .saturating_add(old.old_migration_stake_datura) ); - let new_null_stake_datura = - Self::get_stake_for_coldkey_and_hotkey(migration_ck_acct, datura_old_hk_acct); + let new_null_stake_datura = Stake::::get(datura_old_hk_acct, migration_ck_acct); assert_eq!( new_null_stake_datura, @@ -353,14 +346,8 @@ pub mod migration { .saturating_add(PendingdHotkeyEmission::::get(taostats_new_hk_acct)); Ok::<(u64, u64), sp_runtime::TryRuntimeError>(( - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - null_account, - taostats_old_hk_acct, - ), - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - migration_acct, - taostats_old_hk_acct, - ), + Stake::::get(taostats_old_hk_acct, null_account), + Stake::::get(taostats_old_hk_acct, migration_acct), )) } _ => { @@ -386,14 +373,8 @@ pub mod migration { .saturating_add(PendingdHotkeyEmission::::get(datura_new_hk_acct)); Ok::<(u64, u64), sp_runtime::TryRuntimeError>(( - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - null_account, - datura_old_hk_acct, - ), - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - migration_acct, - datura_old_hk_acct, - ), + Stake::::get(datura_old_hk_acct, null_account), + Stake::::get(datura_old_hk_acct, migration_acct), )) } _ => { diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index be068bf68..c641ad8d9 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -119,8 +119,7 @@ impl Pallet { let mut delegates: Vec<(DelegateInfo, Compact)> = Vec::new(); for delegate in as IterableStorageMap>::iter_keys() { - let staked_to_this_delegatee = - Self::get_stake_for_coldkey_and_hotkey(&delegatee.clone(), &delegate.clone()); + let staked_to_this_delegatee = Stake::::get(&delegate, &delegatee); if staked_to_this_delegatee == 0 { continue; // No stake to this delegate } diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 1e223d4f8..facfb2605 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -41,12 +41,6 @@ impl Pallet { TotalColdkeyStake::::get(coldkey) } - // Returns the stake under the cold - hot pairing in the staking table. - // - pub fn get_stake_for_coldkey_and_hotkey(coldkey: &T::AccountId, hotkey: &T::AccountId) -> u64 { - Stake::::get(hotkey, coldkey) - } - pub fn get_target_stakes_per_interval() -> u64 { TargetStakesPerInterval::::get() } @@ -111,7 +105,7 @@ impl Pallet { /// # Returns /// True if the account has enough balance, false otherwise. pub fn has_enough_stake(coldkey: &T::AccountId, hotkey: &T::AccountId, decrement: u64) -> bool { - Self::get_stake_for_coldkey_and_hotkey(coldkey, hotkey) >= decrement + Stake::::get(hotkey, coldkey) >= decrement } /// Increases the stake on the hotkey account under its owning coldkey. diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index f5cf87bc7..7a101a8ae 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -81,7 +81,7 @@ impl Pallet { // If the stake is below the minimum, we clear the nomination from storage. // This only applies to nominator stakes. // If the coldkey does not own the hotkey, it's a nominator stake. - let new_stake = Self::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let new_stake = Stake::::get(&hotkey, &coldkey); Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake); // Check if stake lowered below MinStake and remove Pending children if it did diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 552add3cc..3b222a73c 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -1823,8 +1823,7 @@ fn test_childkey_single_parent_emission() { } step_block(7200 + 1); // Check emission distribution - let parent_stake: u64 = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_parent, &parent); + let parent_stake: u64 = Stake::::get(parent, coldkey_parent); let parent_stake_on_subnet: u64 = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); @@ -1834,8 +1833,7 @@ fn test_childkey_single_parent_emission() { parent_stake_on_subnet ); - let child_stake: u64 = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_child, &child); + let child_stake: u64 = Stake::::get(child, coldkey_child); let child_stake_on_subnet: u64 = SubtensorModule::get_stake_for_hotkey_on_subnet(&child, netuid); @@ -1845,10 +1843,7 @@ fn test_childkey_single_parent_emission() { child_stake_on_subnet ); - let weight_setter_stake: u64 = SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_weight_setter, - &weight_setter, - ); + let weight_setter_stake: u64 = Stake::::get(weight_setter, coldkey_weight_setter); let weight_setter_stake_on_subnet: u64 = SubtensorModule::get_stake_for_hotkey_on_subnet(&weight_setter, netuid); @@ -1969,7 +1964,7 @@ fn test_childkey_multiple_parents_emission() { ]; for (coldkey, hotkey, name) in stakes.iter() { - let stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(coldkey, hotkey); + let stake = Stake::::get(hotkey, coldkey); let stake_on_subnet = SubtensorModule::get_stake_for_hotkey_on_subnet(hotkey, netuid); log::debug!( "{} stake: {:?}, {} stake on subnet: {:?}", @@ -1980,15 +1975,10 @@ fn test_childkey_multiple_parents_emission() { ); } - let parent1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_parent1, &parent1); - let parent2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_parent2, &parent2); - let child_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_child, &child); - let weight_setter_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_weight_setter, - &weight_setter, - ); + let parent1_stake = Stake::::get(parent1, coldkey_parent1); + let parent2_stake = Stake::::get(parent2, coldkey_parent2); + let child_stake = Stake::::get(child, coldkey_child); + let weight_setter_stake = Stake::::get(weight_setter, coldkey_weight_setter); assert!( parent1_stake > 200_000, diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 8ba9e4c1d..a2baed44e 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -6,7 +6,7 @@ use sp_core::U256; use substrate_fixed::types::I64F64; use crate::{ - HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, TargetStakesPerInterval, + HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, Stake, TargetStakesPerInterval, }; // Test the ability to hash all sorts of hotkeys. @@ -312,9 +312,9 @@ fn test_coinbase_nominator_drainage_overflow() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); @@ -349,11 +349,9 @@ fn test_coinbase_nominator_drainage_overflow() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let hotkey_stake = Stake::::get(hotkey, coldkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", @@ -465,9 +463,9 @@ fn test_coinbase_nominator_drainage_no_deltas() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); @@ -498,11 +496,9 @@ fn test_coinbase_nominator_drainage_no_deltas() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let hotkey_stake = Stake::::get(hotkey, coldkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", @@ -608,14 +604,13 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator1_stake_before = Stake::::get(hotkey, nominator1); assert_eq!(nominator1_stake_before, 100 + 123); // The stake should include the added stake // 5. Set emission and verify initial states @@ -648,11 +643,9 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let hotkey_stake = Stake::::get(hotkey, coldkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", @@ -765,14 +758,13 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator_1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!(nominator_1_stake_before, 100 - 12); @@ -806,12 +798,10 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", @@ -931,14 +921,13 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the unchanged from the initial stake assert_eq!(nominator1_stake_before, 100); @@ -969,12 +958,10 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", @@ -1075,11 +1062,9 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator1, &hotkey, 100); SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 100); - let initial_nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let initial_nominator1_stake = Stake::::get(hotkey, nominator1); let intial_total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let initial_nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let initial_nominator2_stake = Stake::::get(hotkey, nominator2); assert_eq!(initial_nominator1_stake, initial_nominator2_stake); // Initial stakes should be equal @@ -1107,14 +1092,13 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator_1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!( nominator_1_stake_before, @@ -1151,12 +1135,10 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", @@ -1274,11 +1256,9 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator1, &hotkey, 300); SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 300); - let initial_nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let initial_nominator1_stake = Stake::::get(hotkey, nominator1); let intial_total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let initial_nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let initial_nominator2_stake = Stake::::get(hotkey, nominator2); assert_eq!(initial_nominator1_stake, initial_nominator2_stake); // Initial stakes should be equal @@ -1307,15 +1287,14 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); let total_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator_1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!( nominator_1_stake_before, @@ -1353,12 +1332,10 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 0daba9744..7fe0bedb5 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -651,34 +651,19 @@ fn test_migrate_fix_pending_emissions() { assert_eq!(TotalStake::::get(), expected_total_issuance); // Check the total stake maps are updated following the migration (removal of old null_account stake entries) assert_eq!(TotalColdkeyStake::::get(null_account), 0); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(null_account, datura_old_hk_account), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - null_account, - taostats_old_hk_account - ), - 0 - ); + assert_eq!(Stake::::get(datura_old_hk_account, null_account), 0); + assert_eq!(Stake::::get(taostats_old_hk_account, null_account), 0); // Check staking hotkeys is updated assert_eq!(StakingHotkeys::::get(null_account), vec![]); // Check the migration key has stake with both *old* hotkeys assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - migration_account, - datura_old_hk_account - ), + Stake::::get(datura_old_hk_account, migration_account), null_stake_datura ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - migration_account, - taostats_old_hk_account - ), + Stake::::get(taostats_old_hk_account, migration_account), null_stake_tao_stats ); assert_eq!( diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index a0a2f81c6..27f0df6ef 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -14,7 +14,7 @@ use sp_runtime::{ BuildStorage, }; -use crate::{migrations, Error, Owner, SubnetworkN}; +use crate::{migrations, Error, Owner, Stake, SubnetworkN}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -101,7 +101,7 @@ fn test_senate_join_works() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -167,7 +167,7 @@ fn test_senate_vote_works() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -329,7 +329,7 @@ fn test_senate_leave_works() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -396,7 +396,7 @@ fn test_senate_leave_vote_removal() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -533,7 +533,7 @@ fn test_senate_not_leave_when_stake_removed() { stake_amount )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), stake_amount - 1 // Need to account for ED ); assert_eq!( @@ -749,10 +749,7 @@ fn test_adjust_senate_events() { 1 // Will be more than the last one in the senate by stake (has 0 stake) )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &replacement_hotkey_account_id - ), + Stake::::get(replacement_hotkey_account_id, coldkey_account_id), 1 ); assert_eq!( diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 688800b4f..79d986288 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1107,10 +1107,7 @@ fn test_has_enough_stake_yes() { SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 10000 ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_id, &hotkey_id), - 10000 - ); + assert_eq!(Stake::::get(hotkey_id, coldkey_id), 10000); assert!(SubtensorModule::has_enough_stake( &coldkey_id, &hotkey_id, @@ -1147,10 +1144,7 @@ fn test_non_existent_account() { &(U256::from(0)), 10, ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&U256::from(0), &U256::from(0)), - 10 - ); + assert_eq!(Stake::::get(U256::from(0), U256::from(0)), 10); assert_eq!( SubtensorModule::get_total_stake_for_coldkey(&(U256::from(0))), 10 @@ -1245,22 +1239,10 @@ fn test_unstake_all_coldkeys_from_hotkey_account() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); // Vefify stake for all coldkeys is 0 - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0_id, &hotkey_id), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1_id, &hotkey_id), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2_id, &hotkey_id), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey3_id, &hotkey_id), - 0 - ); + assert_eq!(Stake::::get(hotkey_id, coldkey0_id), 0); + assert_eq!(Stake::::get(hotkey_id, coldkey1_id), 0); + assert_eq!(Stake::::get(hotkey_id, coldkey2_id), 0); + assert_eq!(Stake::::get(hotkey_id, coldkey3_id), 0); // Verify free balance is correct for all coldkeys assert_eq!(Balances::free_balance(coldkey0_id), amount); @@ -1311,10 +1293,7 @@ fn test_unstake_all_coldkeys_from_hotkey_account_single_staker() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); // Vefify stake for single coldkey is 0 - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0_id, &hotkey_id), - 0 - ); + assert_eq!(Stake::::get(hotkey_id, coldkey0_id), 0); // Verify free balance is correct for single coldkey assert_eq!(Balances::free_balance(coldkey0_id), amount); @@ -1403,10 +1382,7 @@ fn test_clear_small_nominations() { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); assert_eq!(Balances::free_balance(cold1), 4); // Add stake cold2 --> hot1 (is delegation.) @@ -1416,10 +1392,7 @@ fn test_clear_small_nominations() { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold2), 1); assert_eq!(Balances::free_balance(cold2), 4); // Add stake cold1 --> hot2 (non delegation.) @@ -1429,10 +1402,7 @@ fn test_clear_small_nominations() { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold1), 1); assert_eq!(Balances::free_balance(cold1), 8); // Add stake cold2 --> hot2 (is delegation.) @@ -1442,31 +1412,16 @@ fn test_clear_small_nominations() { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold2), 1); assert_eq!(Balances::free_balance(cold2), 8); // Run clear all small nominations when min stake is zero (noop) SubtensorModule::set_nominator_min_required_stake(0); SubtensorModule::clear_small_nominations(); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 1); + assert_eq!(Stake::::get(hot1, cold2), 1); + assert_eq!(Stake::::get(hot2, cold2), 1); // Set min nomination to 10 let total_cold1_stake_before = TotalColdkeyStake::::get(cold1); @@ -1480,22 +1435,10 @@ fn test_clear_small_nominations() { // Run clear all small nominations (removes delegations under 10) SubtensorModule::clear_small_nominations(); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 0); + assert_eq!(Stake::::get(hot1, cold2), 0); + assert_eq!(Stake::::get(hot2, cold2), 1); // Balances have been added back into accounts. assert_eq!(Balances::free_balance(cold1), 9); @@ -1621,7 +1564,7 @@ fn test_remove_stake_below_minimum_threshold() { // without unstaking all and removing the nomination. let total_hotkey_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey1); let bal_before = Balances::free_balance(coldkey2); - let staked_before = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey1); + let staked_before = Stake::::get(hotkey1, coldkey2); let total_network_stake_before = SubtensorModule::get_total_stake(); let total_issuance_before = SubtensorModule::get_total_issuance(); // check the premise of the test is correct @@ -1633,10 +1576,7 @@ fn test_remove_stake_below_minimum_threshold() { )); // Has no stake now - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey1), - 0 - ); + assert_eq!(Stake::::get(hotkey1, coldkey2), 0); let stake_removed = staked_before; // All stake was removed // Has the full balance assert_eq!(Balances::free_balance(coldkey2), bal_before + stake_removed); diff --git a/pallets/subtensor/src/tests/uids.rs b/pallets/subtensor/src/tests/uids.rs index 4310218d1..1c25a2ba8 100644 --- a/pallets/subtensor/src/tests/uids.rs +++ b/pallets/subtensor/src/tests/uids.rs @@ -255,24 +255,15 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { // Check stake on neuron assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account_id), stake_amount ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account1_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account1_id), stake_amount + 1 ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account2_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account2_id), stake_amount + 2 ); @@ -297,24 +288,15 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { // Check the stake is still on the coldkey accounts. assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account_id), stake_amount ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account1_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account1_id), stake_amount + 1 ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account2_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account2_id), stake_amount + 2 ); @@ -338,20 +320,11 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { )); // Check the stake is now on the free balance of the coldkey accounts. - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &hotkey_account_id - ), - 0 - ); + assert_eq!(Stake::::get(hotkey_account_id, coldkey_account_id), 0); assert_eq!(Balances::free_balance(coldkey_account_id), stake_amount); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account1_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account1_id), 0 ); assert_eq!( @@ -360,10 +333,7 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account2_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account2_id), 0 ); assert_eq!( From ebfe64b589574bf733b09325e4350f3b32c95433 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 20:01:26 +0100 Subject: [PATCH 089/137] Remove get_subnet_emission_value from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 11 ---------- pallets/subtensor/src/tests/coinbase.rs | 21 +++++++++--------- pallets/subtensor/src/tests/epoch.rs | 5 +---- pallets/subtensor/src/tests/migration.rs | 2 +- pallets/subtensor/src/tests/root.rs | 27 ++++++++++-------------- 5 files changed, 24 insertions(+), 42 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index f72d279a0..409b840eb 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -52,17 +52,6 @@ impl Pallet { SubnetworkN::::get(Self::ROOT_NETUID) } - /// Returns the emission value for the given subnet. - /// - /// This function retrieves the emission value for the given subnet. - /// - /// # Returns: - /// * 'u64': The emission value for the given subnet. - /// - pub fn get_subnet_emission_value(netuid: u16) -> u64 { - EmissionValues::::get(netuid) - } - /// Returns true if the subnetwork exists. /// /// This function checks if a subnetwork with the given UID exists. diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index a2baed44e..103d9cce5 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -6,7 +6,8 @@ use sp_core::U256; use substrate_fixed::types::I64F64; use crate::{ - HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, Stake, TargetStakesPerInterval, + EmissionValues, HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, Stake, + TargetStakesPerInterval, }; // Test the ability to hash all sorts of hotkeys. @@ -67,7 +68,7 @@ fn test_coinbase_basic() { // Set the subnet emission value to 1. SubtensorModule::set_emission_values(&[netuid], vec![1]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 1); + assert_eq!(EmissionValues::::get(netuid), 1); // Hotkey has no pending emission assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); @@ -321,7 +322,7 @@ fn test_coinbase_nominator_drainage_overflow() { // 5. Set emission and verify initial states let to_emit = 20_000e9 as u64; SubtensorModule::set_emission_values(&[netuid], vec![to_emit]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), to_emit); + assert_eq!(EmissionValues::::get(netuid), to_emit); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), @@ -471,7 +472,7 @@ fn test_coinbase_nominator_drainage_no_deltas() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); + assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); assert_eq!(PendingEmission::::get(netuid), 0); @@ -615,7 +616,7 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); + assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), @@ -770,7 +771,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); + assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), @@ -933,7 +934,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); + assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); assert_eq!(PendingEmission::::get(netuid), 0); @@ -1107,7 +1108,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { // 5. Set emission and verify initial states SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); + assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), @@ -1304,7 +1305,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { // 5. Set emission and verify initial states let to_emit = 10_000e9 as u64; SubtensorModule::set_emission_values(&[netuid], vec![to_emit]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), to_emit); + assert_eq!(EmissionValues::::get(netuid), to_emit); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), @@ -1454,7 +1455,7 @@ fn test_emission_with_registration_disabled_subnet() { // Configure emission rate for the subnet SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); + assert_eq!(EmissionValues::::get(netuid), 10); // Verify initial emission state is zero assert_eq!(PendingEmission::::get(netuid), 0); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 655907cce..43a68053c 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -564,10 +564,7 @@ fn test_1_graph() { // SubtensorModule::set_weights_for_testing( netuid, i as u16, vec![ ( 0, u16::MAX )]); // doesn't set update status // SubtensorModule::set_bonds_for_testing( netuid, uid, vec![ ( 0, u16::MAX )]); // rather, bonds are calculated in epoch SubtensorModule::set_emission_values(&[netuid], vec![1_000_000_000]).unwrap(); - assert_eq!( - SubtensorModule::get_subnet_emission_value(netuid), - 1_000_000_000 - ); + assert_eq!(EmissionValues::::get(netuid), 1_000_000_000); SubtensorModule::epoch(netuid, 1_000_000_000); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey), diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 7fe0bedb5..eae259682 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -239,7 +239,7 @@ fn test_total_issuance_global() { let emission: u64 = 1_000_000_000; SubtensorModule::set_tempo(netuid, 1); SubtensorModule::set_emission_values(&[netuid], vec![emission]).unwrap(); // Set the emission value for the network to 1_000_000_000. - assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), emission); // Verify the emission value is set correctly for the network. + assert_eq!(EmissionValues::::get(netuid), emission); // Verify the emission value is set correctly for the network. assert_eq!( SubtensorModule::get_total_issuance(), account_balance + lockcost - burn_cost + new_stake diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 25d50fc43..5b4194196 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -7,8 +7,9 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ - migrations, utils::rate_limiting::TransactionType, Error, NetworkRateLimit, PendingEmission, - SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, TotalNetworks, + migrations, utils::rate_limiting::TransactionType, EmissionValues, Error, NetworkRateLimit, + PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, + TotalNetworks, }; #[allow(dead_code)] @@ -296,10 +297,7 @@ fn test_root_set_weights() { // Check that the emission values have been set. for netuid in 1..n { log::debug!("check emission for netuid: {}", netuid); - assert_eq!( - SubtensorModule::get_subnet_emission_value(netuid as u16), - 99_999_999 - ); + assert_eq!(EmissionValues::::get(netuid as u16), 99_999_999); } step_block(2); // Check that the pending emission values have been set. @@ -403,10 +401,7 @@ fn test_root_set_weights_out_of_order_netuids() { // Check that the emission values have been set. for netuid in subnets.iter() { log::debug!("check emission for netuid: {}", netuid); - assert_eq!( - SubtensorModule::get_subnet_emission_value(*netuid), - 99_999_999 - ); + assert_eq!(EmissionValues::::get(*netuid), 99_999_999); } step_block(2); // Check that the pending emission values have been set. @@ -598,12 +593,12 @@ fn test_network_pruning() { step_block(1); assert_ok!(SubtensorModule::root_epoch(1_000_000_000)); - assert_eq!(SubtensorModule::get_subnet_emission_value(0), 385_861_815); - assert_eq!(SubtensorModule::get_subnet_emission_value(1), 249_435_914); - assert_eq!(SubtensorModule::get_subnet_emission_value(2), 180_819_837); - assert_eq!(SubtensorModule::get_subnet_emission_value(3), 129_362_980); - assert_eq!(SubtensorModule::get_subnet_emission_value(4), 50_857_187); - assert_eq!(SubtensorModule::get_subnet_emission_value(5), 3_530_356); + assert_eq!(EmissionValues::::get(0), 385_861_815); + assert_eq!(EmissionValues::::get(1), 249_435_914); + assert_eq!(EmissionValues::::get(2), 180_819_837); + assert_eq!(EmissionValues::::get(3), 129_362_980); + assert_eq!(EmissionValues::::get(4), 50_857_187); + assert_eq!(EmissionValues::::get(5), 3_530_356); step_block(1); assert_eq!(PendingEmission::::get(0), 0); // root network gets no pending emission. assert_eq!(PendingEmission::::get(1), 249_435_914); From 9f05e46b3ad2c416740d5695ba3921d6cb73566a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 17 Dec 2024 20:17:27 +0100 Subject: [PATCH 090/137] Remove get_subnet_locked_balance from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 409b840eb..27de2bc14 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -1085,7 +1085,7 @@ impl Pallet { 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); + let reserved_amount: u64 = SubnetLocked::::get(netuid); // --- 2. Remove network count. SubnetworkN::::remove(netuid); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9b9514393..0dfa9a38b 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -251,9 +251,7 @@ impl Pallet { pub fn set_subnet_locked_balance(netuid: u16, amount: u64) { SubnetLocked::::insert(netuid, amount); } - pub fn get_subnet_locked_balance(netuid: u16) -> u64 { - SubnetLocked::::get(netuid) - } + pub fn get_total_subnet_locked() -> u64 { let mut total_subnet_locked: u64 = 0; for (_, locked) in SubnetLocked::::iter() { From be84827807c7893755ad55736031e8c57cbf8492 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 14:50:02 +0100 Subject: [PATCH 091/137] Remove get_subnet_owner from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 4 ++-- pallets/subtensor/src/tests/migration.rs | 4 ++-- pallets/subtensor/src/tests/root.rs | 8 ++++---- pallets/subtensor/src/utils/identity.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index bef08a1e0..f802c0514 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -141,7 +141,7 @@ impl Pallet { // --- 4.6.3 Add the cut to the balance of the owner Self::add_balance_to_coldkey_account( - &Self::get_subnet_owner(*netuid), + &SubnetOwner::::get(*netuid), owner_cut.to_num::(), ); diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 92710f3b0..2ca8b78df 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -128,7 +128,7 @@ impl Pallet { network_connect, emission_values: emission_values.into(), burn, - owner: Self::get_subnet_owner(netuid), + owner: SubnetOwner::::get(netuid), }) } @@ -200,7 +200,7 @@ impl Pallet { network_connect, emission_values: emission_values.into(), burn, - owner: Self::get_subnet_owner(netuid), + owner: SubnetOwner::::get(netuid), identity, }) } diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index eae259682..4e93ac563 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -265,7 +265,7 @@ fn test_migration_transfer_nets_to_foundation() { // Create subnet 11 add_network(11, 1, 0); - log::info!("{:?}", SubtensorModule::get_subnet_owner(1)); + log::info!("{:?}", SubnetOwner::::get(1)); //assert_eq!(SubtensorModule::::get_subnet_owner(1), ); // Run the migration to transfer ownership @@ -273,7 +273,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)); + log::info!("new owner: {:?}", SubnetOwner::::get(1)); }) } diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 5b4194196..2a19c0459 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -8,8 +8,8 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, EmissionValues, Error, NetworkRateLimit, - PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetworkN, - TotalNetworks, + PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetOwner, + SubnetworkN, TotalNetworks, }; #[allow(dead_code)] @@ -887,7 +887,7 @@ fn test_dissolve_network_ok() { let hotkey = U256::from(1); add_network(netuid, 0, 0); - let owner_coldkey = SubtensorModule::get_subnet_owner(netuid); + let owner_coldkey = SubnetOwner::::get(netuid); register_ok_neuron(netuid, hotkey, owner_coldkey, 3); assert!(SubtensorModule::if_subnet_exist(netuid)); @@ -908,7 +908,7 @@ fn test_dissolve_network_refund_coldkey_ok() { let subnet_locked_balance = 1000; add_network(netuid, 0, 0); - let owner_coldkey = SubtensorModule::get_subnet_owner(netuid); + let owner_coldkey = SubnetOwner::::get(netuid); register_ok_neuron(netuid, hotkey, owner_coldkey, 3); SubtensorModule::set_subnet_locked_balance(netuid, subnet_locked_balance); diff --git a/pallets/subtensor/src/utils/identity.rs b/pallets/subtensor/src/utils/identity.rs index 7babb04f4..f6ec95c8c 100644 --- a/pallets/subtensor/src/utils/identity.rs +++ b/pallets/subtensor/src/utils/identity.rs @@ -104,7 +104,7 @@ impl Pallet { // Ensure that the coldkey owns the subnet ensure!( - Self::get_subnet_owner(netuid) == coldkey, + SubnetOwner::::get(netuid) == coldkey, Error::::NotSubnetOwner ); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0dfa9a38b..231f18413 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -469,9 +469,6 @@ impl Pallet { )); } - pub fn get_subnet_owner(netuid: u16) -> T::AccountId { - SubnetOwner::::get(netuid) - } pub fn get_subnet_owner_cut() -> u16 { SubnetOwnerCut::::get() } From ef38ed7fa6b7963ee72c30dfba536fb743853fe5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 15:10:52 +0100 Subject: [PATCH 092/137] Remove get_subnet_owner_cut from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 186831031..3d2b05621 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -268,7 +268,7 @@ fn test_sudo_set_adjustment_alpha() { fn test_sudo_subnet_owner_cut() { new_test_ext().execute_with(|| { let to_be_set: u16 = 10; - let init_value: u16 = SubtensorModule::get_subnet_owner_cut(); + let init_value: u16 = SubnetOwnerCut::::get(); assert_eq!( AdminUtils::sudo_set_subnet_owner_cut( <::RuntimeOrigin>::signed(U256::from(0)), @@ -276,12 +276,12 @@ fn test_sudo_subnet_owner_cut() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_subnet_owner_cut(), init_value); + assert_eq!(SubnetOwnerCut::::get(), init_value); assert_ok!(AdminUtils::sudo_set_subnet_owner_cut( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_subnet_owner_cut(), to_be_set); + assert_eq!(SubnetOwnerCut::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index f802c0514..5a0189440 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -132,7 +132,7 @@ impl Pallet { // --- 4.6.1 Compute the subnet owner cut. let owner_cut: I96F32 = I96F32::from_num(subnet_emission).saturating_mul( - I96F32::from_num(Self::get_subnet_owner_cut()) + I96F32::from_num(SubnetOwnerCut::::get()) .saturating_div(I96F32::from_num(u16::MAX)), ); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 231f18413..c86f157db 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -469,9 +469,6 @@ impl Pallet { )); } - pub fn get_subnet_owner_cut() -> u16 { - SubnetOwnerCut::::get() - } pub fn set_subnet_owner_cut(subnet_owner_cut: u16) { SubnetOwnerCut::::set(subnet_owner_cut); Self::deposit_event(Event::SubnetOwnerCutSet(subnet_owner_cut)); From 0a64cb4ec9b7cb51e4a5c904f844a37cdb88bbbd Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 15:20:42 +0100 Subject: [PATCH 093/137] Remove get_target_stakes_per_interval from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 9 +++------ pallets/subtensor/src/staking/helpers.rs | 4 ---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 3d2b05621..8ab992be0 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -1093,7 +1093,7 @@ fn test_sudo_set_commit_reveal_weights_enabled() { fn test_sudo_set_target_stakes_per_interval() { new_test_ext().execute_with(|| { let to_be_set = 100; - let init_value = SubtensorModule::get_target_stakes_per_interval(); + let init_value = TargetStakesPerInterval::::get(); assert_eq!( AdminUtils::sudo_set_target_stakes_per_interval( <::RuntimeOrigin>::signed(U256::from(1)), @@ -1101,15 +1101,12 @@ fn test_sudo_set_target_stakes_per_interval() { ), Err(DispatchError::BadOrigin) ); - assert_eq!( - SubtensorModule::get_target_stakes_per_interval(), - init_value - ); + assert_eq!(TargetStakesPerInterval::::get(), init_value); assert_ok!(AdminUtils::sudo_set_target_stakes_per_interval( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_target_stakes_per_interval(), to_be_set); + assert_eq!(TargetStakesPerInterval::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index facfb2605..c70733bad 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -41,10 +41,6 @@ impl Pallet { TotalColdkeyStake::::get(coldkey) } - pub fn get_target_stakes_per_interval() -> u64 { - TargetStakesPerInterval::::get() - } - // Creates a cold - hot pairing account if the hotkey is not already an active account. // pub fn create_account_if_non_existent(coldkey: &T::AccountId, hotkey: &T::AccountId) { From 5976158c51934b81db6d43c21faf7799279bb673 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 15:50:00 +0100 Subject: [PATCH 094/137] Remove get_tempo from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/rpc_info/delegate_info.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +++--- pallets/subtensor/src/subnets/weights.rs | 4 ++-- pallets/subtensor/src/tests/mock.rs | 6 ++++-- pallets/subtensor/src/tests/registration.rs | 7 ++++--- pallets/subtensor/src/tests/weights.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 7 ------- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 27de2bc14..d651df21c 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -277,7 +277,7 @@ impl Pallet { // --- 1. Check if we should update the emission values based on blocks since emission was last set. let blocks_until_next_epoch: u64 = - Self::blocks_until_next_epoch(root_netuid, Self::get_tempo(root_netuid), block_number); + Self::blocks_until_next_epoch(root_netuid, Tempo::::get(root_netuid), block_number); if blocks_until_next_epoch != 0 { // Not the block to update emission values. log::debug!("blocks_until_next_epoch: {:?}", blocks_until_next_epoch); diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 5a0189440..8053a8a0e 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -550,7 +550,7 @@ impl Pallet { /// # Returns /// * `bool` - True if the epoch should run, false otherwise. pub fn should_run_epoch(netuid: u16, current_block: u64) -> bool { - Self::blocks_until_next_epoch(netuid, Self::get_tempo(netuid), current_block) == 0 + Self::blocks_until_next_epoch(netuid, Tempo::::get(netuid), current_block) == 0 } /// Helper function which returns the number of blocks remaining before we will run the epoch on this diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index c641ad8d9..44d810f34 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -48,7 +48,7 @@ impl Pallet { } let emission: U64F64 = Self::get_emission_for_uid(*netuid, uid).into(); - let tempo: U64F64 = Self::get_tempo(*netuid).into(); + let tempo: U64F64 = Tempo::::get(*netuid).into(); if tempo > U64F64::from_num(0) { let epochs_per_day: U64F64 = U64F64::from_num(7200).saturating_div(tempo); emissions_per_day = diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 2ca8b78df..bf4b53ecc 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -100,7 +100,7 @@ impl Pallet { let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = MaxAllowedUids::::get(netuid); let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); - let tempo = Self::get_tempo(netuid); + let tempo = Tempo::::get(netuid); let network_modality = >::get(netuid); let emission_values = EmissionValues::::get(netuid); let burn: Compact = Burn::::get(netuid).into(); @@ -170,7 +170,7 @@ impl Pallet { let subnetwork_n = SubnetworkN::::get(netuid); let max_allowed_uids = MaxAllowedUids::::get(netuid); let blocks_since_last_step = BlocksSinceLastStep::::get(netuid); - let tempo = Self::get_tempo(netuid); + let tempo = Tempo::::get(netuid); let network_modality = >::get(netuid); let emission_values = EmissionValues::::get(netuid); let burn: Compact = Burn::::get(netuid).into(); @@ -235,7 +235,7 @@ impl Pallet { let immunity_period = ImmunityPeriod::::get(netuid); let min_allowed_weights = MinAllowedWeights::::get(netuid); let max_weights_limit = MaxWeightsLimit::::get(netuid); - let tempo = Self::get_tempo(netuid); + let tempo = Tempo::::get(netuid); let min_difficulty = MinDifficulty::::get(netuid); let max_difficulty = MaxDifficulty::::get(netuid); let weights_version = Self::get_weights_version_key(netuid); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 9b1422a28..7a54942a6 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -1038,7 +1038,7 @@ impl Pallet { } pub fn get_epoch_index(netuid: u16, block_number: u64) -> u64 { - let tempo: u64 = Self::get_tempo(netuid) as u64; + let tempo: u64 = Tempo::::get(netuid) as u64; let tempo_plus_one: u64 = tempo.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); @@ -1057,7 +1057,7 @@ impl Pallet { pub fn get_reveal_blocks(netuid: u16, commit_block: u64) -> (u64, u64) { let reveal_period: u64 = RevealPeriodEpochs::::get(netuid); - let tempo: u64 = Self::get_tempo(netuid) as u64; + let tempo: u64 = Tempo::::get(netuid) as u64; let tempo_plus_one: u64 = tempo.saturating_add(1); let netuid_plus_one: u64 = (netuid as u64).saturating_add(1); diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 3f6697f38..672d78244 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -1,5 +1,5 @@ #![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)] -use crate::utils::rate_limiting::TransactionType; + use frame_support::derive_impl; use frame_support::dispatch::DispatchResultWithPostInfo; use frame_support::weights::constants::RocksDbWeight; @@ -19,6 +19,8 @@ use sp_runtime::{ }; use sp_std::cmp::Ordering; +use crate::{utils::rate_limiting::TransactionType, Tempo}; + type Block = frame_system::mocking::MockBlock; // Configure a mock runtime to test the pallet. @@ -596,7 +598,7 @@ pub(crate) fn step_epochs(count: u16, netuid: u16) { for _ in 0..count { let blocks_to_next_epoch = SubtensorModule::blocks_until_next_epoch( netuid, - SubtensorModule::get_tempo(netuid), + Tempo::::get(netuid), SubtensorModule::get_current_block_as_u64(), ); step_block(blocks_to_next_epoch as u16); diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index e5c67ff33..3838fd036 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -14,6 +14,7 @@ use crate::{ Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, RegistrationsThisBlock, RegistrationsThisInterval, SubnetworkN, SubtensorSignedExtension, + Tempo, }; /******************************************** @@ -1509,9 +1510,9 @@ fn test_full_pass_through() { add_network(netuid2, tempo2, 0); // Check their tempo. - assert_eq!(SubtensorModule::get_tempo(netuid0), tempo0); - assert_eq!(SubtensorModule::get_tempo(netuid1), tempo1); - assert_eq!(SubtensorModule::get_tempo(netuid2), tempo2); + assert_eq!(Tempo::::get(netuid0), tempo0); + assert_eq!(Tempo::::get(netuid1), tempo1); + assert_eq!(Tempo::::get(netuid2), tempo2); // Check their emission value. assert_eq!(EmissionValues::::get(netuid0), 0); diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index 0f18265b6..4516ea0d3 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -30,7 +30,7 @@ use sp_core::Encode; use super::mock::*; use crate::{ coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, - RevealPeriodEpochs, SubnetworkN, MAX_CRV3_COMMIT_SIZE_BYTES, + RevealPeriodEpochs, SubnetworkN, Tempo, MAX_CRV3_COMMIT_SIZE_BYTES, }; /*************************** @@ -3943,7 +3943,7 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { ); assert_eq!(RevealPeriodEpochs::::get(netuid), 10); - assert_eq!(SubtensorModule::get_tempo(netuid), 200); + assert_eq!(Tempo::::get(netuid), 200); }) } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index c86f157db..88bfd43e1 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -212,13 +212,6 @@ impl Pallet { StakeThreshold::::get() } - // ============================ - // ==== Subnetwork Getters ==== - // ============================ - pub fn get_tempo(netuid: u16) -> u16 { - Tempo::::get(netuid) - } - // ======================== // ===== Take checks ====== // ======================== From 07bb940fedc566af462abc93cfc5c52ed0d5d54d Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 16:10:26 +0100 Subject: [PATCH 095/137] Remove get_total_issuance from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 2 +- pallets/subtensor/src/coinbase/root.rs | 2 +- .../migrate_fix_pending_emission.rs | 4 +- pallets/subtensor/src/tests/migration.rs | 53 ++++++++----------- pallets/subtensor/src/tests/root.rs | 6 +-- pallets/subtensor/src/tests/staking.rs | 4 +- pallets/subtensor/src/tests/swap_coldkey.rs | 8 +-- pallets/subtensor/src/utils/misc.rs | 3 -- 8 files changed, 35 insertions(+), 47 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 8ab992be0..8d2a4c13a 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -333,7 +333,7 @@ fn test_sudo_set_issuance() { <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_total_issuance(), to_be_set); + assert_eq!(TotalIssuance::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index d651df21c..e0c1272e8 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -90,7 +90,7 @@ impl Pallet { /// pub fn get_block_emission() -> Result { // Convert the total issuance to a fixed-point number for calculation. - Self::get_block_emission_for_issuance(Self::get_total_issuance()) + Self::get_block_emission_for_issuance(TotalIssuance::::get()) } /// Returns the block emission for an issuance value. diff --git a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs index 46f7c5373..a572ccac0 100644 --- a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs +++ b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs @@ -294,7 +294,7 @@ impl Pallet { // Check the total issuance is the SAME following migration (no TAO issued) let expected_total_issuance = old.total_issuance_before; let expected_total_stake = old.total_stake_before; - assert_eq!(Self::get_total_issuance(), expected_total_issuance); + assert_eq!(TotalIssuance::::get(), expected_total_issuance); // Check total stake is the SAME following the migration (no new TAO staked) assert_eq!(TotalStake::::get(), expected_total_stake); @@ -331,7 +331,7 @@ pub mod migration { let taostats_old_hk_account = &get_account_id_from_ss58::(taostats_old_hotkey); let taostats_new_hk_account = &get_account_id_from_ss58::(taostats_new_hotkey); - let total_issuance_before = crate::Pallet::::get_total_issuance(); + let total_issuance_before = TotalIssuance::::get(); let mut expected_taostats_new_hk_pending_emission: u64 = 0; let mut expected_datura_new_hk_pending_emission: u64 = 0; let (old_null_stake_taostats, old_migration_stake_taostats) = match ( diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 4e93ac563..7035c5960 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -140,23 +140,23 @@ fn test_migrate_total_issuance() { // Run the migration to check total issuance. let test: bool = true; - assert_eq!(SubtensorModule::get_total_issuance(), 0); + assert_eq!(TotalIssuance::::get(), 0); crate::migrations::migrate_total_issuance::migrate_total_issuance::(test); - assert_eq!(SubtensorModule::get_total_issuance(), 0); + assert_eq!(TotalIssuance::::get(), 0); SubtensorModule::add_balance_to_coldkey_account(&U256::from(1), 10000); - assert_eq!(SubtensorModule::get_total_issuance(), 0); + assert_eq!(TotalIssuance::::get(), 0); crate::migrations::migrate_total_issuance::migrate_total_issuance::(test); - assert_eq!(SubtensorModule::get_total_issuance(), 10000); + assert_eq!(TotalIssuance::::get(), 10000); SubtensorModule::increase_stake_on_coldkey_hotkey_account( &U256::from(1), &U256::from(1), 30000, ); - assert_eq!(SubtensorModule::get_total_issuance(), 10000); + assert_eq!(TotalIssuance::::get(), 10000); crate::migrations::migrate_total_issuance::migrate_total_issuance::(test); - assert_eq!(SubtensorModule::get_total_issuance(), 10000 + 30000); + assert_eq!(TotalIssuance::::get(), 10000 + 30000); }) } @@ -173,35 +173,29 @@ fn test_total_issuance_global() { let lockcost: u64 = SubtensorModule::get_network_lock_cost(); SubtensorModule::add_balance_to_coldkey_account(&owner, lockcost); // Add a balance of 20000 to the coldkey account. - assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero. + assert_eq!(TotalIssuance::::get(), 0); // initial is zero. assert_ok!(SubtensorModule::register_network( <::RuntimeOrigin>::signed(owner), )); SubtensorModule::set_max_allowed_uids(netuid, 1); // Set the maximum allowed unique identifiers for the network to 1. - assert_eq!(SubtensorModule::get_total_issuance(), 0); // initial is zero. + assert_eq!(TotalIssuance::::get(), 0); // initial is zero. crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Pick up lock. - assert_eq!(SubtensorModule::get_total_issuance(), lockcost); // Verify the total issuance is updated to 20000 after migration. + assert_eq!(TotalIssuance::::get(), lockcost); // Verify the total issuance is updated to 20000 after migration. assert!(SubtensorModule::if_subnet_exist(netuid)); // Test the migration's effect on total issuance after adding balance to a coldkey account. let account_balance: u64 = 20000; let _hotkey_account_id_1 = U256::from(1); // Define a hotkey account ID for further operations. let _coldkey_account_id_1 = U256::from(1); // Define a coldkey account ID for further operations. - assert_eq!(SubtensorModule::get_total_issuance(), lockcost); // Ensure the total issuance starts at 0 before the migration. + assert_eq!(TotalIssuance::::get(), lockcost); // Ensure the total issuance starts at 0 before the migration. SubtensorModule::add_balance_to_coldkey_account(&coldkey, account_balance); // Add a balance of 20000 to the coldkey account. crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Execute the migration to update total issuance. - assert_eq!( - SubtensorModule::get_total_issuance(), - account_balance + lockcost - ); // Verify the total issuance is updated to 20000 after migration. + assert_eq!(TotalIssuance::::get(), account_balance + lockcost); // Verify the total issuance is updated to 20000 after migration. // Test the effect of burning on total issuance. let burn_cost: u64 = 10000; SubtensorModule::set_burn(netuid, burn_cost); // Set the burn amount to 10000 for the network. - assert_eq!( - SubtensorModule::get_total_issuance(), - account_balance + lockcost - ); // Confirm the total issuance remains 20000 before burning. + assert_eq!(TotalIssuance::::get(), account_balance + lockcost); // Confirm the total issuance remains 20000 before burning. assert_ok!(SubtensorModule::burned_register( <::RuntimeOrigin>::signed(hotkey), netuid, @@ -209,29 +203,29 @@ fn test_total_issuance_global() { )); // Execute the burn operation, reducing the total issuance. assert_eq!(SubnetworkN::::get(netuid), 1); // Ensure the subnetwork count increases to 1 after burning assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost ); // Verify the total issuance is reduced to 10000 after burning. crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Execute the migration to update total issuance. assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost ); // Verify the total issuance is updated to 10000 nothing changes // Test staking functionality and its effect on total issuance. let new_stake: u64 = 10000; assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost ); // Same SubtensorModule::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, new_stake); // Stake an additional 10000 to the coldkey-hotkey account. This is i assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost ); // Same crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Fix issuance assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost + new_stake ); // New @@ -241,17 +235,17 @@ fn test_total_issuance_global() { SubtensorModule::set_emission_values(&[netuid], vec![emission]).unwrap(); // Set the emission value for the network to 1_000_000_000. assert_eq!(EmissionValues::::get(netuid), emission); // Verify the emission value is set correctly for the network. assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost + new_stake ); run_to_block(2); // Advance to block number 2 to trigger the emission through the subnet. assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost + new_stake + emission ); // Verify the total issuance reflects the staked amount and emission value that has been put through the epoch. crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Test migration does not change amount. assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), account_balance + lockcost - burn_cost + new_stake + emission ); // Verify the total issuance reflects the staked amount and emission value that has been put through the epoch. }) @@ -607,7 +601,7 @@ fn test_migrate_fix_pending_emissions() { Stake::::insert(taostats_old_hk_account, null_account, null_stake_tao_stats); let expected_taostats_new_hk_pending_emission: u64 = 987_654 + 100_000; - let total_issuance_before = SubtensorModule::get_total_issuance(); + let total_issuance_before = TotalIssuance::::get(); // Run migration let first_weight = run_pending_emissions_migration_and_check(migration_name); @@ -642,10 +636,7 @@ fn test_migrate_fix_pending_emissions() { // Check the total issuance is the SAME following migration (no TAO issued) let expected_total_issuance = total_issuance_before; - assert_eq!( - SubtensorModule::get_total_issuance(), - expected_total_issuance - ); + assert_eq!(TotalIssuance::::get(), expected_total_issuance); // Check total stake is the SAME following the migration (no new TAO staked) assert_eq!(TotalStake::::get(), expected_total_issuance); diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 2a19c0459..f52653a98 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -9,7 +9,7 @@ use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, EmissionValues, Error, NetworkRateLimit, PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetOwner, - SubnetworkN, TotalNetworks, + SubnetworkN, TotalIssuance, TotalNetworks, }; #[allow(dead_code)] @@ -526,7 +526,7 @@ fn test_network_pruning() { System::set_block_number(0); migrations::migrate_create_root_network::migrate_create_root_network::(); - assert_eq!(SubtensorModule::get_total_issuance(), 0); + assert_eq!(TotalIssuance::::get(), 0); let n: usize = 10; let root_netuid: u16 = 0; @@ -656,7 +656,7 @@ fn test_weights_after_network_pruning() { new_test_ext(1).execute_with(|| { migrations::migrate_create_root_network::migrate_create_root_network::(); - assert_eq!(SubtensorModule::get_total_issuance(), 0); + assert_eq!(TotalIssuance::::get(), 0); // Set up N subnets, with max N + 1 allowed UIDs let n: usize = 2; diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 79d986288..d3ad252b0 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1566,7 +1566,7 @@ fn test_remove_stake_below_minimum_threshold() { let bal_before = Balances::free_balance(coldkey2); let staked_before = Stake::::get(hotkey1, coldkey2); let total_network_stake_before = SubtensorModule::get_total_stake(); - let total_issuance_before = SubtensorModule::get_total_issuance(); + let total_issuance_before = TotalIssuance::::get(); // check the premise of the test is correct assert!(initial_stake - stake_amount_to_remove < minimum_threshold); assert_ok!(SubtensorModule::remove_stake( @@ -1599,7 +1599,7 @@ fn test_remove_stake_below_minimum_threshold() { // Total issuance is the same assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), total_issuance_before // Nothing was issued ); }); diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 735e03eb8..8c748d163 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -671,7 +671,7 @@ fn test_swap_stake_for_coldkey() { TotalStake::::put(total_stake); // Record initial values - let initial_total_issuance = SubtensorModule::get_total_issuance(); + let initial_total_issuance = TotalIssuance::::get(); let initial_total_stake = SubtensorModule::get_total_stake(); // Perform the swap @@ -710,7 +710,7 @@ fn test_swap_stake_for_coldkey() { "Total stake changed unexpectedly" ); assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), initial_total_issuance, "Total issuance changed unexpectedly" ); @@ -784,7 +784,7 @@ fn test_swap_delegated_stake_for_coldkey() { TotalStake::::put(total_stake); // Record initial values - let initial_total_issuance = SubtensorModule::get_total_issuance(); + let initial_total_issuance = TotalIssuance::::get(); let initial_total_stake = SubtensorModule::get_total_stake(); // Perform the swap @@ -811,7 +811,7 @@ fn test_swap_delegated_stake_for_coldkey() { "Total stake changed unexpectedly" ); assert_eq!( - SubtensorModule::get_total_issuance(), + TotalIssuance::::get(), initial_total_issuance, "Total issuance changed unexpectedly" ); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 88bfd43e1..cc9872a65 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -56,9 +56,6 @@ impl Pallet { // ======================== // ==== Global Getters ==== // ======================== - pub fn get_total_issuance() -> u64 { - TotalIssuance::::get() - } pub fn get_current_block_as_u64() -> u64 { TryInto::try_into(>::block_number()) .ok() From 98afbc7b91f331c750da77fadb013e54ab4d7f23 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 16:35:46 +0100 Subject: [PATCH 096/137] Remove get_total_stake from pallet-subtensor::Pallet --- pallets/subtensor/src/benchmarks.rs | 2 +- .../migrate_fix_pending_emission.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 6 --- pallets/subtensor/src/tests/epoch.rs | 2 +- pallets/subtensor/src/tests/migration.rs | 6 +-- pallets/subtensor/src/tests/staking.rs | 47 +++++++++---------- pallets/subtensor/src/tests/swap_coldkey.rs | 27 ++++------- 7 files changed, 36 insertions(+), 56 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index f2798cdbb..404bd40cd 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -143,7 +143,7 @@ benchmarks! { Subtensor::::set_target_stakes_per_interval(100); // Set our total stake to 1000 TAO - TotalStake::::put(Subtensor::::get_total_stake().saturating_add(1_000_000_000_000)); + TotalStake::::put(TotalStake::::get().saturating_add(1_000_000_000_000)); Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_network_registration_allowed( netuid, true ); diff --git a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs index a572ccac0..ac63706ae 100644 --- a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs +++ b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs @@ -383,7 +383,7 @@ pub mod migration { } }?; - let total_stake_before: u64 = crate::Pallet::::get_total_stake(); + let total_stake_before = TotalStake::::get(); let result = v0::OldStorage { total_issuance_before, diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index c70733bad..26f65aad2 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -23,12 +23,6 @@ impl Pallet { Delegates::::insert(hotkey, take); } - // Returns the total amount of stake in the staking table. - // - pub fn get_total_stake() -> u64 { - TotalStake::::get() - } - // Returns the total amount of stake under a hotkey (delegative or otherwise) // pub fn get_total_stake_for_hotkey(hotkey: &T::AccountId) -> u64 { diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 43a68053c..7b9a26db8 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -858,7 +858,7 @@ fn test_4096_graph() { 0, true, ); - assert_eq!(SubtensorModule::get_total_stake(), 21_000_000_000_000_000); + assert_eq!(TotalStake::::get(), 21_000_000_000_000_000); let bonds = SubtensorModule::get_bonds(netuid); for uid in &validators { assert_eq!( diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 7035c5960..447d8e18a 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -65,7 +65,7 @@ fn test_migration_fix_total_stake_maps() { total_stake_amount += 1_123_000_000; // Check that the total stake is correct - assert_eq!(SubtensorModule::get_total_stake(), total_stake_amount); + assert_eq!(TotalStake::::get(), total_stake_amount); // Check that the total coldkey stake is correct assert_eq!( @@ -96,14 +96,14 @@ fn test_migration_fix_total_stake_maps() { // Mess up the total stake crate::TotalStake::::put(123_456_789); // Verify that the total stake is now wrong - assert_ne!(SubtensorModule::get_total_stake(), total_stake_amount); + assert_ne!(TotalStake::::get(), total_stake_amount); // Run the migration to fix the total stake maps crate::migrations::migrate_to_v2_fixed_total_stake::migrate_to_v2_fixed_total_stake::( ); // Verify that the total stake is now correct - assert_eq!(SubtensorModule::get_total_stake(), total_stake_amount); + assert_eq!(TotalStake::::get(), total_stake_amount); // Verify that the total coldkey stake is now correct for each coldkey assert_eq!( SubtensorModule::get_total_stake_for_coldkey(&ck1), diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index d3ad252b0..88012adc7 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -58,7 +58,7 @@ fn test_add_stake_ok_no_emission() { ); // Also total stake should be zero - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); // Transfer to hotkey account, and check if the result is ok assert_ok!(SubtensorModule::add_stake( @@ -77,7 +77,7 @@ fn test_add_stake_ok_no_emission() { assert_eq!(SubtensorModule::get_coldkey_balance(&coldkey_account_id), 1); // Check if total stake has increased accordingly. - assert_eq!(SubtensorModule::get_total_stake(), 9999); + assert_eq!(TotalStake::::get(), 9999); }); } @@ -251,7 +251,7 @@ fn test_add_stake_total_balance_no_change() { assert_eq!(initial_total_balance, initial_balance); // Also total stake should be zero - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); // Stake to hotkey account, and check if the result is ok assert_ok!(SubtensorModule::add_stake( @@ -269,7 +269,7 @@ fn test_add_stake_total_balance_no_change() { assert_eq!(new_free_balance, 0); // Check if total stake has increased accordingly. - assert_eq!(SubtensorModule::get_total_stake(), 10000); + assert_eq!(TotalStake::::get(), 10000); // Check if total balance has remained the same. (no fee, includes reserved/locked balance) let total_balance = Balances::total_balance(&coldkey_account_id); @@ -312,7 +312,7 @@ fn test_add_stake_total_issuance_no_change() { assert_eq!(initial_total_issuance, initial_balance); // Also total stake should be zero - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); // Stake to hotkey account, and check if the result is ok assert_ok!(SubtensorModule::add_stake( @@ -330,7 +330,7 @@ fn test_add_stake_total_issuance_no_change() { assert_eq!(new_free_balance, 0); // Check if total stake has increased accordingly. - assert_eq!(SubtensorModule::get_total_stake(), 10000); + assert_eq!(TotalStake::::get(), 10000); // Check if total issuance has remained the same. (no fee, includes reserved/locked balance) let total_issuance = Balances::total_issuance(); @@ -550,7 +550,7 @@ fn test_remove_stake_ok_no_emission() { register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, start_nonce); // Some basic assertions - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 @@ -575,7 +575,7 @@ fn test_remove_stake_ok_no_emission() { SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 ); - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); }); } @@ -596,7 +596,7 @@ fn test_remove_stake_amount_zero() { register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, start_nonce); // Some basic assertions - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 @@ -707,7 +707,7 @@ fn test_remove_stake_total_balance_no_change() { register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, start_nonce); // Some basic assertions - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 @@ -734,7 +734,7 @@ fn test_remove_stake_total_balance_no_change() { SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 ); - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); // Check total balance is equal to the added stake. Even after remove stake (no fee, includes reserved/locked balance) let total_balance = Balances::total_balance(&coldkey_account_id); @@ -763,7 +763,7 @@ fn test_remove_stake_total_issuance_no_change() { register_ok_neuron(netuid, hotkey_account_id, coldkey_account_id, start_nonce); // Some basic assertions - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 @@ -794,7 +794,7 @@ fn test_remove_stake_total_issuance_no_change() { SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), 0 ); - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); // Check if total issuance is equal to the added stake, even after remove stake (no fee, includes reserved/locked balance) // Should also be equal to the total issuance after adding stake @@ -853,7 +853,7 @@ fn test_add_stake_to_hotkey_account_ok() { register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); // There is not stake in the system at first, so result should be 0; - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); SubtensorModule::increase_stake_on_hotkey_account(&hotkey_id, amount); @@ -864,7 +864,7 @@ fn test_add_stake_to_hotkey_account_ok() { ); // The total stake should have been increased by the amount -> 0 + amount = amount - assert_eq!(SubtensorModule::get_total_stake(), amount); + assert_eq!(TotalStake::::get(), amount); }); } @@ -890,7 +890,7 @@ fn test_remove_stake_from_hotkey_account() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey_id, amount); // Prelimiary checks - assert_eq!(SubtensorModule::get_total_stake(), amount); + assert_eq!(TotalStake::::get(), amount); assert_eq!( SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), amount @@ -907,7 +907,7 @@ fn test_remove_stake_from_hotkey_account() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); // The total amount of stake should be 0 - assert_eq!(SubtensorModule::get_total_stake(), 0); + assert_eq!(TotalStake::::get(), 0); }); } @@ -981,16 +981,11 @@ fn test_decrease_total_stake_ok() { let initial_total_stake = 10000; let decrement = 5000; - TotalStake::::put( - SubtensorModule::get_total_stake().saturating_add(initial_total_stake), - ); - TotalStake::::put(SubtensorModule::get_total_stake().saturating_sub(decrement)); + TotalStake::::put(TotalStake::::get().saturating_add(initial_total_stake)); + TotalStake::::put(TotalStake::::get().saturating_sub(decrement)); // The total stake remaining should be the difference between the initial stake and the decrement - assert_eq!( - SubtensorModule::get_total_stake(), - initial_total_stake - decrement - ); + assert_eq!(TotalStake::::get(), initial_total_stake - decrement); }); } @@ -1565,7 +1560,7 @@ fn test_remove_stake_below_minimum_threshold() { let total_hotkey_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey1); let bal_before = Balances::free_balance(coldkey2); let staked_before = Stake::::get(hotkey1, coldkey2); - let total_network_stake_before = SubtensorModule::get_total_stake(); + let total_network_stake_before = TotalStake::::get(); let total_issuance_before = TotalIssuance::::get(); // check the premise of the test is correct assert!(initial_stake - stake_amount_to_remove < minimum_threshold); diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 8c748d163..61379d1ff 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -504,10 +504,7 @@ fn test_do_swap_coldkey_success() { ); // Log initial state - log::info!( - "Initial total stake: {}", - SubtensorModule::get_total_stake() - ); + log::info!("Initial total stake: {}", TotalStake::::get()); log::info!( "Initial old coldkey stake: {}", SubtensorModule::get_total_stake_for_coldkey(&old_coldkey) @@ -546,10 +543,7 @@ fn test_do_swap_coldkey_success() { assert!(Identities::::get(new_coldkey).is_none()); // Log state after adding stake - log::info!( - "Total stake after adding: {}", - SubtensorModule::get_total_stake() - ); + log::info!("Total stake after adding: {}", TotalStake::::get()); log::info!( "Old coldkey stake after adding: {}", SubtensorModule::get_total_stake_for_coldkey(&old_coldkey) @@ -560,7 +554,7 @@ fn test_do_swap_coldkey_success() { ); // Record total stake before swap - let total_stake_before_swap = SubtensorModule::get_total_stake(); + let total_stake_before_swap = TotalStake::::get(); // Perform the swap assert_ok!(SubtensorModule::do_swap_coldkey( @@ -570,10 +564,7 @@ fn test_do_swap_coldkey_success() { )); // Log state after swap - log::info!( - "Total stake after swap: {}", - SubtensorModule::get_total_stake() - ); + log::info!("Total stake after swap: {}", TotalStake::::get()); log::info!( "Old coldkey stake after swap: {}", SubtensorModule::get_total_stake_for_coldkey(&old_coldkey) @@ -612,7 +603,7 @@ fn test_do_swap_coldkey_success() { // Verify total stake remains unchanged assert_eq!( - SubtensorModule::get_total_stake(), + TotalStake::::get(), total_stake_before_swap, "Total stake changed unexpectedly" ); @@ -672,7 +663,7 @@ fn test_swap_stake_for_coldkey() { // Record initial values let initial_total_issuance = TotalIssuance::::get(); - let initial_total_stake = SubtensorModule::get_total_stake(); + let initial_total_stake = TotalStake::::get(); // Perform the swap SubtensorModule::perform_swap_coldkey(&old_coldkey, &new_coldkey, &mut weight); @@ -705,7 +696,7 @@ fn test_swap_stake_for_coldkey() { // Verify total stake and issuance remain unchanged assert_eq!( - SubtensorModule::get_total_stake(), + TotalStake::::get(), initial_total_stake, "Total stake changed unexpectedly" ); @@ -785,7 +776,7 @@ fn test_swap_delegated_stake_for_coldkey() { // Record initial values let initial_total_issuance = TotalIssuance::::get(); - let initial_total_stake = SubtensorModule::get_total_stake(); + let initial_total_stake = TotalStake::::get(); // Perform the swap SubtensorModule::perform_swap_coldkey(&old_coldkey, &new_coldkey, &mut weight); @@ -806,7 +797,7 @@ fn test_swap_delegated_stake_for_coldkey() { // Verify total stake and issuance remain unchanged assert_eq!( - SubtensorModule::get_total_stake(), + TotalStake::::get(), initial_total_stake, "Total stake changed unexpectedly" ); From 9900c177cc373ddd0d68dad9366845cf3d0301a3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 16:51:27 +0100 Subject: [PATCH 097/137] Remove get_total_stake_for_coldkey from pallet-subtensor::Pallet --- pallets/subtensor/src/staking/helpers.rs | 6 ---- pallets/subtensor/src/tests/migration.rs | 26 +++++----------- pallets/subtensor/src/tests/staking.rs | 5 +--- pallets/subtensor/src/tests/swap_coldkey.rs | 33 ++++++++------------- 4 files changed, 20 insertions(+), 50 deletions(-) diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 26f65aad2..37cd36bf6 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -29,12 +29,6 @@ impl Pallet { TotalHotkeyStake::::get(hotkey) } - // Returns the total amount of stake held by the coldkey (delegative or otherwise) - // - pub fn get_total_stake_for_coldkey(coldkey: &T::AccountId) -> u64 { - TotalColdkeyStake::::get(coldkey) - } - // Creates a cold - hot pairing account if the hotkey is not already an active account. // pub fn create_account_if_non_existent(coldkey: &T::AccountId, hotkey: &T::AccountId) { diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 447d8e18a..37f328791 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -68,15 +68,9 @@ fn test_migration_fix_total_stake_maps() { assert_eq!(TotalStake::::get(), total_stake_amount); // Check that the total coldkey stake is correct - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&ck1), - 100 + 1_123_000_000 - ); - assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&ck2), 10_101); - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&ck3), - 100_000_000 - ); + assert_eq!(TotalColdkeyStake::::get(ck1), 100 + 1_123_000_000); + assert_eq!(TotalColdkeyStake::::get(ck2), 10_101); + assert_eq!(TotalColdkeyStake::::get(ck3), 100_000_000); // Check that the total hotkey stake is correct assert_eq!( @@ -91,7 +85,7 @@ fn test_migration_fix_total_stake_maps() { // Mess up the total coldkey stake crate::TotalColdkeyStake::::insert(ck1, 0); // Verify that the total coldkey stake is now 0 for ck1 - assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&ck1), 0); + assert_eq!(TotalColdkeyStake::::get(ck1), 0); // Mess up the total stake crate::TotalStake::::put(123_456_789); @@ -105,15 +99,9 @@ fn test_migration_fix_total_stake_maps() { // Verify that the total stake is now correct assert_eq!(TotalStake::::get(), total_stake_amount); // Verify that the total coldkey stake is now correct for each coldkey - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&ck1), - 100 + 1_123_000_000 - ); - assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&ck2), 10_101); - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&ck3), - 100_000_000 - ); + assert_eq!(TotalColdkeyStake::::get(ck1), 100 + 1_123_000_000); + assert_eq!(TotalColdkeyStake::::get(ck2), 10_101); + assert_eq!(TotalColdkeyStake::::get(ck3), 100_000_000); // Verify that the total hotkey stake is STILL correct for each hotkey assert_eq!( diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 88012adc7..d15efc764 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1140,10 +1140,7 @@ fn test_non_existent_account() { 10, ); assert_eq!(Stake::::get(U256::from(0), U256::from(0)), 10); - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&(U256::from(0))), - 10 - ); + assert_eq!(TotalColdkeyStake::::get((U256::from(0))), 10); }); } diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 61379d1ff..cf205cc20 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -507,11 +507,11 @@ fn test_do_swap_coldkey_success() { log::info!("Initial total stake: {}", TotalStake::::get()); log::info!( "Initial old coldkey stake: {}", - SubtensorModule::get_total_stake_for_coldkey(&old_coldkey) + TotalColdkeyStake::::get(old_coldkey) ); log::info!( "Initial new coldkey stake: {}", - SubtensorModule::get_total_stake_for_coldkey(&new_coldkey) + TotalColdkeyStake::::get(new_coldkey) ); // Add stake to the neurons @@ -546,11 +546,11 @@ fn test_do_swap_coldkey_success() { log::info!("Total stake after adding: {}", TotalStake::::get()); log::info!( "Old coldkey stake after adding: {}", - SubtensorModule::get_total_stake_for_coldkey(&old_coldkey) + TotalColdkeyStake::::get(old_coldkey) ); log::info!( "New coldkey stake after adding: {}", - SubtensorModule::get_total_stake_for_coldkey(&new_coldkey) + TotalColdkeyStake::::get(new_coldkey) ); // Record total stake before swap @@ -567,11 +567,11 @@ fn test_do_swap_coldkey_success() { log::info!("Total stake after swap: {}", TotalStake::::get()); log::info!( "Old coldkey stake after swap: {}", - SubtensorModule::get_total_stake_for_coldkey(&old_coldkey) + TotalColdkeyStake::::get(old_coldkey) ); log::info!( "New coldkey stake after swap: {}", - SubtensorModule::get_total_stake_for_coldkey(&new_coldkey) + TotalColdkeyStake::::get(new_coldkey) ); // Verify the swap @@ -1094,7 +1094,7 @@ fn test_coldkey_swap_total() { StakingHotkeys::::get(coldkey), vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); - assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&coldkey), 600); + assert_eq!(TotalColdkeyStake::::get(coldkey), 600); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 300); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey2), 300); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey3), 300); @@ -1137,17 +1137,14 @@ fn test_coldkey_swap_total() { // Perform the swap let new_coldkey = U256::from(1100); - assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&coldkey), 600); + assert_eq!(TotalColdkeyStake::::get(coldkey), 600); let mut weight = Weight::zero(); assert_ok!(SubtensorModule::perform_swap_coldkey( &coldkey, &new_coldkey, &mut weight )); - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&new_coldkey), - 600 - ); + assert_eq!(TotalColdkeyStake::::get(new_coldkey), 600); // Check everything is swapped. assert_eq!( @@ -1158,10 +1155,7 @@ fn test_coldkey_swap_total() { StakingHotkeys::::get(new_coldkey), vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&new_coldkey), - 600 - ); + assert_eq!(TotalColdkeyStake::::get(new_coldkey), 600); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 300); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey2), 300); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey3), 300); @@ -1278,11 +1272,8 @@ fn test_coldkey_delegations() { &mut weight )); assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate), 100); - assert_eq!(SubtensorModule::get_total_stake_for_coldkey(&coldkey), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_coldkey(&new_coldkey), - 100 - ); + assert_eq!(TotalColdkeyStake::::get(coldkey), 0); + assert_eq!(TotalColdkeyStake::::get(new_coldkey), 100); assert_eq!(Stake::::get(delegate, new_coldkey), 100); assert_eq!(Stake::::get(delegate, coldkey), 0); }); From 33cf8ccbc546ad19f28e808889e27d5fb36839d2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 17:29:53 +0100 Subject: [PATCH 098/137] Remove get_total_stake_for_hotkey from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 16 +-- .../subtensor/src/coinbase/run_coinbase.rs | 4 +- pallets/subtensor/src/epoch/run_epoch.rs | 4 +- .../subtensor/src/rpc_info/delegate_info.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 6 -- pallets/subtensor/src/staking/remove_stake.rs | 2 +- pallets/subtensor/src/staking/set_children.rs | 2 +- pallets/subtensor/src/tests/coinbase.rs | 74 +++++-------- pallets/subtensor/src/tests/epoch.rs | 36 ++----- pallets/subtensor/src/tests/migration.rs | 14 +-- pallets/subtensor/src/tests/senate.rs | 26 ++--- pallets/subtensor/src/tests/staking.rs | 102 ++++++------------ pallets/subtensor/src/tests/swap_coldkey.rs | 26 ++--- pallets/subtensor/src/tests/uids.rs | 9 +- pallets/subtensor/src/tests/weights.rs | 36 +++---- pallets/subtensor/src/utils/misc.rs | 4 - 16 files changed, 121 insertions(+), 242 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index e0c1272e8..5b460217d 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -319,7 +319,7 @@ impl Pallet { // Stakes are stored in a 64-bit fixed point representation for precise calculations. let mut stake_i64: Vec = vec![I64F64::from_num(0.0); n as usize]; for ((_, hotkey), stake) in hotkeys.iter().zip(&mut stake_i64) { - *stake = I64F64::from_num(Self::get_total_stake_for_hotkey(hotkey)); + *stake = I64F64::from_num(TotalHotkeyStake::::get(hotkey)); } inplace_normalize_64(&mut stake_i64); log::debug!("S:\n{:?}\n", &stake_i64); @@ -491,7 +491,7 @@ impl Pallet { root_netuid, ) { - let stake_i: u64 = Self::get_total_stake_for_hotkey(&hotkey_i); + let stake_i: u64 = TotalHotkeyStake::::get(&hotkey_i); if stake_i < lowest_stake { lowest_stake = stake_i; lowest_uid = uid_i; @@ -503,7 +503,7 @@ impl Pallet { // --- 13.1.2 The new account has a higher stake than the one being replaced. ensure!( - lowest_stake < Self::get_total_stake_for_hotkey(&hotkey), + lowest_stake < TotalHotkeyStake::::get(&hotkey), Error::::StakeTooLowForRoot ); @@ -640,7 +640,7 @@ impl Pallet { ); // --- 3. Grab the hotkey's stake. - let current_stake = Self::get_total_stake_for_hotkey(hotkey); + let current_stake = TotalHotkeyStake::::get(hotkey); // Add the hotkey to the Senate. // If we're full, we'll swap out the lowest stake member. @@ -649,14 +649,14 @@ 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_total_stake_for_hotkey(a); - let b_stake = Self::get_total_stake_for_hotkey(b); + let a_stake = TotalHotkeyStake::::get(a); + let b_stake = TotalHotkeyStake::::get(b); b_stake.cmp(&a_stake) }); if let Some(last) = sorted_members.last() { - let last_stake = Self::get_total_stake_for_hotkey(last); + let last_stake = TotalHotkeyStake::::get(last); if last_stake < current_stake { // Swap the member with the lowest stake. @@ -732,7 +732,7 @@ impl Pallet { // Check to see if the hotkey has enough stake to set weights. ensure!( - Self::get_total_stake_for_hotkey(&hotkey) >= Self::get_stake_threshold(), + TotalHotkeyStake::::get(&hotkey) >= Self::get_stake_threshold(), Error::::NotEnoughStakeToSetWeights ); diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 8053a8a0e..b06fb8a4f 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -374,7 +374,7 @@ impl Pallet { // and calculate their share of the emission accordingly. for (proportion, parent) in ParentKeys::::get(hotkey, netuid) { // --- 4.1 Retrieve the parent's stake. This is the raw stake value including nominators. - let parent_stake: u64 = Self::get_total_stake_for_hotkey(&parent); + let parent_stake: u64 = TotalHotkeyStake::::get(&parent); // --- 4.2 Calculate the portion of the hotkey's total stake contributed by this parent. // Then, determine the parent's share of the remaining emission. @@ -456,7 +456,7 @@ impl Pallet { LastHotkeyEmissionDrain::::insert(hotkey, block_number); // --- 3 Retrieve the total stake for the hotkey from all nominations. - let total_hotkey_stake: u64 = Self::get_total_stake_for_hotkey(hotkey); + let total_hotkey_stake: u64 = TotalHotkeyStake::::get(hotkey); // --- 4 Calculate the emission take for the hotkey. // This is only the hotkey take. Childkey take was already deducted from validator emissions in diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 128fe120f..363eb8014 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -33,7 +33,7 @@ impl Pallet { /// pub fn get_stake_for_hotkey_on_subnet(hotkey: &T::AccountId, netuid: u16) -> u64 { // Retrieve the initial total stake for the hotkey without any child/parent adjustments. - let initial_stake: u64 = Self::get_total_stake_for_hotkey(hotkey); + let initial_stake: u64 = TotalHotkeyStake::::get(hotkey); log::debug!("Initial stake: {:?}", initial_stake); let mut stake_to_children: u64 = 0; let mut stake_from_parents: u64 = 0; @@ -58,7 +58,7 @@ impl Pallet { // Iterate over parents to calculate the total stake received from them. for (proportion, parent) in parents { // Retrieve the parent's total stake. - let parent_stake: u64 = Self::get_total_stake_for_hotkey(&parent); + let parent_stake: u64 = TotalHotkeyStake::::get(&parent); // Calculate the stake proportion received from the parent. let normalized_proportion: I96F32 = I96F32::from_num(proportion).saturating_div(I96F32::from_num(u64::MAX)); diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index 44d810f34..2521ee8c7 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -60,7 +60,7 @@ impl Pallet { let owner = Owner::::get(&delegate.clone()); let take: Compact = >::get(delegate.clone()).into(); - let total_stake: U64F64 = Self::get_total_stake_for_hotkey(&delegate.clone()).into(); + let total_stake: U64F64 = TotalHotkeyStake::::get(&delegate.clone()).into(); let return_per_1000: U64F64 = if total_stake > U64F64::from_num(0) { emissions_per_day diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 37cd36bf6..8f2d21ddd 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -23,12 +23,6 @@ impl Pallet { Delegates::::insert(hotkey, take); } - // Returns the total amount of stake under a hotkey (delegative or otherwise) - // - pub fn get_total_stake_for_hotkey(hotkey: &T::AccountId) -> u64 { - TotalHotkeyStake::::get(hotkey) - } - // Creates a cold - hot pairing account if the hotkey is not already an active account. // pub fn create_account_if_non_existent(coldkey: &T::AccountId, hotkey: &T::AccountId) { diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index 7a101a8ae..b962b56a8 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -85,7 +85,7 @@ impl Pallet { Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake); // Check if stake lowered below MinStake and remove Pending children if it did - if Self::get_total_stake_for_hotkey(&hotkey) < StakeThreshold::::get() { + if TotalHotkeyStake::::get(&hotkey) < StakeThreshold::::get() { Self::get_all_subnet_netuids().iter().for_each(|netuid| { PendingChildKeys::::remove(netuid, &hotkey); }) diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index 2c6fcf6f7..ee7fd3149 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -115,7 +115,7 @@ impl Pallet { // grandparent stake in this case) ensure!( children.is_empty() - || Self::get_total_stake_for_hotkey(&hotkey) >= StakeThreshold::::get(), + || TotalHotkeyStake::::get(&hotkey) >= StakeThreshold::::get(), Error::::NotEnoughStakeToSetChildkeys ); diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 103d9cce5..0e3f8397f 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -7,7 +7,7 @@ use substrate_fixed::types::I64F64; use crate::{ EmissionValues, HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, Stake, - TargetStakesPerInterval, + TargetStakesPerInterval, TotalHotkeyStake, }; // Test the ability to hash all sorts of hotkeys. @@ -74,7 +74,7 @@ fn test_coinbase_basic() { assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has same stake - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 1000); + assert_eq!(TotalHotkeyStake::::get(hotkey), 1000); // Subnet has no pending emission. assert_eq!(PendingEmission::::get(netuid), 0); @@ -86,7 +86,7 @@ fn test_coinbase_basic() { assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has same stake - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 1000); + assert_eq!(TotalHotkeyStake::::get(hotkey), 1000); // Subnet has no pending emission of 1 ( from coinbase ) assert_eq!(PendingEmission::::get(netuid), 1); @@ -101,10 +101,7 @@ fn test_coinbase_basic() { assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has NEW stake - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - 1000 + 2 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), 1000 + 2); // Set the hotkey drain time to 2 block. SubtensorModule::set_hotkey_emission_tempo(2); @@ -119,10 +116,7 @@ fn test_coinbase_basic() { assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has same stake - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - 1000 + 2 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), 1000 + 2); // Step block releases next_block(); @@ -134,10 +128,7 @@ fn test_coinbase_basic() { assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); // Hotkey has 2 new TAO. - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - 1000 + 4 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), 1000 + 4); }); } @@ -324,10 +315,7 @@ fn test_coinbase_nominator_drainage_overflow() { SubtensorModule::set_emission_values(&[netuid], vec![to_emit]).unwrap(); assert_eq!(EmissionValues::::get(netuid), to_emit); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - initial_stake * 2 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), initial_stake * 2); assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -381,7 +369,7 @@ fn test_coinbase_nominator_drainage_overflow() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Assertions @@ -474,7 +462,7 @@ fn test_coinbase_nominator_drainage_no_deltas() { SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); + assert_eq!(TotalHotkeyStake::::get(hotkey), 200); assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -527,7 +515,7 @@ fn test_coinbase_nominator_drainage_no_deltas() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Assertions @@ -618,10 +606,7 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - 200 + 123 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), 200 + 123); assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -675,7 +660,7 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Assertions @@ -773,10 +758,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - 200 - 12 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), 200 - 12); assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -800,7 +782,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { // 8. Check final stakes let delegate_stake = Stake::::get(hotkey, coldkey); - let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_hotkey_stake = TotalHotkeyStake::::get(hotkey); let nominator1_stake = Stake::::get(hotkey, nominator1); let nominator2_stake = Stake::::get(hotkey, nominator2); @@ -834,7 +816,7 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Assertions @@ -936,7 +918,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap(); assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey), 200); + assert_eq!(TotalHotkeyStake::::get(hotkey), 200); assert_eq!(PendingEmission::::get(netuid), 0); log::debug!("Emission set and initial states verified"); @@ -960,7 +942,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { // 8. Check final stakes let delegate_stake = Stake::::get(hotkey, coldkey); - let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_hotkey_stake = TotalHotkeyStake::::get(hotkey); let nominator1_stake = Stake::::get(hotkey, nominator1); let nominator2_stake = Stake::::get(hotkey, nominator2); @@ -994,7 +976,7 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Assertions @@ -1064,7 +1046,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 100); let initial_nominator1_stake = Stake::::get(hotkey, nominator1); - let intial_total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let intial_total_hotkey_stake = TotalHotkeyStake::::get(hotkey); let initial_nominator2_stake = Stake::::get(hotkey, nominator2); assert_eq!(initial_nominator1_stake, initial_nominator2_stake); // Initial stakes should be equal @@ -1111,7 +1093,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { assert_eq!(EmissionValues::::get(netuid), 10); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), + TotalHotkeyStake::::get(hotkey), u64::try_from(200 + net_change).unwrap() ); assert_eq!(PendingEmission::::get(netuid), 0); @@ -1137,7 +1119,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { // 8. Check final stakes let delegate_stake = Stake::::get(hotkey, coldkey); - let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_hotkey_stake = TotalHotkeyStake::::get(hotkey); let nominator1_stake = Stake::::get(hotkey, nominator1); let nominator2_stake = Stake::::get(hotkey, nominator2); @@ -1175,7 +1157,7 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Assertions @@ -1258,7 +1240,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 300); let initial_nominator1_stake = Stake::::get(hotkey, nominator1); - let intial_total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let intial_total_hotkey_stake = TotalHotkeyStake::::get(hotkey); let initial_nominator2_stake = Stake::::get(hotkey, nominator2); assert_eq!(initial_nominator1_stake, initial_nominator2_stake); // Initial stakes should be equal @@ -1294,7 +1276,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { ); log::debug!("Stakes added for nominators"); - let total_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake_before = TotalHotkeyStake::::get(hotkey); let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!( @@ -1308,7 +1290,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { assert_eq!(EmissionValues::::get(netuid), to_emit); assert_eq!(PendingdHotkeyEmission::::get(hotkey), 0); assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), + TotalHotkeyStake::::get(hotkey), u64::try_from(600 + net_change).unwrap() ); assert_eq!(PendingEmission::::get(netuid), 0); @@ -1334,7 +1316,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { // 8. Check final stakes let delegate_stake = Stake::::get(hotkey, coldkey); - let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_hotkey_stake = TotalHotkeyStake::::get(hotkey); let nominator1_stake = Stake::::get(hotkey, nominator1); let nominator2_stake = Stake::::get(hotkey, nominator2); @@ -1373,7 +1355,7 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { log::debug!("Actual nominator2 stake: {}", nominator2_stake); // Debug: Check the total stake for the hotkey - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); log::debug!("Total stake for hotkey: {}", total_stake); // Do a fuzzy check on the final stakes @@ -1476,7 +1458,7 @@ fn test_emission_with_registration_disabled_subnet() { // Verify total stake remains unchanged after many blocks // This confirms no emissions were added to stake - let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); + let total_stake = TotalHotkeyStake::::get(hotkey); assert_eq!( total_stake, 1000, "Total stake should not increase when registration is disabled" diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 7b9a26db8..380c4d559 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -110,7 +110,7 @@ fn distribute_nodes( fn uid_stats(netuid: u16, uid: u16) { log::info!( "stake: {:?}", - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))) + TotalHotkeyStake::::get(U256::from(uid)) ); log::info!("rank: {:?}", SubtensorModule::get_rank_for_uid(netuid, uid)); log::info!( @@ -566,10 +566,7 @@ fn test_1_graph() { SubtensorModule::set_emission_values(&[netuid], vec![1_000_000_000]).unwrap(); assert_eq!(EmissionValues::::get(netuid), 1_000_000_000); SubtensorModule::epoch(netuid, 1_000_000_000); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - stake_amount - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), stake_amount); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, uid), 0); assert_eq!(SubtensorModule::get_trust_for_uid(netuid, uid), 0); assert_eq!(SubtensorModule::get_consensus_for_uid(netuid, uid), 0); @@ -630,10 +627,7 @@ fn test_10_graph() { SubtensorModule::epoch(netuid, 1_000_000_000); // Check return values. for i in 0..n { - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(i))), - 1 - ); + assert_eq!(TotalHotkeyStake::::get(U256::from(i)), 1); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, i as u16), 0); assert_eq!(SubtensorModule::get_trust_for_uid(netuid, i as u16), 0); assert_eq!(SubtensorModule::get_consensus_for_uid(netuid, i as u16), 0); @@ -686,7 +680,7 @@ fn test_512_graph() { let bonds = SubtensorModule::get_bonds(netuid); for uid in validators { assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))), + TotalHotkeyStake::::get(U256::from(uid)), max_stake_per_validator ); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, uid), 0); @@ -700,10 +694,7 @@ fn test_512_graph() { // Note B_ij = floor(1 / 64 * 65_535) / 65_535 = 1023 / 65_535, then max-upscaled to 65_535 } for uid in servers { - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(U256::from(uid)), 0); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, uid), 146); // Note R = floor(1 / (512 - 64) * 65_535) = 146 assert_eq!(SubtensorModule::get_trust_for_uid(netuid, uid), 65535); assert_eq!(SubtensorModule::get_consensus_for_uid(netuid, uid), 146); // Note C = floor(1 / (512 - 64) * 65_535) = 146 @@ -862,7 +853,7 @@ fn test_4096_graph() { let bonds = SubtensorModule::get_bonds(netuid); for uid in &validators { assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(*uid as u64))), + TotalHotkeyStake::::get(U256::from(*uid as u64)), max_stake_per_validator ); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, *uid), 0); @@ -878,10 +869,7 @@ fn test_4096_graph() { ); // Note B_ij = floor(1 / 256 * 65_535) / 65_535 } for uid in &servers { - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(*uid as u64))), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(U256::from(*uid as u64)), 0); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, *uid), 17); // Note R = floor(1 / (4096 - 256) * 65_535) = 17 assert_eq!(SubtensorModule::get_trust_for_uid(netuid, *uid), 65535); assert_eq!(SubtensorModule::get_consensus_for_uid(netuid, *uid), 17); // Note C = floor(1 / (4096 - 256) * 65_535) = 17 @@ -927,10 +915,7 @@ fn test_16384_graph_sparse() { ); let bonds = SubtensorModule::get_bonds(netuid); for uid in validators { - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))), - 1 - ); + assert_eq!(TotalHotkeyStake::::get(U256::from(uid)), 1); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, uid), 0); assert_eq!(SubtensorModule::get_trust_for_uid(netuid, uid), 0); assert_eq!(SubtensorModule::get_consensus_for_uid(netuid, uid), 438); // Note C = 0.0066928507 = (0.0066928507*65_535) = floor( 438.6159706245 ) @@ -944,10 +929,7 @@ fn test_16384_graph_sparse() { ); // Note B_ij = floor(1 / 512 * 65_535) / 65_535 = 127 / 65_535 } for uid in servers { - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&(U256::from(uid))), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(U256::from(uid)), 0); assert_eq!(SubtensorModule::get_rank_for_uid(netuid, uid), 4); // Note R = floor(1 / (16384 - 512) * 65_535) = 4 assert_eq!(SubtensorModule::get_trust_for_uid(netuid, uid), 65535); assert_eq!(SubtensorModule::get_consensus_for_uid(netuid, uid), 4); // Note C = floor(1 / (16384 - 512) * 65_535) = 4 diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 37f328791..020d5647b 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -73,12 +73,9 @@ fn test_migration_fix_total_stake_maps() { assert_eq!(TotalColdkeyStake::::get(ck3), 100_000_000); // Check that the total hotkey stake is correct + assert_eq!(TotalHotkeyStake::::get(hk1), 100 + 10_101); assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hk1), - 100 + 10_101 - ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hk2), + TotalHotkeyStake::::get(hk2), 100_000_000 + 1_123_000_000 ); @@ -104,12 +101,9 @@ fn test_migration_fix_total_stake_maps() { assert_eq!(TotalColdkeyStake::::get(ck3), 100_000_000); // Verify that the total hotkey stake is STILL correct for each hotkey + assert_eq!(TotalHotkeyStake::::get(hk1), 100 + 10_101); assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hk1), - 100 + 10_101 - ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hk2), + TotalHotkeyStake::::get(hk2), 100_000_000 + 1_123_000_000 ); diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index 27f0df6ef..70960ed7d 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -14,7 +14,7 @@ use sp_runtime::{ BuildStorage, }; -use crate::{migrations, Error, Owner, Stake, SubnetworkN}; +use crate::{migrations, Error, Owner, Stake, SubnetworkN, TotalHotkeyStake}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -104,10 +104,7 @@ fn test_senate_join_works() { Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 99_999 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 99_999); assert_ok!(SubtensorModule::root_register( <::RuntimeOrigin>::signed(coldkey_account_id), @@ -170,10 +167,7 @@ fn test_senate_vote_works() { Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 99_999 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 99_999); assert_ok!(SubtensorModule::root_register( <::RuntimeOrigin>::signed(coldkey_account_id), @@ -332,10 +326,7 @@ fn test_senate_leave_works() { Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 99_999 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 99_999); assert_ok!(SubtensorModule::root_register( <::RuntimeOrigin>::signed(coldkey_account_id), @@ -399,10 +390,7 @@ fn test_senate_leave_vote_removal() { Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 99_999 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 99_999); assert_ok!(SubtensorModule::root_register( coldkey_origin.clone(), @@ -537,7 +525,7 @@ fn test_senate_not_leave_when_stake_removed() { stake_amount - 1 // Need to account for ED ); assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), + TotalHotkeyStake::::get(hotkey_account_id), stake_amount - 1 // Need to account for ED ); @@ -753,7 +741,7 @@ fn test_adjust_senate_events() { 1 ); assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&replacement_hotkey_account_id), + TotalHotkeyStake::::get(replacement_hotkey_account_id), 1 ); diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index d15efc764..e989cbf17 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -52,10 +52,7 @@ fn test_add_stake_ok_no_emission() { SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); // Check we have zero staked before transfer - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); // Also total stake should be zero assert_eq!(TotalStake::::get(), 0); @@ -68,10 +65,7 @@ fn test_add_stake_ok_no_emission() { )); // Check if stake has increased - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 9999 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 9999); // Check if balance has decreased assert_eq!(SubtensorModule::get_coldkey_balance(&coldkey_account_id), 1); @@ -107,7 +101,7 @@ fn test_dividends_with_run_to_block() { // Check if the initial stake has arrived assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&neuron_src_hotkey_id), + TotalHotkeyStake::::get(neuron_src_hotkey_id), initial_stake ); @@ -119,15 +113,12 @@ fn test_dividends_with_run_to_block() { // Check if the stake is equal to the inital stake + transfer assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&neuron_src_hotkey_id), + TotalHotkeyStake::::get(neuron_src_hotkey_id), initial_stake ); // Check if the stake is equal to the inital stake + transfer - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&neuron_dest_hotkey_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(neuron_dest_hotkey_id), 0); }); } @@ -243,7 +234,7 @@ fn test_add_stake_total_balance_no_change() { SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, initial_balance); // Check we have zero staked before transfer - let initial_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id); + let initial_stake = TotalHotkeyStake::::get(hotkey_account_id); assert_eq!(initial_stake, 0); // Check total balance is equal to initial balance @@ -261,7 +252,7 @@ fn test_add_stake_total_balance_no_change() { )); // Check if stake has increased - let new_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id); + let new_stake = TotalHotkeyStake::::get(hotkey_account_id); assert_eq!(new_stake, 10000); // Check if free balance has decreased @@ -300,7 +291,7 @@ fn test_add_stake_total_issuance_no_change() { SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, initial_balance); // Check we have zero staked before transfer - let initial_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id); + let initial_stake = TotalHotkeyStake::::get(hotkey_account_id); assert_eq!(initial_stake, 0); // Check total balance is equal to initial balance @@ -322,7 +313,7 @@ fn test_add_stake_total_issuance_no_change() { )); // Check if stake has increased - let new_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id); + let new_stake = TotalHotkeyStake::::get(hotkey_account_id); assert_eq!(new_stake, 10000); // Check if free balance has decreased @@ -551,10 +542,7 @@ fn test_remove_stake_ok_no_emission() { // Some basic assertions assert_eq!(TotalStake::::get(), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(SubtensorModule::get_coldkey_balance(&coldkey_account_id), 0); // Give the neuron some stake to remove @@ -571,10 +559,7 @@ fn test_remove_stake_ok_no_emission() { SubtensorModule::get_coldkey_balance(&coldkey_account_id), amount ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(TotalStake::::get(), 0); }); } @@ -597,10 +582,7 @@ fn test_remove_stake_amount_zero() { // Some basic assertions assert_eq!(TotalStake::::get(), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(SubtensorModule::get_coldkey_balance(&coldkey_account_id), 0); // Give the neuron some stake to remove @@ -676,7 +658,7 @@ fn test_remove_stake_no_enough_stake() { register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), 0); let result = SubtensorModule::remove_stake( <::RuntimeOrigin>::signed(coldkey_id), @@ -708,10 +690,7 @@ fn test_remove_stake_total_balance_no_change() { // Some basic assertions assert_eq!(TotalStake::::get(), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(SubtensorModule::get_coldkey_balance(&coldkey_account_id), 0); let initial_total_balance = Balances::total_balance(&coldkey_account_id); assert_eq!(initial_total_balance, 0); @@ -730,10 +709,7 @@ fn test_remove_stake_total_balance_no_change() { SubtensorModule::get_coldkey_balance(&coldkey_account_id), amount ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(TotalStake::::get(), 0); // Check total balance is equal to the added stake. Even after remove stake (no fee, includes reserved/locked balance) @@ -764,10 +740,7 @@ fn test_remove_stake_total_issuance_no_change() { // Some basic assertions assert_eq!(TotalStake::::get(), 0); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(SubtensorModule::get_coldkey_balance(&coldkey_account_id), 0); let initial_total_balance = Balances::total_balance(&coldkey_account_id); assert_eq!(initial_total_balance, 0); @@ -790,10 +763,7 @@ fn test_remove_stake_total_issuance_no_change() { SubtensorModule::get_coldkey_balance(&coldkey_account_id), amount ); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); assert_eq!(TotalStake::::get(), 0); // Check if total issuance is equal to the added stake, even after remove stake (no fee, includes reserved/locked balance) @@ -858,10 +828,7 @@ fn test_add_stake_to_hotkey_account_ok() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey_id, amount); // The stake that is now in the account, should equal the amount - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), - amount - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), amount); // The total stake should have been increased by the amount -> 0 + amount = amount assert_eq!(TotalStake::::get(), amount); @@ -891,10 +858,7 @@ fn test_remove_stake_from_hotkey_account() { // Prelimiary checks assert_eq!(TotalStake::::get(), amount); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), - amount - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), amount); // Remove stake SubtensorModule::decrease_stake_on_coldkey_hotkey_account( @@ -904,7 +868,7 @@ fn test_remove_stake_from_hotkey_account() { ); // The stake on the hotkey account should be 0 - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), 0); // The total amount of stake should be 0 assert_eq!(TotalStake::::get(), 0); @@ -1098,10 +1062,7 @@ fn test_has_enough_stake_yes() { add_network(netuid, tempo, 0); register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); SubtensorModule::increase_stake_on_hotkey_account(&hotkey_id, intial_amount); - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), - 10000 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), 10000); assert_eq!(Stake::::get(hotkey_id, coldkey_id), 10000); assert!(SubtensorModule::has_enough_stake( &coldkey_id, @@ -1140,7 +1101,7 @@ fn test_non_existent_account() { 10, ); assert_eq!(Stake::::get(U256::from(0), U256::from(0)), 10); - assert_eq!(TotalColdkeyStake::::get((U256::from(0))), 10); + assert_eq!(TotalColdkeyStake::::get(U256::from(0)), 10); }); } @@ -1220,7 +1181,7 @@ fn test_unstake_all_coldkeys_from_hotkey_account() { // Verify total stake is correct assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), + TotalHotkeyStake::::get(hotkey_id), amount * 4 + (2 + 3 + 4) ); @@ -1228,7 +1189,7 @@ fn test_unstake_all_coldkeys_from_hotkey_account() { SubtensorModule::unstake_all_coldkeys_from_hotkey_account(&hotkey_id); // Verify total stake is 0 - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), 0); // Vefify stake for all coldkeys is 0 assert_eq!(Stake::::get(hotkey_id, coldkey0_id), 0); @@ -1273,16 +1234,13 @@ fn test_unstake_all_coldkeys_from_hotkey_account_single_staker() { assert_eq!(Balances::free_balance(coldkey0_id), 0); // Verify total stake is correct - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), - amount - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), amount); // Run unstake_all_coldkeys_from_hotkey_account SubtensorModule::unstake_all_coldkeys_from_hotkey_account(&hotkey_id); // Verify total stake is 0 - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); + assert_eq!(TotalHotkeyStake::::get(hotkey_id), 0); // Vefify stake for single coldkey is 0 assert_eq!(Stake::::get(hotkey_id, coldkey0_id), 0); @@ -1554,7 +1512,7 @@ fn test_remove_stake_below_minimum_threshold() { // Nomination stake cannot unstake below min threshold, // without unstaking all and removing the nomination. - let total_hotkey_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey1); + let total_hotkey_stake_before = TotalHotkeyStake::::get(hotkey1); let bal_before = Balances::free_balance(coldkey2); let staked_before = Stake::::get(hotkey1, coldkey2); let total_network_stake_before = TotalStake::::get(); @@ -2091,7 +2049,7 @@ fn test_get_total_delegated_stake_single_delegator() { println!("Delegator: {:?}", delegator); println!("Stake amount: {}", stake_amount); println!("Existential deposit: {}", existential_deposit); - println!("Total stake for hotkey: {}", SubtensorModule::get_total_stake_for_hotkey(&delegate_hotkey)); + println!("Total stake for hotkey: {}", TotalHotkeyStake::::get(delegate_hotkey)); println!("Delegated stake for coldkey: {}", SubtensorModule::get_total_delegated_stake(&delegate_coldkey)); // Calculate expected delegated stake @@ -2149,7 +2107,7 @@ fn test_get_total_delegated_stake_multiple_delegators() { println!("Delegator1 stake: {}", stake1); println!("Delegator2 stake: {}", stake2); println!("Existential deposit: {}", existential_deposit); - println!("Total stake for hotkey: {}", SubtensorModule::get_total_stake_for_hotkey(&delegate_hotkey)); + println!("Total stake for hotkey: {}", TotalHotkeyStake::::get(delegate_hotkey)); println!("Delegated stake for coldkey: {}", SubtensorModule::get_total_delegated_stake(&delegate_coldkey)); // Calculate expected total delegated stake @@ -2208,7 +2166,7 @@ fn test_get_total_delegated_stake_exclude_owner_stake() { println!("Existential deposit: {}", existential_deposit); println!( "Total stake for hotkey: {}", - SubtensorModule::get_total_stake_for_hotkey(&delegate_hotkey) + TotalHotkeyStake::::get(delegate_hotkey) ); println!( "Delegated stake for coldkey: {}", diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index cf205cc20..0dc0abaab 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -1095,12 +1095,12 @@ fn test_coldkey_swap_total() { vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); assert_eq!(TotalColdkeyStake::::get(coldkey), 600); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey2), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey3), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate1), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate2), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate3), 300); + assert_eq!(TotalHotkeyStake::::get(hotkey1), 300); + assert_eq!(TotalHotkeyStake::::get(hotkey2), 300); + assert_eq!(TotalHotkeyStake::::get(hotkey3), 300); + assert_eq!(TotalHotkeyStake::::get(delegate1), 300); + assert_eq!(TotalHotkeyStake::::get(delegate2), 300); + assert_eq!(TotalHotkeyStake::::get(delegate3), 300); assert_eq!(OwnedHotkeys::::get(delegate1), vec![delegate1]); assert_eq!(OwnedHotkeys::::get(delegate2), vec![delegate2]); @@ -1156,12 +1156,12 @@ fn test_coldkey_swap_total() { vec![hotkey1, hotkey2, hotkey3, delegate1, delegate2, delegate3] ); assert_eq!(TotalColdkeyStake::::get(new_coldkey), 600); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey1), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey2), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey3), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate1), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate2), 300); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate3), 300); + assert_eq!(TotalHotkeyStake::::get(hotkey1), 300); + assert_eq!(TotalHotkeyStake::::get(hotkey2), 300); + assert_eq!(TotalHotkeyStake::::get(hotkey3), 300); + assert_eq!(TotalHotkeyStake::::get(delegate1), 300); + assert_eq!(TotalHotkeyStake::::get(delegate2), 300); + assert_eq!(TotalHotkeyStake::::get(delegate3), 300); assert_eq!(OwnedHotkeys::::get(delegate1), vec![delegate1]); assert_eq!(OwnedHotkeys::::get(delegate2), vec![delegate2]); @@ -1271,7 +1271,7 @@ fn test_coldkey_delegations() { &new_coldkey, &mut weight )); - assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&delegate), 100); + assert_eq!(TotalHotkeyStake::::get(delegate), 100); assert_eq!(TotalColdkeyStake::::get(coldkey), 0); assert_eq!(TotalColdkeyStake::::get(new_coldkey), 100); assert_eq!(Stake::::get(delegate, new_coldkey), 100); diff --git a/pallets/subtensor/src/tests/uids.rs b/pallets/subtensor/src/tests/uids.rs index 1c25a2ba8..0c21d185b 100644 --- a/pallets/subtensor/src/tests/uids.rs +++ b/pallets/subtensor/src/tests/uids.rs @@ -269,7 +269,7 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { // Check total stake on neuron assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), + TotalHotkeyStake::::get(hotkey_account_id), (stake_amount * 3) + (1 + 2) ); @@ -302,7 +302,7 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { // Check total stake on neuron assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), + TotalHotkeyStake::::get(hotkey_account_id), (stake_amount * 3) + (1 + 2) ); @@ -342,10 +342,7 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { ); // Check total stake on neuron - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id), - 0 - ); + assert_eq!(TotalHotkeyStake::::get(hotkey_account_id), 0); }); } diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index 4516ea0d3..f76958c13 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -30,7 +30,7 @@ use sp_core::Encode; use super::mock::*; use crate::{ coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, - RevealPeriodEpochs, SubnetworkN, Tempo, MAX_CRV3_COMMIT_SIZE_BYTES, + RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, MAX_CRV3_COMMIT_SIZE_BYTES, }; /*************************** @@ -114,7 +114,7 @@ fn test_set_rootweights_validate() { SubtensorModule::set_stake_threshold(min_stake); // Verify stake is less than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + assert!(TotalHotkeyStake::::get(hotkey) < min_stake); let info: DispatchInfo = DispatchInfoOf::<::RuntimeCall>::default(); @@ -132,10 +132,7 @@ fn test_set_rootweights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); // Verify stake is equal to minimum - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - min_stake - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), min_stake); // Submit to the signed extension validate function let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); @@ -146,7 +143,7 @@ fn test_set_rootweights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 1); // Verify stake is more than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) > min_stake); + assert!(TotalHotkeyStake::::get(hotkey) > min_stake); let result_more_stake = extension.validate(&who, &call.clone(), &info, 10); // The call should still pass @@ -214,7 +211,7 @@ fn test_commit_weights_validate() { SubtensorModule::set_stake_threshold(min_stake); // Verify stake is less than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + assert!(TotalHotkeyStake::::get(hotkey) < min_stake); let info: DispatchInfo = DispatchInfoOf::<::RuntimeCall>::default(); @@ -232,10 +229,7 @@ fn test_commit_weights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); // Verify stake is equal to minimum - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - min_stake - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), min_stake); // Submit to the signed extension validate function let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); @@ -246,7 +240,7 @@ fn test_commit_weights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 1); // Verify stake is more than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) > min_stake); + assert!(TotalHotkeyStake::::get(hotkey) > min_stake); let result_more_stake = extension.validate(&who, &call.clone(), &info, 10); // The call should still pass @@ -308,7 +302,7 @@ fn test_set_weights_validate() { SubtensorModule::set_stake_threshold(min_stake); // Verify stake is less than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + assert!(TotalHotkeyStake::::get(hotkey) < min_stake); let info: DispatchInfo = DispatchInfoOf::<::RuntimeCall>::default(); @@ -325,10 +319,7 @@ fn test_set_weights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); // Verify stake is equal to minimum - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - min_stake - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), min_stake); // Submit to the signed extension validate function let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); @@ -373,7 +364,7 @@ fn test_reveal_weights_validate() { SubtensorModule::set_stake_threshold(min_stake); // Verify stake is less than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + assert!(TotalHotkeyStake::::get(hotkey) < min_stake); let info: DispatchInfo = DispatchInfoOf::<::RuntimeCall>::default(); @@ -391,10 +382,7 @@ fn test_reveal_weights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); // Verify stake is equal to minimum - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - min_stake - ); + assert_eq!(TotalHotkeyStake::::get(hotkey), min_stake); // Submit to the signed extension validate function let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); @@ -405,7 +393,7 @@ fn test_reveal_weights_validate() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 1); // Verify stake is more than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) > min_stake); + assert!(TotalHotkeyStake::::get(hotkey) > min_stake); let result_more_stake = extension.validate(&who, &call.clone(), &info, 10); // The call should still pass diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index cc9872a65..987e20ee4 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -65,10 +65,6 @@ impl Pallet { // ============================== // ==== YumaConsensus params ==== // ============================== - pub fn get_trust(netuid: u16) -> Vec { - Trust::::get(netuid) - } - pub fn get_validator_trust(netuid: u16) -> Vec { ValidatorTrust::::get(netuid) } From d6d0933961d66fa8a5f049115b51571fef9b76ae Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 17:47:36 +0100 Subject: [PATCH 099/137] Remove get_tx_childkey_take_rate_limit from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/children.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 3b222a73c..1db7b814c 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -1069,7 +1069,7 @@ fn test_multiple_networks_childkey_take() { assert_noop!(result, Error::::TxChildkeyTakeRateLimitExceeded); // Advance blocks to bypass rate limit - run_to_block(SubtensorModule::get_tx_childkey_take_rate_limit() + 1); + run_to_block(TxChildkeyTakeRateLimit::::get() + 1); // Now setting childkey take should succeed assert_ok!(SubtensorModule::set_childkey_take( diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 987e20ee4..c853dc981 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -274,9 +274,6 @@ impl Pallet { Self::deposit_event(Event::MaxDelegateTakeSet(take)); } - pub fn get_tx_childkey_take_rate_limit() -> u64 { - TxChildkeyTakeRateLimit::::get() - } pub fn set_tx_childkey_take_rate_limit(tx_rate_limit: u64) { TxChildkeyTakeRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxChildKeyTakeRateLimitSet(tx_rate_limit)); From 53ecf59beec62df6751473cb10d353a60e6c1bcc Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 18:06:35 +0100 Subject: [PATCH 100/137] Remove get_tx_delegate_take_rate_limit from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 12 +++--------- pallets/subtensor/src/utils/misc.rs | 3 --- pallets/subtensor/src/utils/rate_limiting.rs | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 8d2a4c13a..cf115338a 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -1025,7 +1025,7 @@ mod sudo_set_nominator_min_required_stake { fn test_sudo_set_tx_delegate_take_rate_limit() { new_test_ext().execute_with(|| { let to_be_set: u64 = 10; - let init_value: u64 = SubtensorModule::get_tx_delegate_take_rate_limit(); + let init_value: u64 = TxDelegateTakeRateLimit::::get(); assert_eq!( AdminUtils::sudo_set_tx_delegate_take_rate_limit( <::RuntimeOrigin>::signed(U256::from(1)), @@ -1033,18 +1033,12 @@ fn test_sudo_set_tx_delegate_take_rate_limit() { ), Err(DispatchError::BadOrigin) ); - assert_eq!( - SubtensorModule::get_tx_delegate_take_rate_limit(), - init_value - ); + assert_eq!(TxDelegateTakeRateLimit::::get(), init_value); assert_ok!(AdminUtils::sudo_set_tx_delegate_take_rate_limit( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!( - SubtensorModule::get_tx_delegate_take_rate_limit(), - to_be_set - ); + assert_eq!(TxDelegateTakeRateLimit::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index c853dc981..4cb60cc31 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -258,9 +258,6 @@ impl Pallet { TxRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxRateLimitSet(tx_rate_limit)); } - pub fn get_tx_delegate_take_rate_limit() -> u64 { - TxDelegateTakeRateLimit::::get() - } pub fn set_tx_delegate_take_rate_limit(tx_rate_limit: u64) { TxDelegateTakeRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxDelegateTakeRateLimitSet(tx_rate_limit)); diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index 299f4ebd2..406ef42ce 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -143,7 +143,7 @@ impl Pallet { current_block.saturating_sub(prev_tx_block) <= rate_limit } pub fn exceeds_tx_delegate_take_rate_limit(prev_tx_block: u64, current_block: u64) -> bool { - let rate_limit: u64 = Self::get_tx_delegate_take_rate_limit(); + let rate_limit: u64 = TxDelegateTakeRateLimit::::get(); if rate_limit == 0 || prev_tx_block == 0 { return false; } From c4df467776bb1ad34b0a6f860655bb07dc356ee9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 18:14:39 +0100 Subject: [PATCH 101/137] Remove get_tx_rate_limit from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/swap_hotkey.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 7 ------- pallets/subtensor/src/utils/rate_limiting.rs | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/pallets/subtensor/src/tests/swap_hotkey.rs b/pallets/subtensor/src/tests/swap_hotkey.rs index f30d97b92..c3f14ccb2 100644 --- a/pallets/subtensor/src/tests/swap_hotkey.rs +++ b/pallets/subtensor/src/tests/swap_hotkey.rs @@ -669,13 +669,13 @@ fn test_swap_hotkey_tx_rate_limit_exceeded() { let tx_rate_limit = 1; // Get the current transaction rate limit - let current_tx_rate_limit = SubtensorModule::get_tx_rate_limit(); + let current_tx_rate_limit = TxRateLimit::::get(); log::info!("current_tx_rate_limit: {:?}", current_tx_rate_limit); // Set the transaction rate limit SubtensorModule::set_tx_rate_limit(tx_rate_limit); // assert the rate limit is set to 1000 blocks - assert_eq!(SubtensorModule::get_tx_rate_limit(), tx_rate_limit); + assert_eq!(TxRateLimit::::get(), tx_rate_limit); // Setup initial state add_network(netuid, tempo, 0); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 4cb60cc31..776c9b38c 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -246,14 +246,7 @@ impl Pallet { total_subnet_locked } - // ======================== - // ========= Sudo ========= - // ======================== - // Configure tx rate limiting - pub fn get_tx_rate_limit() -> u64 { - TxRateLimit::::get() - } pub fn set_tx_rate_limit(tx_rate_limit: u64) { TxRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxRateLimitSet(tx_rate_limit)); diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index 406ef42ce..2939e0ab8 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -135,7 +135,7 @@ impl Pallet { } pub fn exceeds_tx_rate_limit(prev_tx_block: u64, current_block: u64) -> bool { - let rate_limit: u64 = Self::get_tx_rate_limit(); + let rate_limit: u64 = TxRateLimit::::get(); if rate_limit == 0 || prev_tx_block == 0 { return false; } From 3b718a47c1fe5445d3bf727d6730067f75cf9fd2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 18:21:57 +0100 Subject: [PATCH 102/137] Remove get_validator_permit from pallet-subtensor::Pallet --- pallets/subtensor/src/epoch/run_epoch.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/epoch/run_epoch.rs b/pallets/subtensor/src/epoch/run_epoch.rs index 363eb8014..5bc4603ce 100644 --- a/pallets/subtensor/src/epoch/run_epoch.rs +++ b/pallets/subtensor/src/epoch/run_epoch.rs @@ -160,7 +160,7 @@ impl Pallet { // ======================= // Get validator permits. - let validator_permits: Vec = Self::get_validator_permit(netuid); + let validator_permits: Vec = ValidatorPermit::::get(netuid); log::trace!("validator_permits: {:?}", validator_permits); // Logical negation of validator_permits. @@ -496,7 +496,7 @@ impl Pallet { // ======================= // Get current validator permits. - let validator_permits: Vec = Self::get_validator_permit(netuid); + let validator_permits: Vec = ValidatorPermit::::get(netuid); log::trace!("validator_permits: {:?}", validator_permits); // Logical negation of validator_permits. diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 776c9b38c..1d0e24edf 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -68,9 +68,6 @@ impl Pallet { pub fn get_validator_trust(netuid: u16) -> Vec { ValidatorTrust::::get(netuid) } - pub fn get_validator_permit(netuid: u16) -> Vec { - ValidatorPermit::::get(netuid) - } // ================================== // ==== YumaConsensus UID params ==== @@ -106,7 +103,7 @@ impl Pallet { }); } 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 mut updated_validator_permits = ValidatorPermit::::get(netuid); let Some(updated_validator_permit) = updated_validator_permits.get_mut(uid as usize) else { return; }; From 77b2c4e7400ff3849267878b7c838e1c7cebcf3f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 18:29:22 +0100 Subject: [PATCH 103/137] Remove get_validator_trust from pallet-subtensor::Pallet --- pallets/subtensor/src/utils/misc.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 1d0e24edf..0f41e98a6 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -53,22 +53,12 @@ impl Pallet { BurnRegistrationsThisInterval::::insert(netuid, burn_registrations_this_interval); } - // ======================== - // ==== Global Getters ==== - // ======================== pub fn get_current_block_as_u64() -> u64 { TryInto::try_into(>::block_number()) .ok() .expect("blockchain will not exceed 2^64 blocks; QED.") } - // ============================== - // ==== YumaConsensus params ==== - // ============================== - pub fn get_validator_trust(netuid: u16) -> Vec { - ValidatorTrust::::get(netuid) - } - // ================================== // ==== YumaConsensus UID params ==== // ================================== From 7c491c3380d5633dc56abde2bbcd74f1b7b62ab3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 19:19:43 +0100 Subject: [PATCH 104/137] Remove get_weights_set_rate_limit from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 12 +++--------- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/weights.rs | 2 +- pallets/subtensor/src/tests/weights.rs | 5 +++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index cf115338a..ccf283f9a 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -165,7 +165,7 @@ fn test_sudo_set_weights_set_rate_limit() { 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); + let init_value: u64 = WeightsSetRateLimit::::get(netuid); assert_eq!( AdminUtils::sudo_set_weights_set_rate_limit( <::RuntimeOrigin>::signed(U256::from(1)), @@ -182,19 +182,13 @@ fn test_sudo_set_weights_set_rate_limit() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!( - SubtensorModule::get_weights_set_rate_limit(netuid), - init_value - ); + assert_eq!(WeightsSetRateLimit::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_weights_set_rate_limit( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!( - SubtensorModule::get_weights_set_rate_limit(netuid), - to_be_set - ); + assert_eq!(WeightsSetRateLimit::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index bf4b53ecc..b58b90ac7 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -239,7 +239,7 @@ impl Pallet { let min_difficulty = MinDifficulty::::get(netuid); let max_difficulty = MaxDifficulty::::get(netuid); let weights_version = Self::get_weights_version_key(netuid); - let weights_rate_limit = Self::get_weights_set_rate_limit(netuid); + let weights_rate_limit = WeightsSetRateLimit::::get(netuid); let adjustment_interval = AdjustmentInterval::::get(netuid); let activity_cutoff = ActivityCutoff::::get(netuid); let registration_allowed = NetworkRegistrationAllowed::::get(netuid); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 7a54942a6..dfb92085f 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -918,7 +918,7 @@ impl Pallet { return true; } // (Storage default) Never set weights. return current_block.saturating_sub(last_set_weights) - >= Self::get_weights_set_rate_limit(netuid); + >= WeightsSetRateLimit::::get(netuid); } // --- 3. Non registered peers cant pass. false diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index f76958c13..2ac7e3efc 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -30,7 +30,8 @@ use sp_core::Encode; use super::mock::*; use crate::{ coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, - RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, MAX_CRV3_COMMIT_SIZE_BYTES, + RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, WeightsSetRateLimit, + MAX_CRV3_COMMIT_SIZE_BYTES, }; /*************************** @@ -612,7 +613,7 @@ fn test_weights_err_setting_weights_too_fast() { .expect("Not registered."); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 10); - assert_eq!(SubtensorModule::get_weights_set_rate_limit(netuid), 10); + assert_eq!(WeightsSetRateLimit::::get(netuid), 10); let weights_keys: Vec = vec![1, 2]; let weight_values: Vec = vec![1, 2]; From 670729965572875590853d1b342d38b194eaa62e Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 19:29:40 +0100 Subject: [PATCH 105/137] Remove get_weights_version_key from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/tests/batch_tx.rs | 8 ++++---- pallets/subtensor/src/tests/children.rs | 12 ++++++------ pallets/subtensor/src/tests/weights.rs | 18 +++++++++--------- pallets/subtensor/src/utils/misc.rs | 6 ------ 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index ccf283f9a..35c7b9623 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -132,7 +132,7 @@ fn test_sudo_set_weights_version_key() { let netuid: u16 = 1; let to_be_set: u64 = 10; add_network(netuid, 10); - let init_value: u64 = SubtensorModule::get_weights_version_key(netuid); + let init_value: u64 = WeightsVersionKey::::get(netuid); assert_eq!( AdminUtils::sudo_set_weights_version_key( <::RuntimeOrigin>::signed(U256::from(1)), @@ -149,13 +149,13 @@ fn test_sudo_set_weights_version_key() { ), Err(Error::::SubnetDoesNotExist.into()) ); - assert_eq!(SubtensorModule::get_weights_version_key(netuid), init_value); + assert_eq!(WeightsVersionKey::::get(netuid), init_value); assert_ok!(AdminUtils::sudo_set_weights_version_key( <::RuntimeOrigin>::root(), netuid, to_be_set )); - assert_eq!(SubtensorModule::get_weights_version_key(netuid), to_be_set); + assert_eq!(WeightsVersionKey::::get(netuid), to_be_set); }); } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index b58b90ac7..5e8629745 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -238,7 +238,7 @@ impl Pallet { let tempo = Tempo::::get(netuid); let min_difficulty = MinDifficulty::::get(netuid); let max_difficulty = MaxDifficulty::::get(netuid); - let weights_version = Self::get_weights_version_key(netuid); + let weights_version = WeightsVersionKey::::get(netuid); let weights_rate_limit = WeightsSetRateLimit::::get(netuid); let adjustment_interval = AdjustmentInterval::::get(netuid); let activity_cutoff = ActivityCutoff::::get(netuid); diff --git a/pallets/subtensor/src/tests/batch_tx.rs b/pallets/subtensor/src/tests/batch_tx.rs index 5768ee97d..dcc806aeb 100644 --- a/pallets/subtensor/src/tests/batch_tx.rs +++ b/pallets/subtensor/src/tests/batch_tx.rs @@ -7,7 +7,7 @@ use sp_runtime::{ DispatchError, }; -use crate::{Error, Event}; +use crate::{Error, Event, WeightsVersionKey}; use super::mock::*; @@ -92,9 +92,9 @@ fn test_batch_set_weights() { // Set weights on the other hotkey and Use maximum value for u16 let weights: Vec<(Compact, Compact)> = vec![(Compact(1), Compact(u16::MAX))]; - let version_key_0: Compact = SubtensorModule::get_weights_version_key(netuid_0).into(); - let version_key_1: Compact = SubtensorModule::get_weights_version_key(netuid_1).into(); - let version_key_2: Compact = SubtensorModule::get_weights_version_key(netuid_2).into(); + let version_key_0: Compact = WeightsVersionKey::::get(netuid_0).into(); + let version_key_1: Compact = WeightsVersionKey::::get(netuid_1).into(); + let version_key_2: Compact = WeightsVersionKey::::get(netuid_2).into(); // Set the min stake very high SubtensorModule::set_stake_threshold(stake_to_give_child * 5); diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index 1db7b814c..fb7766737 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -1791,7 +1791,7 @@ fn test_childkey_single_parent_emission() { let origin = RuntimeOrigin::signed(weight_setter); let uids: Vec = vec![1]; // Only set weight for the child (UID 1) let values: Vec = vec![u16::MAX]; // Use maximum value for u16 - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); assert_ok!(SubtensorModule::set_weights( origin, netuid, @@ -1922,7 +1922,7 @@ fn test_childkey_multiple_parents_emission() { // Set weights let uids: Vec = vec![0, 1, 2]; let values: Vec = vec![0, 65354, 65354]; - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(weight_setter), netuid, @@ -2081,7 +2081,7 @@ fn test_parent_child_chain_emission() { let origin = RuntimeOrigin::signed(hotkey_a); let uids: Vec = vec![0, 1, 2]; // UIDs for hotkey_a, hotkey_b, hotkey_c let values: Vec = vec![65535, 65535, 65535]; // Set equal weights for all hotkeys - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); // Ensure we can set weights without rate limiting SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -2220,7 +2220,7 @@ fn test_dynamic_parent_child_relationships() { let origin = RuntimeOrigin::signed(parent); let uids: Vec = vec![0, 1, 2]; // UIDs for parent, child1, child2 let values: Vec = vec![65535, 65535, 65535]; // Set equal weights for all hotkeys - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); // Ensure we can set weights without rate limiting SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3134,7 +3134,7 @@ fn test_childkey_set_weights_single_parent() { let origin = RuntimeOrigin::signed(weight_setter); let uids: Vec = vec![1]; // Only set weight for the child (UID 1) let values: Vec = vec![u16::MAX]; // Use maximum value for u16 - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); assert_ok!(SubtensorModule::set_weights( origin, netuid, @@ -3224,7 +3224,7 @@ fn test_set_weights_no_parent() { let uids: Vec = vec![1]; // Set weights on the other hotkey let values: Vec = vec![u16::MAX]; // Use maximum value for u16 - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); // Set the min stake very high SubtensorModule::set_stake_threshold(stake_to_give_child * 5); diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index 2ac7e3efc..b98f07afd 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -31,7 +31,7 @@ use super::mock::*; use crate::{ coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, WeightsSetRateLimit, - MAX_CRV3_COMMIT_SIZE_BYTES, + WeightsVersionKey, MAX_CRV3_COMMIT_SIZE_BYTES, }; /*************************** @@ -4262,7 +4262,7 @@ fn test_reveal_crv3_commits_success() { SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid1, true); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid2, true); - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); let payload = WeightsTlockPayload { values: vec![10, 20], @@ -4402,7 +4402,7 @@ fn test_reveal_crv3_commits_cannot_reveal_after_reveal_epoch() { SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid1, true); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid2, true); - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); let payload = WeightsTlockPayload { values: vec![10, 20], @@ -4833,7 +4833,7 @@ fn test_reveal_crv3_commits_multiple_commits_some_fail_some_succeed() { // Prepare a valid payload for hotkey1 let neuron_uid1 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey1) .expect("Failed to get neuron UID for hotkey1"); - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); let valid_payload = WeightsTlockPayload { values: vec![10], uids: vec![neuron_uid1], @@ -4952,7 +4952,7 @@ fn test_reveal_crv3_commits_do_set_weights_failure() { SubtensorModule::set_weights_set_rate_limit(netuid, 0); // Prepare payload with mismatched uids and values lengths - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); let payload = WeightsTlockPayload { values: vec![10, 20], // Length 2 uids: vec![0], // Length 1 @@ -5114,7 +5114,7 @@ fn test_reveal_crv3_commits_signature_deserialization_failure() { SubtensorModule::set_reveal_period(netuid, 3); SubtensorModule::set_weights_set_rate_limit(netuid, 0); - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); let payload = WeightsTlockPayload { values: vec![10, 20], uids: vec![0, 1], @@ -5259,7 +5259,7 @@ fn test_reveal_crv3_commits_with_incorrect_identity_message() { // Prepare a valid payload but use incorrect identity message during encryption let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey) .expect("Failed to get neuron UID for hotkey"); - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); let payload = WeightsTlockPayload { values: vec![10], uids: vec![neuron_uid], @@ -5459,7 +5459,7 @@ fn test_reveal_crv3_commits_multiple_valid_commits_all_processed() { ); } - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); // Prepare payloads and commits for each hotkey let esk = [2; 32]; @@ -5646,7 +5646,7 @@ fn test_reveal_crv3_commits_max_neurons() { ); } - let version_key = SubtensorModule::get_weights_version_key(netuid); + let version_key = WeightsVersionKey::::get(netuid); // Prepare payloads and commits for 3 hotkeys let esk = [2; 32]; diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0f41e98a6..d731250d8 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -279,17 +279,11 @@ impl Pallet { Self::deposit_event(Event::MaxDifficultySet(netuid, max_difficulty)); } - pub fn get_weights_version_key(netuid: u16) -> u64 { - WeightsVersionKey::::get(netuid) - } 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: u16) -> u64 { - WeightsSetRateLimit::::get(netuid) - } 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( From 4a2b2c26a9e64f33c186d8baafe78252b986e75d Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 19:45:24 +0100 Subject: [PATCH 106/137] Remove get_key_swap_cost method from Pallet of pallet-subtensor --- pallets/subtensor/src/benchmarks.rs | 10 +++++----- pallets/subtensor/src/swap/swap_coldkey.rs | 2 +- pallets/subtensor/src/swap/swap_hotkey.rs | 2 +- pallets/subtensor/src/tests/swap_coldkey.rs | 4 ++-- pallets/subtensor/src/tests/swap_hotkey.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 5 ----- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 404bd40cd..af907b659 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -2,16 +2,16 @@ #![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)] #![cfg(feature = "runtime-benchmarks")] -use crate::Pallet as Subtensor; -use crate::*; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; use frame_support::assert_ok; use frame_system::RawOrigin; -pub use pallet::*; -use sp_core::H256; +use sp_core::{Get, H256}; use sp_runtime::traits::{BlakeTwo256, Hash}; use sp_std::vec; +use crate::Pallet as Subtensor; +use crate::*; + benchmarks! { // Add individual benchmarks here benchmark_register { @@ -471,7 +471,7 @@ reveal_weights { let netuid = 1u16; let stake_amount1 = 1000u64; let stake_amount2 = 2000u64; - let swap_cost = Subtensor::::get_key_swap_cost(); + let swap_cost = T::KeySwapCost::get(); let free_balance_old = 12345u64 + swap_cost; let tempo: u16 = 1; diff --git a/pallets/subtensor/src/swap/swap_coldkey.rs b/pallets/subtensor/src/swap/swap_coldkey.rs index 4742c3fca..ad5cf2f67 100644 --- a/pallets/subtensor/src/swap/swap_coldkey.rs +++ b/pallets/subtensor/src/swap/swap_coldkey.rs @@ -55,7 +55,7 @@ impl Pallet { } // 6. Calculate the swap cost and ensure sufficient balance - let swap_cost = Self::get_key_swap_cost(); + let swap_cost = T::KeySwapCost::get(); ensure!( Self::can_remove_balance_from_coldkey_account(old_coldkey, swap_cost), Error::::NotEnoughBalanceToPaySwapColdKey diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index 5f62ce163..7ff98f130 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -66,7 +66,7 @@ impl Pallet { ); // 10. Get the cost for swapping the key - let swap_cost = Self::get_key_swap_cost(); + let swap_cost = T::KeySwapCost::get(); log::debug!("Swap cost: {:?}", swap_cost); // 11. Ensure the coldkey has enough balance to pay for the swap diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 0dc0abaab..6f2246613 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -489,7 +489,7 @@ fn test_do_swap_coldkey_success() { let netuid = 1u16; let stake_amount1 = 1000u64; let stake_amount2 = 2000u64; - let swap_cost = SubtensorModule::get_key_swap_cost(); + let swap_cost = ::KeySwapCost::get(); let free_balance_old = 12345u64 + swap_cost; // Setup initial state @@ -888,7 +888,7 @@ fn test_do_swap_coldkey_with_subnet_ownership() { let hotkey = U256::from(3); let netuid = 1u16; let stake_amount: u64 = 1000u64; - let swap_cost = SubtensorModule::get_key_swap_cost(); + let swap_cost = ::KeySwapCost::get(); // Setup initial state add_network(netuid, 13, 0); diff --git a/pallets/subtensor/src/tests/swap_hotkey.rs b/pallets/subtensor/src/tests/swap_hotkey.rs index c3f14ccb2..10f4c48c1 100644 --- a/pallets/subtensor/src/tests/swap_hotkey.rs +++ b/pallets/subtensor/src/tests/swap_hotkey.rs @@ -936,7 +936,7 @@ fn test_swap_hotkey_error_cases() { LastTxBlock::::insert(coldkey, 0); // Test not enough balance - let swap_cost = SubtensorModule::get_key_swap_cost(); + let swap_cost = ::KeySwapCost::get(); assert_noop!( SubtensorModule::do_swap_hotkey( RuntimeOrigin::signed(coldkey), @@ -946,7 +946,7 @@ fn test_swap_hotkey_error_cases() { Error::::NotEnoughBalanceToPaySwapHotKey ); - let initial_balance = SubtensorModule::get_key_swap_cost() + 1000; + let initial_balance = ::KeySwapCost::get() + 1000; SubtensorModule::add_balance_to_coldkey_account(&coldkey, initial_balance); // Test new hotkey same as old diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index d731250d8..9823341f2 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -3,7 +3,6 @@ use crate::{ system::{ensure_signed_or_root, pallet_prelude::BlockNumberFor}, Error, }; -use sp_core::Get; use sp_runtime::Saturating; use substrate_fixed::types::I32F32; @@ -459,10 +458,6 @@ impl Pallet { NominatorMinRequiredStake::::put(min_stake); } - pub fn get_key_swap_cost() -> u64 { - T::KeySwapCost::get() - } - pub fn get_alpha_values_32(netuid: u16) -> (I32F32, I32F32) { let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); let converted_low = I32F32::from_num(alpha_low).saturating_div(I32F32::from_num(u16::MAX)); From 5339e64e6382c21d2d7bc47ab4a226a4d5336ea8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 20:04:41 +0100 Subject: [PATCH 107/137] Update spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 212226f9a..77fc9415e 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 217, + spec_version: 218, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 0f04c47774226a9f6f5848231ac17dcd972f7eee Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 18 Dec 2024 20:21:01 +0100 Subject: [PATCH 108/137] Remove get_rate_limit_on_subnet method from Pallet of pallet-subtensor --- pallets/subtensor/src/tests/children.rs | 35 ++++++++++---------- pallets/subtensor/src/tests/mock.rs | 4 +-- pallets/subtensor/src/tests/root.rs | 2 +- pallets/subtensor/src/utils/rate_limiting.rs | 12 +------ 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index fb7766737..fc278f903 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -162,7 +162,7 @@ fn test_do_set_child_singular_old_children_cleanup() { // Set old child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, old_child)]); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Set new child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, new_child)]); @@ -237,7 +237,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(min_proportion, child)]); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Set child with maximum proportion let max_proportion: u64 = u64::MAX; @@ -275,7 +275,7 @@ fn test_do_set_child_singular_multiple_children() { // Set first child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion1, child1)]); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Set second child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion1, child2)]); @@ -317,7 +317,7 @@ fn test_add_singular_child() { Err(Error::::SubNetworkDoesNotExist.into()) ); add_network(netuid, 0, 0); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); assert_eq!( SubtensorModule::do_schedule_children( RuntimeOrigin::signed(coldkey), @@ -328,7 +328,7 @@ fn test_add_singular_child() { Err(Error::::NonAssociatedColdKey.into()) ); SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); assert_eq!( SubtensorModule::do_schedule_children( RuntimeOrigin::signed(coldkey), @@ -339,7 +339,7 @@ fn test_add_singular_child() { Err(Error::::InvalidChild.into()) ); let child = U256::from(3); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); mock_set_children(&coldkey, &hotkey, netuid, &[(u64::MAX, child)]); }) @@ -422,7 +422,7 @@ fn test_do_revoke_child_singular_success() { let children = ChildKeys::::get(hotkey, netuid); assert_eq!(children, vec![(proportion, child)]); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Revoke child mock_set_children(&coldkey, &hotkey, netuid, &[]); @@ -708,7 +708,7 @@ fn test_do_schedule_children_multiple_old_children_cleanup() { // Set old child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, old_child)]); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Set new children mock_set_children( @@ -800,7 +800,7 @@ fn test_do_schedule_children_multiple_overwrite_existing() { &[(proportion, child1), (proportion, child2)], ); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Overwrite with new children mock_set_children( @@ -947,7 +947,7 @@ fn test_childkey_take_rate_limiting() { &hotkey, netuid, ); - let limit = SubtensorModule::get_rate_limit_on_subnet(&TransactionType::SetChildkeyTake, netuid); + let limit = SubtensorModule::get_rate_limit(&TransactionType::SetChildkeyTake); log::info!( "Rate limit info: current_block: {}, last_block: {}, limit: {}, passes: {}, diff: {}", current_block, @@ -1142,7 +1142,7 @@ fn test_do_revoke_children_multiple_success() { &[(proportion1, child1), (proportion2, child2)], ); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Revoke multiple children mock_set_children(&coldkey, &hotkey, netuid, &[]); @@ -1253,7 +1253,7 @@ fn test_do_revoke_children_multiple_partial_revocation() { ], ); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Revoke only child3 mock_set_children( @@ -1301,7 +1301,7 @@ fn test_do_revoke_children_multiple_non_existent_children() { // Set one child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child1)]); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Attempt to revoke existing and non-existent children mock_set_children(&coldkey, &hotkey, netuid, &[]); @@ -1379,7 +1379,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { ], ); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Revoke child2 mock_set_children( @@ -1397,7 +1397,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { let parents2 = ParentKeys::::get(child2, netuid); assert!(parents2.is_empty()); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Revoke remaining children mock_set_children(&coldkey, &hotkey, netuid, &[]); @@ -2247,7 +2247,7 @@ fn test_dynamic_parent_child_relationships() { // Step blocks to allow for emission distribution step_block(11); - step_rate_limit(&TransactionType::SetChildren, netuid); + step_rate_limit(&TransactionType::SetChildren); // Change parent-child relationships mock_set_children(&coldkey_parent, &parent, netuid, &[(u64::MAX / 4, child1), (u64::MAX / 3, child2)]); @@ -3584,8 +3584,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { // Try again after rate limit period has passed // Check rate limit - let limit = - SubtensorModule::get_rate_limit_on_subnet(&TransactionType::SetChildren, netuid); + let limit = SubtensorModule::get_rate_limit(&TransactionType::SetChildren); // Step that many blocks step_block(limit as u16); diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 672d78244..17bf17ddd 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -709,9 +709,9 @@ pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec: // Helper function to wait for the rate limit #[allow(dead_code)] -pub fn step_rate_limit(transaction_type: &TransactionType, netuid: u16) { +pub fn step_rate_limit(transaction_type: &TransactionType) { // Check rate limit - let limit = SubtensorModule::get_rate_limit_on_subnet(transaction_type, netuid); + let limit = SubtensorModule::get_rate_limit(transaction_type); // Step that many blocks step_block(limit as u16); diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index f52653a98..41693d1f7 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -1059,7 +1059,7 @@ fn test_register_network_rate_limit() { ); // Step the rate limit. - step_rate_limit(&TransactionType::RegisterNetwork, 0); + step_rate_limit(&TransactionType::RegisterNetwork); // Give more TAO lock_cost = SubtensorModule::get_network_lock_cost(); diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index 2939e0ab8..b3b2c1339 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -33,9 +33,6 @@ impl From for TransactionType { } } impl Pallet { - // ======================== - // ==== Rate Limiting ===== - // ======================== /// Get the rate limit for a specific transaction type pub fn get_rate_limit(tx_type: &TransactionType) -> u64 { match tx_type { @@ -46,13 +43,6 @@ impl Pallet { } } - pub fn get_rate_limit_on_subnet(tx_type: &TransactionType, _netuid: u16) -> u64 { - #[allow(clippy::match_single_binding)] - match tx_type { - _ => Self::get_rate_limit(tx_type), - } - } - pub fn check_passes_rate_limit(limit: u64, block: u64, last_block: u64) -> bool { // Allow the first transaction (when last_block is 0) or if the rate limit has passed last_block == 0 || block.saturating_sub(last_block) >= limit @@ -73,7 +63,7 @@ impl Pallet { netuid: u16, ) -> bool { let block: u64 = Self::get_current_block_as_u64(); - let limit: u64 = Self::get_rate_limit_on_subnet(tx_type, netuid); + let limit: u64 = Self::get_rate_limit(tx_type); let last_block: u64 = Self::get_last_transaction_block_on_subnet(hotkey, netuid, tx_type); Self::check_passes_rate_limit(limit, block, last_block) From 0d13daae18925e4d3afacbddb9170ce925995e6d Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 14:36:46 +0100 Subject: [PATCH 109/137] Remove has_enough_stake method from Pallet of pallet-subtensor --- pallets/subtensor/src/staking/remove_stake.rs | 2 +- pallets/subtensor/src/tests/staking.rs | 12 ++---------- pallets/subtensor/src/tests/swap_coldkey.rs | 13 ++++++------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index b962b56a8..da8486856 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -61,7 +61,7 @@ impl Pallet { // Ensure that the hotkey has enough stake to withdraw. ensure!( - Self::has_enough_stake(&coldkey, &hotkey, stake_to_be_removed), + Stake::::get(&hotkey, &coldkey) >= stake_to_be_removed, Error::::NotEnoughStakeToWithdraw ); diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index e989cbf17..fbd639cc5 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1064,11 +1064,7 @@ fn test_has_enough_stake_yes() { SubtensorModule::increase_stake_on_hotkey_account(&hotkey_id, intial_amount); assert_eq!(TotalHotkeyStake::::get(hotkey_id), 10000); assert_eq!(Stake::::get(hotkey_id, coldkey_id), 10000); - assert!(SubtensorModule::has_enough_stake( - &coldkey_id, - &hotkey_id, - 5000 - )); + assert!(Stake::::get(hotkey_id, coldkey_id) >= 5000); }); } @@ -1084,11 +1080,7 @@ fn test_has_enough_stake_no() { add_network(netuid, tempo, 0); register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); SubtensorModule::increase_stake_on_hotkey_account(&hotkey_id, intial_amount); - assert!(!SubtensorModule::has_enough_stake( - &coldkey_id, - &hotkey_id, - 5000 - )); + assert!(Stake::::get(hotkey_id, coldkey_id) < 5000); }); } diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 6f2246613..db0c20e5d 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -1,20 +1,19 @@ #![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)] use codec::Encode; -use frame_support::weights::Weight; -use frame_support::{assert_err, assert_noop, assert_ok}; -use frame_system::{Config, RawOrigin}; - -use super::mock::*; -use crate::*; -// use crate::{Call, ColdkeySwapScheduleDuration, Error}; use frame_support::error::BadOrigin; use frame_support::traits::schedule::v3::Named as ScheduleNamed; use frame_support::traits::schedule::DispatchTime; use frame_support::traits::OnInitialize; +use frame_support::weights::Weight; +use frame_support::{assert_err, assert_noop, assert_ok}; +use frame_system::{Config, RawOrigin}; use sp_core::H256; use sp_core::U256; use sp_runtime::DispatchError; +use super::mock::*; +use crate::*; + // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_coldkey -- test_swap_total_hotkey_coldkey_stakes_this_interval --exact --nocapture #[test] fn test_swap_total_hotkey_coldkey_stakes_this_interval() { From 0319a01122fed3319fb587f2918eb0d2fba485c4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 14:57:20 +0100 Subject: [PATCH 110/137] Remove hotkey_account_exists method from Pallet of pallet-subtensor --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/staking/add_stake.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 15 ++------------- pallets/subtensor/src/staking/remove_stake.rs | 2 +- pallets/subtensor/src/swap/swap_coldkey.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 2 +- 6 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 5b460217d..d6005676d 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -692,7 +692,7 @@ impl Pallet { // Check the hotkey account exists. ensure!( - Self::hotkey_account_exists(&hotkey), + Owner::::contains_key(&hotkey), Error::::HotKeyAccountNotExists ); diff --git a/pallets/subtensor/src/staking/add_stake.rs b/pallets/subtensor/src/staking/add_stake.rs index 6438212e7..0b1178544 100644 --- a/pallets/subtensor/src/staking/add_stake.rs +++ b/pallets/subtensor/src/staking/add_stake.rs @@ -52,7 +52,7 @@ impl Pallet { // Ensure that the hotkey account exists this is only possible through registration. ensure!( - Self::hotkey_account_exists(&hotkey), + Owner::::contains_key(&hotkey), Error::::HotKeyAccountNotExists ); diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 8f2d21ddd..dd3cf3dbe 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -26,7 +26,7 @@ impl Pallet { // Creates a cold - hot pairing account if the hotkey is not already an active account. // pub fn create_account_if_non_existent(coldkey: &T::AccountId, hotkey: &T::AccountId) { - if !Self::hotkey_account_exists(hotkey) { + if !Owner::::contains_key(hotkey) { Stake::::insert(hotkey, coldkey, 0); Owner::::insert(hotkey, coldkey); @@ -46,17 +46,6 @@ impl Pallet { } } - /// Returns true if the hotkey account has been created. - /// - /// # Arguments - /// * `hotkey` - The hotkey account ID. - /// - /// # Returns - /// True if the hotkey account exists, false otherwise. - pub fn hotkey_account_exists(hotkey: &T::AccountId) -> bool { - Owner::::contains_key(hotkey) - } - /// Returns true if the passed coldkey owns the hotkey. /// /// # Arguments @@ -66,7 +55,7 @@ impl Pallet { /// # Returns /// True if the coldkey owns the hotkey, false otherwise. pub fn coldkey_owns_hotkey(coldkey: &T::AccountId, hotkey: &T::AccountId) -> bool { - if Self::hotkey_account_exists(hotkey) { + if Owner::::contains_key(hotkey) { Owner::::get(hotkey) == *coldkey } else { false diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index da8486856..39ac0b937 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -46,7 +46,7 @@ impl Pallet { // Ensure that the hotkey account exists this is only possible through registration. ensure!( - Self::hotkey_account_exists(&hotkey), + Owner::::contains_key(&hotkey), Error::::HotKeyAccountNotExists ); diff --git a/pallets/subtensor/src/swap/swap_coldkey.rs b/pallets/subtensor/src/swap/swap_coldkey.rs index ad5cf2f67..71777d19c 100644 --- a/pallets/subtensor/src/swap/swap_coldkey.rs +++ b/pallets/subtensor/src/swap/swap_coldkey.rs @@ -44,7 +44,7 @@ impl Pallet { // 4. Ensure the new coldkey is not a hotkey ensure!( - !Self::hotkey_account_exists(new_coldkey), + !Owner::::contains_key(new_coldkey), Error::::NewColdKeyIsHotkey ); weight = weight.saturating_add(T::DbWeight::get().reads(1)); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9823341f2..07c6cc484 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -197,7 +197,7 @@ impl Pallet { pub fn do_take_checks(coldkey: &T::AccountId, hotkey: &T::AccountId) -> Result<(), Error> { // Ensure we are delegating a known key. ensure!( - Self::hotkey_account_exists(hotkey), + Owner::::contains_key(hotkey), Error::::HotKeyAccountNotExists ); From 7d5279642205039805aab7c394ed326065c59739 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 15:08:47 +0100 Subject: [PATCH 111/137] Remove hotkey_is_delegate from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/staking/add_stake.rs | 2 +- pallets/subtensor/src/staking/become_delegate.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 6 ------ pallets/subtensor/src/staking/remove_stake.rs | 2 +- pallets/subtensor/src/tests/root.rs | 10 +++++----- pallets/subtensor/src/tests/senate.rs | 4 ++-- 7 files changed, 11 insertions(+), 17 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index d6005676d..44d08e580 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -524,7 +524,7 @@ impl Pallet { let _ = Self::join_senate_if_eligible(&hotkey)?; // --- 14. Force all members on root to become a delegate. - if !Self::hotkey_is_delegate(&hotkey) { + if !Delegates::::contains_key(&hotkey) { Self::delegate_hotkey(&hotkey, 11_796); // 18% cut defaulted. } diff --git a/pallets/subtensor/src/staking/add_stake.rs b/pallets/subtensor/src/staking/add_stake.rs index 0b1178544..1bded70bf 100644 --- a/pallets/subtensor/src/staking/add_stake.rs +++ b/pallets/subtensor/src/staking/add_stake.rs @@ -58,7 +58,7 @@ impl Pallet { // Ensure that the hotkey allows delegation or that the hotkey is owned by the calling coldkey. ensure!( - Self::hotkey_is_delegate(&hotkey) || Self::coldkey_owns_hotkey(&coldkey, &hotkey), + Delegates::::contains_key(&hotkey) || Self::coldkey_owns_hotkey(&coldkey, &hotkey), Error::::HotKeyNotDelegateAndSignerNotOwnHotKey ); diff --git a/pallets/subtensor/src/staking/become_delegate.rs b/pallets/subtensor/src/staking/become_delegate.rs index 9be107ec7..e1e78c05d 100644 --- a/pallets/subtensor/src/staking/become_delegate.rs +++ b/pallets/subtensor/src/staking/become_delegate.rs @@ -47,7 +47,7 @@ impl Pallet { // --- 4. Ensure we are not already a delegate (dont allow changing delegate take.) ensure!( - !Self::hotkey_is_delegate(&hotkey), + !Delegates::::contains_key(&hotkey), Error::::HotKeyAlreadyDelegate ); diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index dd3cf3dbe..6789564f2 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -11,12 +11,6 @@ use frame_support::{ }; impl Pallet { - // Returns true if the passed hotkey allow delegative staking. - // - pub fn hotkey_is_delegate(hotkey: &T::AccountId) -> bool { - Delegates::::contains_key(hotkey) - } - // Sets the hotkey as a delegate with take. // pub fn delegate_hotkey(hotkey: &T::AccountId, take: u16) { diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index 39ac0b937..6bf5df18a 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -52,7 +52,7 @@ impl Pallet { // Ensure that the hotkey allows delegation or that the hotkey is owned by the calling coldkey. ensure!( - Self::hotkey_is_delegate(&hotkey) || Self::coldkey_owns_hotkey(&coldkey, &hotkey), + Delegates::::contains_key(&hotkey) || Self::coldkey_owns_hotkey(&coldkey, &hotkey), Error::::HotKeyNotDelegateAndSignerNotOwnHotKey ); diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 41693d1f7..8dd4390fc 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -7,9 +7,9 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ - migrations, utils::rate_limiting::TransactionType, EmissionValues, Error, NetworkRateLimit, - PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetOwner, - SubnetworkN, TotalIssuance, TotalNetworks, + migrations, utils::rate_limiting::TransactionType, Delegates, EmissionValues, Error, + NetworkRateLimit, PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, + SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, TotalNetworks, }; #[allow(dead_code)] @@ -147,7 +147,7 @@ fn test_root_register_stake_based_pruning_works() { // Check successful registration. assert!(SubtensorModule::get_uid_for_net_and_hotkey(other_netuid, &hot).is_ok()); // Check that they are NOT all delegates - assert!(!SubtensorModule::hotkey_is_delegate(&hot)); + assert!(!Delegates::::contains_key(hot)); } // Register the first 64 accounts with stake to the root network. @@ -161,7 +161,7 @@ fn test_root_register_stake_based_pruning_works() { // Check successful registration. 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)); + assert!(Delegates::::contains_key(hot)); } // Register the second 64 accounts with stake to the root network. diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index 70960ed7d..b63103009 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -14,7 +14,7 @@ use sp_runtime::{ BuildStorage, }; -use crate::{migrations, Error, Owner, Stake, SubnetworkN, TotalHotkeyStake}; +use crate::{migrations, Delegates, Error, Owner, Stake, SubnetworkN, TotalHotkeyStake}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -453,7 +453,7 @@ fn test_senate_leave_vote_removal() { assert!(SubtensorModule::get_uid_for_net_and_hotkey(other_netuid, &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)); + assert!(Delegates::::contains_key(hot)); } // No longer a root member assert!( From ad91c8cc2c37ba6e4e627a15453dc2c0afdf9ee3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 15:18:00 +0100 Subject: [PATCH 112/137] Remove delegate_hotkey from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/staking/become_delegate.rs | 2 +- pallets/subtensor/src/staking/helpers.rs | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 44d08e580..25f06913d 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -525,7 +525,7 @@ impl Pallet { // --- 14. Force all members on root to become a delegate. if !Delegates::::contains_key(&hotkey) { - Self::delegate_hotkey(&hotkey, 11_796); // 18% cut defaulted. + Delegates::::insert(&hotkey, 11_796); // 18% cut defaulted. } // --- 15. Update the registration counters for both the block and interval. diff --git a/pallets/subtensor/src/staking/become_delegate.rs b/pallets/subtensor/src/staking/become_delegate.rs index e1e78c05d..9e0a8479e 100644 --- a/pallets/subtensor/src/staking/become_delegate.rs +++ b/pallets/subtensor/src/staking/become_delegate.rs @@ -65,7 +65,7 @@ impl Pallet { ensure!(take <= max_take, Error::::DelegateTakeTooHigh); // --- 6. Delegate the key. - Self::delegate_hotkey(&hotkey, take); + Delegates::::insert(&hotkey, take); // Set last block for rate limiting Self::set_last_tx_block(&coldkey, block); diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 6789564f2..60e3340f4 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -11,12 +11,6 @@ use frame_support::{ }; impl Pallet { - // Sets the hotkey as a delegate with take. - // - pub fn delegate_hotkey(hotkey: &T::AccountId, take: u16) { - Delegates::::insert(hotkey, take); - } - // Creates a cold - hot pairing account if the hotkey is not already an active account. // pub fn create_account_if_non_existent(coldkey: &T::AccountId, hotkey: &T::AccountId) { From 440bb6cdf358588a63d08b59f178b28f9c7f71df Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 15:49:33 +0100 Subject: [PATCH 113/137] Remove if_subnet_exist from pallet-subtensor::Pallet --- pallets/admin-utils/src/lib.rs | 48 +++++++++---------- pallets/subtensor/src/coinbase/root.rs | 23 +++------ .../migrations/migrate_delete_subnet_21.rs | 2 +- .../src/migrations/migrate_delete_subnet_3.rs | 2 +- pallets/subtensor/src/rpc_info/neuron_info.rs | 8 ++-- pallets/subtensor/src/rpc_info/subnet_info.rs | 6 +-- pallets/subtensor/src/staking/set_children.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 4 +- pallets/subtensor/src/subnets/weights.rs | 2 +- pallets/subtensor/src/tests/migration.rs | 10 ++-- pallets/subtensor/src/tests/networks.rs | 21 ++++---- pallets/subtensor/src/tests/root.rs | 18 +++---- 12 files changed, 68 insertions(+), 78 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 3257835b0..2b3692f7e 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -161,7 +161,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_min_difficulty(netuid, min_difficulty); @@ -186,7 +186,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_max_difficulty(netuid, max_difficulty); @@ -211,7 +211,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_weights_version_key(netuid, weights_version_key); @@ -236,7 +236,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_weights_set_rate_limit( @@ -264,7 +264,7 @@ pub mod pallet { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_adjustment_interval(netuid, adjustment_interval); @@ -295,7 +295,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_adjustment_alpha(netuid, adjustment_alpha); @@ -319,7 +319,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_max_weight_limit(netuid, max_weight_limit); @@ -343,7 +343,7 @@ pub mod pallet { ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); @@ -369,7 +369,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_min_allowed_weights(netuid, min_allowed_weights); @@ -393,7 +393,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); ensure!( @@ -418,7 +418,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_kappa(netuid, kappa); @@ -435,7 +435,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_rho(netuid, rho); @@ -456,7 +456,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_activity_cutoff(netuid, activity_cutoff); @@ -538,7 +538,7 @@ pub mod pallet { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_target_registrations_per_interval( @@ -566,7 +566,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_min_burn(netuid, min_burn); @@ -591,7 +591,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_max_burn(netuid, max_burn); @@ -615,7 +615,7 @@ pub mod pallet { ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_difficulty(netuid, difficulty); @@ -639,7 +639,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); ensure!( @@ -672,7 +672,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_bonds_moving_average(netuid, bonds_moving_average); @@ -697,7 +697,7 @@ pub mod pallet { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_max_registrations_per_block( @@ -763,7 +763,7 @@ pub mod pallet { pub fn sudo_set_tempo(origin: OriginFor, netuid: u16, tempo: u16) -> DispatchResult { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_tempo(netuid, tempo); @@ -887,7 +887,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); pallet_subtensor::Pallet::::set_rao_recycled(netuid, rao_recycled); @@ -990,7 +990,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); @@ -1214,7 +1214,7 @@ pub mod pallet { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), + pallet_subtensor::NetworksAdded::::get(netuid), Error::::SubnetDoesNotExist ); diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 25f06913d..38d5569de 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -52,17 +52,6 @@ impl Pallet { SubnetworkN::::get(Self::ROOT_NETUID) } - /// Returns true if the subnetwork exists. - /// - /// This function checks if a subnetwork with the given UID exists. - /// - /// # Returns: - /// * 'bool': Whether the subnet exists. - /// - pub fn if_subnet_exist(netuid: u16) -> bool { - NetworksAdded::::get(netuid) - } - /// Returns a list of subnet netuid equal to total networks. /// /// @@ -154,7 +143,7 @@ impl Pallet { /// pub fn contains_invalid_root_uids(netuids: &[u16]) -> bool { for netuid in netuids { - if !Self::if_subnet_exist(*netuid) { + if !NetworksAdded::::get(*netuid) { log::debug!( "contains_invalid_root_uids: netuid {:?} does not exist", netuid @@ -429,7 +418,7 @@ impl Pallet { let root_netuid: u16 = Self::ROOT_NETUID; let current_block_number: u64 = Self::get_current_block_as_u64(); ensure!( - Self::if_subnet_exist(root_netuid), + NetworksAdded::::get(root_netuid), Error::::RootNetworkDoesNotExist ); @@ -565,7 +554,7 @@ impl Pallet { // --- 0. Get the unique identifier (UID) for the root network. let root_netuid: u16 = Self::ROOT_NETUID; ensure!( - Self::if_subnet_exist(root_netuid), + NetworksAdded::::get(root_netuid), Error::::RootNetworkDoesNotExist ); @@ -704,7 +693,7 @@ impl Pallet { // Check to see if this is a valid network. ensure!( - Self::if_subnet_exist(netuid), + NetworksAdded::::get(netuid), Error::::SubNetworkDoesNotExist ); @@ -890,7 +879,7 @@ impl Pallet { let mut next_available_netuid = 0; loop { next_available_netuid.saturating_inc(); - if !Self::if_subnet_exist(next_available_netuid) { + if !NetworksAdded::::get(next_available_netuid) { log::debug!("got subnet id: {:?}", next_available_netuid); break next_available_netuid; } @@ -965,7 +954,7 @@ impl Pallet { pub fn user_remove_network(coldkey: T::AccountId, netuid: u16) -> dispatch::DispatchResult { // --- 1. Ensure this subnet exists. ensure!( - Self::if_subnet_exist(netuid), + NetworksAdded::::get(netuid), Error::::SubNetworkDoesNotExist ); diff --git a/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs b/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs index c917c7cab..5a4e56d89 100644 --- a/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs +++ b/pallets/subtensor/src/migrations/migrate_delete_subnet_21.rs @@ -50,7 +50,7 @@ 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(21) { + if onchain_version < new_storage_version && NetworksAdded::::get(21) { info!(target: LOG_TARGET, ">>> Removing subnet 21 {:?}", onchain_version); let netuid = 21; diff --git a/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs b/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs index 217696357..8c619506f 100644 --- a/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs +++ b/pallets/subtensor/src/migrations/migrate_delete_subnet_3.rs @@ -50,7 +50,7 @@ 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) { + if onchain_version < new_storage_version && NetworksAdded::::get(3) { info!( target: LOG_TARGET, "Removing subnet 3. Current version: {:?}", diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index 8cbb66ab2..42194eec2 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -54,7 +54,7 @@ pub struct NeuronInfoLite { impl Pallet { pub fn get_neurons(netuid: u16) -> Vec> { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return Vec::new(); } @@ -147,7 +147,7 @@ impl Pallet { } pub fn get_neuron(netuid: u16, uid: u16) -> Option> { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return None; } @@ -208,7 +208,7 @@ impl Pallet { } pub fn get_neurons_lite(netuid: u16) -> Vec> { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return Vec::new(); } @@ -226,7 +226,7 @@ impl Pallet { } pub fn get_neuron_lite(netuid: u16, uid: u16) -> Option> { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return None; } diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index 5e8629745..d45ca0507 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -85,7 +85,7 @@ pub struct SubnetHyperparams { impl Pallet { pub fn get_subnet_info(netuid: u16) -> Option> { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return None; } @@ -155,7 +155,7 @@ impl Pallet { } pub fn get_subnet_info_v2(netuid: u16) -> Option> { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return None; } @@ -226,7 +226,7 @@ impl Pallet { subnets_info } pub fn get_subnet_hyperparams(netuid: u16) -> Option { - if !Self::if_subnet_exist(netuid) { + if !NetworksAdded::::get(netuid) { return None; } diff --git a/pallets/subtensor/src/staking/set_children.rs b/pallets/subtensor/src/staking/set_children.rs index ee7fd3149..65391c450 100644 --- a/pallets/subtensor/src/staking/set_children.rs +++ b/pallets/subtensor/src/staking/set_children.rs @@ -76,7 +76,7 @@ impl Pallet { // Check that the network we are trying to create the child on exists. ensure!( - Self::if_subnet_exist(netuid), + NetworksAdded::::get(netuid), Error::::SubNetworkDoesNotExist ); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 4602694b0..1934313ed 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -54,7 +54,7 @@ impl Pallet { Error::::RegistrationNotPermittedOnRootSubnet ); ensure!( - Self::if_subnet_exist(netuid), + NetworksAdded::::get(netuid), Error::::SubNetworkDoesNotExist ); @@ -238,7 +238,7 @@ impl Pallet { Error::::RegistrationNotPermittedOnRootSubnet ); ensure!( - Self::if_subnet_exist(netuid), + NetworksAdded::::get(netuid), Error::::SubNetworkDoesNotExist ); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index dfb92085f..ae4ef5299 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -699,7 +699,7 @@ impl Pallet { // --- 3. Check to see if this is a valid network. ensure!( - Self::if_subnet_exist(netuid), + NetworksAdded::::get(netuid), Error::::SubNetworkDoesNotExist ); diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 020d5647b..aa98d346d 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -163,7 +163,7 @@ fn test_total_issuance_global() { assert_eq!(TotalIssuance::::get(), 0); // initial is zero. crate::migrations::migrate_total_issuance::migrate_total_issuance::(true); // Pick up lock. assert_eq!(TotalIssuance::::get(), lockcost); // Verify the total issuance is updated to 20000 after migration. - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); // Test the migration's effect on total issuance after adding balance to a coldkey account. let account_balance: u64 = 20000; @@ -258,12 +258,12 @@ fn test_migration_delete_subnet_3() { new_test_ext(1).execute_with(|| { // Create subnet 3 add_network(3, 1, 0); - assert!(SubtensorModule::if_subnet_exist(3)); + assert!(NetworksAdded::::get(3)); // Run the migration to transfer ownership crate::migrations::migrate_delete_subnet_3::migrate_delete_subnet_3::(); - assert!(!SubtensorModule::if_subnet_exist(3)); + assert!(!NetworksAdded::::get(3)); }) } @@ -272,12 +272,12 @@ fn test_migration_delete_subnet_21() { new_test_ext(1).execute_with(|| { // Create subnet 21 add_network(21, 1, 0); - assert!(SubtensorModule::if_subnet_exist(21)); + assert!(NetworksAdded::::get(21)); // Run the migration to transfer ownership crate::migrations::migrate_delete_subnet_21::migrate_delete_subnet_21::(); - assert!(!SubtensorModule::if_subnet_exist(21)); + assert!(!NetworksAdded::::get(21)); }) } diff --git a/pallets/subtensor/src/tests/networks.rs b/pallets/subtensor/src/tests/networks.rs index 3c0f70b79..bb4b84280 100644 --- a/pallets/subtensor/src/tests/networks.rs +++ b/pallets/subtensor/src/tests/networks.rs @@ -1,9 +1,10 @@ use super::mock::*; -use crate::{ColdkeySwapScheduleDuration, DissolveNetworkScheduleDuration, Event}; use frame_support::assert_ok; use frame_system::Config; use sp_core::U256; +use crate::{ColdkeySwapScheduleDuration, DissolveNetworkScheduleDuration, Event, NetworksAdded}; + #[test] fn test_registration_ok() { new_test_ext(1).execute_with(|| { @@ -37,7 +38,7 @@ fn test_registration_ok() { netuid )); - assert!(!SubtensorModule::if_subnet_exist(netuid)) + assert!(!NetworksAdded::::get(netuid)) }) } @@ -69,7 +70,7 @@ fn test_schedule_dissolve_network_execution() { coldkey_account_id )); - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); assert_ok!(SubtensorModule::schedule_dissolve_network( <::RuntimeOrigin>::signed(coldkey_account_id), @@ -89,7 +90,7 @@ fn test_schedule_dissolve_network_execution() { ); run_to_block(execution_block); - assert!(!SubtensorModule::if_subnet_exist(netuid)); + assert!(!NetworksAdded::::get(netuid)); }) } @@ -122,7 +123,7 @@ fn test_non_owner_schedule_dissolve_network_execution() { coldkey_account_id )); - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); assert_ok!(SubtensorModule::schedule_dissolve_network( <::RuntimeOrigin>::signed(non_network_owner_account_id), @@ -143,7 +144,7 @@ fn test_non_owner_schedule_dissolve_network_execution() { run_to_block(execution_block); // network exists since the caller is no the network owner - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); }) } @@ -176,7 +177,7 @@ fn test_new_owner_schedule_dissolve_network_execution() { coldkey_account_id )); - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); // the account is not network owner when schedule the call assert_ok!(SubtensorModule::schedule_dissolve_network( @@ -201,7 +202,7 @@ fn test_new_owner_schedule_dissolve_network_execution() { run_to_block(execution_block); // network exists since the caller is no the network owner - assert!(!SubtensorModule::if_subnet_exist(netuid)); + assert!(!NetworksAdded::::get(netuid)); }) } @@ -237,7 +238,7 @@ fn test_schedule_dissolve_network_execution_with_coldkey_swap() { coldkey_account_id )); - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); // the account is not network owner when schedule the call assert_ok!(SubtensorModule::schedule_swap_coldkey( @@ -277,6 +278,6 @@ fn test_schedule_dissolve_network_execution_with_coldkey_swap() { run_to_block(execution_block); // network exists since the caller is no the network owner - assert!(!SubtensorModule::if_subnet_exist(netuid)); + assert!(!NetworksAdded::::get(netuid)); }) } diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 8dd4390fc..a8da79ce4 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -8,8 +8,8 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, Delegates, EmissionValues, Error, - NetworkRateLimit, PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, - SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, TotalNetworks, + NetworkRateLimit, NetworksAdded, PendingEmission, SubnetIdentities, SubnetIdentity, + SubnetIdentityOf, SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, TotalNetworks, }; #[allow(dead_code)] @@ -556,7 +556,7 @@ fn test_network_pruning() { <::RuntimeOrigin>::signed(cold), )); log::debug!("Adding network with netuid: {}", (i as u16) + 1); - assert!(SubtensorModule::if_subnet_exist((i as u16) + 1)); + assert!(NetworksAdded::::get((i as u16) + 1)); assert!(SubtensorModule::is_hotkey_registered_on_network( root_netuid, &hot @@ -681,7 +681,7 @@ fn test_weights_after_network_pruning() { )); log::debug!("Adding network with netuid: {}", (i as u16) + 1); - assert!(SubtensorModule::if_subnet_exist((i as u16) + 1)); + assert!(NetworksAdded::::get((i as u16) + 1)); step_block(3); } @@ -741,7 +741,7 @@ fn test_weights_after_network_pruning() { )); // Subnet should not exist, as it would replace a previous subnet. - assert!(!SubtensorModule::if_subnet_exist(i + 1)); + assert!(!NetworksAdded::::get(i + 1)); log::info!( "Root network weights: {:?}", @@ -890,13 +890,13 @@ fn test_dissolve_network_ok() { let owner_coldkey = SubnetOwner::::get(netuid); register_ok_neuron(netuid, hotkey, owner_coldkey, 3); - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); assert_ok!(SubtensorModule::dissolve_network( RuntimeOrigin::root(), owner_coldkey, netuid )); - assert!(!SubtensorModule::if_subnet_exist(netuid)) + assert!(!NetworksAdded::::get(netuid)) }); } @@ -914,13 +914,13 @@ fn test_dissolve_network_refund_coldkey_ok() { SubtensorModule::set_subnet_locked_balance(netuid, subnet_locked_balance); let coldkey_balance = SubtensorModule::get_coldkey_balance(&owner_coldkey); - assert!(SubtensorModule::if_subnet_exist(netuid)); + assert!(NetworksAdded::::get(netuid)); assert_ok!(SubtensorModule::dissolve_network( RuntimeOrigin::root(), owner_coldkey, netuid )); - assert!(!SubtensorModule::if_subnet_exist(netuid)); + assert!(!NetworksAdded::::get(netuid)); let coldkey_new_balance = SubtensorModule::get_coldkey_balance(&owner_coldkey); From 16fb6b344cd1586a149ae8f96367b6ca2ddcaf89 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 16:22:25 +0100 Subject: [PATCH 114/137] Remove is_uid_exist_on_network from pallet-subtensor::Pallet --- pallets/subtensor/src/subnets/uids.rs | 6 ------ pallets/subtensor/src/subnets/weights.rs | 4 ++-- pallets/subtensor/src/tests/registration.rs | 14 +++++++------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pallets/subtensor/src/subnets/uids.rs b/pallets/subtensor/src/subnets/uids.rs index 21e8247f6..3d7c34adb 100644 --- a/pallets/subtensor/src/subnets/uids.rs +++ b/pallets/subtensor/src/subnets/uids.rs @@ -79,12 +79,6 @@ impl Pallet { IsNetworkMember::::insert(new_hotkey.clone(), netuid, true); // Fill network is member. } - /// Returns true if the uid is set on the network. - /// - 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: u16, hotkey: &T::AccountId) -> bool { diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index ae4ef5299..20dd1cae8 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -911,7 +911,7 @@ impl Pallet { /// Checks if the neuron has set weights within the weights_set_rate_limit. /// pub fn check_rate_limit(netuid: u16, neuron_uid: u16, current_block: u64) -> bool { - if Self::is_uid_exist_on_network(netuid, neuron_uid) { + if Keys::::contains_key(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); if last_set_weights == 0 { @@ -927,7 +927,7 @@ impl Pallet { /// Checks for any invalid uids on this network. pub fn contains_invalid_uids(netuid: u16, uids: &[u16]) -> bool { for uid in uids { - if !Self::is_uid_exist_on_network(netuid, *uid) { + if !Keys::::contains_key(netuid, *uid) { log::debug!( "contains_invalid_uids( netuid:{:?}, uid:{:?} does not exist on network. )", netuid, diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 3838fd036..2bac180f9 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -11,7 +11,7 @@ use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::mock::*; use crate::{ - Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, + Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, Keys, MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, RegistrationsThisBlock, RegistrationsThisInterval, SubnetworkN, SubtensorSignedExtension, Tempo, @@ -1601,14 +1601,14 @@ fn test_full_pass_through() { assert_eq!(SubnetworkN::::get(netuid2), 2); // Check the uids exist. - assert!(SubtensorModule::is_uid_exist_on_network(netuid0, 0)); - assert!(SubtensorModule::is_uid_exist_on_network(netuid1, 0)); - assert!(SubtensorModule::is_uid_exist_on_network(netuid2, 0)); + assert!(Keys::::contains_key(netuid0, 0)); + assert!(Keys::::contains_key(netuid1, 0)); + assert!(Keys::::contains_key(netuid2, 0)); // Check the other exists. - assert!(SubtensorModule::is_uid_exist_on_network(netuid0, 1)); - assert!(SubtensorModule::is_uid_exist_on_network(netuid1, 1)); - assert!(SubtensorModule::is_uid_exist_on_network(netuid2, 1)); + assert!(Keys::::contains_key(netuid0, 1)); + assert!(Keys::::contains_key(netuid1, 1)); + assert!(Keys::::contains_key(netuid2, 1)); // Get the hotkey under each uid. assert_eq!( From b1d44653d84c0963bc3c61922daa75a7987285f3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 16:32:47 +0100 Subject: [PATCH 115/137] Remove set_blocks_since_last_step from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/run_coinbase.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index b06fb8a4f..91f5f5634 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -117,8 +117,8 @@ impl Pallet { subnet_emission ); - // --- 4.5 Set last step counter. - Self::set_blocks_since_last_step(*netuid, 0); + // --- 4.4 Set last step counter. + BlocksSinceLastStep::::insert(*netuid, 0); Self::set_last_mechanism_step_block(*netuid, current_block); if *netuid == 0 || !Self::get_network_registration_allowed(*netuid) { @@ -171,7 +171,7 @@ impl Pallet { } } else { // No epoch, increase blocks since last step and continue - Self::set_blocks_since_last_step( + BlocksSinceLastStep::::insert( *netuid, BlocksSinceLastStep::::get(*netuid).saturating_add(1), ); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 07c6cc484..658aab494 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -30,9 +30,7 @@ impl Pallet { 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: u16, blocks_since_last_step: u64) { - BlocksSinceLastStep::::insert(netuid, blocks_since_last_step); - } + pub fn set_registrations_this_block(netuid: u16, registrations_this_block: u16) { RegistrationsThisBlock::::insert(netuid, registrations_this_block); } From 4454f707de6d6ba7b394ffcd298d0ea256908e94 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 16:53:59 +0100 Subject: [PATCH 116/137] Remove set_burn from pallet-subtensor::Pallet --- pallets/subtensor/src/benchmarks.rs | 18 +++++++++--------- pallets/subtensor/src/coinbase/block_step.rs | 8 ++++---- pallets/subtensor/src/tests/migration.rs | 2 +- pallets/subtensor/src/tests/registration.rs | 20 ++++++++++---------- pallets/subtensor/src/tests/root.rs | 8 ++++---- pallets/subtensor/src/tests/senate.rs | 20 ++++++++++---------- pallets/subtensor/src/tests/swap_coldkey.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 3 --- 8 files changed, 41 insertions(+), 44 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index af907b659..3085b365a 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -61,7 +61,7 @@ benchmarks! { let coldkey: T::AccountId = account("Test", 0, seed); seed += 1; - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); let amount_to_be_staked = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); @@ -87,7 +87,7 @@ benchmarks! { let seed : u32 = 1; Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); Subtensor::::set_max_allowed_uids( netuid, 4096 ); Subtensor::::set_network_registration_allowed( netuid, true); @@ -115,7 +115,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); Subtensor::::set_network_registration_allowed( netuid, true ); Subtensor::::set_max_allowed_uids( netuid, 4096 ); @@ -153,7 +153,7 @@ benchmarks! { let coldkey: T::AccountId = account("Test", 0, seed); let hotkey: T::AccountId = account("Alice", 0, seed); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); let wallet_bal = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), wallet_bal); @@ -189,7 +189,7 @@ benchmarks! { Subtensor::::set_max_allowed_uids( netuid, 4096 ); assert_eq!(MaxAllowedUids::::get(netuid), 4096); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); let amount_to_be_staked = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); @@ -215,7 +215,7 @@ benchmarks! { Subtensor::::set_max_allowed_uids( netuid, 4096 ); assert_eq!(MaxAllowedUids::::get(netuid), 4096); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); let amount_to_be_staked = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&caller.clone(), amount_to_be_staked); @@ -257,7 +257,7 @@ benchmarks! { let tempo: u16 = 1; Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); let amount_to_be_staked = 1000000u32.into(); Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); @@ -273,7 +273,7 @@ benchmarks! { Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); Subtensor::::set_network_registration_allowed( netuid, true); Subtensor::::set_max_allowed_uids( netuid, 4096 ); @@ -457,7 +457,7 @@ reveal_weights { Subtensor::::init_new_network(netuid, tempo); // Register the hotkey - Subtensor::::set_burn(netuid, 1); + Burn::::insert(netuid, 1); let amount_to_be_staked = 1_000_000u32.into(); Subtensor::::add_balance_to_coldkey_account(&coldkey, amount_to_be_staked); assert_ok!(Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())); diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 379a79af4..6183e7d03 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -71,7 +71,7 @@ impl Pallet { // B. There are too many registrations this interval and most of them are burn registrations // this triggers an increase in the burn cost. // burn_cost ++ - Self::set_burn( + Burn::::insert( netuid, Self::upgraded_burn( netuid, @@ -84,7 +84,7 @@ impl Pallet { // F. There are too many registrations this interval and the pow and burn registrations are equal // this triggers an increase in the burn cost and pow difficulty // burn_cost ++ - Self::set_burn( + Burn::::insert( netuid, Self::upgraded_burn( netuid, @@ -111,7 +111,7 @@ impl Pallet { // C. There are not enough registrations this interval and most of them are pow registrations // this triggers a decrease in the burn cost // burn_cost -- - Self::set_burn( + Burn::::insert( netuid, Self::upgraded_burn( netuid, @@ -137,7 +137,7 @@ impl Pallet { // E. There are not enough registrations this interval and the pow and burn registrations are equal // this triggers a decrease in the burn cost and pow difficulty // burn_cost -- - Self::set_burn( + Burn::::insert( netuid, Self::upgraded_burn( netuid, diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index aa98d346d..9f69204cf 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -176,7 +176,7 @@ fn test_total_issuance_global() { // Test the effect of burning on total issuance. let burn_cost: u64 = 10000; - SubtensorModule::set_burn(netuid, burn_cost); // Set the burn amount to 10000 for the network. + Burn::::insert(netuid, burn_cost); // Set the burn amount to 10000 for the network. assert_eq!(TotalIssuance::::get(), account_balance + lockcost); // Confirm the total issuance remains 20000 before burning. assert_ok!(SubtensorModule::burned_register( <::RuntimeOrigin>::signed(hotkey), diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 2bac180f9..929ff33db 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -295,7 +295,7 @@ fn test_burned_registration_under_limit() { let who: ::AccountId = coldkey_account_id; let burn_cost = 1000; // Set the burn cost - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, 13, 0); // Add the network // Give it some TAO to the coldkey balance; more than the burn cost @@ -375,7 +375,7 @@ fn test_burned_registration_rate_allows_burn_adjustment() { let burn_cost = 1000; // Set the burn cost - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, 13, 0); // Add the network // Give it some TAO to the coldkey balance; more than the burn cost @@ -421,7 +421,7 @@ fn test_burned_registration_ok() { let burn_cost = 1000; let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -465,7 +465,7 @@ fn test_burn_registration_without_neuron_slot() { let burn_cost = 1000; let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -491,7 +491,7 @@ fn test_burn_adjustment() { let adjustment_interval = 1; let target_registrations_per_interval = 1; add_network(netuid, tempo, 0); - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); SubtensorModule::set_adjustment_interval(netuid, adjustment_interval); SubtensorModule::set_adjustment_alpha(netuid, 58000); // Set to old value. SubtensorModule::set_target_registrations_per_interval( @@ -542,7 +542,7 @@ fn test_burn_registration_pruning_scenarios() { const NOT_IMMUNE: bool = false; // Initial setup - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); SubtensorModule::set_max_allowed_uids(netuid, max_allowed_uids); SubtensorModule::set_target_registrations_per_interval(netuid, max_allowed_uids); SubtensorModule::set_immunity_period(netuid, immunity_period); @@ -1980,7 +1980,7 @@ fn test_registration_disabled() { // let burn_cost = 1000; // let coldkey_account_id = U256::from(667); -// SubtensorModule::set_burn(netuid, burn_cost); +// Burn::::insert(netuid, burn_cost); // add_network(netuid, tempo, 0); // // Give it some $$$ in his coldkey balance @@ -2021,7 +2021,7 @@ fn test_registration_disabled() { // let coldkey_account_id = U256::from(2); // let not_owner_coldkey = U256::from(3); -// SubtensorModule::set_burn(netuid, burn_cost); +// Burn::::insert(netuid, burn_cost); // add_network(netuid, tempo, 0); // // Give it some $$$ in his coldkey balance @@ -2056,7 +2056,7 @@ fn test_registration_disabled() { // let burn_cost = 1000; // let coldkey_account_id = U256::from(2); -// SubtensorModule::set_burn(netuid, burn_cost); +// Burn::::insert(netuid, burn_cost); // add_network(netuid, tempo, 0); // // Give it some $$$ in his coldkey balance @@ -2090,7 +2090,7 @@ fn test_registration_disabled() { // let burn_cost = 1000; // let coldkey_account_id = U256::from(2); -// SubtensorModule::set_burn(netuid, burn_cost); +// Burn::::insert(netuid, burn_cost); // add_network(netuid, tempo, 0); // // Give it some $$$ in his coldkey balance diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index a8da79ce4..247924ceb 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -7,7 +7,7 @@ use sp_core::{Get, H256, U256}; use super::mock::*; use crate::{ - migrations, utils::rate_limiting::TransactionType, Delegates, EmissionValues, Error, + migrations, utils::rate_limiting::TransactionType, Burn, Delegates, EmissionValues, Error, NetworkRateLimit, NetworksAdded, PendingEmission, SubnetIdentities, SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, TotalNetworks, }; @@ -75,7 +75,7 @@ fn test_root_register_normal_on_root_fails() { let coldkey_account_id = U256::from(667); // Burn registration fails. - SubtensorModule::set_burn(root_netuid, 0); + Burn::::insert(root_netuid, 0); SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 1); assert_eq!( SubtensorModule::burned_register( @@ -119,7 +119,7 @@ fn test_root_register_stake_based_pruning_works() { add_network(other_netuid, 0, 0); // Set params to allow all registrations to subnet. - SubtensorModule::set_burn(other_netuid, 0); + Burn::::insert(other_netuid, 0); SubtensorModule::set_max_registrations_per_block(other_netuid, 256); SubtensorModule::set_target_registrations_per_interval(other_netuid, 256); @@ -571,7 +571,7 @@ fn test_network_pruning() { 0 )); SubtensorModule::set_tempo((i as u16) + 1, 1); - SubtensorModule::set_burn((i as u16) + 1, 0); + Burn::::insert((i as u16) + 1, 0); assert_ok!(SubtensorModule::burned_register( <::RuntimeOrigin>::signed(cold), (i as u16) + 1, diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index b63103009..cf8c57f88 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -14,7 +14,7 @@ use sp_runtime::{ BuildStorage, }; -use crate::{migrations, Delegates, Error, Owner, Stake, SubnetworkN, TotalHotkeyStake}; +use crate::{migrations, Burn, Delegates, Error, Owner, Stake, SubnetworkN, TotalHotkeyStake}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -64,7 +64,7 @@ fn test_senate_join_works() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -127,7 +127,7 @@ fn test_senate_vote_works() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -229,7 +229,7 @@ fn test_senate_vote_not_member() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -286,7 +286,7 @@ fn test_senate_leave_works() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -350,7 +350,7 @@ fn test_senate_leave_vote_removal() { let coldkey_origin = <::RuntimeOrigin>::signed(coldkey_account_id); //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -422,7 +422,7 @@ fn test_senate_leave_vote_removal() { let root_netuid: u16 = 0; let other_netuid: u16 = 5; add_network(other_netuid, 0, 0); - SubtensorModule::set_burn(other_netuid, 0); + Burn::::insert(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(root_netuid, 1000); @@ -483,7 +483,7 @@ fn test_senate_not_leave_when_stake_removed() { SubtensorModule::set_target_stakes_per_interval(2); //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -559,7 +559,7 @@ fn test_senate_join_current_delegate() { let coldkey_account_id = U256::from(667); //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give some coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -639,7 +639,7 @@ fn test_adjust_senate_events() { let replacement_hotkey_account_id = U256::from(7); // Will be added to the senate to replace hotkey_account_id //add network - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); // Give some coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, balance_to_add); diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index db0c20e5d..091590ffe 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -1478,7 +1478,7 @@ fn test_coldkey_swap_delegate_identity_updated() { let burn_cost = 10; let tempo = 1; - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 100_000_000_000); @@ -1525,7 +1525,7 @@ fn test_coldkey_swap_no_identity_no_changes() { let burn_cost = 10; let tempo = 1; - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 100_000_000_000); @@ -1558,7 +1558,7 @@ fn test_coldkey_swap_no_identity_no_changes_newcoldkey_exists() { let burn_cost = 10; let tempo = 1; - SubtensorModule::set_burn(netuid, burn_cost); + Burn::::insert(netuid, burn_cost); add_network(netuid, tempo, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 100_000_000_000); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 658aab494..172ddb1cf 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -380,9 +380,6 @@ impl Pallet { pub fn get_burn_as_u64(netuid: u16) -> u64 { Burn::::get(netuid) } - pub fn set_burn(netuid: u16, burn: u64) { - Burn::::insert(netuid, burn); - } pub fn set_min_burn(netuid: u16, min_burn: u64) { MinBurn::::insert(netuid, min_burn); From ef592a5ef77eee21a83e0deb5eec3cb4fa85884a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 17:03:35 +0100 Subject: [PATCH 117/137] Remove set_burn_registrations_this_interval from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 6183e7d03..8f5454b18 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -163,7 +163,7 @@ impl Pallet { Self::set_last_adjustment_block(netuid, current_block); Self::set_registrations_this_interval(netuid, 0); Self::set_pow_registrations_this_interval(netuid, 0); - Self::set_burn_registrations_this_interval(netuid, 0); + BurnRegistrationsThisInterval::::insert(netuid, 0); } else { log::debug!("interval not reached."); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 172ddb1cf..0a295acf4 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -43,12 +43,6 @@ impl Pallet { 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: u16, - burn_registrations_this_interval: u16, - ) { - BurnRegistrationsThisInterval::::insert(netuid, burn_registrations_this_interval); - } pub fn get_current_block_as_u64() -> u64 { TryInto::try_into(>::block_number()) @@ -377,10 +371,6 @@ impl Pallet { )); } - pub fn get_burn_as_u64(netuid: u16) -> u64 { - Burn::::get(netuid) - } - pub fn set_min_burn(netuid: u16, min_burn: u64) { MinBurn::::insert(netuid, min_burn); Self::deposit_event(Event::MinBurnSet(netuid, min_burn)); From 23e69eb47934a50fae3c67c6f199fbc4737c1ca9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 17:40:20 +0100 Subject: [PATCH 118/137] Remove set_commit_reveal_weights_enabled from pallet-subtensor::Pallet --- pallets/admin-utils/src/lib.rs | 2 +- pallets/subtensor/src/benchmarks.rs | 2 +- pallets/subtensor/src/tests/batch_tx.rs | 16 ++-- pallets/subtensor/src/tests/weights.rs | 104 ++++++++++++------------ pallets/subtensor/src/utils/misc.rs | 3 - 5 files changed, 62 insertions(+), 65 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 2b3692f7e..1ab95b1b1 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -994,7 +994,7 @@ pub mod pallet { Error::::SubnetDoesNotExist ); - pallet_subtensor::Pallet::::set_commit_reveal_weights_enabled(netuid, enabled); + pallet_subtensor::CommitRevealWeightsEnabled::::set(netuid, enabled); log::debug!("ToggleSetWeightsCommitReveal( netuid: {:?} ) ", netuid); Ok(()) } diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 3085b365a..b9227bed1 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -531,7 +531,7 @@ batch_reveal_weights { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_network_registration_allowed(netuid, true); Subtensor::::set_network_pow_registration_allowed(netuid, true); - Subtensor::::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); Subtensor::::set_weights_set_rate_limit(netuid, 0); // Disable rate limiting for benchmarking let block_number: u64 = Subtensor::::get_current_block_as_u64(); diff --git a/pallets/subtensor/src/tests/batch_tx.rs b/pallets/subtensor/src/tests/batch_tx.rs index dcc806aeb..82a3268f3 100644 --- a/pallets/subtensor/src/tests/batch_tx.rs +++ b/pallets/subtensor/src/tests/batch_tx.rs @@ -7,7 +7,7 @@ use sp_runtime::{ DispatchError, }; -use crate::{Error, Event, WeightsVersionKey}; +use crate::{CommitRevealWeightsEnabled, Error, Event, WeightsVersionKey}; use super::mock::*; @@ -274,9 +274,9 @@ fn test_batch_commit_weights() { SubtensorModule::set_weights_set_rate_limit(netuid_2, 0); // Disable commit reveal for all networks (pre-emptively) - SubtensorModule::set_commit_reveal_weights_enabled(netuid_0, false); - SubtensorModule::set_commit_reveal_weights_enabled(netuid_1, false); - SubtensorModule::set_commit_reveal_weights_enabled(netuid_2, false); + CommitRevealWeightsEnabled::::set(netuid_0, false); + CommitRevealWeightsEnabled::::set(netuid_1, false); + CommitRevealWeightsEnabled::::set(netuid_2, false); // Has stake and no parent step_block(7200 + 1); @@ -323,9 +323,9 @@ fn test_batch_commit_weights() { System::reset_events(); // Enable commit reveal for all networks - SubtensorModule::set_commit_reveal_weights_enabled(netuid_0, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid_1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid_2, true); + CommitRevealWeightsEnabled::::set(netuid_0, true); + CommitRevealWeightsEnabled::::set(netuid_1, true); + CommitRevealWeightsEnabled::::set(netuid_2, true); // Set a minimum stake to set weights SubtensorModule::set_stake_threshold(stake_to_give_child - 5); @@ -366,7 +366,7 @@ fn test_batch_commit_weights() { // Test again, but with only one failure, different reason // Disable commit reveal for one network - SubtensorModule::set_commit_reveal_weights_enabled(netuid_2, false); + CommitRevealWeightsEnabled::::set(netuid_2, false); assert_ok!(SubtensorModule::batch_commit_weights( RuntimeOrigin::signed(hotkey), netuids_vec.clone(), diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index b98f07afd..c63173239 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -29,8 +29,8 @@ use sp_core::Encode; use super::mock::*; use crate::{ - coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, Error, Owner, - RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, WeightsSetRateLimit, + coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, CommitRevealWeightsEnabled, + Error, Owner, RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, WeightsSetRateLimit, WeightsVersionKey, MAX_CRV3_COMMIT_SIZE_BYTES, }; @@ -1343,7 +1343,7 @@ fn test_set_weights_commit_reveal_enabled_error() { let version_key: u64 = 0; let hotkey = U256::from(1); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); assert_err!( SubtensorModule::set_weights( @@ -1356,7 +1356,7 @@ fn test_set_weights_commit_reveal_enabled_error() { Error::::CommitRevealEnabled ); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); assert_ok!(SubtensorModule::set_weights( RuntimeOrigin::signed(hotkey), @@ -1400,7 +1400,7 @@ fn test_reveal_weights_when_commit_reveal_disabled() { SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); // Enable commit-reveal and commit - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); assert_ok!(SubtensorModule::commit_weights( RuntimeOrigin::signed(hotkey), netuid, @@ -1410,7 +1410,7 @@ fn test_reveal_weights_when_commit_reveal_disabled() { step_epochs(1, netuid); // Disable commit-reveal before reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); // Attempt to reveal, should fail with CommitRevealDisabled assert_err!( @@ -1457,7 +1457,7 @@ fn test_commit_reveal_weights_ok() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // Commit at block 0 assert_ok!(SubtensorModule::commit_weights( @@ -1509,7 +1509,7 @@ fn test_commit_reveal_tempo_interval() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // Commit at block 0 assert_ok!(SubtensorModule::commit_weights( @@ -1630,7 +1630,7 @@ fn test_commit_reveal_hash() { SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); let commit_hash: H256 = BlakeTwo256::hash_of(&( hotkey, @@ -1715,7 +1715,7 @@ fn test_commit_reveal_disabled_or_enabled() { SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); // Disable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); // Attempt to commit, should fail assert_err!( @@ -1724,7 +1724,7 @@ fn test_commit_reveal_disabled_or_enabled() { ); // Enable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // Commit should now succeed assert_ok!(SubtensorModule::commit_weights( @@ -1776,7 +1776,7 @@ fn test_toggle_commit_reveal_weights_and_set_weights() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); // Enable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // Commit at block 0 assert_ok!(SubtensorModule::commit_weights( @@ -1798,7 +1798,7 @@ fn test_toggle_commit_reveal_weights_and_set_weights() { )); // Disable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); // Advance to allow setting weights (due to rate limit) step_block(5); @@ -1843,7 +1843,7 @@ fn test_tempo_change_during_commit_reveal_process() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); assert_ok!(SubtensorModule::commit_weights( RuntimeOrigin::signed(hotkey), @@ -1976,7 +1976,7 @@ fn test_commit_reveal_multiple_commits() { SubtensorModule::set_weights_set_rate_limit(netuid, 0); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // 1. Commit 10 times successfully let mut commit_info = Vec::new(); @@ -2316,7 +2316,7 @@ fn commit_reveal_set_weights( salt: Vec, version_key: u64, ) -> DispatchResult { - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); let commit_hash: H256 = BlakeTwo256::hash_of(&( hotkey, @@ -2356,7 +2356,7 @@ fn test_expired_commits_handling_in_commit_and_reveal() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); // Register neurons @@ -2539,7 +2539,7 @@ fn test_reveal_at_exact_epoch() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2686,7 +2686,7 @@ fn test_tempo_and_reveal_period_change_during_commit_reveal_process() { let initial_reveal_period: u64 = 1; add_network(netuid, initial_tempo, 0); SubtensorModule::set_reveal_period(netuid, initial_reveal_period); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -2861,7 +2861,7 @@ fn test_commit_reveal_order_enforcement() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2947,7 +2947,7 @@ fn test_reveal_at_exact_block() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3118,7 +3118,7 @@ fn test_successful_batch_reveal() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3180,7 +3180,7 @@ fn test_batch_reveal_with_expired_commits() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3282,7 +3282,7 @@ fn test_batch_reveal_with_invalid_input_lengths() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // Base data for valid inputs let uids_list: Vec> = vec![vec![0, 1], vec![1, 0]]; @@ -3383,7 +3383,7 @@ fn test_batch_reveal_with_no_commits() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // 1. Attempt to perform batch reveal without any commits let result = SubtensorModule::do_batch_reveal_weights( @@ -3411,7 +3411,7 @@ fn test_batch_reveal_before_reveal_period() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); @@ -3468,7 +3468,7 @@ fn test_batch_reveal_after_commits_expired() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); @@ -3548,7 +3548,7 @@ fn test_batch_reveal_when_commit_reveal_disabled() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); // 1. Attempt to perform batch reveal when commit-reveal is disabled let result = SubtensorModule::do_batch_reveal_weights( @@ -3576,7 +3576,7 @@ fn test_batch_reveal_with_out_of_order_commits() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3671,7 +3671,7 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { // ==== Setup Network ==== add_network(netuid, initial_tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); SubtensorModule::set_reveal_period(netuid, initial_reveal_period); SubtensorModule::set_max_registrations_per_block(netuid, u16::MAX); @@ -3970,7 +3970,7 @@ fn test_get_reveal_blocks() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); // **6. Commit Weights at Block 0** assert_ok!(SubtensorModule::commit_weights( @@ -4088,7 +4088,7 @@ fn test_commit_weights_rate_limit() { SubtensorModule::set_weights_set_rate_limit(netuid, 10); // Rate limit is 10 blocks SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey).expect("expected uid"); @@ -4128,7 +4128,7 @@ fn test_commit_weights_rate_limit() { new_commit_hash )); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); let weights_keys: Vec = vec![0]; let weight_values: Vec = vec![1]; @@ -4251,7 +4251,7 @@ fn test_reveal_crv3_commits_success() { register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 3); let neuron_uid1 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey1) @@ -4391,7 +4391,7 @@ fn test_reveal_crv3_commits_cannot_reveal_after_reveal_epoch() { register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 3); let neuron_uid1 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey1) @@ -4514,7 +4514,7 @@ fn test_do_commit_crv3_weights_success() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); assert_ok!(SubtensorModule::do_commit_crv3_weights( RuntimeOrigin::signed(hotkey), @@ -4548,7 +4548,7 @@ fn test_do_commit_crv3_weights_disabled() { register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 5); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); + CommitRevealWeightsEnabled::::set(netuid, false); assert_err!( SubtensorModule::do_commit_crv3_weights( RuntimeOrigin::signed(hotkey), @@ -4575,7 +4575,7 @@ fn test_do_commit_crv3_weights_hotkey_not_registered() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 5); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); assert_err!( SubtensorModule::do_commit_crv3_weights( @@ -4603,7 +4603,7 @@ fn test_do_commit_crv3_weights_committing_too_fast() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 5); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey).expect("Expected uid"); SubtensorModule::set_last_update_for_uid(netuid, neuron_uid, 0); @@ -4670,7 +4670,7 @@ fn test_do_commit_crv3_weights_too_many_unrevealed_commits() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey1, U256::from(2), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(3), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); // Hotkey1 submits 10 commits successfully @@ -4773,7 +4773,7 @@ fn test_reveal_crv3_commits_decryption_failure() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); let commit_bytes: Vec = vec![0xff; 100]; let bounded_commit_bytes = commit_bytes @@ -4826,7 +4826,7 @@ fn test_reveal_crv3_commits_multiple_commits_some_fail_some_succeed() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 1); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -4947,7 +4947,7 @@ fn test_reveal_crv3_commits_do_set_weights_failure() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 3); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5032,7 +5032,7 @@ fn test_reveal_crv3_commits_payload_decoding_failure() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 3); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5110,7 +5110,7 @@ fn test_reveal_crv3_commits_signature_deserialization_failure() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 3); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5189,7 +5189,7 @@ fn test_do_commit_crv3_weights_commit_size_exceeds_limit() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); let max_commit_size = MAX_CRV3_COMMIT_SIZE_BYTES as usize; @@ -5228,7 +5228,7 @@ fn test_reveal_crv3_commits_with_empty_commit_queue() { let netuid: u16 = 1; add_network(netuid, 5, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); step_epochs(2, netuid); @@ -5252,7 +5252,7 @@ fn test_reveal_crv3_commits_with_incorrect_identity_message() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 1); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5337,7 +5337,7 @@ fn test_multiple_commits_by_same_hotkey_within_limit() { add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 1); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5374,7 +5374,7 @@ fn test_reveal_crv3_commits_removes_past_epoch_commits() { // Initialize network and neuron add_network(netuid, 5, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 1); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5438,7 +5438,7 @@ fn test_reveal_crv3_commits_multiple_valid_commits_all_processed() { // Initialize the network add_network(netuid, 5, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 1); SubtensorModule::set_weights_set_rate_limit(netuid, 0); SubtensorModule::set_max_registrations_per_block(netuid, 100); @@ -5625,7 +5625,7 @@ fn test_reveal_crv3_commits_max_neurons() { let reveal_round: u64 = 1000; add_network(netuid, 5, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); + CommitRevealWeightsEnabled::::set(netuid, true); SubtensorModule::set_reveal_period(netuid, 1); SubtensorModule::set_weights_set_rate_limit(netuid, 0); SubtensorModule::set_max_registrations_per_block(netuid, 10000); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0a295acf4..5a81b674c 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -334,9 +334,6 @@ impl Pallet { Kappa::::insert(netuid, kappa); Self::deposit_event(Event::KappaSet(netuid, kappa)); } - pub fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool) { - CommitRevealWeightsEnabled::::set(netuid, enabled); - } pub fn set_rho(netuid: u16, rho: u16) { Rho::::insert(netuid, rho); From 372ddc6b9adfd0a2b66f3feced4dc2ced4c89b42 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 18:01:35 +0100 Subject: [PATCH 119/137] Remove set_last_adjustment_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 8f5454b18..cfdd651b4 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -160,7 +160,7 @@ impl Pallet { } // --- 6. Drain all counters for this network for this interval. - Self::set_last_adjustment_block(netuid, current_block); + LastAdjustmentBlock::::insert(netuid, current_block); Self::set_registrations_this_interval(netuid, 0); Self::set_pow_registrations_this_interval(netuid, 0); BurnRegistrationsThisInterval::::insert(netuid, 0); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 5a81b674c..9c7971e33 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -27,9 +27,6 @@ impl Pallet { Tempo::::insert(netuid, tempo); Self::deposit_event(Event::TempoSet(netuid, tempo)); } - pub fn set_last_adjustment_block(netuid: u16, last_adjustment_block: u64) { - LastAdjustmentBlock::::insert(netuid, last_adjustment_block); - } pub fn set_registrations_this_block(netuid: u16, registrations_this_block: u16) { RegistrationsThisBlock::::insert(netuid, registrations_this_block); From f281f619179d468b0fe98bedbf269a064e380f2a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 18:44:18 +0100 Subject: [PATCH 120/137] Remove set_last_mechanism_step_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/run_coinbase.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 91f5f5634..ce948d32d 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -119,7 +119,7 @@ impl Pallet { // --- 4.4 Set last step counter. BlocksSinceLastStep::::insert(*netuid, 0); - Self::set_last_mechanism_step_block(*netuid, current_block); + LastMechansimStepBlock::::insert(*netuid, current_block); if *netuid == 0 || !Self::get_network_registration_allowed(*netuid) { // Skip netuid 0 payouts diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9c7971e33..dfb4b2605 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -31,9 +31,7 @@ impl Pallet { 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: u16, last_mechanism_step_block: u64) { - LastMechansimStepBlock::::insert(netuid, last_mechanism_step_block); - } + pub fn set_registrations_this_interval(netuid: u16, registrations_this_interval: u16) { RegistrationsThisInterval::::insert(netuid, registrations_this_interval); } From 664678ca06b49badfd799d1e81a53163bdccd16a Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 18:52:34 +0100 Subject: [PATCH 121/137] Remove set_last_tx_block from pallet-subtensor::Pallet --- pallets/subtensor/src/staking/add_stake.rs | 2 +- pallets/subtensor/src/staking/become_delegate.rs | 2 +- pallets/subtensor/src/staking/remove_stake.rs | 2 +- pallets/subtensor/src/swap/swap_coldkey.rs | 2 +- pallets/subtensor/src/swap/swap_hotkey.rs | 2 +- pallets/subtensor/src/utils/rate_limiting.rs | 4 ---- 6 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pallets/subtensor/src/staking/add_stake.rs b/pallets/subtensor/src/staking/add_stake.rs index 1bded70bf..7656c22aa 100644 --- a/pallets/subtensor/src/staking/add_stake.rs +++ b/pallets/subtensor/src/staking/add_stake.rs @@ -89,7 +89,7 @@ impl Pallet { // Set last block for rate limiting let block = Self::get_current_block_as_u64(); - Self::set_last_tx_block(&coldkey, block); + LastTxBlock::::insert(&coldkey, block); log::debug!( "StakeAdded( hotkey:{:?}, stake_to_be_added:{:?} )", diff --git a/pallets/subtensor/src/staking/become_delegate.rs b/pallets/subtensor/src/staking/become_delegate.rs index 9e0a8479e..0bbaf4c31 100644 --- a/pallets/subtensor/src/staking/become_delegate.rs +++ b/pallets/subtensor/src/staking/become_delegate.rs @@ -68,7 +68,7 @@ impl Pallet { Delegates::::insert(&hotkey, take); // Set last block for rate limiting - Self::set_last_tx_block(&coldkey, block); + LastTxBlock::::insert(&coldkey, block); Self::set_last_tx_block_delegate_take(&coldkey, block); // --- 7. Emit the staking event. diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index 6bf5df18a..e3841d10e 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -93,7 +93,7 @@ impl Pallet { // Set last block for rate limiting let block = Self::get_current_block_as_u64(); - Self::set_last_tx_block(&coldkey, block); + LastTxBlock::::insert(&coldkey, block); // Emit the unstaking event. log::debug!( diff --git a/pallets/subtensor/src/swap/swap_coldkey.rs b/pallets/subtensor/src/swap/swap_coldkey.rs index 71777d19c..758590891 100644 --- a/pallets/subtensor/src/swap/swap_coldkey.rs +++ b/pallets/subtensor/src/swap/swap_coldkey.rs @@ -72,7 +72,7 @@ impl Pallet { let _ = Self::perform_swap_coldkey(old_coldkey, new_coldkey, &mut weight); // 10. Update the last transaction block for the new coldkey - Self::set_last_tx_block(new_coldkey, Self::get_current_block_as_u64()); + LastTxBlock::::insert(new_coldkey, Self::get_current_block_as_u64()); weight.saturating_accrue(T::DbWeight::get().writes(1)); // 11. Remove the coldkey swap scheduled record diff --git a/pallets/subtensor/src/swap/swap_hotkey.rs b/pallets/subtensor/src/swap/swap_hotkey.rs index 7ff98f130..aea981874 100644 --- a/pallets/subtensor/src/swap/swap_hotkey.rs +++ b/pallets/subtensor/src/swap/swap_hotkey.rs @@ -85,7 +85,7 @@ impl Pallet { let _ = Self::perform_hotkey_swap(old_hotkey, new_hotkey, &coldkey, &mut weight); // 15. Update the last transaction block for the coldkey - Self::set_last_tx_block(&coldkey, block); + LastTxBlock::::insert(&coldkey, block); weight.saturating_accrue(T::DbWeight::get().writes(1)); // 16. Emit an event for the hotkey swap diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index b3b2c1339..f85548f49 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -116,10 +116,6 @@ impl Pallet { } } - pub fn set_last_tx_block(key: &T::AccountId, block: u64) { - LastTxBlock::::insert(key, block) - } - pub fn set_last_tx_block_delegate_take(key: &T::AccountId, block: u64) { LastTxBlockDelegateTake::::insert(key, block) } From 2ad4c7ce15abb5f2d52e25cf0493556b31ed1906 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 19:01:36 +0100 Subject: [PATCH 122/137] Remove set_last_tx_block_delegate_take from pallet-subtensor::Pallet --- pallets/subtensor/src/staking/become_delegate.rs | 2 +- pallets/subtensor/src/staking/increase_take.rs | 2 +- pallets/subtensor/src/utils/rate_limiting.rs | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/staking/become_delegate.rs b/pallets/subtensor/src/staking/become_delegate.rs index 0bbaf4c31..80b68e81f 100644 --- a/pallets/subtensor/src/staking/become_delegate.rs +++ b/pallets/subtensor/src/staking/become_delegate.rs @@ -69,7 +69,7 @@ impl Pallet { // Set last block for rate limiting LastTxBlock::::insert(&coldkey, block); - Self::set_last_tx_block_delegate_take(&coldkey, block); + LastTxBlockDelegateTake::::insert(&coldkey, block); // --- 7. Emit the staking event. log::debug!( diff --git a/pallets/subtensor/src/staking/increase_take.rs b/pallets/subtensor/src/staking/increase_take.rs index 444d16223..063b0746d 100644 --- a/pallets/subtensor/src/staking/increase_take.rs +++ b/pallets/subtensor/src/staking/increase_take.rs @@ -68,7 +68,7 @@ impl Pallet { ); // Set last block for rate limiting - Self::set_last_tx_block_delegate_take(&coldkey, block); + LastTxBlockDelegateTake::::insert(&coldkey, block); // --- 6. Set the new take value. Delegates::::insert(hotkey.clone(), take); diff --git a/pallets/subtensor/src/utils/rate_limiting.rs b/pallets/subtensor/src/utils/rate_limiting.rs index f85548f49..c9d0843e5 100644 --- a/pallets/subtensor/src/utils/rate_limiting.rs +++ b/pallets/subtensor/src/utils/rate_limiting.rs @@ -116,10 +116,6 @@ impl Pallet { } } - pub fn set_last_tx_block_delegate_take(key: &T::AccountId, block: u64) { - LastTxBlockDelegateTake::::insert(key, block) - } - pub fn exceeds_tx_rate_limit(prev_tx_block: u64, current_block: u64) -> bool { let rate_limit: u64 = TxRateLimit::::get(); if rate_limit == 0 || prev_tx_block == 0 { From b1f791ce4ec003d09f3809707046cd9c3d2807d6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 19:13:53 +0100 Subject: [PATCH 123/137] Remove set_liquid_alpha_enabled from pallet-subtensor::Pallet --- pallets/admin-utils/src/lib.rs | 2 +- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/tests/epoch.rs | 14 +++++++------- pallets/subtensor/src/utils/misc.rs | 4 ---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 1ab95b1b1..1946b4a8f 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -1016,7 +1016,7 @@ pub mod pallet { enabled: bool, ) -> DispatchResult { pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; - pallet_subtensor::Pallet::::set_liquid_alpha_enabled(netuid, enabled); + pallet_subtensor::LiquidAlphaOn::::set(netuid, enabled); log::debug!( "LiquidAlphaEnableToggled( netuid: {:?}, Enabled: {:?} ) ", netuid, diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 35c7b9623..02c4e79ce 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -1146,7 +1146,7 @@ fn test_sudo_get_set_alpha() { let signer = <::RuntimeOrigin>::signed(coldkey); // Enable Liquid Alpha and setup - SubtensorModule::set_liquid_alpha_enabled(netuid, true); + LiquidAlphaOn::::set(netuid, true); migrations::migrate_create_root_network::migrate_create_root_network::(); SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000); assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,)); @@ -1204,13 +1204,13 @@ fn test_sudo_get_set_alpha() { ); // 1. Liquid alpha disabled - SubtensorModule::set_liquid_alpha_enabled(netuid, false); + LiquidAlphaOn::::set(netuid, false); assert_err!( AdminUtils::sudo_set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high), SubtensorError::::LiquidAlphaDisabled ); // Correct scenario after error - SubtensorModule::set_liquid_alpha_enabled(netuid, true); // Re-enable for further tests + LiquidAlphaOn::::set(netuid, true); // Re-enable for further tests assert_ok!(AdminUtils::sudo_set_alpha_values( signer.clone(), netuid, diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index 380c4d559..cbc1f9363 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -1297,7 +1297,7 @@ fn test_bonds_with_liquid_alpha() { } // Enable Liquid Alpha - SubtensorModule::set_liquid_alpha_enabled(netuid, true); + LiquidAlphaOn::::set(netuid, true); // Run epoch with Liquid Alpha if sparse { SubtensorModule::epoch(netuid, 1_000_000_000); @@ -1460,7 +1460,7 @@ fn test_set_alpha_disabled() { let signer = <::RuntimeOrigin>::signed(coldkey); // Enable Liquid Alpha and setup - SubtensorModule::set_liquid_alpha_enabled(netuid, true); + LiquidAlphaOn::::set(netuid, true); migrations::migrate_create_root_network::migrate_create_root_network::(); SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000); assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,)); @@ -1469,13 +1469,13 @@ fn test_set_alpha_disabled() { assert_ok!(SubtensorModule::register_network(signer.clone())); // Explicitly set to false - SubtensorModule::set_liquid_alpha_enabled(netuid, false); + LiquidAlphaOn::::set(netuid, false); assert_err!( SubtensorModule::do_set_alpha_values(signer.clone(), netuid, 12_u16, u16::MAX), Error::::LiquidAlphaDisabled ); - SubtensorModule::set_liquid_alpha_enabled(netuid, true); + LiquidAlphaOn::::set(netuid, true); assert_ok!(SubtensorModule::do_set_alpha_values( signer.clone(), netuid, @@ -2534,7 +2534,7 @@ fn test_get_set_alpha() { let signer = <::RuntimeOrigin>::signed(coldkey); // Enable Liquid Alpha and setup - SubtensorModule::set_liquid_alpha_enabled(netuid, true); + LiquidAlphaOn::::set(netuid, true); migrations::migrate_create_root_network::migrate_create_root_network::(); SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000); assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,)); @@ -2592,13 +2592,13 @@ fn test_get_set_alpha() { ); // 1. Liquid alpha disabled - SubtensorModule::set_liquid_alpha_enabled(netuid, false); + LiquidAlphaOn::::set(netuid, false); assert_err!( SubtensorModule::do_set_alpha_values(signer.clone(), netuid, alpha_low, alpha_high), Error::::LiquidAlphaDisabled ); // Correct scenario after error - SubtensorModule::set_liquid_alpha_enabled(netuid, true); // Re-enable for further tests + LiquidAlphaOn::::set(netuid, true); // Re-enable for further tests assert_ok!(SubtensorModule::do_set_alpha_values( signer.clone(), netuid, diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index dfb4b2605..9402a6eb4 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -444,10 +444,6 @@ impl Pallet { (converted_low, converted_high) } - pub fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) { - LiquidAlphaOn::::set(netuid, enabled); - } - /// Sets the hotkey emission tempo. /// /// # Arguments From f9c4b384f61ff05da036dd4c7eaa4f0a641da6f8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 19:26:46 +0100 Subject: [PATCH 124/137] Remove set_network_last_lock from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 38d5569de..b697d43a1 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -903,7 +903,7 @@ impl Pallet { // --- 5. Perform the lock operation. let actual_lock_amount = Self::remove_balance_from_coldkey_account(&coldkey, lock_amount)?; Self::set_subnet_locked_balance(netuid_to_register, actual_lock_amount); - Self::set_network_last_lock(actual_lock_amount); + NetworkLastLockCost::::set(actual_lock_amount); // --- 6. Set initial and custom parameters for the network. Self::init_new_network(netuid_to_register, 360); @@ -1255,10 +1255,6 @@ impl Pallet { Self::deposit_event(Event::NetworkMinLockCostSet(net_min_lock)); } - pub fn set_network_last_lock(net_last_lock: u64) { - NetworkLastLockCost::::set(net_last_lock); - } - pub fn set_network_last_lock_block(block: u64) { NetworkLastRegistered::::set(block); } From 6d252b3499104bb1989f51376b077395cf07a44e Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 19:37:59 +0100 Subject: [PATCH 125/137] Remove set_pow_registrations_this_interval from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index cfdd651b4..98ca07daf 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -162,7 +162,7 @@ impl Pallet { // --- 6. Drain all counters for this network for this interval. LastAdjustmentBlock::::insert(netuid, current_block); Self::set_registrations_this_interval(netuid, 0); - Self::set_pow_registrations_this_interval(netuid, 0); + POWRegistrationsThisInterval::::insert(netuid, 0); BurnRegistrationsThisInterval::::insert(netuid, 0); } else { log::debug!("interval not reached."); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 9402a6eb4..5cb4573ca 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -35,9 +35,6 @@ impl Pallet { 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: u16, pow_registrations_this_interval: u16) { - POWRegistrationsThisInterval::::insert(netuid, pow_registrations_this_interval); - } pub fn get_current_block_as_u64() -> u64 { TryInto::try_into(>::block_number()) From 12f259bb3f3314b2d32a71a9f05abd5ba298ecc2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 19:47:39 +0100 Subject: [PATCH 126/137] Remove set_registrations_this_block from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/utils/misc.rs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 98ca07daf..423b5cf71 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -169,7 +169,7 @@ impl Pallet { } // --- 7. Drain block registrations for each network. Needed for registration rate limits. - Self::set_registrations_this_block(netuid, 0); + RegistrationsThisBlock::::insert(netuid, 0); } } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 5cb4573ca..024e39045 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -28,10 +28,6 @@ impl Pallet { Self::deposit_event(Event::TempoSet(netuid, tempo)); } - pub fn set_registrations_this_block(netuid: u16, registrations_this_block: u16) { - RegistrationsThisBlock::::insert(netuid, registrations_this_block); - } - pub fn set_registrations_this_interval(netuid: u16, registrations_this_interval: u16) { RegistrationsThisInterval::::insert(netuid, registrations_this_interval); } From 892481fb04c156a1efa2020a0d58ec1b834dfb9b Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 20:09:22 +0100 Subject: [PATCH 127/137] Remove get_stake_threshold from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/lib.rs | 2 +- pallets/subtensor/src/tests/batch_tx.rs | 8 ++++---- pallets/subtensor/src/tests/children.rs | 8 ++++---- pallets/subtensor/src/tests/weights.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 3 --- 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 02c4e79ce..2f3048d24 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -675,7 +675,7 @@ fn test_sudo_set_max_allowed_validators() { fn test_sudo_set_stake_threshold() { new_test_ext().execute_with(|| { let to_be_set: u64 = 10; - let init_value: u64 = SubtensorModule::get_stake_threshold(); + let init_value: u64 = StakeThreshold::::get(); assert_eq!( AdminUtils::sudo_set_stake_threshold( <::RuntimeOrigin>::signed(U256::from(1)), @@ -683,12 +683,12 @@ fn test_sudo_set_stake_threshold() { ), Err(DispatchError::BadOrigin) ); - assert_eq!(SubtensorModule::get_stake_threshold(), init_value); + assert_eq!(StakeThreshold::::get(), init_value); assert_ok!(AdminUtils::sudo_set_stake_threshold( <::RuntimeOrigin>::root(), to_be_set )); - assert_eq!(SubtensorModule::get_stake_threshold(), to_be_set); + assert_eq!(StakeThreshold::::get(), to_be_set); }); } diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index b697d43a1..9d02502fb 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -721,7 +721,7 @@ impl Pallet { // Check to see if the hotkey has enough stake to set weights. ensure!( - TotalHotkeyStake::::get(&hotkey) >= Self::get_stake_threshold(), + TotalHotkeyStake::::get(&hotkey) >= StakeThreshold::::get(), Error::::NotEnoughStakeToSetWeights ); diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index c52f89f1e..da7b67367 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1371,7 +1371,7 @@ pub mod pallet { /// Is the caller allowed to set weights pub fn check_weights_min_stake(hotkey: &T::AccountId, netuid: u16) -> bool { // Blacklist weights transactions for low stake peers. - Self::get_stake_for_hotkey_on_subnet(hotkey, netuid) >= Self::get_stake_threshold() + Self::get_stake_for_hotkey_on_subnet(hotkey, netuid) >= StakeThreshold::::get() } } } diff --git a/pallets/subtensor/src/tests/batch_tx.rs b/pallets/subtensor/src/tests/batch_tx.rs index 82a3268f3..c3a5b1e59 100644 --- a/pallets/subtensor/src/tests/batch_tx.rs +++ b/pallets/subtensor/src/tests/batch_tx.rs @@ -7,7 +7,7 @@ use sp_runtime::{ DispatchError, }; -use crate::{CommitRevealWeightsEnabled, Error, Event, WeightsVersionKey}; +use crate::{CommitRevealWeightsEnabled, Error, Event, StakeThreshold, WeightsVersionKey}; use super::mock::*; @@ -102,7 +102,7 @@ fn test_batch_set_weights() { // Check the key has less stake than required assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid_0) - < SubtensorModule::get_stake_threshold() + < StakeThreshold::::get() ); let netuids_vec: Vec> = @@ -155,7 +155,7 @@ fn test_batch_set_weights() { // Check if the stake for the hotkey is above assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid_0) - >= SubtensorModule::get_stake_threshold() + >= StakeThreshold::::get() ); // Try with enough stake @@ -333,7 +333,7 @@ fn test_batch_commit_weights() { // Check if the stake for the hotkey is above assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid_0) - >= SubtensorModule::get_stake_threshold() + >= StakeThreshold::::get() ); // Try with commit reveal enabled diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index fc278f903..a96632337 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -3149,7 +3149,7 @@ fn test_childkey_set_weights_single_parent() { // Check the child has less stake than required assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&child, netuid) - < SubtensorModule::get_stake_threshold() + < StakeThreshold::::get() ); // Check the child cannot set weights @@ -3172,7 +3172,7 @@ fn test_childkey_set_weights_single_parent() { // Check if the stake for the child is above assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&child, netuid) - >= SubtensorModule::get_stake_threshold() + >= StakeThreshold::::get() ); // Check the child can set weights @@ -3232,7 +3232,7 @@ fn test_set_weights_no_parent() { // Check the key has less stake than required assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid) - < SubtensorModule::get_stake_threshold() + < StakeThreshold::::get() ); // Check the hotkey cannot set weights @@ -3255,7 +3255,7 @@ fn test_set_weights_no_parent() { // Check if the stake for the hotkey is above assert!( SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid) - >= SubtensorModule::get_stake_threshold() + >= StakeThreshold::::get() ); // Check the hotkey can set weights diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index c63173239..d0e8ee33b 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -30,8 +30,8 @@ use sp_core::Encode; use super::mock::*; use crate::{ coinbase::run_coinbase::WeightsTlockPayload, CRV3WeightCommits, CommitRevealWeightsEnabled, - Error, Owner, RevealPeriodEpochs, SubnetworkN, Tempo, TotalHotkeyStake, WeightsSetRateLimit, - WeightsVersionKey, MAX_CRV3_COMMIT_SIZE_BYTES, + Error, Owner, RevealPeriodEpochs, StakeThreshold, SubnetworkN, Tempo, TotalHotkeyStake, + WeightsSetRateLimit, WeightsVersionKey, MAX_CRV3_COMMIT_SIZE_BYTES, }; /*************************** @@ -485,7 +485,7 @@ fn test_set_stake_threshold_failed() { SubtensorModule::set_stake_threshold(20_000_000_000_000); // Check the signed extension function. - assert_eq!(SubtensorModule::get_stake_threshold(), 20_000_000_000_000); + assert_eq!(StakeThreshold::::get(), 20_000_000_000_000); assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid)); SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 19_000_000_000_000); assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid)); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 024e39045..576d11929 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -167,9 +167,6 @@ impl Pallet { let vec = ValidatorPermit::::get(netuid); vec.get(uid as usize).copied().unwrap_or(false) } - pub fn get_stake_threshold() -> u64 { - StakeThreshold::::get() - } // ======================== // ===== Take checks ====== From a5f1f072b555993baed7bd510d585f6d75e8b3c5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 20:17:51 +0100 Subject: [PATCH 128/137] Remove set_registrations_this_interval from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/tests/registration.rs | 6 ++--- pallets/subtensor/src/utils/misc.rs | 23 ++++++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 423b5cf71..6ec8b159f 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -161,7 +161,7 @@ impl Pallet { // --- 6. Drain all counters for this network for this interval. LastAdjustmentBlock::::insert(netuid, current_block); - Self::set_registrations_this_interval(netuid, 0); + RegistrationsThisInterval::::insert(netuid, 0); POWRegistrationsThisInterval::::insert(netuid, 0); BurnRegistrationsThisInterval::::insert(netuid, 0); } else { diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 929ff33db..894c6f7e9 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -253,7 +253,7 @@ fn test_registration_rate_limit_exceeded() { let target_registrants = 1; let max_registrants = target_registrants * 3; SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); - SubtensorModule::set_registrations_this_interval(netuid, max_registrants); + RegistrationsThisInterval::::insert(netuid, max_registrants); let (nonce, work) = SubtensorModule::create_work_for_block_number( netuid, @@ -343,7 +343,7 @@ fn test_burned_registration_rate_limit_exceeded() { SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); // Set the current registrations to the maximum; should not be able to register more - SubtensorModule::set_registrations_this_interval(netuid, max_registrants); + RegistrationsThisInterval::::insert(netuid, max_registrants); let call_burned_register: crate::Call = crate::Call::burned_register { netuid, @@ -384,7 +384,7 @@ fn test_burned_registration_rate_allows_burn_adjustment() { let target_registrants = 1; // Target is 1, but we can register more than that, up to some maximum. SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); // Set the current registrations to above the target; we should be able to register at least 1 more - SubtensorModule::set_registrations_this_interval(netuid, target_registrants); + RegistrationsThisInterval::::insert(netuid, target_registrants); // Register one more, so the current registrations are above the target let call_burned_register: crate::Call = crate::Call::burned_register { diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 576d11929..8ea67f603 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -20,18 +20,11 @@ impl Pallet { } } - // ======================== - // ==== Global Setters ==== - // ======================== pub fn set_tempo(netuid: u16, tempo: u16) { Tempo::::insert(netuid, tempo); Self::deposit_event(Event::TempoSet(netuid, tempo)); } - pub fn set_registrations_this_interval(netuid: u16, registrations_this_interval: u16) { - RegistrationsThisInterval::::insert(netuid, registrations_this_interval); - } - pub fn get_current_block_as_u64() -> u64 { TryInto::try_into(>::block_number()) .ok() @@ -49,6 +42,7 @@ impl Pallet { *updated_last_update = last_update; LastUpdate::::insert(netuid, updated_last_update_vec); } + pub fn set_active_for_uid(netuid: u16, uid: u16, active: bool) { let mut updated_active_vec = Active::::get(netuid); let Some(updated_active) = updated_active_vec.get_mut(uid as usize) else { @@ -57,6 +51,7 @@ impl Pallet { *updated_active = active; Active::::insert(netuid, updated_active_vec); } + pub fn set_pruning_score_for_uid(netuid: u16, uid: u16, pruning_score: u16) { log::debug!("netuid = {:?}", netuid); log::debug!( @@ -71,6 +66,7 @@ impl Pallet { } }); } + pub fn set_validator_permit_for_uid(netuid: u16, uid: u16, validator_permit: bool) { let mut updated_validator_permits = ValidatorPermit::::get(netuid); let Some(updated_validator_permit) = updated_validator_permits.get_mut(uid as usize) else { @@ -79,10 +75,12 @@ impl Pallet { *updated_validator_permit = validator_permit; ValidatorPermit::::insert(netuid, updated_validator_permits); } + pub fn set_stake_threshold(min_stake: u64) { StakeThreshold::::put(min_stake); Self::deposit_event(Event::StakeThresholdSet(min_stake)); } + pub fn set_target_stakes_per_interval(target_stakes_per_interval: u64) { TargetStakesPerInterval::::set(target_stakes_per_interval); Self::deposit_event(Event::TargetStakesPerIntervalSet( @@ -123,46 +121,57 @@ impl Pallet { pub fn set_stake_interval(block: u64) { StakeInterval::::set(block); } + 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: u16, uid: u16) -> bool { let vec = ValidatorPermit::::get(netuid); vec.get(uid as usize).copied().unwrap_or(false) From 05822559c0902b07f8426346bbd3975d7a0250f4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 20:24:40 +0100 Subject: [PATCH 129/137] Remove set_senate_required_stake_perc method from Pallet of pallet-subtensor --- pallets/subtensor/src/utils/misc.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 8ea67f603..2de6ae5cb 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -418,10 +418,6 @@ impl Pallet { Self::set_rao_recycled(netuid, rao_recycled); } - pub fn set_senate_required_stake_perc(required_percent: u64) { - SenateRequiredStakePercentage::::put(required_percent); - } - pub fn is_senate_member(hotkey: &T::AccountId) -> bool { T::SenateMembers::is_member(hotkey) } From 24a36b295057064e4151393e5f577c4b268d6b59 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 21:05:43 +0100 Subject: [PATCH 130/137] Remove is_senate_member method from Pallet of pallet-subtensor --- pallets/subtensor/src/tests/root.rs | 19 +++++-------------- pallets/subtensor/src/utils/misc.rs | 12 ++++++++---- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 247924ceb..98f005cca 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -2,25 +2,16 @@ use frame_support::{assert_err, assert_ok}; use frame_system::Config; -use frame_system::{EventRecord, Phase}; -use sp_core::{Get, H256, U256}; +use sp_core::{Get, U256}; use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, Burn, Delegates, EmissionValues, Error, - NetworkRateLimit, NetworksAdded, PendingEmission, SubnetIdentities, SubnetIdentity, - SubnetIdentityOf, SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, TotalNetworks, + MemberManagement, NetworkRateLimit, NetworksAdded, PendingEmission, SubnetIdentities, + SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, + TotalNetworks, }; -#[allow(dead_code)] -fn record(event: RuntimeEvent) -> EventRecord { - EventRecord { - phase: Phase::Initialization, - event, - topics: vec![], - } -} - #[test] fn test_root_register_network_exist() { new_test_ext(1).execute_with(|| { @@ -192,7 +183,7 @@ fn test_root_register_stake_based_pruning_works() { // Check for unsuccessful registration. assert!(SubtensorModule::get_uid_for_net_and_hotkey(root_netuid, &hot).is_err()); // Check that they are NOT senate members - assert!(!SubtensorModule::is_senate_member(&hot)); + assert!(!::SenateMembers::is_member(&hot)); } }); } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 2de6ae5cb..892eadbca 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -202,6 +202,7 @@ impl Pallet { pub fn burn_tokens(amount: u64) { TotalIssuance::::put(TotalIssuance::::get().saturating_sub(amount)); } + pub fn coinbase(amount: u64) { TotalIssuance::::put(TotalIssuance::::get().saturating_add(amount)); } @@ -223,14 +224,17 @@ impl Pallet { TxRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxRateLimitSet(tx_rate_limit)); } + pub fn set_tx_delegate_take_rate_limit(tx_rate_limit: u64) { TxDelegateTakeRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxDelegateTakeRateLimitSet(tx_rate_limit)); } + pub fn set_min_delegate_take(take: u16) { MinDelegateTake::::put(take); Self::deposit_event(Event::MinDelegateTakeSet(take)); } + pub fn set_max_delegate_take(take: u16) { MaxDelegateTake::::put(take); Self::deposit_event(Event::MaxDelegateTakeSet(take)); @@ -240,10 +244,12 @@ impl Pallet { TxChildkeyTakeRateLimit::::put(tx_rate_limit); Self::deposit_event(Event::TxChildKeyTakeRateLimitSet(tx_rate_limit)); } + pub fn set_min_childkey_take(take: u16) { MinChildkeyTake::::put(take); Self::deposit_event(Event::MinChildKeyTakeSet(take)); } + pub fn set_max_childkey_take(take: u16) { MaxChildkeyTake::::put(take); Self::deposit_event(Event::MaxChildKeyTakeSet(take)); @@ -306,6 +312,7 @@ impl Pallet { 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: u16, uid: u16) -> bool { let registered_at = BlockAtRegistration::::get(netuid, uid); @@ -351,6 +358,7 @@ impl Pallet { pub fn get_target_registrations_per_interval(netuid: u16) -> u16 { TargetRegistrationsPerInterval::::get(netuid) } + pub fn set_target_registrations_per_interval( netuid: u16, target_registrations_per_interval: u16, @@ -418,10 +426,6 @@ impl Pallet { Self::set_rao_recycled(netuid, rao_recycled); } - pub fn is_senate_member(hotkey: &T::AccountId) -> bool { - T::SenateMembers::is_member(hotkey) - } - pub fn is_subnet_owner(address: &T::AccountId) -> bool { SubnetOwner::::iter_values().any(|owner| *address == owner) } From 2de5083b7c9e130714210bc0fd6eccc3b621ccd8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Thu, 19 Dec 2024 21:16:14 +0100 Subject: [PATCH 131/137] Remove set_nominator_min_required_stake from pallet-subtensor::Pallet --- pallets/admin-utils/src/lib.rs | 2 +- pallets/subtensor/src/tests/staking.rs | 8 ++++---- pallets/subtensor/src/utils/misc.rs | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 1946b4a8f..83bcb42e4 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -918,7 +918,7 @@ pub mod pallet { ensure_root(origin)?; let prev_min_stake = pallet_subtensor::NominatorMinRequiredStake::::get(); log::trace!("Setting minimum stake to: {}", min_stake); - pallet_subtensor::Pallet::::set_nominator_min_required_stake(min_stake); + pallet_subtensor::NominatorMinRequiredStake::::put(min_stake); if min_stake > prev_min_stake { log::trace!("Clearing small nominations"); pallet_subtensor::Pallet::::clear_small_nominations(); diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index fbd639cc5..e42dc2d88 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1358,7 +1358,7 @@ fn test_clear_small_nominations() { assert_eq!(Balances::free_balance(cold2), 8); // Run clear all small nominations when min stake is zero (noop) - SubtensorModule::set_nominator_min_required_stake(0); + NominatorMinRequiredStake::::put(0); SubtensorModule::clear_small_nominations(); assert_eq!(Stake::::get(hot1, cold1), 1); assert_eq!(Stake::::get(hot2, cold1), 1); @@ -1373,7 +1373,7 @@ fn test_clear_small_nominations() { let _ = Stake::::try_get(hot2, cold1).unwrap(); // ensure exists before let _ = Stake::::try_get(hot1, cold2).unwrap(); // ensure exists before let total_stake_before = TotalStake::::get(); - SubtensorModule::set_nominator_min_required_stake(10); + NominatorMinRequiredStake::::put(10); // Run clear all small nominations (removes delegations under 10) SubtensorModule::clear_small_nominations(); @@ -1424,7 +1424,7 @@ fn test_add_stake_below_minimum_threshold() { // Add balances. SubtensorModule::add_balance_to_coldkey_account(&coldkey1, 100_000); SubtensorModule::add_balance_to_coldkey_account(&coldkey2, 100_000); - SubtensorModule::set_nominator_min_required_stake(minimum_threshold); + NominatorMinRequiredStake::::put(minimum_threshold); SubtensorModule::set_target_stakes_per_interval(10); // Create network @@ -1472,7 +1472,7 @@ fn test_remove_stake_below_minimum_threshold() { // Add balances. SubtensorModule::add_balance_to_coldkey_account(&coldkey1, initial_balance); SubtensorModule::add_balance_to_coldkey_account(&coldkey2, initial_balance); - SubtensorModule::set_nominator_min_required_stake(minimum_threshold); + NominatorMinRequiredStake::::put(minimum_threshold); SubtensorModule::set_target_stakes_per_interval(10); // Create network diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 892eadbca..1c32abab6 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -430,10 +430,6 @@ impl Pallet { SubnetOwner::::iter_values().any(|owner| *address == owner) } - pub fn set_nominator_min_required_stake(min_stake: u64) { - NominatorMinRequiredStake::::put(min_stake); - } - pub fn get_alpha_values_32(netuid: u16) -> (I32F32, I32F32) { let (alpha_low, alpha_high): (u16, u16) = AlphaValues::::get(netuid); let converted_low = I32F32::from_num(alpha_low).saturating_div(I32F32::from_num(u16::MAX)); From c8bd7eb064c54d9e3195aa12657e7244ddd82ce4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 20 Dec 2024 15:47:24 +0100 Subject: [PATCH 132/137] Remove set_stake_interval from pallet-subtensor::Pallet --- pallets/subtensor/src/tests/staking.rs | 4 ++-- pallets/subtensor/src/utils/misc.rs | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index e42dc2d88..4ccce34e7 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -335,7 +335,7 @@ fn test_reset_stakes_per_interval() { let coldkey = U256::from(561330); let hotkey = U256::from(561337); - SubtensorModule::set_stake_interval(3); + StakeInterval::::set(3); SubtensorModule::set_target_stakes_per_interval(3); assert_ok!(SubtensorModule::try_increase_staking_counter( @@ -399,7 +399,7 @@ fn test_staking_rate_limit() { let netuid = 1; let max_stakes = 3; - SubtensorModule::set_stake_interval(3); + StakeInterval::::set(3); SubtensorModule::set_target_stakes_per_interval(max_stakes); add_network(netuid, 13, 0); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 1c32abab6..95893a825 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -118,10 +118,6 @@ impl Pallet { Ok(()) } - pub fn set_stake_interval(block: u64) { - StakeInterval::::set(block); - } - 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) From 97c54125824d16024f570b62e835813c07948c62 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 20 Dec 2024 15:58:06 +0100 Subject: [PATCH 133/137] Remove set_subnet_locked_balance from pallet-subtensor::Pallet --- pallets/subtensor/src/coinbase/root.rs | 4 ++-- pallets/subtensor/src/tests/root.rs | 6 +++--- pallets/subtensor/src/utils/misc.rs | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 9d02502fb..1d2f93027 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -902,7 +902,7 @@ impl Pallet { // --- 5. Perform the lock operation. let actual_lock_amount = Self::remove_balance_from_coldkey_account(&coldkey, lock_amount)?; - Self::set_subnet_locked_balance(netuid_to_register, actual_lock_amount); + SubnetLocked::::insert(netuid_to_register, actual_lock_amount); NetworkLastLockCost::::set(actual_lock_amount); // --- 6. Set initial and custom parameters for the network. @@ -1146,7 +1146,7 @@ impl Pallet { // --- 12. Add the balance back to the owner. Self::add_balance_to_coldkey_account(&owner_coldkey, reserved_amount); - Self::set_subnet_locked_balance(netuid, 0); + SubnetLocked::::insert(netuid, 0); SubnetOwner::::remove(netuid); // --- 13. Remove subnet identity if it exists. diff --git a/pallets/subtensor/src/tests/root.rs b/pallets/subtensor/src/tests/root.rs index 98f005cca..d15cc2ed8 100644 --- a/pallets/subtensor/src/tests/root.rs +++ b/pallets/subtensor/src/tests/root.rs @@ -8,8 +8,8 @@ use super::mock::*; use crate::{ migrations, utils::rate_limiting::TransactionType, Burn, Delegates, EmissionValues, Error, MemberManagement, NetworkRateLimit, NetworksAdded, PendingEmission, SubnetIdentities, - SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetOwner, SubnetworkN, TotalIssuance, - TotalNetworks, + SubnetIdentity, SubnetIdentityOf, SubnetLimit, SubnetLocked, SubnetOwner, SubnetworkN, + TotalIssuance, TotalNetworks, }; #[test] @@ -902,7 +902,7 @@ fn test_dissolve_network_refund_coldkey_ok() { let owner_coldkey = SubnetOwner::::get(netuid); register_ok_neuron(netuid, hotkey, owner_coldkey, 3); - SubtensorModule::set_subnet_locked_balance(netuid, subnet_locked_balance); + SubnetLocked::::insert(netuid, subnet_locked_balance); let coldkey_balance = SubtensorModule::get_coldkey_balance(&owner_coldkey); assert!(NetworksAdded::::get(netuid)); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 95893a825..81ae13364 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -203,10 +203,6 @@ impl Pallet { TotalIssuance::::put(TotalIssuance::::get().saturating_add(amount)); } - pub fn set_subnet_locked_balance(netuid: u16, amount: u64) { - SubnetLocked::::insert(netuid, amount); - } - pub fn get_total_subnet_locked() -> u64 { let mut total_subnet_locked: u64 = 0; for (_, locked) in SubnetLocked::::iter() { From f24a08b7af8377e1bfbe9537a9498f473c2d61e5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 20 Dec 2024 16:15:06 +0100 Subject: [PATCH 134/137] Remove get_target_registrations_per_interval from pallet-subtensor::Pallet --- pallets/admin-utils/src/tests/mod.rs | 6 +++--- pallets/subtensor/src/coinbase/block_step.rs | 2 +- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/lib.rs | 2 +- pallets/subtensor/src/rpc_info/subnet_info.rs | 2 +- pallets/subtensor/src/subnets/registration.rs | 4 ++-- pallets/subtensor/src/tests/difficulty.rs | 17 ++++------------- pallets/subtensor/src/tests/registration.rs | 9 +++------ pallets/subtensor/src/utils/misc.rs | 4 ---- 9 files changed, 16 insertions(+), 32 deletions(-) diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 2f3048d24..bff892ecf 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -572,7 +572,7 @@ fn test_sudo_set_target_registrations_per_interval() { 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); + let init_value: u16 = TargetRegistrationsPerInterval::::get(netuid); assert_eq!( AdminUtils::sudo_set_target_registrations_per_interval( <::RuntimeOrigin>::signed(U256::from(1)), @@ -590,7 +590,7 @@ fn test_sudo_set_target_registrations_per_interval() { Err(Error::::SubnetDoesNotExist.into()) ); assert_eq!( - SubtensorModule::get_target_registrations_per_interval(netuid), + TargetRegistrationsPerInterval::::get(netuid), init_value ); assert_ok!(AdminUtils::sudo_set_target_registrations_per_interval( @@ -599,7 +599,7 @@ fn test_sudo_set_target_registrations_per_interval() { to_be_set )); assert_eq!( - SubtensorModule::get_target_registrations_per_interval(netuid), + TargetRegistrationsPerInterval::::get(netuid), to_be_set ); }); diff --git a/pallets/subtensor/src/coinbase/block_step.rs b/pallets/subtensor/src/coinbase/block_step.rs index 6ec8b159f..a1aed77b1 100644 --- a/pallets/subtensor/src/coinbase/block_step.rs +++ b/pallets/subtensor/src/coinbase/block_step.rs @@ -49,7 +49,7 @@ impl Pallet { let burn_registrations_this_interval: u16 = BurnRegistrationsThisInterval::::get(netuid); let target_registrations_this_interval: u16 = - Self::get_target_registrations_per_interval(netuid); + TargetRegistrationsPerInterval::::get(netuid); // --- 5. Adjust burn + pow // There are six cases to consider. A, B, C, D, E, F if registrations_this_interval > target_registrations_this_interval { diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 1d2f93027..c751bf0ea 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -440,7 +440,7 @@ impl Pallet { // --- 3. Ensure that the number of registrations in this interval doesn't exceed thrice the target limit. ensure!( RegistrationsThisInterval::::get(root_netuid) - < Self::get_target_registrations_per_interval(root_netuid).saturating_mul(3), + < TargetRegistrationsPerInterval::::get(root_netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index da7b67367..81906bb36 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1561,7 +1561,7 @@ where Some(Call::register { netuid, .. } | Call::burned_register { netuid, .. }) => { let registrations_this_interval = RegistrationsThisInterval::::get(*netuid); let max_registrations_per_interval = - Pallet::::get_target_registrations_per_interval(*netuid); + TargetRegistrationsPerInterval::::get(netuid); if registrations_this_interval >= (max_registrations_per_interval.saturating_mul(3)) { // If the registration limit for the interval is exceeded, reject the transaction diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index d45ca0507..d4a3dab78 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -243,7 +243,7 @@ impl Pallet { let adjustment_interval = AdjustmentInterval::::get(netuid); let activity_cutoff = ActivityCutoff::::get(netuid); let registration_allowed = NetworkRegistrationAllowed::::get(netuid); - let target_regs_per_interval = Self::get_target_registrations_per_interval(netuid); + let target_regs_per_interval = TargetRegistrationsPerInterval::::get(netuid); let min_burn = MinBurn::::get(netuid); let max_burn = MaxBurn::::get(netuid); let bonds_moving_avg = BondsMovingAverage::::get(netuid); diff --git a/pallets/subtensor/src/subnets/registration.rs b/pallets/subtensor/src/subnets/registration.rs index 1934313ed..487b801d0 100644 --- a/pallets/subtensor/src/subnets/registration.rs +++ b/pallets/subtensor/src/subnets/registration.rs @@ -73,7 +73,7 @@ impl Pallet { // --- 4. Ensure we are not exceeding the max allowed registrations per interval. ensure!( RegistrationsThisInterval::::get(netuid) - < Self::get_target_registrations_per_interval(netuid).saturating_mul(3), + < TargetRegistrationsPerInterval::::get(netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); @@ -257,7 +257,7 @@ impl Pallet { // --- 5. Ensure we are not exceeding the max allowed registrations per interval. ensure!( RegistrationsThisInterval::::get(netuid) - < Self::get_target_registrations_per_interval(netuid).saturating_mul(3), + < TargetRegistrationsPerInterval::::get(netuid).saturating_mul(3), Error::::TooManyRegistrationsThisInterval ); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index e9e744dd7..680787e94 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -6,7 +6,7 @@ use super::mock::*; use crate::{ AdjustmentInterval, Difficulty, LastAdjustmentBlock, MaxAllowedUids, MaxDifficulty, MaxRegistrationsPerBlock, MinDifficulty, NetworkRegistrationAllowed, RegistrationsThisBlock, - RegistrationsThisInterval, SubnetworkN, + RegistrationsThisInterval, SubnetworkN, TargetRegistrationsPerInterval, }; #[test] @@ -35,10 +35,7 @@ fn test_registration_difficulty_adjustment() { SubtensorModule::set_network_registration_allowed(netuid, true); assert_eq!(Difficulty::::get(netuid), 20000); // Check set difficutly. assert_eq!(AdjustmentInterval::::get(netuid), 1); // Check set adjustment interval. - assert_eq!( - SubtensorModule::get_target_registrations_per_interval(netuid), - 1 - ); // Check set adjustment interval. + assert_eq!(TargetRegistrationsPerInterval::::get(netuid), 1); // Check set adjustment interval. assert_eq!(MaxRegistrationsPerBlock::::get(netuid), 3); // Check set registrations per block. assert_eq!(MaxAllowedUids::::get(netuid), 3); // Check set registrations per block. assert!(NetworkRegistrationAllowed::::get(netuid)); // Check set registration allowed @@ -86,10 +83,7 @@ fn test_registration_difficulty_adjustment() { assert_eq!(AdjustmentInterval::::get(netuid), 3); // Check set adjustment interval. SubtensorModule::set_target_registrations_per_interval(netuid, 3); - assert_eq!( - SubtensorModule::get_target_registrations_per_interval(netuid), - 3 - ); // Target is default. + assert_eq!(TargetRegistrationsPerInterval::::get(netuid), 3); // Target is default. // Register 3 more register_ok_neuron(netuid, hotkey0 + 1, coldkey0 + 1, 3942084); @@ -156,10 +150,7 @@ fn test_registration_difficulty_adjustment() { register_ok_neuron(netuid, hotkey2 + 3, coldkey2 + 3, 324123920); register_ok_neuron(netuid, hotkey2 + 4, coldkey2 + 4, 524123920); assert_eq!(RegistrationsThisInterval::::get(netuid), 4); - assert_eq!( - SubtensorModule::get_target_registrations_per_interval(netuid), - 3 - ); + assert_eq!(TargetRegistrationsPerInterval::::get(netuid), 3); step_block(1); // Step assert_eq!(Difficulty::::get(netuid), 5833); // Difficulty increased 5000 * ( 4 + 3 ) / (3 + 3) = 1.16 * 5000 = 5833 diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 894c6f7e9..227a8474b 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -14,7 +14,7 @@ use crate::{ Axons, BlockAtRegistration, Burn, Difficulty, EmissionValues, Error, ImmunityPeriod, Keys, MaxAllowedUids, MaxRegistrationsPerBlock, Owner, RAORecycledForRegistration, RegistrationsThisBlock, RegistrationsThisInterval, SubnetworkN, SubtensorSignedExtension, - Tempo, + TargetRegistrationsPerInterval, Tempo, }; /******************************************** @@ -236,7 +236,7 @@ fn test_registration_under_limit() { )); let current_registrants = RegistrationsThisInterval::::get(netuid); - let target_registrants = SubtensorModule::get_target_registrations_per_interval(netuid); + let target_registrants = TargetRegistrationsPerInterval::::get(netuid); assert!(current_registrants <= target_registrants); }); } @@ -849,10 +849,7 @@ fn test_registration_too_many_registrations_per_interval() { SubtensorModule::set_max_registrations_per_block(netuid, 11); assert_eq!(MaxRegistrationsPerBlock::::get(netuid), 11); SubtensorModule::set_target_registrations_per_interval(netuid, 3); - assert_eq!( - SubtensorModule::get_target_registrations_per_interval(netuid), - 3 - ); + assert_eq!(TargetRegistrationsPerInterval::::get(netuid), 3); // Then the max is 3 * 3 = 9 let block_number: u64 = 0; diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 81ae13364..755f54583 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -347,10 +347,6 @@ impl Pallet { Self::deposit_event(Event::PowRegistrationAllowed(netuid, registration_allowed)); } - pub fn get_target_registrations_per_interval(netuid: u16) -> u16 { - TargetRegistrationsPerInterval::::get(netuid) - } - pub fn set_target_registrations_per_interval( netuid: u16, target_registrations_per_interval: u16, From b17c9daea34c712e277e46fad1440047a5636ade Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 20 Dec 2024 17:03:29 +0100 Subject: [PATCH 135/137] Remove uids_match_values method from Pallet of pallet-subtensor --- pallets/subtensor/src/coinbase/root.rs | 2 +- pallets/subtensor/src/subnets/weights.rs | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index c751bf0ea..fc531d38a 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -702,7 +702,7 @@ impl Pallet { // Check that the length of uid list and value list are equal for this network. ensure!( - Self::uids_match_values(&uids, &values), + uids.len() == values.len(), Error::::WeightVecNotEqualSize ); diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 20dd1cae8..4b5044b14 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -693,7 +693,7 @@ impl Pallet { // --- 2. Check that the length of uid list and value list are equal for this network. ensure!( - Self::uids_match_values(&uids, &values), + uids.len() == values.len(), Error::::WeightVecNotEqualSize ); @@ -939,11 +939,6 @@ impl Pallet { false } - /// Returns true if the passed uids have the same length of the passed values. - pub fn uids_match_values(uids: &[u16], values: &[u16]) -> bool { - uids.len() == values.len() - } - /// Returns true if the items contain duplicates. pub fn has_duplicate_uids(items: &[u16]) -> bool { let mut parsed: Vec = Vec::new(); From 8d2e05a2b7b884bc323b9cee33e57eb5ce9c2f66 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Fri, 20 Dec 2024 19:35:25 +0100 Subject: [PATCH 136/137] Fix rebase --- pallets/subtensor/src/coinbase/run_coinbase.rs | 4 ++-- pallets/subtensor/src/tests/children.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index ce948d32d..c70457ff5 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -65,7 +65,7 @@ impl Pallet { // --- 3. Drain the subnet block emission and accumulate it as subnet emission, which increases until the tempo is reached in #4. // subnet_blockwise_emission -> subnet_pending_emission for netuid in subnets.clone().iter() { - if *netuid == 0 || !Self::get_network_registration_allowed(*netuid) { + if *netuid == 0 || !NetworkRegistrationAllowed::::get(*netuid) { continue; } // --- 3.1 Get the network's block-wise emission amount. @@ -121,7 +121,7 @@ impl Pallet { BlocksSinceLastStep::::insert(*netuid, 0); LastMechansimStepBlock::::insert(*netuid, current_block); - if *netuid == 0 || !Self::get_network_registration_allowed(*netuid) { + if *netuid == 0 || !NetworkRegistrationAllowed::::get(*netuid) { // Skip netuid 0 payouts continue; } diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index a96632337..209ef902b 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -3750,14 +3750,14 @@ fn test_revoke_child_no_min_stake_check() { )); // Ensure the childkeys are not yet applied - let children_before = SubtensorModule::get_children(&parent, netuid); + let children_before = ChildKeys::::get(parent, netuid); assert_eq!(children_before, vec![]); wait_and_set_pending_children(netuid); TotalHotkeyStake::::insert(parent, parent_total_stake_original); // Ensure the childkeys are applied - let children_after = SubtensorModule::get_children(&parent, netuid); + let children_after = ChildKeys::::get(parent, netuid); assert_eq!(children_after, vec![(proportion, child)]); // Reduce the stake below required threshold @@ -3783,7 +3783,7 @@ fn test_revoke_child_no_min_stake_check() { TotalHotkeyStake::::insert(parent, parent_total_stake_original); // Ensure the childkeys are revoked - let children_after = SubtensorModule::get_children(&parent, netuid); + let children_after = ChildKeys::::get(parent, netuid); assert_eq!(children_after, vec![]); }); } @@ -3822,7 +3822,7 @@ fn test_do_set_child_registration_disabled() { TotalHotkeyStake::::insert(parent, parent_total_stake_original); // Ensure the childkeys are applied - let children_after = SubtensorModule::get_children(&parent, netuid); + let children_after = ChildKeys::::get(parent, netuid); assert_eq!(children_after, vec![(proportion, child)]); }); } From f9981096a3d9eba6ca8f662024234bbd736828e0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Mon, 23 Dec 2024 16:57:13 +0100 Subject: [PATCH 137/137] Remove get_total_hotkey_delegated_stake from pallet_subtensor::Pallet --- pallets/subtensor/src/rpc_info/delegate_info.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index 2521ee8c7..b5fa47a7e 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -154,18 +154,4 @@ impl Pallet { ); total_delegated } - - // Helper function to get total delegated stake for a hotkey - pub fn get_total_hotkey_delegated_stake(hotkey: &T::AccountId) -> u64 { - let mut total_delegated = 0u64; - - // Iterate through all delegators for this hotkey - for (delegator, stake) in Stake::::iter_prefix(hotkey) { - if delegator != Owner::::get(hotkey) { - total_delegated = total_delegated.saturating_add(stake); - } - } - - total_delegated - } }