diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 01e9e7b33e..f8f9a56838 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -236,6 +236,7 @@ pub mod pallet { netuid, &[Hyperparameter::ServingRateLimit.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_serving_rate_limit(netuid, serving_rate_limit); log::debug!("ServingRateLimitSet( serving_rate_limit: {serving_rate_limit:?} ) "); pallet_subtensor::Pallet::::record_owner_rl( @@ -288,6 +289,7 @@ pub mod pallet { netuid, &[Hyperparameter::MaxDifficulty.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -322,6 +324,7 @@ pub mod pallet { netuid, &[TransactionType::SetWeightsVersionKey], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -413,6 +416,7 @@ pub mod pallet { netuid, &[Hyperparameter::AdjustmentAlpha.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -445,6 +449,7 @@ pub mod pallet { netuid, &[Hyperparameter::ImmunityPeriod.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), Error::::SubnetDoesNotExist @@ -479,6 +484,7 @@ pub mod pallet { netuid, &[Hyperparameter::MinAllowedWeights.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -513,6 +519,7 @@ pub mod pallet { netuid, &[Hyperparameter::MaxAllowedUids.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), Error::::SubnetDoesNotExist @@ -572,6 +579,7 @@ pub mod pallet { netuid, &[Hyperparameter::Rho.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -604,6 +612,7 @@ pub mod pallet { netuid, &[Hyperparameter::ActivityCutoff.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -672,6 +681,7 @@ pub mod pallet { netuid, &[Hyperparameter::PowRegistrationAllowed.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_network_pow_registration_allowed( netuid, @@ -733,6 +743,7 @@ pub mod pallet { netuid, &[Hyperparameter::MinBurn.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), Error::::SubnetDoesNotExist @@ -773,6 +784,7 @@ pub mod pallet { netuid, &[Hyperparameter::MaxBurn.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), Error::::SubnetDoesNotExist @@ -868,6 +880,7 @@ pub mod pallet { netuid, &[Hyperparameter::BondsMovingAverage.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; if maybe_owner.is_some() { ensure!( bonds_moving_average <= 975000, @@ -908,6 +921,7 @@ pub mod pallet { netuid, &[Hyperparameter::BondsPenalty.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -1245,6 +1259,7 @@ pub mod pallet { netuid, &[Hyperparameter::CommitRevealEnabled.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -1288,6 +1303,7 @@ pub mod pallet { netuid, &[Hyperparameter::LiquidAlphaEnabled.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_liquid_alpha_enabled(netuid, enabled); log::debug!("LiquidAlphaEnableToggled( netuid: {netuid:?}, Enabled: {enabled:?} ) "); pallet_subtensor::Pallet::::record_owner_rl( @@ -1318,6 +1334,7 @@ pub mod pallet { netuid, &[Hyperparameter::AlphaValues.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; let res = pallet_subtensor::Pallet::::do_set_alpha_values( origin, netuid, alpha_low, alpha_high, ); @@ -1437,6 +1454,7 @@ pub mod pallet { netuid, &[Hyperparameter::WeightCommitInterval.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -1535,6 +1553,7 @@ pub mod pallet { netuid, &[Hyperparameter::TransferEnabled.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; let res = pallet_subtensor::Pallet::::toggle_transfer(netuid, toggle); if res.is_ok() { pallet_subtensor::Pallet::::record_owner_rl( @@ -1567,6 +1586,7 @@ pub mod pallet { netuid, &[Hyperparameter::RecycleOrBurn.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_recycle_or_burn(netuid, recycle_or_burn); pallet_subtensor::Pallet::::record_owner_rl( @@ -1734,6 +1754,7 @@ pub mod pallet { netuid, &[Hyperparameter::AlphaSigmoidSteepness.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; ensure!( pallet_subtensor::Pallet::::if_subnet_exist(netuid), @@ -1784,6 +1805,7 @@ pub mod pallet { netuid, &[Hyperparameter::Yuma3Enabled.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_yuma3_enabled(netuid, enabled); Self::deposit_event(Event::Yuma3EnableToggled { netuid, enabled }); @@ -1823,6 +1845,7 @@ pub mod pallet { netuid, &[Hyperparameter::BondsResetEnabled.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_bonds_reset(netuid, enabled); Self::deposit_event(Event::BondsResetToggled { netuid, enabled }); @@ -1948,6 +1971,7 @@ pub mod pallet { netuid, &[Hyperparameter::ImmuneNeuronLimit.into()], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::set_owner_immune_neuron_limit(netuid, immune_neurons)?; pallet_subtensor::Pallet::::record_owner_rl( maybe_owner, @@ -2021,6 +2045,7 @@ pub mod pallet { netuid, &[TransactionType::MechanismCountUpdate], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::do_set_mechanism_count(netuid, mechanism_count)?; @@ -2047,6 +2072,7 @@ pub mod pallet { netuid, &[TransactionType::MechanismEmission], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::do_set_emission_split(netuid, maybe_split)?; @@ -2077,6 +2103,7 @@ pub mod pallet { netuid, &[TransactionType::MaxUidsTrimming], )?; + pallet_subtensor::Pallet::::ensure_admin_window_open(netuid)?; pallet_subtensor::Pallet::::trim_to_max_allowed_uids(netuid, max_n)?; diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 2a13a18aa0..0e53facabc 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -1619,6 +1619,7 @@ mod pallet_benchmarks { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); diff --git a/pallets/subtensor/src/coinbase/root.rs b/pallets/subtensor/src/coinbase/root.rs index 642a7f18ac..80965f0bbb 100644 --- a/pallets/subtensor/src/coinbase/root.rs +++ b/pallets/subtensor/src/coinbase/root.rs @@ -348,7 +348,6 @@ impl Pallet { RAORecycledForRegistration::::remove(netuid); MaxRegistrationsPerBlock::::remove(netuid); WeightsVersionKey::::remove(netuid); - PendingRootAlphaDivs::::remove(netuid); // --- 17. Subtoken / feature flags. LiquidAlphaOn::::remove(netuid); diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 53ac3c6ac5..0ae326bd1c 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -34,13 +34,21 @@ impl Pallet { // 2. Get subnets to emit to and emissions let subnet_emissions = Self::get_subnet_block_emissions(&subnets, block_emission); let subnets_to_emit_to: Vec = subnet_emissions.keys().copied().collect(); + let total_ema_price: U96F32 = subnets_to_emit_to + .iter() + .map(|netuid| Self::get_moving_alpha_price(*netuid)) + .sum(); + let subsidy_mode = total_ema_price <= U96F32::saturating_from_num(1); + log::debug!("subsidy_mode: {subsidy_mode:?}"); + log::debug!("total_ema_price: {total_ema_price:?}"); // --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out) // Computation is described in detail in the dtao whitepaper. let mut tao_in: BTreeMap = BTreeMap::new(); let mut alpha_in: BTreeMap = BTreeMap::new(); let mut alpha_out: BTreeMap = BTreeMap::new(); - let mut is_subsidized: BTreeMap = BTreeMap::new(); + let mut subsidy_amount: BTreeMap = BTreeMap::new(); + // Only calculate for subnets that we are emitting to. for netuid_i in subnets_to_emit_to.iter() { // Get subnet price. @@ -52,6 +60,8 @@ impl Pallet { .copied() .unwrap_or(asfloat!(0)); log::debug!("default_tao_in_i: {default_tao_in_i:?}"); + let default_alpha_in_i: U96F32 = + default_tao_in_i.safe_div_or(price_i, U96F32::saturating_from_num(0.0)); // Get alpha_emission total let alpha_emission_i: U96F32 = asfloat!( Self::get_block_emission_for_issuance(Self::get_alpha_issuance(*netuid_i).into()) @@ -62,32 +72,16 @@ impl Pallet { // Get initial alpha_in let mut alpha_in_i: U96F32; let mut tao_in_i: U96F32; - let tao_in_ratio: U96F32 = default_tao_in_i.safe_div_or( - U96F32::saturating_from_num(block_emission), - U96F32::saturating_from_num(0.0), - ); - if price_i < tao_in_ratio { - tao_in_i = price_i.saturating_mul(U96F32::saturating_from_num(block_emission)); - alpha_in_i = block_emission; + + if default_alpha_in_i > alpha_emission_i { + alpha_in_i = alpha_emission_i; + tao_in_i = alpha_in_i.saturating_mul(price_i); let difference_tao: U96F32 = default_tao_in_i.saturating_sub(tao_in_i); - // Difference becomes buy. - let buy_swap_result = Self::swap_tao_for_alpha( - *netuid_i, - tou64!(difference_tao).into(), - T::SwapInterface::max_price(), - true, - ); - if let Ok(buy_swap_result_ok) = buy_swap_result { - let bought_alpha = AlphaCurrency::from(buy_swap_result_ok.amount_paid_out); - SubnetAlphaOut::::mutate(*netuid_i, |total| { - *total = total.saturating_sub(bought_alpha); - }); - } - is_subsidized.insert(*netuid_i, true); + subsidy_amount.insert(*netuid_i, difference_tao); } else { tao_in_i = default_tao_in_i; - alpha_in_i = tao_in_i.safe_div_or(price_i, alpha_emission_i); - is_subsidized.insert(*netuid_i, false); + alpha_in_i = default_alpha_in_i; + subsidy_amount.insert(*netuid_i, U96F32::from_num(0.0)); } log::debug!("alpha_in_i: {alpha_in_i:?}"); @@ -110,9 +104,33 @@ impl Pallet { log::debug!("alpha_in: {alpha_in:?}"); log::debug!("alpha_out: {alpha_out:?}"); - // --- 4. Injection. - // Actually perform the injection of alpha_in, alpha_out and tao_in into the subnet pool. - // This operation changes the pool liquidity each block. + // --- 4. Inject and subsidize + for netuid_i in subnets_to_emit_to.iter() { + let tao_in_i: TaoCurrency = + tou64!(*tao_in.get(netuid_i).unwrap_or(&asfloat!(0))).into(); + let alpha_in_i: AlphaCurrency = + AlphaCurrency::from(tou64!(*alpha_in.get(netuid_i).unwrap_or(&asfloat!(0)))); + let difference_tao: U96F32 = *subsidy_amount.get(netuid_i).unwrap_or(&asfloat!(0)); + + T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); + + if difference_tao > asfloat!(0) { + let buy_swap_result = Self::swap_tao_for_alpha( + *netuid_i, + tou64!(difference_tao).into(), + T::SwapInterface::max_price(), + true, + ); + if let Ok(buy_swap_result_ok) = buy_swap_result { + let bought_alpha = AlphaCurrency::from(buy_swap_result_ok.amount_paid_out); + SubnetAlphaOut::::mutate(*netuid_i, |total| { + *total = total.saturating_sub(bought_alpha); + }); + } + } + } + + // --- 5. Update counters for netuid_i in subnets_to_emit_to.iter() { // Inject Alpha in. let alpha_in_i = @@ -138,14 +156,15 @@ impl Pallet { TotalStake::::mutate(|total| { *total = total.saturating_add(tao_in_i.into()); }); + + let difference_tao: U96F32 = *subsidy_amount.get(netuid_i).unwrap_or(&asfloat!(0)); TotalIssuance::::mutate(|total| { *total = total.saturating_add(tao_in_i.into()); + *total = total.saturating_add(tou64!(difference_tao).into()); }); - // Adjust protocol liquidity based on new reserves - T::SwapInterface::adjust_protocol_liquidity(*netuid_i, tao_in_i, alpha_in_i); } - // --- 5. Compute owner cuts and remove them from alpha_out remaining. + // --- 6. Compute owner cuts and remove them from alpha_out remaining. // Remove owner cuts here so that we can properly seperate root dividends in the next step. // Owner cuts are accumulated and then fed to the drain at the end of this func. let cut_percent: U96F32 = Self::get_float_subnet_owner_cut(); @@ -174,7 +193,7 @@ impl Pallet { let tao_weight: U96F32 = root_tao.saturating_mul(Self::get_tao_weight()); log::debug!("tao_weight: {tao_weight:?}"); - // --- 6. Seperate out root dividends in alpha and keep them. + // --- 7. Seperate out root dividends in alpha and keep them. // Then accumulate those dividends for later. for netuid_i in subnets_to_emit_to.iter() { // Get remaining alpha out. @@ -189,36 +208,37 @@ impl Pallet { .unwrap_or(asfloat!(0.0)); log::debug!("root_proportion: {root_proportion:?}"); // Get root proportion of alpha_out dividends. - let root_alpha: U96F32 = root_proportion - .saturating_mul(alpha_out_i) // Total alpha emission per block remaining. - .saturating_mul(asfloat!(0.5)); // 50% to validators. + let mut root_alpha: U96F32 = asfloat!(0.0); + if !subsidy_mode { + // Only give root alpha if not being subsidized. + root_alpha = root_proportion + .saturating_mul(alpha_out_i) // Total alpha emission per block remaining. + .saturating_mul(asfloat!(0.5)); // 50% to validators. + PendingRootAlphaDivs::::mutate(*netuid_i, |total| { + *total = total.saturating_add(tou64!(root_alpha).into()); + }); + } // Remove root alpha from alpha_out. log::debug!("root_alpha: {root_alpha:?}"); + // Get pending alpha as original alpha_out - root_alpha. let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha); log::debug!("pending_alpha: {pending_alpha:?}"); - let subsidized: bool = *is_subsidized.get(netuid_i).unwrap_or(&false); - if !subsidized { - PendingRootAlphaDivs::::mutate(*netuid_i, |total| { - *total = total.saturating_add(tou64!(root_alpha).into()); - }); - } - // Accumulate alpha emission in pending. PendingEmission::::mutate(*netuid_i, |total| { *total = total.saturating_add(tou64!(pending_alpha).into()); }); } - // --- 7. Update moving prices after using them in the emission calculation. + // --- 8. Update moving prices after using them in the emission calculation. // Only update price EMA for subnets that we emit to. for netuid_i in subnets_to_emit_to.iter() { // Update moving prices after using them above. Self::update_moving_price(*netuid_i); } - // --- 8. Drain pending emission through the subnet based on tempo. + // --- 9. Drain pending emission through the subnet based on tempo. // Run the epoch for *all* subnets, even if we don't emit anything. for &netuid in subnets.iter() { // Reveal matured weights. @@ -229,6 +249,9 @@ impl Pallet { if Self::should_run_epoch(netuid, current_block) && Self::is_epoch_input_state_consistent(netuid) { + let alpha_out_i: AlphaCurrency = + tou64!(*alpha_out.get(&netuid).unwrap_or(&asfloat!(0.0))).into(); + // Restart counters. BlocksSinceLastStep::::insert(netuid, 0); LastMechansimStepBlock::::insert(netuid, current_block); @@ -246,7 +269,13 @@ impl Pallet { PendingOwnerCut::::insert(netuid, AlphaCurrency::ZERO); // Drain pending root alpha divs, alpha emission, and owner cut. - Self::drain_pending_emission(netuid, pending_alpha, pending_root_alpha, owner_cut); + Self::drain_pending_emission( + netuid, + pending_alpha, + pending_root_alpha, + alpha_out_i, + owner_cut, + ); } else { // Increment BlocksSinceLastStep::::mutate(netuid, |total| *total = total.saturating_add(1)); @@ -604,6 +633,7 @@ impl Pallet { netuid: NetUid, pending_alpha: AlphaCurrency, pending_root_alpha: AlphaCurrency, + alpha_out: AlphaCurrency, // total alpha out for the subnet owner_cut: AlphaCurrency, ) { log::debug!( @@ -614,7 +644,7 @@ impl Pallet { // Run the epoch. let hotkey_emission: Vec<(T::AccountId, AlphaCurrency, AlphaCurrency)> = - Self::epoch_with_mechanisms(netuid, pending_alpha.saturating_add(pending_root_alpha)); + Self::epoch_with_mechanisms(netuid, alpha_out); log::debug!("hotkey_emission: {hotkey_emission:?}"); // Compute the pending validator alpha. @@ -630,8 +660,7 @@ impl Pallet { log::debug!("incentive_sum: {incentive_sum:?}"); let pending_validator_alpha = if !incentive_sum.is_zero() { - pending_alpha - .saturating_add(pending_root_alpha) + alpha_out .saturating_div(2.into()) .saturating_sub(pending_root_alpha) } else { diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index e9b8c2aa6b..ebf455b110 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -31,7 +31,7 @@ fn test_do_set_child_singular_success() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set child @@ -78,7 +78,7 @@ fn test_do_set_child_singular_invalid_child() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Attempt to set child as the same hotkey @@ -108,7 +108,7 @@ fn test_do_set_child_singular_non_associated_coldkey() { let proportion: u64 = 1000; // Add network and register hotkey with a different coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(999), 0); // Attempt to set child @@ -136,7 +136,7 @@ fn test_do_set_child_singular_root_network() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); // Attempt to set child assert_err!( @@ -170,7 +170,7 @@ fn test_do_set_child_singular_old_children_cleanup() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set old child @@ -208,7 +208,7 @@ fn test_do_set_child_singular_new_children_assignment() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set child @@ -240,7 +240,7 @@ fn test_do_set_child_singular_proportion_edge_cases() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set child with minimum proportion @@ -283,7 +283,7 @@ fn test_do_set_child_singular_multiple_children() { let proportion2: u64 = 500; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set first child @@ -330,7 +330,7 @@ fn test_add_singular_child() { ), Err(Error::::SubnetNotExists.into()) ); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); step_rate_limit(&TransactionType::SetChildren, netuid); assert_eq!( SubtensorModule::do_schedule_children( @@ -375,7 +375,7 @@ fn test_get_stake_for_hotkey_on_subnet() { let child = U256::from(2); let coldkey1 = U256::from(3); let coldkey2 = U256::from(4); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, parent, coldkey1, 0); register_ok_neuron(netuid, child, coldkey2, 0); // Set parent-child relationship with 100% stake allocation @@ -437,7 +437,7 @@ fn test_do_revoke_child_singular_success() { let netuid = NetUid::from(1); let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set child mock_set_children(&coldkey, &hotkey, netuid, &[(proportion, child)]); @@ -491,7 +491,7 @@ fn test_do_revoke_child_singular_non_associated_coldkey() { let netuid = NetUid::from(1); // Add network and register hotkey with a different coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(999), 0); // Attempt to revoke child @@ -522,7 +522,7 @@ fn test_do_revoke_child_singular_child_not_associated() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); // Attempt to revoke child that is not associated assert_err!( SubtensorModule::do_schedule_children( @@ -555,7 +555,7 @@ fn test_do_schedule_children_multiple_success() { let proportion2: u64 = 2000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set multiple children @@ -621,7 +621,7 @@ fn test_do_schedule_children_multiple_invalid_child() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Attempt to set child as the same hotkey @@ -653,7 +653,7 @@ fn test_do_schedule_children_multiple_non_associated_coldkey() { let proportion: u64 = 1000; // Add network and register hotkey with a different coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(999), 0); // Attempt to set children @@ -685,7 +685,7 @@ fn test_do_schedule_children_multiple_root_network() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); // Attempt to set children assert_err!( @@ -720,7 +720,7 @@ fn test_do_schedule_children_multiple_old_children_cleanup() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set old child @@ -765,7 +765,7 @@ fn test_do_schedule_children_multiple_proportion_edge_cases() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set children with minimum and maximum proportions @@ -807,7 +807,7 @@ fn test_do_schedule_children_multiple_overwrite_existing() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set initial children @@ -864,7 +864,7 @@ fn test_childkey_take_functionality() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Test default and max childkey take @@ -940,7 +940,7 @@ fn test_childkey_take_rate_limiting() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set a rate limit for childkey take changes @@ -1041,7 +1041,7 @@ fn test_multiple_networks_childkey_take() { for netuid in 1..NUM_NETWORKS { let netuid = NetUid::from(netuid); // Add network - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); // Register neuron register_ok_neuron(netuid, hotkey, coldkey, 0); @@ -1118,7 +1118,7 @@ fn test_do_schedule_children_multiple_empty_list() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set empty children list @@ -1150,7 +1150,7 @@ fn test_do_revoke_children_multiple_success() { let proportion2: u64 = 2000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set multiple children @@ -1221,7 +1221,7 @@ fn test_do_revoke_children_multiple_non_associated_coldkey() { let netuid = NetUid::from(1); // Add network and register hotkey with a different coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(999), 0); // Attempt to revoke children @@ -1257,7 +1257,7 @@ fn test_do_revoke_children_multiple_partial_revocation() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set multiple children @@ -1314,7 +1314,7 @@ fn test_do_revoke_children_multiple_non_existent_children() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set one child @@ -1349,7 +1349,7 @@ fn test_do_revoke_children_multiple_empty_list() { let netuid = NetUid::from(1); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Attempt to revoke with an empty list @@ -1383,7 +1383,7 @@ fn test_do_revoke_children_multiple_complex_scenario() { let proportion3: u64 = 3000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set multiple children @@ -1533,7 +1533,7 @@ fn test_get_parents_chain() { log::info!("Created hotkeys: {hotkeys:?}"); // Add network - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); SubtensorModule::set_max_registrations_per_block(netuid, 1000); SubtensorModule::set_target_registrations_per_interval(netuid, 1000); log::info!("Network added and parameters set: netuid={netuid}"); @@ -1653,7 +1653,7 @@ fn test_get_stake_for_hotkey_on_subnet_basic() { let hotkey = U256::from(1); let coldkey = U256::from(2); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey, @@ -1682,7 +1682,7 @@ fn test_get_stake_for_hotkey_on_subnet_multiple_coldkeys() { let coldkey1 = U256::from(2); let coldkey2 = U256::from(3); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey, coldkey1, 0); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( @@ -2157,8 +2157,8 @@ fn test_get_stake_for_hotkey_on_subnet_multiple_networks() { let hotkey = U256::from(1); let coldkey = U256::from(2); - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); register_ok_neuron(netuid1, hotkey, coldkey, 0); register_ok_neuron(netuid2, hotkey, coldkey, 0); @@ -2196,7 +2196,7 @@ fn test_do_set_child_below_min_stake() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); StakeThreshold::::set(1_000_000_000_000); @@ -2231,7 +2231,7 @@ fn test_do_remove_stake_clears_pending_childkeys() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(&coldkey, 10_000_000_000_000); @@ -2305,7 +2305,7 @@ fn test_do_set_child_cooldown_period() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, parent, coldkey, 0); // Set minimum stake for setting children @@ -2378,7 +2378,7 @@ fn test_do_set_pending_children_runs_in_epoch() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, parent, coldkey, 0); // Set minimum stake for setting children @@ -2443,8 +2443,8 @@ fn test_revoke_child_no_min_stake_check() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(NetUid::ROOT, 13, 0); - add_network(netuid, 13, 0); + add_network(NetUid::ROOT, 13, 0, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, parent, coldkey, 0); let reserve = 1_000_000_000_000_000; @@ -2517,7 +2517,7 @@ fn test_do_set_child_registration_disabled() { let proportion: u64 = 1000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, parent, coldkey, 0); let reserve = 1_000_000_000_000_000; @@ -2579,7 +2579,7 @@ fn test_set_children_rate_limit_fail_then_succeed() { let tempo = 13; // Add network and register hotkey - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // First set_children transaction @@ -2849,7 +2849,7 @@ fn test_childkey_take_drain() { let proportion: u64 = u64::MAX / 2; // Add network, register hotkeys, and setup network parameters - add_network(netuid, subnet_tempo, 0); + add_network(netuid, subnet_tempo, 0, 0); SubtensorModule::set_ck_burn(0); mock::setup_reserves(netuid, (stake * 10_000).into(), (stake * 10_000).into()); register_ok_neuron(netuid, child_hotkey, child_coldkey, 0); @@ -3182,7 +3182,7 @@ fn test_parent_child_chain_emission() { fn test_parent_child_chain_epoch() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::set_ck_burn(0); // Set owner cut to 0 SubtensorModule::set_subnet_owner_cut(0_u16); @@ -3327,7 +3327,7 @@ fn test_parent_child_chain_epoch() { fn test_dividend_distribution_with_children() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::set_ck_burn(0); mock::setup_reserves( netuid, @@ -3863,7 +3863,7 @@ fn test_do_set_child_as_sn_owner_not_enough_stake() { fn test_dividend_distribution_with_children_same_coldkey_owner() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Set SN owner cut to 0 SubtensorModule::set_subnet_owner_cut(0_u16); mock::setup_reserves(netuid, 1_000_000_000_000.into(), 1_000_000_000_000.into()); @@ -4044,7 +4044,7 @@ fn test_pending_cooldown_as_expected() { let expected_cooldown = PendingChildKeyCooldown::::get(); // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set multiple children @@ -4075,7 +4075,7 @@ fn test_do_set_childkey_take_success() { let take = 5000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set childkey take @@ -4104,7 +4104,7 @@ fn test_do_set_childkey_take_non_associated_coldkey() { let take = 5000; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set childkey take @@ -4125,7 +4125,7 @@ fn test_do_set_childkey_take_invalid_take_value() { let take = SubtensorModule::get_max_childkey_take() + 1; // Add network and register hotkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set childkey take @@ -4147,7 +4147,7 @@ fn test_do_set_childkey_take_rate_limit_exceeded() { let higher_take = 5000; let lower_take = 1000; - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set initial childkey take diff --git a/pallets/subtensor/src/tests/claim_root.rs b/pallets/subtensor/src/tests/claim_root.rs index e73417a326..a196cbdc39 100644 --- a/pallets/subtensor/src/tests/claim_root.rs +++ b/pallets/subtensor/src/tests/claim_root.rs @@ -3,12 +3,7 @@ use crate::tests::mock::{ RuntimeOrigin, SubtensorModule, Test, add_dynamic_network, new_test_ext, run_to_block, }; -use crate::{ - DefaultMinRootClaimAmount, Error, MAX_NUM_ROOT_CLAIMS, MAX_ROOT_CLAIM_THRESHOLD, NetworksAdded, - NumRootClaim, NumStakingColdkeys, PendingRootAlphaDivs, RootClaimable, RootClaimableThreshold, - StakingColdkeys, StakingColdkeysByIndex, SubnetAlphaIn, SubnetMechanism, SubnetTAO, - SubtokenEnabled, Tempo, pallet, -}; +use crate::*; use crate::{RootClaimType, RootClaimTypeEnum, RootClaimed}; use approx::assert_abs_diff_eq; use frame_support::dispatch::RawOrigin; @@ -18,7 +13,7 @@ use frame_support::{assert_err, assert_noop, assert_ok}; use sp_core::{H256, U256}; use sp_runtime::DispatchError; use std::collections::BTreeSet; -use substrate_fixed::types::{I96F32, U96F32}; +use substrate_fixed::types::{I64F64, I96F32, U96F32}; use subtensor_runtime_common::{AlphaCurrency, Currency, NetUid, TaoCurrency}; use subtensor_swap_interface::SwapHandler; @@ -76,6 +71,7 @@ fn test_claim_root_with_drain_emissions() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -144,6 +140,7 @@ fn test_claim_root_with_drain_emissions() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -245,6 +242,7 @@ fn test_claim_root_adding_stake_proportionally_for_two_stakers() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -346,6 +344,7 @@ fn test_claim_root_adding_stake_disproportionally_for_two_stakers() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -437,6 +436,7 @@ fn test_claim_root_with_changed_stake() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -489,6 +489,7 @@ fn test_claim_root_with_changed_stake() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -542,6 +543,7 @@ fn test_claim_root_with_changed_stake() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -634,6 +636,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -678,6 +681,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -714,6 +718,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -763,6 +768,7 @@ fn test_claim_root_with_run_coinbase() { let root_stake = 200_000_000u64; SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(root_stake)); + SubnetMovingPrice::::insert(netuid, I96F32::from(2)); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey, @@ -869,6 +875,7 @@ fn test_claim_root_with_block_emissions() { let root_stake = 200_000_000u64; SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(root_stake)); + SubnetMovingPrice::::insert(netuid, I96F32::from(2)); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey, @@ -972,6 +979,10 @@ fn test_claim_root_coinbase_distribution() { let root_stake = 200_000_000u64; let initial_tao = 200_000_000u64; SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(initial_tao)); + SubnetEmaTaoFlow::::insert(netuid, (1u64, I64F64::from(1))); + + // Avoid subsidy mode + SubnetMovingPrice::::insert(netuid, I96F32::from(2)); SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet( &hotkey, @@ -996,7 +1007,12 @@ fn test_claim_root_coinbase_distribution() { run_to_block(2); let alpha_issuance = SubtensorModule::get_alpha_issuance(netuid); - assert_eq!(initial_alpha_issuance + alpha_emissions, alpha_issuance); + + // Both alpha_in and alpha_out are increased, hence multiply emissions by 2 to get total issuance increase + assert_eq!( + initial_alpha_issuance + alpha_emissions * AlphaCurrency::from(2), + alpha_issuance + ); let root_prop = initial_tao as f64 / (u64::from(alpha_issuance) + initial_tao) as f64; let root_validators_share = 0.5f64; @@ -1100,6 +1116,7 @@ fn test_claim_root_with_swap_coldkey() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -1190,6 +1207,7 @@ fn test_claim_root_with_swap_hotkey() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -1306,6 +1324,7 @@ fn test_claim_root_on_network_deregistration() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); @@ -1446,6 +1465,7 @@ fn test_claim_root_with_unrelated_subnets() { netuid, AlphaCurrency::ZERO, pending_root_alpha.into(), + pending_root_alpha.into(), // alpha out AlphaCurrency::ZERO, ); diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 60644b2a28..4e336bd445 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -105,7 +105,8 @@ fn test_coinbase_tao_issuance_base_low() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); let emission = TaoCurrency::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 1); + SubnetEmaTaoFlow::::insert(netuid, (1_u64, I64F64::from(1))); assert_eq!(SubnetTAO::::get(netuid), TaoCurrency::ZERO); SubtensorModule::run_coinbase(U96F32::from_num(emission)); assert_eq!(SubnetTAO::::get(netuid), emission); @@ -152,9 +153,9 @@ fn test_coinbase_tao_issuance_multiple() { let netuid2 = NetUid::from(2); let netuid3 = NetUid::from(3); let emission = TaoCurrency::from(3_333_333); - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); - add_network(netuid3, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); + add_network(netuid3, 1, 0, 0); assert_eq!(SubnetTAO::::get(netuid1), TaoCurrency::ZERO); assert_eq!(SubnetTAO::::get(netuid2), TaoCurrency::ZERO); assert_eq!(SubnetTAO::::get(netuid3), TaoCurrency::ZERO); @@ -191,8 +192,8 @@ fn test_coinbase_tao_issuance_different_prices() { let netuid1 = NetUid::from(1); let netuid2 = NetUid::from(2); let emission = 100_000_000; - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Setup prices 0.1 and 0.2 let initial_tao: u64 = 100_000_u64; @@ -245,7 +246,7 @@ fn test_coinbase_tao_issuance_different_prices() { ); // Prices are low => we limit tao issued (buy alpha with it) - let tao_issued = TaoCurrency::from(((0.1 + 0.2) * emission as f64) as u64); + let tao_issued = TaoCurrency::from(((1.0) * emission as f64) as u64); assert_abs_diff_eq!( TotalIssuance::::get(), tao_issued, @@ -350,7 +351,7 @@ fn test_coinbase_tao_issuance_different_prices() { fn test_coinbase_moving_prices() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Set price to 1.0 SubnetTAO::::insert(netuid, TaoCurrency::from(1_000_000)); SubnetAlphaIn::::insert(netuid, AlphaCurrency::from(1_000_000)); @@ -406,7 +407,7 @@ fn test_coinbase_moving_prices() { fn test_update_moving_price_initial() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Set current price to 1.0 SubnetTAO::::insert(netuid, TaoCurrency::from(1_000_000)); SubnetAlphaIn::::insert(netuid, AlphaCurrency::from(1_000_000)); @@ -431,7 +432,7 @@ fn test_update_moving_price_initial() { fn test_update_moving_price_after_time() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Set current price to 1.0 SubnetTAO::::insert(netuid, TaoCurrency::from(1_000_000)); SubnetAlphaIn::::insert(netuid, AlphaCurrency::from(1_000_000)); @@ -462,8 +463,8 @@ fn test_coinbase_alpha_issuance_base() { let netuid1 = NetUid::from(1); let netuid2 = NetUid::from(2); let emission: u64 = 1_000_000; - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Set up prices 1 and 1 let initial: u64 = 1_000_000; SubnetTAO::::insert(netuid1, TaoCurrency::from(initial)); @@ -499,8 +500,8 @@ fn test_coinbase_alpha_issuance_different() { let netuid1 = NetUid::from(1); let netuid2 = NetUid::from(2); let emission: u64 = 1_000_000; - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Make subnets dynamic. SubnetMechanism::::insert(netuid1, 1); SubnetMechanism::::insert(netuid2, 1); @@ -538,8 +539,8 @@ fn test_coinbase_alpha_issuance_with_cap_trigger() { let netuid1 = NetUid::from(1); let netuid2 = NetUid::from(2); let emission: u64 = 1_000_000; - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Make subnets dynamic. SubnetMechanism::::insert(netuid1, 1); SubnetMechanism::::insert(netuid2, 1); @@ -573,8 +574,8 @@ fn test_coinbase_alpha_issuance_with_cap_trigger_and_block_emission() { let netuid1 = NetUid::from(1); let netuid2 = NetUid::from(2); let emission: u64 = 1_000_000; - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Make subnets dynamic. SubnetMechanism::::insert(netuid1, 1); @@ -645,7 +646,7 @@ fn test_coinbase_alpha_issuance_with_cap_trigger_and_block_emission() { fn test_owner_cut_base() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); mock::setup_reserves(netuid, 1_000_000_000_000.into(), 1_000_000_000_000.into()); SubtensorModule::set_tempo(netuid, 10000); // Large number (dont drain) SubtensorModule::set_subnet_owner_cut(0); @@ -657,27 +658,34 @@ fn test_owner_cut_base() { }); } -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_pending_swapped --exact --show-output --nocapture +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_pending_emission --exact --show-output --nocapture #[test] fn test_pending_emission() { new_test_ext(1).execute_with(|| { - let netuid = NetUid::from(1); - let emission: u64 = 1_000_000; - add_network(netuid, 1, 0); - mock::setup_reserves(netuid, 1_000_000.into(), 1.into()); - SubtensorModule::run_coinbase(U96F32::from_num(0)); - SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000)); // Add root weight. - SubtensorModule::run_coinbase(U96F32::from_num(0)); + let emission: u64 = 1_000_000_000; + let subnet_owner_ck = U256::from(2); + let subnet_owner_hk = U256::from(3); + let netuid = add_dynamic_network(&subnet_owner_hk, &subnet_owner_ck); SubtensorModule::set_tempo(netuid, 10000); // Large number (dont drain) - SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1.0 - SubtensorModule::run_coinbase(U96F32::from_num(0)); - // 1 TAO / ( 1 + 3 ) = 0.25 * 1 / 2 = 125000000 + + // Setup price = 1000000 (1M TAO vs 1 Alpha) + // Alpha issuance = 1 + mock::setup_reserves(netuid, 1_000_000.into(), 1.into()); + + // Add root stake and 100% tao weight + // Alpha issuance = 1 + emission / price + 10^9 = 1000001001 + // root_proportion = root_tao * 1.0 / (root_tao * 1.0 + alpha_issuance) = 0.499999749750125 + // root_alpha = root_proportion * alpha_emission / 2 = 249999875 + // PendingEmission = alpha_emission - 249999875 = 750000125 + SubnetTAO::::insert(NetUid::ROOT, TaoCurrency::from(1_000_000_000)); + SubtensorModule::set_tao_weight(u64::MAX); + SubtensorModule::run_coinbase(U96F32::from_num(emission)); assert_abs_diff_eq!( u64::from(PendingEmission::::get(netuid)), - 1_000_000_000 - 125000000, + 750000125, epsilon = 1 - ); // 1 - swapped. + ); }); } @@ -690,6 +698,7 @@ fn test_drain_base() { AlphaCurrency::ZERO, AlphaCurrency::ZERO, AlphaCurrency::ZERO, + AlphaCurrency::ZERO, ) }); } @@ -699,12 +708,13 @@ fn test_drain_base() { fn test_drain_base_with_subnet() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::drain_pending_emission( netuid, AlphaCurrency::ZERO, AlphaCurrency::ZERO, AlphaCurrency::ZERO, + AlphaCurrency::ZERO, ) }); } @@ -714,7 +724,7 @@ fn test_drain_base_with_subnet() { fn test_drain_base_with_subnet_with_single_staker_not_registered() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); let stake_before = AlphaCurrency::from(1_000_000_000); @@ -730,6 +740,7 @@ fn test_drain_base_with_subnet_with_single_staker_not_registered() { pending_alpha.into(), AlphaCurrency::ZERO, AlphaCurrency::ZERO, + AlphaCurrency::ZERO, ); let stake_after = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid); @@ -742,7 +753,7 @@ fn test_drain_base_with_subnet_with_single_staker_not_registered() { fn test_drain_base_with_subnet_with_single_staker_registered() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); let stake_before = AlphaCurrency::from(1_000_000_000); @@ -758,6 +769,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered() { netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); let stake_after = @@ -775,7 +787,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered() { fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); let stake_before = AlphaCurrency::from(1_000_000_000); @@ -802,6 +814,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { netuid, pending_alpha, pending_root_alpha, + pending_alpha.saturating_add(pending_root_alpha), AlphaCurrency::ZERO, ); let stake_after = @@ -825,7 +838,7 @@ fn test_drain_base_with_subnet_with_single_staker_registered_root_weight() { fn test_drain_base_with_subnet_with_two_stakers_registered() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); let coldkey = U256::from(3); @@ -849,6 +862,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered() { netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); let stake_after1 = @@ -873,7 +887,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered() { fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); let coldkey = U256::from(3); @@ -914,6 +928,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); let stake_after1 = @@ -948,7 +963,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root() { fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_amounts() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); let coldkey = U256::from(3); @@ -989,6 +1004,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, 0.into(), ); let stake_after1 = @@ -1028,7 +1044,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let hotkey1 = U256::from(1); let hotkey2 = U256::from(2); let coldkey = U256::from(3); @@ -1069,6 +1085,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); let stake_after1 = @@ -1107,7 +1124,7 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am fn test_drain_alpha_childkey_parentkey() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::set_ck_burn(0); let parent = U256::from(1); let child = U256::from(2); @@ -1130,6 +1147,7 @@ fn test_drain_alpha_childkey_parentkey() { netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); let parent_stake_after = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); @@ -1155,8 +1173,8 @@ fn test_get_root_children() { new_test_ext(1).execute_with(|| { // Init netuid 1 let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); - add_network(alpha, 1, 0); + add_network(NetUid::ROOT, 1, 0, 0); + add_network(alpha, 1, 0, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1281,8 +1299,8 @@ fn test_get_root_children_drain() { new_test_ext(1).execute_with(|| { // Init netuid 1 let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); - add_network(alpha, 1, 0); + add_network(NetUid::ROOT, 1, 0, 0); + add_network(alpha, 1, 0, 0); SubtensorModule::set_ck_burn(0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1355,6 +1373,7 @@ fn test_get_root_children_drain() { alpha, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); @@ -1379,6 +1398,7 @@ fn test_get_root_children_drain() { pending_alpha, // pending_root1, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); @@ -1402,6 +1422,7 @@ fn test_get_root_children_drain() { alpha, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); @@ -1425,8 +1446,8 @@ fn test_get_root_children_drain_half_proportion() { new_test_ext(1).execute_with(|| { // Init netuid 1 let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); - add_network(alpha, 1, 0); + add_network(NetUid::ROOT, 1, 0, 0); + add_network(alpha, 1, 0, 0); SubtensorModule::set_ck_burn(0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. @@ -1490,6 +1511,7 @@ fn test_get_root_children_drain_half_proportion() { alpha, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); @@ -1513,8 +1535,8 @@ fn test_get_root_children_drain_with_take() { new_test_ext(1).execute_with(|| { // Init netuid 1 let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); - add_network(alpha, 1, 0); + add_network(NetUid::ROOT, 1, 0, 0); + add_network(alpha, 1, 0, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. // Create keys. @@ -1576,6 +1598,7 @@ fn test_get_root_children_drain_with_take() { alpha, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); @@ -1599,8 +1622,8 @@ fn test_get_root_children_drain_with_half_take() { new_test_ext(1).execute_with(|| { // Init netuid 1 let alpha = NetUid::from(1); - add_network(NetUid::ROOT, 1, 0); - add_network(alpha, 1, 0); + add_network(NetUid::ROOT, 1, 0, 0); + add_network(alpha, 1, 0, 0); // Set TAO weight to 1. SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. SubtensorModule::set_ck_burn(0); @@ -1663,6 +1686,7 @@ fn test_get_root_children_drain_with_half_take() { alpha, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); @@ -1686,8 +1710,8 @@ fn test_get_root_children_drain_with_half_take() { // new_test_ext(1).execute_with(|| { // // Init netuid 1 // let alpha = NetUid::from(1); -// add_network(NetUid::ROOT, 1, 0); -// add_network(alpha, 1, 0); +// add_network(NetUid::ROOT, 1, 0, 0); +// add_network(alpha, 1, 0, 0); // // Set TAO weight to 1. // SubtensorModule::set_tao_weight(u64::MAX); // Set TAO weight to 1. // // Create keys. @@ -2378,6 +2402,7 @@ fn test_drain_pending_emission_no_miners_all_drained() { netuid, emission, AlphaCurrency::ZERO, + emission, AlphaCurrency::ZERO, ); @@ -2451,6 +2476,7 @@ fn test_drain_pending_emission_zero_emission() { 0.into(), AlphaCurrency::ZERO, AlphaCurrency::ZERO, + AlphaCurrency::ZERO, ); // Get the new stake of the hotkey. @@ -2717,7 +2743,7 @@ fn test_coinbase_v3_liquidity_update() { fn test_drain_alpha_childkey_parentkey_with_burn() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); let parent = U256::from(1); let child = U256::from(2); let coldkey = U256::from(3); @@ -2743,6 +2769,7 @@ fn test_drain_alpha_childkey_parentkey_with_burn() { netuid, pending_alpha, AlphaCurrency::ZERO, + pending_alpha, AlphaCurrency::ZERO, ); let parent_stake_after = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); diff --git a/pallets/subtensor/src/tests/consensus.rs b/pallets/subtensor/src/tests/consensus.rs index 454f41e2cf..16b8a99600 100644 --- a/pallets/subtensor/src/tests/consensus.rs +++ b/pallets/subtensor/src/tests/consensus.rs @@ -167,7 +167,7 @@ fn init_run_epochs( bonds_penalty: u16, ) { // === Create the network - add_network(netuid, u16::MAX - 1, 0); // set higher tempo to avoid built-in epoch, then manual epoch instead + add_network(netuid, u16::MAX - 1, 0, 0); // set higher tempo to avoid built-in epoch, then manual epoch instead // === Set bonds penalty SubtensorModule::set_bonds_penalty(netuid, bonds_penalty); diff --git a/pallets/subtensor/src/tests/difficulty.rs b/pallets/subtensor/src/tests/difficulty.rs index 78ac8620c9..1f22a223d5 100644 --- a/pallets/subtensor/src/tests/difficulty.rs +++ b/pallets/subtensor/src/tests/difficulty.rs @@ -13,7 +13,7 @@ fn test_registration_difficulty_adjustment() { let netuid = NetUid::from(1); let tempo: u16 = 1; let modality: u16 = 1; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); // owners are not deregistered crate::SubnetOwner::::insert(netuid, U256::from(99999)); diff --git a/pallets/subtensor/src/tests/ensure.rs b/pallets/subtensor/src/tests/ensure.rs index a59bfd7484..9a16619992 100644 --- a/pallets/subtensor/src/tests/ensure.rs +++ b/pallets/subtensor/src/tests/ensure.rs @@ -12,7 +12,7 @@ use crate::{OwnerHyperparamRateLimit, SubnetOwner, SubtokenEnabled}; fn ensure_subnet_owner_returns_who_and_checks_ownership() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); let owner: U256 = U256::from(42); SubnetOwner::::insert(netuid, owner); @@ -40,7 +40,7 @@ fn ensure_subnet_owner_returns_who_and_checks_ownership() { fn ensure_subnet_owner_or_root_distinguishes_root_and_owner() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(2); - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); let owner: U256 = U256::from(9); SubnetOwner::::insert(netuid, owner); @@ -67,7 +67,7 @@ fn ensure_root_with_rate_limit_blocks_in_freeze_window() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); let tempo = 10; - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); // Set freeze window to 3 let freeze_window = 3; @@ -91,7 +91,7 @@ fn ensure_owner_or_root_with_limits_checks_rl_and_freeze() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); let tempo = 10; - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); SubtokenEnabled::::insert(netuid, true); let owner: U256 = U256::from(5); SubnetOwner::::insert(netuid, owner); @@ -111,6 +111,7 @@ fn ensure_owner_or_root_with_limits_checks_rl_and_freeze() { ) .expect("should pass"); assert_eq!(res, Some(owner)); + assert_ok!(crate::Pallet::::ensure_admin_window_open(netuid)); // Simulate previous update at current block -> next call should fail due to rate limit let now = crate::Pallet::::get_current_block_as_u64(); @@ -127,11 +128,14 @@ fn ensure_owner_or_root_with_limits_checks_rl_and_freeze() { // Advance beyond RL and ensure passes again run_to_block(now + 3); + TransactionType::from(Hyperparameter::Kappa) + .set_last_block_on_subnet::(&owner, netuid, 0); assert_ok!(crate::Pallet::::ensure_sn_owner_or_root_with_limits( <::RuntimeOrigin>::signed(owner), netuid, &[Hyperparameter::Kappa.into()] )); + assert_ok!(crate::Pallet::::ensure_admin_window_open(netuid)); // Now advance into the freeze window; ensure blocks // (using loop for clarity, because epoch calculation function uses netuid) @@ -148,12 +152,13 @@ fn ensure_owner_or_root_with_limits_checks_rl_and_freeze() { } run_to_block(cur + 1); } + assert_ok!(crate::Pallet::::ensure_sn_owner_or_root_with_limits( + <::RuntimeOrigin>::signed(owner), + netuid, + &[Hyperparameter::Kappa.into()] + )); assert_noop!( - crate::Pallet::::ensure_sn_owner_or_root_with_limits( - <::RuntimeOrigin>::signed(owner), - netuid, - &[Hyperparameter::Kappa.into()], - ), + crate::Pallet::::ensure_admin_window_open(netuid), crate::Error::::AdminActionProhibitedDuringWeightsWindow ); }); diff --git a/pallets/subtensor/src/tests/epoch.rs b/pallets/subtensor/src/tests/epoch.rs index cdf44df645..50e29954dd 100644 --- a/pallets/subtensor/src/tests/epoch.rs +++ b/pallets/subtensor/src/tests/epoch.rs @@ -493,7 +493,7 @@ fn init_run_epochs( // new_test_ext(1).execute_with(|| { // log::info!("test_overflow:"); // let netuid = NetUid::from(1); -// add_network(netuid, 1, 0); +// add_network(netuid, 1, 0, 0); // SubtensorModule::set_max_allowed_uids(netuid, 3); // SubtensorModule::increase_stake_on_coldkey_hotkey_account( // &U256::from(0), @@ -2160,7 +2160,7 @@ fn test_validator_permits() { } new_test_ext(1).execute_with(|| { let block_number: u64 = 0; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_max_allowed_uids(netuid, network_n as u16); assert_eq!( SubtensorModule::get_max_allowed_uids(netuid), @@ -2420,7 +2420,7 @@ fn test_blocks_since_last_step() { let netuid = NetUid::from(1); let tempo: u16 = 7200; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let original_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid); @@ -2530,7 +2530,7 @@ fn test_epoch_outputs_single_staker_registered_no_weights() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); let high_tempo: u16 = u16::MAX - 1; // Don't run automatically. - add_network(netuid, high_tempo, 0); + add_network(netuid, high_tempo, 0, 0); let hotkey = U256::from(1); let coldkey = U256::from(2); @@ -3583,7 +3583,7 @@ fn test_epoch_masks_incoming_to_sniped_uid_prevents_inheritance() { let tempo: u16 = 10; let reveal: u64 = 2; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::set_reveal_period(netuid, reveal)); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_max_allowed_uids(netuid, 3); @@ -3679,7 +3679,7 @@ fn test_epoch_no_mask_when_commit_reveal_disabled() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(32); let tempo: u16 = 5; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); let (hot, cold) = (U256::from(1000), U256::from(1100)); @@ -3728,7 +3728,7 @@ fn test_epoch_does_not_mask_outside_window_but_masks_inside() { let tempo: u16 = 8; let reveal: u16 = 2; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::set_reveal_period(netuid, reveal as u64)); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_target_registrations_per_interval(netuid, u16::MAX); diff --git a/pallets/subtensor/src/tests/evm.rs b/pallets/subtensor/src/tests/evm.rs index 6d668d738d..7b4137d2d6 100644 --- a/pallets/subtensor/src/tests/evm.rs +++ b/pallets/subtensor/src/tests/evm.rs @@ -38,7 +38,7 @@ fn test_associate_evm_key_success() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); System::set_block_number(EvmKeyAssociateRateLimit::get()); let coldkey = U256::from(1); @@ -87,7 +87,7 @@ fn test_associate_evm_key_different_block_number_success() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); System::set_block_number(EvmKeyAssociateRateLimit::get()); let coldkey = U256::from(1); @@ -134,7 +134,7 @@ fn test_associate_evm_key_coldkey_does_not_own_hotkey() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); let hotkey = U256::from(2); @@ -169,7 +169,7 @@ fn test_associate_evm_key_hotkey_not_registered_in_subnet() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); let coldkey = U256::from(1); let hotkey = U256::from(2); @@ -206,7 +206,7 @@ fn test_associate_evm_key_using_wrong_hash_function() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); System::set_block_number(EvmKeyAssociateRateLimit::get()); let coldkey = U256::from(1); @@ -246,7 +246,7 @@ fn test_associate_evm_key_rate_limit_exceeded() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); System::set_block_number(EvmKeyAssociateRateLimit::get()); let coldkey = U256::from(1); @@ -318,7 +318,7 @@ fn test_associate_evm_key_uid_not_found() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); let hotkey = U256::from(2); diff --git a/pallets/subtensor/src/tests/mechanism.rs b/pallets/subtensor/src/tests/mechanism.rs index e5c46e8722..6dee857d90 100644 --- a/pallets/subtensor/src/tests/mechanism.rs +++ b/pallets/subtensor/src/tests/mechanism.rs @@ -1058,7 +1058,7 @@ fn test_commit_reveal_mechanism_weights_ok() { let netuid = NetUid::from(1); let tempo: u16 = 13; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Three neurons: validator (caller) + two destinations let hk1 = U256::from(55); @@ -1146,7 +1146,7 @@ fn test_commit_reveal_above_mechanism_count_fails() { let netuid = NetUid::from(1); let tempo: u16 = 13; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Two neurons: validator (caller) + miner let hk1 = U256::from(55); @@ -1234,7 +1234,7 @@ fn test_reveal_crv3_commits_sub_success() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); // ensure we actually have mecid=1 available MechanismCountCurrent::::insert(netuid, MechId::from(2u8)); @@ -1340,7 +1340,7 @@ fn test_crv3_above_mechanism_count_fails() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); // ensure we actually have mecid=1 available MechanismCountCurrent::::insert(netuid, MechId::from(2u8)); @@ -1412,7 +1412,7 @@ fn test_do_commit_crv3_mechanism_weights_committing_too_fast() { let commit_data_2: Vec = vec![4, 5, 6]; let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); MechanismCountCurrent::::insert(netuid, MechId::from(2u8)); // allow subids {0,1} register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); @@ -1505,7 +1505,7 @@ fn epoch_mechanism_emergency_mode_distributes_by_stake() { let mecid = MechId::from(1u8); let idx = SubtensorModule::get_mechanism_storage_index(netuid, mecid); let tempo: u16 = 5; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); MechanismCountCurrent::::insert(netuid, MechId::from(2u8)); // allow subids {0,1} SubtensorModule::set_max_registrations_per_block(netuid, 4); SubtensorModule::set_target_registrations_per_interval(netuid, 4); diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 28159d41bc..3f687c2c66 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -65,9 +65,9 @@ fn test_initialise_ti() { fn test_migration_transfer_nets_to_foundation() { new_test_ext(1).execute_with(|| { // Create subnet 1 - add_network(1.into(), 1, 0); + add_network(1.into(), 1, 0, 0); // Create subnet 11 - add_network(11.into(), 1, 0); + add_network(11.into(), 1, 0, 0); log::info!("{:?}", SubtensorModule::get_subnet_owner(1.into())); //assert_eq!(SubtensorModule::::get_subnet_owner(1), ); @@ -85,7 +85,7 @@ fn test_migration_transfer_nets_to_foundation() { fn test_migration_delete_subnet_3() { new_test_ext(1).execute_with(|| { // Create subnet 3 - add_network(3.into(), 1, 0); + add_network(3.into(), 1, 0, 0); assert!(SubtensorModule::if_subnet_exist(3.into())); // Run the migration to transfer ownership @@ -99,7 +99,7 @@ fn test_migration_delete_subnet_3() { fn test_migration_delete_subnet_21() { new_test_ext(1).execute_with(|| { // Create subnet 21 - add_network(21.into(), 1, 0); + add_network(21.into(), 1, 0, 0); assert!(SubtensorModule::if_subnet_exist(21.into())); // Run the migration to transfer ownership @@ -216,10 +216,10 @@ fn test_migrate_commit_reveal_2() { // NetworkMinLockCost::::set(500); // // Add networks root and alpha -// add_network(netuid_0, 1, 0); -// add_network(netuid_1, 1, 0); -// add_network(netuid_2, 1, 0); -// add_network(netuid_3, 1, 0); +// add_network(netuid_0, 1, 0, 0); +// add_network(netuid_1, 1, 0, 0); +// add_network(netuid_2, 1, 0, 0); +// add_network(netuid_3, 1, 0, 0); // // Set subnet lock // SubnetLocked::::insert(netuid_1, lock_amount); @@ -392,7 +392,7 @@ fn test_migrate_subnet_volume() { new_test_ext(1).execute_with(|| { // Setup initial state let netuid_1 = NetUid::from(1); - add_network(netuid_1, 1, 0); + add_network(netuid_1, 1, 0, 0); // SubnetValue for netuid 1 key let old_key: [u8; 34] = hex_literal::hex!( @@ -431,7 +431,7 @@ fn test_migrate_set_first_emission_block_number() { let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; let block_number = 100; for netuid in netuids.iter() { - add_network(*netuid, 1, 0); + add_network(*netuid, 1, 0, 0); } run_to_block(block_number); let weight = crate::migrations::migrate_set_first_emission_block_number::migrate_set_first_emission_block_number::(); @@ -452,7 +452,7 @@ fn test_migrate_set_subtoken_enable() { let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; let block_number = 100; for netuid in netuids.iter() { - add_network(*netuid, 1, 0); + add_network(*netuid, 1, 0, 0); } let new_netuid = NetUid::from(4); @@ -1225,7 +1225,7 @@ fn test_migrate_subnet_symbols() { // Create 100 subnets for i in 0..100 { - add_network(i.into(), 1, 0); + add_network(i.into(), 1, 0, 0); } // Shift some symbols @@ -1279,7 +1279,7 @@ fn test_migrate_set_registration_enable() { // Create 3 subnets let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; for netuid in netuids.iter() { - add_network(*netuid, 1, 0); + add_network(*netuid, 1, 0, 0); // Set registration to false to simulate the need for migration SubtensorModule::set_network_registration_allowed(*netuid, false); SubtensorModule::set_network_pow_registration_allowed(*netuid, false); @@ -1368,7 +1368,7 @@ fn test_migrate_crv3_commits_add_block() { // ------------------------------ // 1. Create a network so helper can compute first‑block // ------------------------------ - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // ------------------------------ // 2. Simulate OLD storage (3‑tuple) @@ -1445,7 +1445,7 @@ fn test_migrate_disable_commit_reveal() { // --------------------------------------------------------------------- new_test_ext(1).execute_with(|| { for (i, netuid) in netuids.iter().enumerate() { - add_network(*netuid, 5u16 + i as u16, 0); + add_network(*netuid, 5u16 + i as u16, 0, 0); CommitRevealWeightsEnabled::::insert(*netuid, true); } assert!( @@ -1505,8 +1505,8 @@ fn test_migrate_commit_reveal_settings() { let netuid1: u16 = 1; let netuid2: u16 = 2; // Add networks to simulate existing networks - add_network(netuid1.into(), 1, 0); - add_network(netuid2.into(), 1, 0); + add_network(netuid1.into(), 1, 0, 0); + add_network(netuid2.into(), 1, 0, 0); // Ensure the storage items use default values initially (but aren't explicitly set) // Since these are ValueQuery storage items, they return defaults even when not set @@ -1579,7 +1579,7 @@ fn test_migrate_commit_reveal_settings_multiple_networks() { // Set up multiple networks let netuids = vec![1u16, 2u16, 3u16, 10u16, 42u16]; for netuid in &netuids { - add_network((*netuid).into(), 1, 0); + add_network((*netuid).into(), 1, 0, 0); } // Run migration @@ -1600,7 +1600,7 @@ fn test_migrate_commit_reveal_settings_multiple_networks() { fn test_migrate_commit_reveal_settings_values_access() { new_test_ext(1).execute_with(|| { let netuid: u16 = 1; - add_network(netuid.into(), 1, 0); + add_network(netuid.into(), 1, 0, 0); // Run migration crate::migrations::migrate_commit_reveal_settings::migrate_commit_reveal_settings::(); @@ -1829,7 +1829,7 @@ fn test_migrate_remove_network_modality() { // Create multiple networks to test let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; for netuid in netuids.iter() { - add_network(*netuid, 1, 0); + add_network(*netuid, 1, 0, 0); } // Set initial storage version to 7 (below target) diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 9d028d76ab..c5b60adea5 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -27,6 +27,7 @@ use sp_runtime::{ }; use sp_std::{cell::RefCell, cmp::Ordering, sync::OnceLock}; use sp_tracing::tracing_subscriber; +use substrate_fixed::types::I96F32; use subtensor_runtime_common::{NetUid, TaoCurrency}; use subtensor_swap_interface::{Order, SwapHandler}; use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt}; @@ -690,10 +691,11 @@ pub fn register_ok_neuron( } #[allow(dead_code)] -pub fn add_network(netuid: NetUid, tempo: u16, _modality: u16) { +pub fn add_network(netuid: NetUid, tempo: u16, _modality: u16, mechanism: u16) { SubtensorModule::init_new_network(netuid, tempo); SubtensorModule::set_network_registration_allowed(netuid, true); SubtensorModule::set_network_pow_registration_allowed(netuid, true); + SubnetMechanism::::insert(netuid, mechanism); FirstEmissionBlockNumber::::insert(netuid, 1); SubtokenEnabled::::insert(netuid, true); } @@ -754,7 +756,7 @@ pub fn add_dynamic_network_disable_commit_reveal(hotkey: &U256, coldkey: &U256) #[allow(dead_code)] pub fn add_network_disable_commit_reveal(netuid: NetUid, tempo: u16, _modality: u16) { - add_network(netuid, tempo, _modality); + add_network(netuid, tempo, _modality, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); } @@ -867,6 +869,8 @@ pub(crate) fn remove_stake_rate_limit_for_tests(hotkey: &U256, coldkey: &U256, n pub(crate) fn setup_reserves(netuid: NetUid, tao: TaoCurrency, alpha: AlphaCurrency) { SubnetTAO::::set(netuid, tao); SubnetAlphaIn::::set(netuid, alpha); + Swap::maybe_initialize_v3(netuid).unwrap(); + SubnetMovingPrice::::insert(netuid, I96F32::from_num(Swap::current_price(netuid))); } pub(crate) fn swap_tao_to_alpha(netuid: NetUid, tao: TaoCurrency) -> (AlphaCurrency, u64) { diff --git a/pallets/subtensor/src/tests/move_stake.rs b/pallets/subtensor/src/tests/move_stake.rs index dfd9927da4..22af61f93d 100644 --- a/pallets/subtensor/src/tests/move_stake.rs +++ b/pallets/subtensor/src/tests/move_stake.rs @@ -289,7 +289,7 @@ fn test_do_move_nonexistent_destination_hotkey() { .unwrap(); // Attempt to move stake from a non-existent origin hotkey - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); assert_noop!( SubtensorModule::do_move_stake( RuntimeOrigin::signed(coldkey), @@ -500,7 +500,7 @@ fn test_do_move_wrong_origin() { ); // Attempt to move stake with wrong origin - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::create_account_if_non_existent(&coldkey, &origin_hotkey); SubtensorModule::create_account_if_non_existent(&coldkey, &destination_hotkey); assert_err!( diff --git a/pallets/subtensor/src/tests/networks.rs b/pallets/subtensor/src/tests/networks.rs index 0449c67f86..23ab45a522 100644 --- a/pallets/subtensor/src/tests/networks.rs +++ b/pallets/subtensor/src/tests/networks.rs @@ -27,7 +27,7 @@ fn test_registration_ok() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1452,7 +1452,7 @@ fn test_migrate_network_immunity_period() { // ); // //add network -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // assert_ok!(SubtensorModule::register( // <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1505,7 +1505,7 @@ fn test_migrate_network_immunity_period() { // ); // //add network -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // assert_ok!(SubtensorModule::register( // <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1559,7 +1559,7 @@ fn test_migrate_network_immunity_period() { // ); // //add network -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // assert_ok!(SubtensorModule::register( // <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1620,7 +1620,7 @@ fn test_migrate_network_immunity_period() { // ); // //add network -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // assert_ok!(SubtensorModule::register( // <::RuntimeOrigin>::signed(hotkey_account_id), diff --git a/pallets/subtensor/src/tests/neuron_info.rs b/pallets/subtensor/src/tests/neuron_info.rs index a954ef6e26..edee24aeba 100644 --- a/pallets/subtensor/src/tests/neuron_info.rs +++ b/pallets/subtensor/src/tests/neuron_info.rs @@ -26,7 +26,7 @@ fn test_get_neuron_some() { let hotkey0 = U256::from(0); let coldkey0 = U256::from(0); - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 39420842); let neuron = SubtensorModule::get_neuron(netuid, uid); @@ -43,7 +43,7 @@ fn test_get_neurons_list() { let tempo: u16 = 2; let modality: u16 = 2; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); let _uid: u16 = 42; diff --git a/pallets/subtensor/src/tests/registration.rs b/pallets/subtensor/src/tests/registration.rs index 48e887d606..2601243646 100644 --- a/pallets/subtensor/src/tests/registration.rs +++ b/pallets/subtensor/src/tests/registration.rs @@ -50,7 +50,7 @@ fn test_registration_invalid_seal_hotkey() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id_1), @@ -90,7 +90,7 @@ fn test_registration_ok() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Subscribe and check extrinsic output assert_ok!(SubtensorModule::register( @@ -146,7 +146,7 @@ fn test_registration_without_neuron_slot() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_max_allowed_uids(netuid, 0); assert_noop!( @@ -207,7 +207,7 @@ fn test_registration_under_limit() { assert_ok!(result); //actually call register - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), netuid, @@ -294,7 +294,7 @@ fn test_burned_registration_under_limit() { let reserve = 1_000_000_000_000; mock::setup_reserves(netuid, reserve.into(), reserve.into()); - add_network(netuid, 13, 0); // Add the network + add_network(netuid, 13, 0, 0); // Add the network // Give it some TAO to the coldkey balance; more than the burn cost SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, burn_cost + 10_000); @@ -394,7 +394,7 @@ fn test_burned_registration_rate_allows_burn_adjustment() { let reserve = 1_000_000_000_000; mock::setup_reserves(netuid, reserve.into(), reserve.into()); - add_network(netuid, 13, 0); // Add the network + add_network(netuid, 13, 0, 0); // Add the network // Give it some TAO to the coldkey balance; more than the burn cost SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, burn_cost + 10_000); @@ -446,7 +446,7 @@ fn test_burned_registration_ok() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network SubtensorModule::set_burn(netuid, burn_cost.into()); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let reserve = 1_000_000_000_000; mock::setup_reserves(netuid, reserve.into(), reserve.into()); @@ -497,7 +497,7 @@ fn test_burn_registration_without_neuron_slot() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network SubtensorModule::set_burn(netuid, burn_cost.into()); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Give it some $$$ in his coldkey balance SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); SubtensorModule::set_max_allowed_uids(netuid, 0); @@ -524,7 +524,7 @@ fn test_burn_registration_doesnt_write_on_failure() { let coldkey_account_id = U256::from(987); // Add network and set burn cost - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_burn(netuid, burn_cost.into()); // Give coldkey balance to pay for registration SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, initial_balance); @@ -561,7 +561,7 @@ fn test_burn_adjustment() { let init_burn_cost: u64 = InitialMinBurn::get() + 10_000; let adjustment_interval = 1; let target_registrations_per_interval = 1; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_burn(netuid, init_burn_cost.into()); SubtensorModule::set_adjustment_interval(netuid, adjustment_interval); SubtensorModule::set_adjustment_alpha(netuid, 58000); // Set to old value. @@ -629,7 +629,7 @@ fn test_burn_registration_pruning_scenarios() { let reserve = 1_000_000_000_000; mock::setup_reserves(netuid, reserve.into(), reserve.into()); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let mint_balance = burn_cost * max_allowed_uids as u64 + 1_000_000_000; SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, mint_balance); @@ -731,7 +731,7 @@ fn test_registration_too_many_registrations_per_block() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); let tempo: u16 = 13; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 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); @@ -927,7 +927,7 @@ fn test_registration_too_many_registrations_per_interval() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); let tempo: u16 = 13; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_max_registrations_per_block(netuid, 11); assert_eq!(SubtensorModule::get_max_registrations_per_block(netuid), 11); SubtensorModule::set_target_registrations_per_interval(netuid, 3); @@ -1129,7 +1129,7 @@ fn test_registration_already_active_hotkey() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1178,7 +1178,7 @@ fn test_registration_invalid_seal() { SubtensorModule::create_work_for_block_number(netuid, 1, 0, &hotkey_account_id); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let result = SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1210,7 +1210,7 @@ fn test_registration_invalid_block_number() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let result = SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1241,7 +1241,7 @@ fn test_registration_invalid_difficulty() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_difficulty(netuid, 18_446_744_073_709_551_615u64); @@ -1291,7 +1291,7 @@ fn test_registration_get_uid_to_prune_all_in_immunity_period() { new_test_ext(1).execute_with(|| { System::set_block_number(0); let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); log::info!("add network"); register_ok_neuron(netuid, U256::from(0), U256::from(0), 39420842); register_ok_neuron(netuid, U256::from(1), U256::from(1), 12412392); @@ -1315,7 +1315,7 @@ fn test_registration_get_uid_to_prune_none_in_immunity_period() { new_test_ext(1).execute_with(|| { System::set_block_number(0); let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); log::info!("add network"); register_ok_neuron(netuid, U256::from(0), U256::from(0), 39420842); register_ok_neuron(netuid, U256::from(1), U256::from(1), 12412392); @@ -1438,7 +1438,7 @@ fn test_registration_pruning() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1513,7 +1513,7 @@ fn test_registration_get_neuron_metadata() { &hotkey_account_id, ); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); assert_ok!(SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -1563,10 +1563,10 @@ fn test_registration_add_network_size() { ); let coldkey_account_id = U256::from(667); - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 0); - add_network(netuid2, 13, 0); + add_network(netuid2, 13, 0, 0); assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 0); assert_ok!(SubtensorModule::register( @@ -1621,10 +1621,10 @@ fn test_burn_registration_increase_recycled_rao() { mock::setup_reserves(netuid, reserve.into(), reserve.into()); mock::setup_reserves(netuid2, reserve.into(), reserve.into()); - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 0); - add_network(netuid2, 13, 0); + add_network(netuid2, 13, 0, 0); assert_eq!(SubtensorModule::get_subnetwork_n(netuid2), 0); run_to_block(1); @@ -1683,9 +1683,9 @@ fn test_full_pass_through() { let coldkey2 = U256::from(2); // Add the 3 networks. - add_network(netuid0, tempo0, 0); - add_network(netuid1, tempo1, 0); - add_network(netuid2, tempo2, 0); + add_network(netuid0, tempo0, 0, 0); + add_network(netuid1, tempo1, 0, 0); + add_network(netuid2, tempo2, 0, 0); // owners are not deregisterd let dummy_owner = U256::from(99999); @@ -1900,8 +1900,8 @@ fn test_full_pass_through() { // // Add a networks and connection requirements. // let netuid_a: u16 = 0; // let netuid_b: u16 = 1; -// add_network(netuid_a, 10, 0); -// add_network(netuid_b, 10, 0); +// add_network(netuid_a, 10, 0, 0); +// add_network(netuid_b, 10, 0, 0); // // Bulk values. // let hotkeys: Vec = (0..=10).map(|x| U256::from(x)).collect(); @@ -2095,7 +2095,7 @@ fn test_registration_origin_hotkey_mismatch() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let result = SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id_1), @@ -2129,7 +2129,7 @@ fn test_registration_disabled() { ); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_network_registration_allowed(netuid, false); SubtensorModule::set_network_pow_registration_allowed(netuid, false); @@ -2159,7 +2159,7 @@ fn test_last_update_correctness() { let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har //add network SubtensorModule::set_burn(netuid, burn_cost.into()); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let reserve = 1_000_000_000_000; mock::setup_reserves(netuid, reserve.into(), reserve.into()); @@ -2199,7 +2199,7 @@ fn test_last_update_correctness() { // let coldkey_account_id = U256::from(667); // SubtensorModule::set_burn(netuid, burn_cost); -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // // Give it some $$$ in his coldkey balance // SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10_000_000_000); @@ -2240,7 +2240,7 @@ fn test_last_update_correctness() { // let not_owner_coldkey = U256::from(3); // SubtensorModule::set_burn(netuid, burn_cost); -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // // Give it some $$$ in his coldkey balance // SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -2275,7 +2275,7 @@ fn test_last_update_correctness() { // let coldkey_account_id = U256::from(2); // SubtensorModule::set_burn(netuid, burn_cost); -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // // Give it some $$$ in his coldkey balance // SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); @@ -2309,7 +2309,7 @@ fn test_last_update_correctness() { // let coldkey_account_id = U256::from(2); // SubtensorModule::set_burn(netuid, burn_cost); -// add_network(netuid, tempo, 0); +// add_network(netuid, tempo, 0, 0); // // Give it some $$$ in his coldkey balance // SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 100_000_000_000); diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index d8a9b866d9..6cddfab2b8 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -74,7 +74,7 @@ fn test_serving_ok() { let protocol: u8 = 0; let placeholder1: u8 = 0; let placeholder2: u8 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); assert_ok!(SubtensorModule::serve_axon( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -113,7 +113,7 @@ fn test_serving_tls_ok() { let placeholder1: u8 = 0; let placeholder2: u8 = 0; let certificate: Vec = "CERT".as_bytes().to_vec(); - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); assert_ok!(SubtensorModule::serve_axon_tls( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -170,7 +170,7 @@ fn test_serving_set_metadata_update() { let protocol: u8 = 0; let placeholder1: u8 = 0; let placeholder2: u8 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); assert_ok!(SubtensorModule::serve_axon( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -234,7 +234,7 @@ fn test_axon_serving_rate_limit_exceeded() { let protocol: u8 = 0; let placeholder1: u8 = 0; let placeholder2: u8 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); run_to_block(1); // Go to block 1 // No issue on multiple @@ -316,7 +316,7 @@ fn test_axon_invalid_port() { let protocol: u8 = 0; let placeholder1: u8 = 0; let placeholder2: u8 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); run_to_block(1); // Go to block 1 assert_eq!( @@ -369,7 +369,7 @@ fn test_prometheus_serving_ok() { let port: u16 = 128; let ip_type: u8 = 4; let modality: u16 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); assert_ok!(SubtensorModule::serve_prometheus( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -398,7 +398,7 @@ fn test_prometheus_serving_set_metadata_update() { let port: u16 = 128; let ip_type: u8 = 4; let modality: u16 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); assert_ok!(SubtensorModule::serve_prometheus( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -444,7 +444,7 @@ fn test_prometheus_serving_rate_limit_exceeded() { let port: u16 = 128; let ip_type: u8 = 4; let modality: u16 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); run_to_block(1); // Go to block 1 // No issue on multiple @@ -507,7 +507,7 @@ fn test_prometheus_invalid_port() { let port: u16 = 0; let ip_type: u8 = 4; let modality: u16 = 0; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); run_to_block(1); // Go to block 1 assert_eq!( @@ -658,7 +658,7 @@ fn test_do_set_identity() { let netuid = NetUid::from(1); // Register a hotkey for the coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Prepare identity data @@ -845,7 +845,7 @@ fn test_set_and_get_identity() { let netuid = NetUid::from(1); // Register a hotkey for the coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Prepare identity data @@ -1119,7 +1119,7 @@ fn test_do_set_subnet_identity() { let netuid = NetUid::from(1); // Register a hotkey for the coldkey - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Set coldkey as the owner of the subnet @@ -1426,7 +1426,7 @@ fn test_serve_axon_validate() { // Register the hotkey in the subnet and try again let coldkey = U256::from(1); - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); // Submit to the signed extension validate function diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 27c5b5c16d..5945562253 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1404,7 +1404,7 @@ fn test_hotkey_belongs_to_coldkey_ok() { let netuid = NetUid::from(1); let tempo: u16 = 13; let start_nonce: u64 = 0; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, hotkey_id, coldkey_id, start_nonce); assert_eq!( SubtensorModule::get_owning_coldkey_for_hotkey(&hotkey_id), @@ -1759,7 +1759,7 @@ fn test_delegate_take_can_be_decreased() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -1794,7 +1794,7 @@ fn test_can_set_min_take_ok() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates @@ -1826,7 +1826,7 @@ fn test_delegate_take_can_not_be_increased_with_decrease_take() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Set min take @@ -1861,7 +1861,7 @@ fn test_delegate_take_can_be_increased() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -1896,7 +1896,7 @@ fn test_delegate_take_can_not_be_decreased_with_increase_take() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -1935,7 +1935,7 @@ fn test_delegate_take_can_be_increased_to_limit() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -1973,7 +1973,7 @@ fn test_delegate_take_can_not_be_increased_beyond_limit() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -2015,7 +2015,7 @@ fn test_rate_limits_enforced_on_increase_take() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -2075,7 +2075,7 @@ fn test_rate_limits_enforced_on_decrease_before_increase_take() { // Register the neuron to a new network let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey0, coldkey0, 124124); // Coldkey / hotkey 0 become delegates with 9% take @@ -2217,7 +2217,7 @@ fn test_get_total_delegated_stake_no_delegations() { let coldkey = U256::from(2); let netuid = NetUid::from(1u16); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, delegate, coldkey, 0); // Check that there's no delegated stake @@ -2408,7 +2408,7 @@ fn test_mining_emission_distribution_validator_valiminer_miner() { let stake = 100_000_000_000; // Add network, register hotkeys, and setup network parameters - add_network(netuid, subnet_tempo, 0); + add_network(netuid, subnet_tempo, 0, 0); register_ok_neuron(netuid, validator_hotkey, validator_coldkey, 0); register_ok_neuron(netuid, validator_miner_hotkey, validator_miner_coldkey, 1); register_ok_neuron(netuid, miner_hotkey, miner_coldkey, 2); @@ -2762,7 +2762,7 @@ fn test_max_amount_add_root() { fn test_max_amount_add_stable() { new_test_ext(0).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // 0 price => max is 0 assert_eq!( @@ -2959,7 +2959,7 @@ fn test_max_amount_remove_root() { fn test_max_amount_remove_stable() { new_test_ext(0).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // 0 price => max is u64::MAX assert_eq!( @@ -3206,7 +3206,7 @@ fn test_max_amount_move_root_root() { fn test_max_amount_move_root_stable() { new_test_ext(0).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // 0 price on (root, stable) exchange => max is u64::MAX assert_eq!( @@ -3272,7 +3272,7 @@ fn test_max_amount_move_stable_dynamic() { new_test_ext(0).execute_with(|| { // Add stable subnet let stable_netuid = NetUid::from(1); - add_network(stable_netuid, 1, 0); + add_network(stable_netuid, 1, 0, 0); // Add dynamic subnet let subnet_owner_coldkey = U256::from(1001); @@ -3372,7 +3372,7 @@ fn test_max_amount_move_dynamic_stable() { new_test_ext(0).execute_with(|| { // Add stable subnet let stable_netuid = NetUid::from(1); - add_network(stable_netuid, 1, 0); + add_network(stable_netuid, 1, 0, 0); // Add dynamic subnet let subnet_owner_coldkey = U256::from(1001); @@ -5463,7 +5463,7 @@ fn test_add_root_updates_counters() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(561337); let coldkey_account_id = U256::from(61337); - add_network(NetUid::ROOT, 10, 0); + add_network(NetUid::ROOT, 10, 0, 0); assert_ok!(SubtensorModule::root_register( RuntimeOrigin::signed(coldkey_account_id).clone(), hotkey_account_id, @@ -5518,7 +5518,7 @@ fn test_remove_root_updates_counters() { new_test_ext(0).execute_with(|| { let hotkey_account_id = U256::from(561337); let coldkey_account_id = U256::from(61337); - add_network(NetUid::ROOT, 10, 0); + add_network(NetUid::ROOT, 10, 0, 0); assert_ok!(SubtensorModule::root_register( RuntimeOrigin::signed(coldkey_account_id).clone(), hotkey_account_id, diff --git a/pallets/subtensor/src/tests/subnet.rs b/pallets/subtensor/src/tests/subnet.rs index a11eae759e..83b76e014b 100644 --- a/pallets/subtensor/src/tests/subnet.rs +++ b/pallets/subtensor/src/tests/subnet.rs @@ -572,8 +572,8 @@ fn test_subtoken_enable_trading_ok_with_enable() { // unstake, transfer, swap just very little let unstake_amount = AlphaCurrency::from(DefaultMinStake::::get().to_u64() * 10); - add_network(netuid, 10, 0); - add_network(netuid2, 10, 0); + add_network(netuid, 10, 0, 0); + add_network(netuid2, 10, 0, 0); let reserve = stake_amount.to_u64() * 1000; mock::setup_reserves(netuid, reserve.into(), reserve.into()); @@ -802,7 +802,7 @@ fn test_get_symbol_for_subnet_returns_default_symbol_if_netuid_is_out_of_bounds( fn test_update_symbol_works_as_root_if_symbol_exists_and_available() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); // only one network so we can set any symbol, except the root symbol for i in 1..SYMBOLS.len() { @@ -824,7 +824,7 @@ fn test_update_symbol_works_as_subnet_owner_if_symbol_exists_and_available() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let netuid = NetUid::from(1); - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); SubnetOwner::::insert(netuid, coldkey); // only one network so we can set any symbol, except the root symbol @@ -848,7 +848,7 @@ fn test_update_symbol_fails_if_symbol_doesnt_exist() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let netuid = NetUid::from(1); - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); SubnetOwner::::insert(netuid, coldkey); assert_err!( @@ -867,12 +867,12 @@ fn test_update_symbol_fails_if_symbol_already_in_use() { new_test_ext(1).execute_with(|| { let coldkey = U256::from(1); let netuid = NetUid::from(1); - add_network(netuid, 10, 0); + add_network(netuid, 10, 0, 0); SubnetOwner::::insert(netuid, coldkey); let coldkey2 = U256::from(2); let netuid2 = NetUid::from(2); - add_network(netuid2, 10, 0); + add_network(netuid2, 10, 0, 0); SubnetOwner::::insert(netuid2, coldkey2); assert_ok!(SubtensorModule::update_symbol( diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 9d3bdbfc62..75809518f0 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -67,7 +67,7 @@ fn test_swap_subnet_owner() { let new_coldkey = U256::from(2); let netuid = NetUid::from(1u16); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubnetOwner::::insert(netuid, old_coldkey); let mut weight = Weight::zero(); @@ -93,7 +93,7 @@ fn test_swap_total_coldkey_stake() { let stake = DefaultMinStake::::get().to_u64() * 10; let netuid = NetUid::from(1u16); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake * 2 + 1_000); register_ok_neuron(netuid, hotkey, old_coldkey, 1001000); register_ok_neuron(netuid, other_hotkey, other_coldkey, 1001000); @@ -260,8 +260,8 @@ fn test_swap_with_multiple_subnets() { let netuid1 = NetUid::from(1); let netuid2 = NetUid::from(2); - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); SubnetOwner::::insert(netuid1, old_coldkey); SubnetOwner::::insert(netuid2, old_coldkey); @@ -310,7 +310,7 @@ fn test_swap_idempotency() { mock::setup_reserves(netuid, reserve.into(), reserve.into()); // Add a network - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake); // Give old coldkey some balance // Stake to a hotkey register_ok_neuron(netuid, hotkey, old_coldkey, 1001000); @@ -364,8 +364,8 @@ fn test_swap_with_max_values() { let max_stake = 21_000_000_000_000_000; // 21 Million TAO; max possible balance. // Add a network - add_network(netuid, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Register hotkey on each subnet. // hotkey2 is owned by other_coldkey. @@ -448,7 +448,7 @@ fn test_swap_with_non_existent_new_coldkey() { let stake = DefaultMinStake::::get().to_u64() * 10; let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey, old_coldkey, 1001000); // Give old coldkey some balance. SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake + 1_000); @@ -592,7 +592,7 @@ fn test_swap_concurrent_modifications() { mock::setup_reserves(netuid, reserve.into(), reserve.into()); // Setup initial state - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); SubtensorModule::add_balance_to_coldkey_account( &new_coldkey, initial_stake + additional_stake + 1_000_000, @@ -693,7 +693,7 @@ fn test_do_swap_coldkey_success() { mock::setup_reserves(netuid, reserve.into(), reserve.into()); // Setup initial state - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey1, old_coldkey, 0); register_ok_neuron(netuid, hotkey2, old_coldkey, 0); @@ -870,7 +870,7 @@ fn test_swap_stake_for_coldkey() { // Setup initial state // Add a network let netuid = NetUid::from(1u16); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Register hotkeys register_ok_neuron(netuid, hotkey1, old_coldkey, 0); @@ -1026,7 +1026,7 @@ fn test_swap_staking_hotkeys_for_coldkey() { // Setup initial state // Add a network let netuid = NetUid::from(1u16); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Give some balance to old coldkey SubtensorModule::add_balance_to_coldkey_account( &old_coldkey, @@ -1090,7 +1090,7 @@ fn test_swap_delegated_stake_for_coldkey() { let netuid = NetUid::from(1); // Setup initial state - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, hotkey1, other_coldkey, 0); register_ok_neuron(netuid, hotkey2, other_coldkey, 0); @@ -1231,8 +1231,8 @@ fn test_swap_subnet_owner_for_coldkey() { let mut weight = Weight::zero(); // Initialize SubnetOwner for old_coldkey - add_network(netuid1, 13, 0); - add_network(netuid2, 14, 0); + add_network(netuid1, 13, 0, 0); + add_network(netuid2, 14, 0, 0); SubnetOwner::::insert(netuid1, old_coldkey); SubnetOwner::::insert(netuid2, old_coldkey); @@ -1260,7 +1260,7 @@ fn test_do_swap_coldkey_with_subnet_ownership() { let swap_cost = SubtensorModule::get_key_swap_cost().to_u64(); // Setup initial state - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, old_coldkey, 0); // Set TotalNetworks because swap relies on it @@ -1292,7 +1292,7 @@ fn test_coldkey_has_associated_hotkeys() { let netuid = NetUid::from(1u16); // Setup initial state - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1000); }); @@ -1330,9 +1330,9 @@ fn test_coldkey_swap_total() { mock::setup_reserves(netuid3, reserve.into(), reserve.into()); // Setup initial state - add_network(netuid1, 13, 0); - add_network(netuid2, 14, 0); - add_network(netuid3, 15, 0); + add_network(netuid1, 13, 0, 0); + add_network(netuid2, 14, 0, 0); + add_network(netuid3, 15, 0, 0); register_ok_neuron(netuid1, hotkey1, coldkey, 0); register_ok_neuron(netuid2, hotkey2, coldkey, 0); register_ok_neuron(netuid3, hotkey3, coldkey, 0); @@ -1633,8 +1633,8 @@ fn test_coldkey_delegations() { mock::setup_reserves(netuid, reserve.into(), reserve.into()); mock::setup_reserves(netuid2, reserve.into(), reserve.into()); - add_network(netuid, 13, 0); // root - add_network(netuid2, 13, 0); + add_network(netuid, 13, 0, 0); // root + add_network(netuid2, 13, 0, 0); assert_ok!(SubtensorModule::root_register( <::RuntimeOrigin>::signed(owner), @@ -1785,7 +1785,7 @@ fn test_schedule_swap_coldkey_execution() { mock::setup_reserves(netuid, reserve.into(), reserve.into()); - add_network(netuid, 13, 0); + add_network(netuid, 13, 0, 0); register_ok_neuron(netuid, hotkey, old_coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 1000000000000000); assert_ok!(SubtensorModule::add_stake( @@ -1994,7 +1994,7 @@ fn test_coldkey_swap_delegate_identity_updated() { let tempo = 1; SubtensorModule::set_burn(netuid, burn_cost); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 100_000_000_000); mock::setup_reserves(netuid, 1_000_000_000_000.into(), 1_000_000_000_000.into()); @@ -2047,7 +2047,7 @@ fn test_coldkey_swap_no_identity_no_changes() { let tempo = 1; SubtensorModule::set_burn(netuid, burn_cost); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 100_000_000_000); mock::setup_reserves(netuid, 1_000_000_000_000.into(), 1_000_000_000_000.into()); @@ -2085,7 +2085,7 @@ fn test_coldkey_swap_no_identity_no_changes_newcoldkey_exists() { let tempo = 1; SubtensorModule::set_burn(netuid, burn_cost); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, 100_000_000_000); mock::setup_reserves(netuid, 1_000_000_000_000.into(), 1_000_000_000_000.into()); @@ -2182,7 +2182,7 @@ fn test_coldkey_in_swap_schedule_prevents_funds_usage() { // others... // Create netuid - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Register the hotkey SubtensorModule::append_neuron(netuid, &hotkey, 0); crate::Owner::::insert(hotkey, coldkey); @@ -2528,7 +2528,7 @@ fn test_coldkey_in_swap_schedule_prevents_critical_calls() { // - dissolve_network // Create netuid - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Register the hotkey SubtensorModule::append_neuron(netuid, &hotkey, 0); crate::Owner::::insert(hotkey, coldkey); @@ -2590,7 +2590,7 @@ fn test_swap_auto_stake_destination_coldkeys() { let netuid = NetUid::from(1u16); let coldkeys = vec![U256::from(4), U256::from(5), old_coldkey]; - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); AutoStakeDestinationColdkeys::::insert(hotkey, netuid, coldkeys.clone()); AutoStakeDestination::::insert(old_coldkey, netuid, hotkey); diff --git a/pallets/subtensor/src/tests/swap_hotkey.rs b/pallets/subtensor/src/tests/swap_hotkey.rs index 71191d1951..e4e47d213a 100644 --- a/pallets/subtensor/src/tests/swap_hotkey.rs +++ b/pallets/subtensor/src/tests/swap_hotkey.rs @@ -152,7 +152,7 @@ fn test_swap_subnet_membership() { let netuid = NetUid::from(0u16); let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); assert_ok!(SubtensorModule::perform_hotkey_swap_on_all_subnets( &old_hotkey, @@ -177,7 +177,7 @@ fn test_swap_uids_and_keys() { let uid = 5u16; let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); Uids::::insert(netuid, old_hotkey, uid); Keys::::insert(netuid, uid, old_hotkey); @@ -206,7 +206,7 @@ fn test_swap_prometheus() { let prometheus_info = PrometheusInfo::default(); let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); Prometheus::::insert(netuid, old_hotkey, prometheus_info.clone()); @@ -236,7 +236,7 @@ fn test_swap_axons() { let axon_info = AxonInfo::default(); let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); Axons::::insert(netuid, old_hotkey, axon_info.clone()); @@ -263,7 +263,7 @@ fn test_swap_certificates() { let certificate = NeuronCertificate::try_from(vec![1, 2, 3]).unwrap(); let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); NeuronCertificates::::insert(netuid, old_hotkey, certificate.clone()); @@ -296,7 +296,7 @@ fn test_swap_weight_commits() { weight_commits.push_back((H256::from_low_u64_be(100), 200, 1, 1)); let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); WeightCommits::::insert( NetUidStorageIndex::from(netuid), @@ -334,7 +334,7 @@ fn test_swap_loaded_emission() { let validator_emission = 1000u64; let mut weight = Weight::zero(); - add_network(netuid, 1, 1); + add_network(netuid, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid, true); LoadedEmission::::insert( netuid, @@ -460,8 +460,8 @@ fn test_swap_hotkey_with_multiple_subnets() { let netuid2 = NetUid::from(1); let mut weight = Weight::zero(); - add_network(netuid1, 1, 1); - add_network(netuid2, 1, 1); + add_network(netuid1, 1, 1, 0); + add_network(netuid2, 1, 1, 0); IsNetworkMember::::insert(old_hotkey, netuid1, true); IsNetworkMember::::insert(old_hotkey, netuid2, true); @@ -589,8 +589,8 @@ fn test_swap_hotkey_with_multiple_coldkeys_and_subnets() { let mut weight = Weight::zero(); // Set up initial state - add_network(netuid1, 1, 1); - add_network(netuid2, 1, 1); + add_network(netuid1, 1, 1, 0); + add_network(netuid2, 1, 1, 0); register_ok_neuron(netuid1, old_hotkey, coldkey1, 1234); register_ok_neuron(netuid2, old_hotkey, coldkey1, 1234); @@ -734,7 +734,7 @@ fn test_swap_hotkey_tx_rate_limit_exceeded() { assert_eq!(SubtensorModule::get_tx_rate_limit(), tx_rate_limit); // Setup initial state - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, old_hotkey, coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(&coldkey, swap_cost); @@ -781,7 +781,7 @@ fn test_do_swap_hotkey_err_not_owner() { let swap_cost = 1_000_000_000u64; // Setup initial state - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, old_hotkey, coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(¬_owner_coldkey, swap_cost); @@ -1083,7 +1083,7 @@ fn test_swap_child_keys() { let mut weight = Weight::zero(); // Initialize ChildKeys for old_hotkey - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); ChildKeys::::insert(old_hotkey, netuid, children.clone()); // Perform the swap @@ -1112,7 +1112,7 @@ fn test_swap_parent_keys() { let mut weight = Weight::zero(); // Initialize ParentKeys for old_hotkey - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); ParentKeys::::insert(old_hotkey, netuid, parents.clone()); // Initialize ChildKeys for parent @@ -1156,8 +1156,8 @@ fn test_swap_multiple_subnets() { let children2 = vec![(300u64, U256::from(6))]; let mut weight = Weight::zero(); - add_network(netuid1, 1, 0); - add_network(netuid2, 1, 0); + add_network(netuid1, 1, 0, 0); + add_network(netuid2, 1, 0, 0); // Initialize ChildKeys for old_hotkey in multiple subnets ChildKeys::::insert(old_hotkey, netuid1, children1.clone()); @@ -1193,7 +1193,7 @@ fn test_swap_complex_parent_child_structure() { let child2 = U256::from(7); let mut weight = Weight::zero(); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Set up complex parent-child structure ParentKeys::::insert( @@ -1252,7 +1252,7 @@ fn test_swap_parent_hotkey_childkey_maps() { let child = U256::from(3); let child_other = U256::from(4); let parent_new = U256::from(5); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::create_account_if_non_existent(&coldkey, &parent_old); // Set child and verify state maps @@ -1306,7 +1306,7 @@ fn test_swap_child_hotkey_childkey_maps() { let coldkey = U256::from(2); let child_old = U256::from(3); let child_new = U256::from(4); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::create_account_if_non_existent(&coldkey, &child_old); SubtensorModule::create_account_if_non_existent(&coldkey, &parent); @@ -1436,7 +1436,7 @@ fn test_swap_parent_hotkey_self_loops_in_pending() { // Same as child_other, so it will self-loop when pending is set. Should fail. let parent_new = U256::from(4); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::create_account_if_non_existent(&coldkey, &parent_old); // Set child and verify state maps @@ -1482,7 +1482,7 @@ fn test_swap_auto_stake_destination_coldkeys() { let mut weight = Weight::zero(); // Initialize ChildKeys for old_hotkey - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); AutoStakeDestinationColdkeys::::insert(old_hotkey, netuid, coldkeys.clone()); AutoStakeDestination::::insert(coldkey, netuid, old_hotkey); diff --git a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs index 6e423c1269..8833f98139 100644 --- a/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs +++ b/pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs @@ -618,8 +618,8 @@ fn test_swap_hotkey_with_multiple_coldkeys_and_subnets() { let stake = DefaultMinStake::::get().to_u64() * 10; // Set up initial state - add_network(netuid1, 1, 1); - add_network(netuid2, 1, 1); + add_network(netuid1, 1, 1, 0); + add_network(netuid2, 1, 1, 0); register_ok_neuron(netuid1, old_hotkey, coldkey1, 1234); register_ok_neuron(netuid2, old_hotkey, coldkey1, 1234); @@ -775,7 +775,7 @@ fn test_swap_hotkey_tx_rate_limit_exceeded() { assert_eq!(SubtensorModule::get_tx_rate_limit(), tx_rate_limit); // Setup initial state - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, old_hotkey, coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(&coldkey, swap_cost); @@ -824,7 +824,7 @@ fn test_do_swap_hotkey_err_not_owner() { let swap_cost = 1_000_000_000u64; // Setup initial state - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, old_hotkey, coldkey, 0); SubtensorModule::add_balance_to_coldkey_account(¬_owner_coldkey, swap_cost); diff --git a/pallets/subtensor/src/tests/uids.rs b/pallets/subtensor/src/tests/uids.rs index 8fee5f7507..130f3abf7d 100644 --- a/pallets/subtensor/src/tests/uids.rs +++ b/pallets/subtensor/src/tests/uids.rs @@ -35,7 +35,7 @@ fn test_replace_neuron() { let certificate = NeuronCertificate::try_from(vec![1, 2, 3]).unwrap(); let evm_address = H160::from_slice(&[1_u8; 20]); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register a neuron. assert_ok!(SubtensorModule::register( @@ -173,7 +173,7 @@ fn test_bonds_cleared_on_replace() { let evm_address = H160::from_slice(&[1_u8; 20]); //add network - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register a neuron. assert_ok!(SubtensorModule::register( @@ -253,8 +253,8 @@ fn test_replace_neuron_multiple_subnets() { let _new_colkey_account_id = U256::from(12345); let evm_address = H160::from_slice(&[1_u8; 20]); //add network - add_network(netuid, tempo, 0); - add_network(netuid1, tempo, 0); + add_network(netuid, tempo, 0, 0); + add_network(netuid1, tempo, 0, 0); // Register a neuron on both networks. assert_ok!(SubtensorModule::register( diff --git a/pallets/subtensor/src/tests/weights.rs b/pallets/subtensor/src/tests/weights.rs index a71a225dc7..9a796e22ae 100644 --- a/pallets/subtensor/src/tests/weights.rs +++ b/pallets/subtensor/src/tests/weights.rs @@ -114,7 +114,7 @@ fn test_commit_weights_validate() { }); // Create netuid - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); // Register the hotkey SubtensorModule::append_neuron(netuid, &hotkey, 0); crate::Owner::::insert(hotkey, coldkey); @@ -245,7 +245,7 @@ fn test_set_weights_validate() { }); // Create netuid - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); mock::setup_reserves(netuid, 1_000_000_000_000.into(), 1_000_000_000_000.into()); // Register the hotkey SubtensorModule::append_neuron(netuid, &hotkey, 0); @@ -351,7 +351,7 @@ fn test_reveal_weights_validate() { SubtensorModule::get_reveal_blocks(netuid, commit_block); // Create netuid - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register the hotkey SubtensorModule::append_neuron(netuid, &hotkey, 0); SubtensorModule::append_neuron(netuid, &hotkey2, 0); @@ -534,7 +534,7 @@ fn test_batch_reveal_weights_validate() { }); // Create netuid - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register the hotkeys SubtensorModule::append_neuron(netuid, &hotkey, 0); SubtensorModule::append_neuron(netuid, &hotkey2, 0); @@ -976,7 +976,7 @@ fn test_weights_err_weights_vec_not_equal_size() { let netuid = NetUid::from(1); let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id) @@ -1005,7 +1005,7 @@ fn test_weights_err_has_duplicate_ids() { let netuid = NetUid::from(1); let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_stake_threshold(0); SubtensorModule::set_max_allowed_uids(netuid, 100); // Allow many registrations per block. @@ -1079,7 +1079,7 @@ fn test_set_weights_err_not_active() { let netuid = NetUid::from(1); let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register one neuron. Should have uid 0 register_ok_neuron(netuid, U256::from(666), U256::from(2), 100000); @@ -1113,7 +1113,7 @@ fn test_set_weights_err_invalid_uid() { let netuid = NetUid::from(1); let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, hotkey_account_id, U256::from(66), 0); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id) @@ -1257,7 +1257,7 @@ fn test_set_weights_sum_larger_than_u16_max() { let netuid = NetUid::from(1); let tempo: u16 = 13; let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(1.into(), U256::from(1), U256::from(2), 100_000); let neuron_uid: u16 = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &U256::from(1)) @@ -1348,7 +1348,7 @@ fn test_check_length_to_few_weights() { let min_allowed_weights = 3; - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); SubtensorModule::set_target_registrations_per_interval(netuid, 100); SubtensorModule::set_max_registrations_per_block(netuid, 100); // register morw than min allowed @@ -1541,7 +1541,7 @@ fn test_check_len_uids_within_allowed_within_network_pool() { let max_registrations_per_block: u16 = 100; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); /* @TODO: use a loop maybe */ register_ok_neuron(netuid, U256::from(1), U256::from(1), 0); @@ -1574,7 +1574,7 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { let max_registrations_per_block: u16 = 100; - add_network(netuid, tempo, modality); + add_network(netuid, tempo, modality, 0); /* @TODO: use a loop maybe */ register_ok_neuron(netuid, U256::from(1), U256::from(1), 0); @@ -1601,7 +1601,7 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { fn test_set_weights_commit_reveal_enabled_error() { new_test_ext(0).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 1, 0); + add_network(netuid, 1, 0, 0); register_ok_neuron(netuid, U256::from(1), U256::from(2), 10); let uids = vec![0]; @@ -1657,7 +1657,7 @@ fn test_reveal_weights_when_commit_reveal_disabled() { System::set_block_number(0); let tempo: u16 = 5; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register neurons and set up configurations register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -1717,7 +1717,7 @@ fn test_commit_reveal_weights_ok() { System::set_block_number(0); let tempo: u16 = 5; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Register neurons and set up configurations register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -1786,7 +1786,7 @@ fn test_commit_reveal_tempo_interval() { System::set_block_number(0); let tempo: u16 = 100; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, U256::from(1), U256::from(2), 100_000); @@ -1921,7 +1921,7 @@ fn test_commit_reveal_hash() { let version_key: u64 = 0; let hotkey: U256 = U256::from(1); - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); System::set_block_number(0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2021,7 +2021,7 @@ fn test_commit_reveal_disabled_or_enabled() { version_key, )); - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); System::set_block_number(0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2098,7 +2098,7 @@ fn test_toggle_commit_reveal_weights_and_set_weights() { version_key, )); - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); System::set_block_number(0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2184,7 +2184,7 @@ fn test_tempo_change_during_commit_reveal_process() { System::set_block_number(0); let tempo: u16 = 100; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, U256::from(1), U256::from(2), 100_000); @@ -2332,7 +2332,7 @@ fn test_commit_reveal_multiple_commits() { System::set_block_number(0); let tempo: u16 = 7200; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // Setup the network and neurons register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2737,7 +2737,7 @@ fn test_expired_commits_handling_in_commit_and_reveal() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -2937,7 +2937,7 @@ fn test_reveal_at_exact_epoch() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3100,7 +3100,7 @@ fn test_tempo_and_reveal_period_change_during_commit_reveal_process() { let initial_tempo: u16 = 100; let initial_reveal_period: u64 = 1; - add_network(netuid, initial_tempo, 0); + add_network(netuid, initial_tempo, 0, 0); assert_ok!(SubtensorModule::set_reveal_period(netuid, initial_reveal_period)); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); @@ -3288,7 +3288,7 @@ fn test_commit_reveal_order_enforcement() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3547,7 +3547,7 @@ fn test_successful_batch_reveal() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3625,7 +3625,7 @@ fn test_batch_reveal_with_expired_commits() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3743,7 +3743,7 @@ fn test_batch_reveal_with_invalid_input_lengths() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); @@ -3845,7 +3845,7 @@ fn test_batch_reveal_with_no_commits() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); @@ -3874,7 +3874,7 @@ fn test_batch_reveal_before_reveal_period() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); @@ -3932,7 +3932,7 @@ fn test_batch_reveal_after_commits_expired() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); @@ -4013,7 +4013,7 @@ fn test_batch_reveal_when_commit_reveal_disabled() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); @@ -4042,7 +4042,7 @@ fn test_batch_reveal_with_out_of_order_commits() { let tempo: u16 = 100; System::set_block_number(0); - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -4154,7 +4154,7 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { let initial_tempo: u16 = 100; // ==== Setup Network ==== - add_network(netuid, initial_tempo, 0); + add_network(netuid, initial_tempo, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); assert_ok!(SubtensorModule::set_reveal_period(netuid, initial_reveal_period)); @@ -4444,7 +4444,7 @@ fn test_get_reveal_blocks() { // **4. Define Network Parameters** let tempo: u16 = 5; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); // **5. Register Neurons and Configure the Network** register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -4579,7 +4579,7 @@ fn test_commit_weights_rate_limit() { System::set_block_number(11); let tempo: u16 = 5; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, U256::from(1), U256::from(2), 100_000); @@ -4761,7 +4761,7 @@ fn test_reveal_crv3_commits_success() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); SubtensorModule::set_stake_threshold(0); @@ -4914,7 +4914,7 @@ fn test_reveal_crv3_commits_cannot_reveal_after_reveal_epoch() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); 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); @@ -5041,7 +5041,7 @@ fn test_do_commit_crv3_weights_success() { let commit_data: Vec = vec![1, 2, 3, 4, 5]; let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 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); @@ -5077,7 +5077,7 @@ fn test_do_commit_crv3_weights_disabled() { let commit_data: Vec = vec![1, 2, 3, 4, 5]; let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 5); @@ -5107,7 +5107,7 @@ fn test_do_commit_crv3_weights_hotkey_not_registered() { let reveal_round: u64 = 1000; let hotkey: AccountId = U256::from(1); - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 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); @@ -5137,7 +5137,7 @@ fn test_do_commit_crv3_weights_committing_too_fast() { let commit_data_2: Vec = vec![4, 5, 6]; let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 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); @@ -5209,7 +5209,7 @@ fn test_do_commit_crv3_weights_too_many_unrevealed_commits() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 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); @@ -5319,7 +5319,7 @@ fn test_reveal_crv3_commits_decryption_failure() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 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); @@ -5372,7 +5372,7 @@ fn test_reveal_crv3_commits_multiple_commits_some_fail_some_succeed() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 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); @@ -5496,7 +5496,7 @@ fn test_reveal_crv3_commits_do_set_weights_failure() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 3)); @@ -5582,7 +5582,7 @@ fn test_reveal_crv3_commits_payload_decoding_failure() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 3)); @@ -5660,7 +5660,7 @@ fn test_reveal_crv3_commits_signature_deserialization_failure() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 3)); @@ -5742,7 +5742,7 @@ fn test_do_commit_crv3_weights_commit_size_exceeds_limit() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5784,7 +5784,7 @@ fn test_reveal_crv3_commits_with_empty_commit_queue() { new_test_ext(1).execute_with(|| { let netuid = NetUid::from(1); - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -5806,7 +5806,7 @@ fn test_reveal_crv3_commits_with_incorrect_identity_message() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 1)); @@ -5894,7 +5894,7 @@ fn test_multiple_commits_by_same_hotkey_within_limit() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 1)); @@ -5933,7 +5933,7 @@ fn test_reveal_crv3_commits_removes_past_epoch_commits() { let hotkey: AccountId = U256::from(1); let reveal_round: u64 = 1_000; - add_network(netuid, /*tempo*/ 5, 0); + add_network(netuid, /*tempo*/ 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 1)); // reveal_period = 1 epoch @@ -5999,7 +5999,7 @@ fn test_reveal_crv3_commits_multiple_valid_commits_all_processed() { let reveal_round: u64 = 1_000; // ───── network parameters ─────────────────────────────────────────── - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 1)); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -6115,7 +6115,7 @@ fn test_reveal_crv3_commits_max_neurons() { let reveal_round: u64 = 1_000; // ───── network parameters ─────────────────────────────────────────── - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 1)); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -6227,7 +6227,7 @@ fn test_get_first_block_of_epoch_epoch_zero() { new_test_ext(1).execute_with(|| { let netuid: NetUid = NetUid::from(1); let tempo: u16 = 10; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let first_block = SubtensorModule::get_first_block_of_epoch(netuid, 0); assert_eq!(first_block, 0); @@ -6242,7 +6242,7 @@ fn test_get_first_block_of_epoch_small_epoch() { new_test_ext(1).execute_with(|| { let netuid: NetUid = NetUid::from(0); let tempo: u16 = 1; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let first_block = SubtensorModule::get_first_block_of_epoch(netuid, 1); assert_eq!(first_block, 1); // 1 * 2 - 1 = 1 @@ -6258,7 +6258,7 @@ fn test_get_first_block_of_epoch_with_offset() { new_test_ext(1).execute_with(|| { let netuid: NetUid = NetUid::from(1); let tempo: u16 = 10; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let first_block = SubtensorModule::get_first_block_of_epoch(netuid, 1); assert_eq!(first_block, 9); // 1 * 11 - 2 = 9 @@ -6274,7 +6274,7 @@ fn test_get_first_block_of_epoch_large_epoch() { new_test_ext(1).execute_with(|| { let netuid: NetUid = NetUid::from(0); let tempo: u16 = 100; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let epoch: u64 = 1000; let first_block = SubtensorModule::get_first_block_of_epoch(netuid, epoch); @@ -6290,7 +6290,7 @@ fn test_get_first_block_of_epoch_step_blocks_and_assert_with_until_next() { new_test_ext(1).execute_with(|| { let netuid: NetUid = NetUid::from(1); let tempo: u16 = 10; - add_network(netuid, tempo, 0); + add_network(netuid, tempo, 0, 0); let mut current_block: u64 = 0; for expected_epoch in 0..10u64 { @@ -6340,7 +6340,7 @@ fn test_reveal_crv3_commits_hotkey_check() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); SubtensorModule::set_stake_threshold(0); @@ -6457,7 +6457,7 @@ fn test_reveal_crv3_commits_hotkey_check() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1000; - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); SubtensorModule::set_stake_threshold(0); @@ -6609,7 +6609,7 @@ fn test_reveal_crv3_commits_retry_on_missing_pulse() { let reveal_round: u64 = 1_000; // ─── network & neuron ─────────────────────────────────────────────── - add_network(netuid, 5, 0); + add_network(netuid, 5, 0, 0); register_ok_neuron(netuid, hotkey, U256::from(3), 100_000); SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::set_reveal_period(netuid, 3)); @@ -6723,7 +6723,7 @@ fn test_reveal_crv3_commits_legacy_payload_success() { let hotkey2: AccountId = U256::from(2); let reveal_round: u64 = 1_000; - add_network(netuid, /*tempo*/ 5, /*modality*/ 0); + add_network(netuid, /*tempo*/ 5, /*modality*/ 0, 0); register_ok_neuron(netuid, hotkey1, U256::from(3), 100_000); register_ok_neuron(netuid, hotkey2, U256::from(4), 100_000); diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 0ba3df1103..7a14fafd6d 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -42,23 +42,16 @@ impl Pallet { netuid: NetUid, ) -> Result<(), DispatchError> { ensure_root(o)?; - let now = Self::get_current_block_as_u64(); - Self::ensure_not_in_admin_freeze_window(netuid, now)?; - Ok(()) + Self::ensure_admin_window_open(netuid) } /// Ensure owner-or-root with a set of TransactionType rate checks (owner only). - /// - Root: only freeze window is enforced; no TransactionType checks. - /// - Owner (Signed): freeze window plus all rate checks in `limits` using signer extracted from - /// origin. pub fn ensure_sn_owner_or_root_with_limits( o: T::RuntimeOrigin, netuid: NetUid, limits: &[crate::utils::rate_limiting::TransactionType], ) -> Result, DispatchError> { let maybe_who = Self::ensure_subnet_owner_or_root(o, netuid)?; - let now = Self::get_current_block_as_u64(); - Self::ensure_not_in_admin_freeze_window(netuid, now)?; if let Some(who) = maybe_who.as_ref() { for tx in limits.iter() { ensure!( @@ -70,26 +63,6 @@ impl Pallet { Ok(maybe_who) } - /// Ensure the caller is the subnet owner and passes all provided rate limits. - /// This does NOT allow root; it is strictly owner-only. - /// Returns the signer (owner) on success so callers may record last-blocks. - pub fn ensure_sn_owner_with_limits( - o: T::RuntimeOrigin, - netuid: NetUid, - limits: &[crate::utils::rate_limiting::TransactionType], - ) -> Result { - let who = Self::ensure_subnet_owner(o, netuid)?; - let now = Self::get_current_block_as_u64(); - Self::ensure_not_in_admin_freeze_window(netuid, now)?; - for tx in limits.iter() { - ensure!( - tx.passes_rate_limit_on_subnet::(&who, netuid), - Error::::TxRateLimitExceeded - ); - } - Ok(who) - } - /// Returns true if the current block is within the terminal freeze window of the tempo for the /// given subnet. During this window, admin ops are prohibited to avoid interference with /// validator weight submissions. @@ -103,7 +76,9 @@ impl Pallet { remaining < window } - fn ensure_not_in_admin_freeze_window(netuid: NetUid, now: u64) -> Result<(), DispatchError> { + /// Ensures the admin freeze window is not currently active for the given subnet. + pub fn ensure_admin_window_open(netuid: NetUid) -> Result<(), DispatchError> { + let now = Self::get_current_block_as_u64(); ensure!( !Self::is_in_admin_freeze_window(netuid, now), Error::::AdminActionProhibitedDuringWeightsWindow diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index 34b5e624e6..de08022060 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -68,7 +68,7 @@ impl Pallet { } // initializes V3 swap for a subnet if needed - pub(super) fn maybe_initialize_v3(netuid: NetUid) -> Result<(), Error> { + pub fn maybe_initialize_v3(netuid: NetUid) -> Result<(), Error> { if SwapV3Initialized::::get(netuid) { return Ok(()); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 266a755708..240c490736 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: 338, + spec_version: 340, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,