From 99d9ba17f7f4c6c457b4abdbd0175f36fd7a69bc Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 23 Apr 2024 15:40:27 +0800 Subject: [PATCH 1/4] fix a wrong comment --- pallets/subtensor/src/block_step.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/block_step.rs b/pallets/subtensor/src/block_step.rs index b645db633..8f2c44c4a 100644 --- a/pallets/subtensor/src/block_step.rs +++ b/pallets/subtensor/src/block_step.rs @@ -517,7 +517,7 @@ impl Pallet { } } - // Performs the burn adjustment by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target * reg_target ) + // Performs the burn adjustment 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( From 198b93ec2fba789743678a1254c035e6c0fc0bda Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 23 Apr 2024 21:52:43 +0800 Subject: [PATCH 2/4] test case for new error --- pallets/subtensor/src/lib.rs | 1 + pallets/subtensor/src/registration.rs | 2 +- pallets/subtensor/tests/registration.rs | 29 ++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 11cb91277..980dc1b43 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -968,6 +968,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 } // ================== diff --git a/pallets/subtensor/src/registration.rs b/pallets/subtensor/src/registration.rs index c5d6b2e30..3392b8eb0 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) { diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index 1ef3670db..fab9edc2d 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; @@ -382,6 +382,33 @@ 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); + + // Subscribe and check extrinsic output + 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(|| { From 0d94a60464c71ff34d1dc8f9e21a10dcf38af569 Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 23 Apr 2024 21:56:45 +0800 Subject: [PATCH 3/4] add test cases --- pallets/subtensor/src/registration.rs | 2 +- pallets/subtensor/tests/registration.rs | 35 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pallets/subtensor/src/registration.rs b/pallets/subtensor/src/registration.rs index 3392b8eb0..8b2e71479 100644 --- a/pallets/subtensor/src/registration.rs +++ b/pallets/subtensor/src/registration.rs @@ -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 fab9edc2d..f1f8a3b09 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -154,6 +154,41 @@ 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); + + // Subscribe and check extrinsic output + 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(|| { From 95d92779582167e0702f57e369843f70fb464233 Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 23 Apr 2024 22:06:27 +0800 Subject: [PATCH 4/4] remove wrong comments --- pallets/subtensor/tests/registration.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index f1f8a3b09..63ef2b947 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -173,7 +173,6 @@ fn test_registration_without_neuron_slot() { add_network(netuid, tempo, 0); SubtensorModule::set_max_allowed_uids(netuid, 0); - // Subscribe and check extrinsic output assert_noop!( SubtensorModule::register( <::RuntimeOrigin>::signed(hotkey_account_id), @@ -432,7 +431,6 @@ fn test_burn_registration_without_neuron_slot() { SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000); SubtensorModule::set_max_allowed_uids(netuid, 0); - // Subscribe and check extrinsic output assert_noop!( SubtensorModule::burned_register( <::RuntimeOrigin>::signed(coldkey_account_id),