Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct a comment and an error #358

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pallets/subtensor/src/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<T: Config> Pallet<T> {
// pow_difficulty ++
Self::set_difficulty(
netuid,
Self::adjust_difficulty(
Self::upgraded_difficulty(
netuid,
current_difficulty,
registrations_this_interval,
Expand All @@ -391,7 +391,7 @@ impl<T: Config> Pallet<T> {
// burn_cost ++
Self::set_burn(
netuid,
Self::adjust_burn(
Self::upgraded_burn(
netuid,
current_burn,
registrations_this_interval,
Expand All @@ -404,7 +404,7 @@ impl<T: Config> Pallet<T> {
// burn_cost ++
Self::set_burn(
netuid,
Self::adjust_burn(
Self::upgraded_burn(
netuid,
current_burn,
registrations_this_interval,
Expand All @@ -414,7 +414,7 @@ impl<T: Config> Pallet<T> {
// pow_difficulty ++
Self::set_difficulty(
netuid,
Self::adjust_difficulty(
Self::upgraded_difficulty(
netuid,
current_difficulty,
registrations_this_interval,
Expand All @@ -430,7 +430,7 @@ impl<T: Config> Pallet<T> {
// burn_cost --
Self::set_burn(
netuid,
Self::adjust_burn(
Self::upgraded_burn(
netuid,
current_burn,
registrations_this_interval,
Expand All @@ -443,7 +443,7 @@ impl<T: Config> Pallet<T> {
// pow_difficulty --
Self::set_difficulty(
netuid,
Self::adjust_difficulty(
Self::upgraded_difficulty(
netuid,
current_difficulty,
registrations_this_interval,
Expand All @@ -456,7 +456,7 @@ impl<T: Config> Pallet<T> {
// burn_cost --
Self::set_burn(
netuid,
Self::adjust_burn(
Self::upgraded_burn(
netuid,
current_burn,
registrations_this_interval,
Expand All @@ -466,7 +466,7 @@ impl<T: Config> Pallet<T> {
// pow_difficulty --
Self::set_difficulty(
netuid,
Self::adjust_difficulty(
Self::upgraded_difficulty(
netuid,
current_difficulty,
registrations_this_interval,
Expand All @@ -490,10 +490,10 @@ impl<T: Config> Pallet<T> {
}
}

// 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,
Expand All @@ -517,10 +517,10 @@ impl<T: Config> Pallet<T> {
}
}

// 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,
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<T: Config> Pallet<T> {
// Possibly there is no neuron slots at all.
ensure!(
Self::get_max_allowed_uids(netuid) != 0,
Error::<T>::NetworkDoesNotExist
Error::<T>::NoNeuronIdAvailable
);

if current_subnetwork_n < Self::get_max_allowed_uids(netuid) {
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<T: Config> Pallet<T> {
// Possibly there is no neuron slots at all.
ensure!(
Self::get_max_allowed_uids(netuid) != 0,
Error::<T>::NetworkDoesNotExist
Error::<T>::NoNeuronIdAvailable
);

if current_subnetwork_n < Self::get_max_allowed_uids(netuid) {
Expand Down
62 changes: 61 additions & 1 deletion pallets/subtensor/tests/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<u8>) = 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(
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id),
netuid,
block_number,
nonce,
work,
hotkey_account_id,
coldkey_account_id
),
Error::<Test>::NoNeuronIdAvailable
);
});
}

#[test]
fn test_registration_under_limit() {
new_test_ext(1).execute_with(|| {
Expand Down Expand Up @@ -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(
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
netuid,
hotkey_account_id
),
Error::<Test>::NoNeuronIdAvailable
);
});
}

#[test]
fn test_burn_adjustment() {
new_test_ext(1).execute_with(|| {
Expand Down
Loading