diff --git a/pallets/subtensor/src/block_step.rs b/pallets/subtensor/src/block_step.rs index b645db633e..168c2879ee 100644 --- a/pallets/subtensor/src/block_step.rs +++ b/pallets/subtensor/src/block_step.rs @@ -378,7 +378,7 @@ impl Pallet { // pow_difficulty ++ Self::set_difficulty( netuid, - Self::adjust_difficulty( + Self::upgraded_difficulty( netuid, current_difficulty, registrations_this_interval, @@ -391,7 +391,7 @@ impl Pallet { // burn_cost ++ Self::set_burn( netuid, - Self::adjust_burn( + Self::upgraded_burn( netuid, current_burn, registrations_this_interval, @@ -404,7 +404,7 @@ impl Pallet { // burn_cost ++ Self::set_burn( netuid, - Self::adjust_burn( + Self::upgraded_burn( netuid, current_burn, registrations_this_interval, @@ -414,7 +414,7 @@ impl Pallet { // pow_difficulty ++ Self::set_difficulty( netuid, - Self::adjust_difficulty( + Self::upgraded_difficulty( netuid, current_difficulty, registrations_this_interval, @@ -430,7 +430,7 @@ impl Pallet { // burn_cost -- Self::set_burn( netuid, - Self::adjust_burn( + Self::upgraded_burn( netuid, current_burn, registrations_this_interval, @@ -443,7 +443,7 @@ impl Pallet { // pow_difficulty -- Self::set_difficulty( netuid, - Self::adjust_difficulty( + Self::upgraded_difficulty( netuid, current_difficulty, registrations_this_interval, @@ -456,7 +456,7 @@ impl Pallet { // burn_cost -- Self::set_burn( netuid, - Self::adjust_burn( + Self::upgraded_burn( netuid, current_burn, registrations_this_interval, @@ -466,7 +466,7 @@ impl Pallet { // pow_difficulty -- Self::set_difficulty( netuid, - Self::adjust_difficulty( + Self::upgraded_difficulty( netuid, current_difficulty, registrations_this_interval, @@ -490,10 +490,10 @@ impl Pallet { } } - // Performs the difficulty adjustment by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target * reg_target ) + // Calculates the upgraded difficulty by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target + reg_target ) // We use I110F18 to avoid any overflows on u64. Also min_difficulty and max_difficulty bound the range. // - pub fn adjust_difficulty( + pub fn upgraded_difficulty( netuid: u16, current_difficulty: u64, registrations_this_interval: u16, @@ -517,10 +517,10 @@ impl Pallet { } } - // Performs the burn adjustment by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target * reg_target ) + // Calculates the upgraded burn by multiplying the current burn by the ratio ( reg_actual + reg_target / reg_target + reg_target ) // We use I110F18 to avoid any overflows on u64. Also min_burn and max_burn bound the range. // - pub fn adjust_burn( + pub fn upgraded_burn( netuid: u16, current_burn: u64, registrations_this_interval: u16, diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 0b9b7f3800..9444e9fe74 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -982,6 +982,7 @@ pub mod pallet { StakeTooLowForRoot, // --- Thrown when a hotkey attempts to join the root subnet with too little stake AllNetworksInImmunity, // --- Thrown when all subnets are in the immunity period NotEnoughBalance, + NoNeuronIdAvailable, // -- Thrown when no neuron id is available /// Thrown a stake would be below the minimum threshold for nominator validations NomStakeBelowMinimumThreshold, } diff --git a/pallets/subtensor/src/registration.rs b/pallets/subtensor/src/registration.rs index 5d91ec03c5..c26c9a8cbb 100644 --- a/pallets/subtensor/src/registration.rs +++ b/pallets/subtensor/src/registration.rs @@ -123,7 +123,7 @@ impl Pallet { // Possibly there is no neuron slots at all. ensure!( Self::get_max_allowed_uids(netuid) != 0, - Error::::NetworkDoesNotExist + Error::::NoNeuronIdAvailable ); if current_subnetwork_n < Self::get_max_allowed_uids(netuid) { @@ -315,7 +315,7 @@ impl Pallet { // Possibly there is no neuron slots at all. ensure!( Self::get_max_allowed_uids(netuid) != 0, - Error::::NetworkDoesNotExist + Error::::NoNeuronIdAvailable ); if current_subnetwork_n < Self::get_max_allowed_uids(netuid) { diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index 1ef3670db1..63ef2b9473 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -3,7 +3,7 @@ use frame_support::traits::Currency; use crate::mock::*; use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays}; use frame_support::sp_runtime::{transaction_validity::InvalidTransaction, DispatchError}; -use frame_support::{assert_err, assert_ok}; +use frame_support::{assert_err, assert_noop, assert_ok}; use frame_system::Config; use pallet_subtensor::{AxonInfoOf, Error, SubtensorSignedExtension}; use sp_core::U256; @@ -154,6 +154,40 @@ fn test_registration_ok() { }); } +#[test] +fn test_registration_without_neuron_slot() { + new_test_ext(1).execute_with(|| { + let block_number: u64 = 0; + let netuid: u16 = 1; + let tempo: u16 = 13; + let hotkey_account_id: U256 = U256::from(1); + let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har + let (nonce, work): (u64, Vec) = SubtensorModule::create_work_for_block_number( + netuid, + block_number, + 129123813, + &hotkey_account_id, + ); + + //add network + add_network(netuid, tempo, 0); + SubtensorModule::set_max_allowed_uids(netuid, 0); + + assert_noop!( + SubtensorModule::register( + <::RuntimeOrigin>::signed(hotkey_account_id), + netuid, + block_number, + nonce, + work, + hotkey_account_id, + coldkey_account_id + ), + Error::::NoNeuronIdAvailable + ); + }); +} + #[test] fn test_registration_under_limit() { new_test_ext(1).execute_with(|| { @@ -382,6 +416,32 @@ fn test_burned_registration_ok() { }); } +#[test] +fn test_burn_registration_without_neuron_slot() { + new_test_ext(1).execute_with(|| { + let netuid: u16 = 1; + let tempo: u16 = 13; + let hotkey_account_id = U256::from(1); + let burn_cost = 1000; + let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har + //add network + SubtensorModule::set_burn(netuid, burn_cost); + add_network(netuid, tempo, 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); + + assert_noop!( + SubtensorModule::burned_register( + <::RuntimeOrigin>::signed(coldkey_account_id), + netuid, + hotkey_account_id + ), + Error::::NoNeuronIdAvailable + ); + }); +} + #[test] fn test_burn_adjustment() { new_test_ext(1).execute_with(|| {