Skip to content

Commit d44ea6e

Browse files
authored
Merge pull request #358 from opentensor/fix-wrong-comments
Correct a comment and an error
2 parents a224692 + bd99247 commit d44ea6e

File tree

4 files changed

+76
-15
lines changed

4 files changed

+76
-15
lines changed

pallets/subtensor/src/block_step.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<T: Config> Pallet<T> {
378378
// pow_difficulty ++
379379
Self::set_difficulty(
380380
netuid,
381-
Self::adjust_difficulty(
381+
Self::upgraded_difficulty(
382382
netuid,
383383
current_difficulty,
384384
registrations_this_interval,
@@ -391,7 +391,7 @@ impl<T: Config> Pallet<T> {
391391
// burn_cost ++
392392
Self::set_burn(
393393
netuid,
394-
Self::adjust_burn(
394+
Self::upgraded_burn(
395395
netuid,
396396
current_burn,
397397
registrations_this_interval,
@@ -404,7 +404,7 @@ impl<T: Config> Pallet<T> {
404404
// burn_cost ++
405405
Self::set_burn(
406406
netuid,
407-
Self::adjust_burn(
407+
Self::upgraded_burn(
408408
netuid,
409409
current_burn,
410410
registrations_this_interval,
@@ -414,7 +414,7 @@ impl<T: Config> Pallet<T> {
414414
// pow_difficulty ++
415415
Self::set_difficulty(
416416
netuid,
417-
Self::adjust_difficulty(
417+
Self::upgraded_difficulty(
418418
netuid,
419419
current_difficulty,
420420
registrations_this_interval,
@@ -430,7 +430,7 @@ impl<T: Config> Pallet<T> {
430430
// burn_cost --
431431
Self::set_burn(
432432
netuid,
433-
Self::adjust_burn(
433+
Self::upgraded_burn(
434434
netuid,
435435
current_burn,
436436
registrations_this_interval,
@@ -443,7 +443,7 @@ impl<T: Config> Pallet<T> {
443443
// pow_difficulty --
444444
Self::set_difficulty(
445445
netuid,
446-
Self::adjust_difficulty(
446+
Self::upgraded_difficulty(
447447
netuid,
448448
current_difficulty,
449449
registrations_this_interval,
@@ -456,7 +456,7 @@ impl<T: Config> Pallet<T> {
456456
// burn_cost --
457457
Self::set_burn(
458458
netuid,
459-
Self::adjust_burn(
459+
Self::upgraded_burn(
460460
netuid,
461461
current_burn,
462462
registrations_this_interval,
@@ -466,7 +466,7 @@ impl<T: Config> Pallet<T> {
466466
// pow_difficulty --
467467
Self::set_difficulty(
468468
netuid,
469-
Self::adjust_difficulty(
469+
Self::upgraded_difficulty(
470470
netuid,
471471
current_difficulty,
472472
registrations_this_interval,
@@ -490,10 +490,10 @@ impl<T: Config> Pallet<T> {
490490
}
491491
}
492492

493-
// Performs the difficulty adjustment by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target * reg_target )
493+
// Calculates the upgraded difficulty by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target + reg_target )
494494
// We use I110F18 to avoid any overflows on u64. Also min_difficulty and max_difficulty bound the range.
495495
//
496-
pub fn adjust_difficulty(
496+
pub fn upgraded_difficulty(
497497
netuid: u16,
498498
current_difficulty: u64,
499499
registrations_this_interval: u16,
@@ -517,10 +517,10 @@ impl<T: Config> Pallet<T> {
517517
}
518518
}
519519

520-
// Performs the burn adjustment by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target * reg_target )
520+
// Calculates the upgraded burn by multiplying the current burn by the ratio ( reg_actual + reg_target / reg_target + reg_target )
521521
// We use I110F18 to avoid any overflows on u64. Also min_burn and max_burn bound the range.
522522
//
523-
pub fn adjust_burn(
523+
pub fn upgraded_burn(
524524
netuid: u16,
525525
current_burn: u64,
526526
registrations_this_interval: u16,

pallets/subtensor/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ pub mod pallet {
982982
StakeTooLowForRoot, // --- Thrown when a hotkey attempts to join the root subnet with too little stake
983983
AllNetworksInImmunity, // --- Thrown when all subnets are in the immunity period
984984
NotEnoughBalance,
985+
NoNeuronIdAvailable, // -- Thrown when no neuron id is available
985986
/// Thrown a stake would be below the minimum threshold for nominator validations
986987
NomStakeBelowMinimumThreshold,
987988
}

pallets/subtensor/src/registration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<T: Config> Pallet<T> {
123123
// Possibly there is no neuron slots at all.
124124
ensure!(
125125
Self::get_max_allowed_uids(netuid) != 0,
126-
Error::<T>::NetworkDoesNotExist
126+
Error::<T>::NoNeuronIdAvailable
127127
);
128128

129129
if current_subnetwork_n < Self::get_max_allowed_uids(netuid) {
@@ -315,7 +315,7 @@ impl<T: Config> Pallet<T> {
315315
// Possibly there is no neuron slots at all.
316316
ensure!(
317317
Self::get_max_allowed_uids(netuid) != 0,
318-
Error::<T>::NetworkDoesNotExist
318+
Error::<T>::NoNeuronIdAvailable
319319
);
320320

321321
if current_subnetwork_n < Self::get_max_allowed_uids(netuid) {

pallets/subtensor/tests/registration.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use frame_support::traits::Currency;
33
use crate::mock::*;
44
use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays};
55
use frame_support::sp_runtime::{transaction_validity::InvalidTransaction, DispatchError};
6-
use frame_support::{assert_err, assert_ok};
6+
use frame_support::{assert_err, assert_noop, assert_ok};
77
use frame_system::Config;
88
use pallet_subtensor::{AxonInfoOf, Error, SubtensorSignedExtension};
99
use sp_core::U256;
@@ -154,6 +154,40 @@ fn test_registration_ok() {
154154
});
155155
}
156156

157+
#[test]
158+
fn test_registration_without_neuron_slot() {
159+
new_test_ext(1).execute_with(|| {
160+
let block_number: u64 = 0;
161+
let netuid: u16 = 1;
162+
let tempo: u16 = 13;
163+
let hotkey_account_id: U256 = U256::from(1);
164+
let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har
165+
let (nonce, work): (u64, Vec<u8>) = SubtensorModule::create_work_for_block_number(
166+
netuid,
167+
block_number,
168+
129123813,
169+
&hotkey_account_id,
170+
);
171+
172+
//add network
173+
add_network(netuid, tempo, 0);
174+
SubtensorModule::set_max_allowed_uids(netuid, 0);
175+
176+
assert_noop!(
177+
SubtensorModule::register(
178+
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id),
179+
netuid,
180+
block_number,
181+
nonce,
182+
work,
183+
hotkey_account_id,
184+
coldkey_account_id
185+
),
186+
Error::<Test>::NoNeuronIdAvailable
187+
);
188+
});
189+
}
190+
157191
#[test]
158192
fn test_registration_under_limit() {
159193
new_test_ext(1).execute_with(|| {
@@ -382,6 +416,32 @@ fn test_burned_registration_ok() {
382416
});
383417
}
384418

419+
#[test]
420+
fn test_burn_registration_without_neuron_slot() {
421+
new_test_ext(1).execute_with(|| {
422+
let netuid: u16 = 1;
423+
let tempo: u16 = 13;
424+
let hotkey_account_id = U256::from(1);
425+
let burn_cost = 1000;
426+
let coldkey_account_id = U256::from(667); // Neighbour of the beast, har har
427+
//add network
428+
SubtensorModule::set_burn(netuid, burn_cost);
429+
add_network(netuid, tempo, 0);
430+
// Give it some $$$ in his coldkey balance
431+
SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, 10000);
432+
SubtensorModule::set_max_allowed_uids(netuid, 0);
433+
434+
assert_noop!(
435+
SubtensorModule::burned_register(
436+
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
437+
netuid,
438+
hotkey_account_id
439+
),
440+
Error::<Test>::NoNeuronIdAvailable
441+
);
442+
});
443+
}
444+
385445
#[test]
386446
fn test_burn_adjustment() {
387447
new_test_ext(1).execute_with(|| {

0 commit comments

Comments
 (0)