diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index b6181e03cd..f25701de0f 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -4,7 +4,7 @@ use super::mock::*; use approx::assert_abs_diff_eq; use frame_support::{assert_err, assert_noop, assert_ok}; -use substrate_fixed::types::I96F32; +use substrate_fixed::types::{I64F64, I96F32}; use crate::{utils::rate_limiting::TransactionType, *}; use sp_core::U256; @@ -2852,13 +2852,23 @@ fn test_set_weights_no_parent() { let values: Vec = vec![u16::MAX]; // Use maximum value for u16 let version_key = SubtensorModule::get_weights_version_key(netuid); - // Set the min stake very high - SubtensorModule::set_stake_threshold(stake_to_give_child * 5); + // Check the stake weight + let curr_stake_weight = + SubtensorModule::get_stake_weights_for_hotkey_on_subnet(&hotkey, netuid).0; + + // Set the min stake very high, above the stake weight of the key + SubtensorModule::set_stake_threshold( + curr_stake_weight + .saturating_mul(I64F64::saturating_from_num(5)) + .saturating_to_num::(), + ); - // Check the key has less stake than required + let curr_stake_threshold = SubtensorModule::get_stake_threshold(); assert!( - SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid) - < SubtensorModule::get_stake_threshold() + curr_stake_weight < curr_stake_threshold, + "{:?} is not less than {:?} ", + curr_stake_weight, + curr_stake_threshold ); // Check the hotkey cannot set weights @@ -2876,12 +2886,21 @@ fn test_set_weights_no_parent() { assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid)); // Set a minimum stake to set weights - SubtensorModule::set_stake_threshold(stake_to_give_child - 5); + SubtensorModule::set_stake_threshold( + curr_stake_weight + .saturating_sub(I64F64::saturating_from_num(5)) + .saturating_to_num::(), + ); // Check if the stake for the hotkey is above + let new_stake_weight = + SubtensorModule::get_stake_weights_for_hotkey_on_subnet(&hotkey, netuid).0; + let new_stake_threshold = SubtensorModule::get_stake_threshold(); assert!( - SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid) - >= SubtensorModule::get_stake_threshold() + new_stake_weight >= new_stake_threshold, + "{:?} is not greater than or equal to {:?} ", + new_stake_weight, + new_stake_threshold ); // Check the hotkey can set weights diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index be22926239..d10346d3fb 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -133,7 +133,7 @@ parameter_types! { pub const SDebug:u64 = 1; pub const InitialRho: u16 = 30; pub const InitialKappa: u16 = 32_767; - pub const InitialTempo: u16 = 0; + pub const InitialTempo: u16 = 360; pub const SelfOwnership: u64 = 2; pub const InitialImmunityPeriod: u16 = 2; pub const InitialMaxAllowedUids: u16 = 2; diff --git a/pallets/subtensor/src/tests/networks.rs b/pallets/subtensor/src/tests/networks.rs index ad50c69e81..f367a01d02 100644 --- a/pallets/subtensor/src/tests/networks.rs +++ b/pallets/subtensor/src/tests/networks.rs @@ -326,3 +326,20 @@ fn test_register_subnet_high_lock_cost() { assert_eq!(SubnetAlphaIn::::get(netuid), lock_cost); }) } + +#[test] +fn test_tempo_greater_than_weight_set_rate_limit() { + new_test_ext(1).execute_with(|| { + let subnet_owner_hotkey = U256::from(1); + let subnet_owner_coldkey = U256::from(2); + + let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); + + // Get tempo + let tempo = SubtensorModule::get_tempo(netuid); + + let weights_set_rate_limit = SubtensorModule::get_weights_set_rate_limit(netuid); + + assert!(tempo as u64 >= weights_set_rate_limit); + }) +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index c796296da7..6d013a460f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1024,7 +1024,7 @@ impl pallet_commitments::Config for Runtime { } #[cfg(not(feature = "fast-blocks"))] -pub const INITIAL_SUBNET_TEMPO: u16 = 99; +pub const INITIAL_SUBNET_TEMPO: u16 = 360; #[cfg(feature = "fast-blocks")] pub const INITIAL_SUBNET_TEMPO: u16 = 10;