Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ specs/*.json

# Git merge/rebase artifacts
*.orig

# VSCode configuration
.vscode
12 changes: 11 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ pub mod pallet {
#[pallet::storage] // --- MAP ( netuid ) --> network_registration_allowed
pub type NetworkRegistrationAllowed<T: Config> =
StorageMap<_, Identity, u16, bool, ValueQuery, DefaultRegistrationAllowed<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> network_pow_allowed
pub type NetworkPowRegistrationAllowed<T: Config> =
StorageMap<_, Identity, u16, bool, ValueQuery, DefaultRegistrationAllowed<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> block_created
pub type NetworkRegisteredAt<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultNetworkRegisteredAt<T>>;
Expand Down Expand Up @@ -844,6 +847,7 @@ pub mod pallet {
TxRateLimitSet(u64), // --- Event created when setting the transaction rate limit.
Sudid(DispatchResult), // --- Event created when a sudo call is done.
RegistrationAllowed(u16, bool), // --- Event created when registration is allowed/disallowed for a subnet.
PowRegistrationAllowed(u16, bool), // --- Event created when POW registration is allowed/disallowed for a subnet.
TempoSet(u16, u16), // --- Event created when setting tempo on a network
RAORecycledForRegistrationSet(u16, u64), // Event created when setting the RAO recycled for registration.
SenateRequiredStakePercentSet(u64), // Event created when setting the minimum required stake amount for senate registration.
Expand Down Expand Up @@ -2042,7 +2046,6 @@ pub mod pallet {
Ok(())
}


#[pallet::call_index(68)]
#[pallet::weight((Weight::from_ref_time(14_000_000)
.saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))]
Expand All @@ -2061,6 +2064,13 @@ pub mod pallet {

Ok(())
}

#[pallet::call_index(69)]
#[pallet::weight((Weight::from_ref_time(14_000_000)
.saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))]
pub fn sudo_set_network_pow_registration_allowed(origin: OriginFor<T>, netuid: u16, registration_allowed: bool) -> DispatchResult {
Self::do_sudo_set_network_pow_registration_allowed(origin, netuid, registration_allowed)
}
}

// ---- Subtensor helper functions.
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 @@ -131,7 +131,7 @@ impl<T: Config> Pallet<T> {

// --- 3. Ensure the passed network allows registrations.
ensure!(
Self::if_subnet_allows_registration(netuid),
Self::get_network_registration_allowed(netuid),
Error::<T>::RegistrationDisabled
);

Expand Down Expand Up @@ -317,7 +317,7 @@ impl<T: Config> Pallet<T> {

// --- 3. Ensure the passed network allows registrations.
ensure!(
Self::if_subnet_allows_registration(netuid),
Self::get_network_pow_registration_allowed(netuid),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there some idiomatic reason for this name change?
I thjink the previous one has a good naming, maybe something like.... Self::subnet_allows_registrations(netuid) which could fit with the context and its semantics. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if_subnet_allows_registration was a duplicate of another function which was already implemented.

Error::<T>::RegistrationDisabled
);

Expand Down
12 changes: 0 additions & 12 deletions pallets/subtensor/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ impl<T: Config> Pallet<T> {
return NetworksAdded::<T>::get(netuid);
}

// Returns true if the subnetwork allows registration.
//
//
// This function checks if a subnetwork allows registrations.
//
// # Returns:
// * 'bool': Whether the subnet allows registrations.
//
pub fn if_subnet_allows_registration(netuid: u16) -> bool {
return NetworkRegistrationAllowed::<T>::get(netuid);
}

// Returns a list of subnet netuid equal to total networks.
//
//
Expand Down
22 changes: 22 additions & 0 deletions pallets/subtensor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,28 @@ impl<T: Config> Pallet<T> {
Ok(())
}

pub fn get_network_pow_registration_allowed(netuid: u16) -> bool {
NetworkPowRegistrationAllowed::<T>::get(netuid)
}
pub fn set_network_pow_registration_allowed(netuid: u16, registration_allowed: bool) {
NetworkPowRegistrationAllowed::<T>::insert(netuid, registration_allowed)
}
pub fn do_sudo_set_network_pow_registration_allowed(
origin: T::RuntimeOrigin,
netuid: u16,
registration_allowed: bool,
) -> DispatchResult {
ensure_root(origin)?;

Self::set_network_pow_registration_allowed(netuid, registration_allowed);
log::info!(
"NetworkPowRegistrationAllowed( registration_allowed: {:?} ) ",
registration_allowed
);
Self::deposit_event(Event::PowRegistrationAllowed(netuid, registration_allowed));
Ok(())
}

pub fn get_target_registrations_per_interval(netuid: u16) -> u16 {
TargetRegistrationsPerInterval::<T>::get(netuid)
}
Expand Down
5 changes: 5 additions & 0 deletions pallets/subtensor/tests/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ fn test_burn_adjustment_case_a() {
add_network(netuid, tempo, 0);
SubtensorModule::set_burn(netuid, burn_cost);
SubtensorModule::set_difficulty(netuid, start_diff);
SubtensorModule::set_min_difficulty(netuid, start_diff);
SubtensorModule::set_adjustment_interval(netuid, adjustment_interval);
SubtensorModule::set_target_registrations_per_interval(
netuid,
Expand Down Expand Up @@ -538,6 +539,7 @@ fn test_burn_adjustment_case_d() {
add_network(netuid, tempo, 0);
SubtensorModule::set_burn(netuid, burn_cost);
SubtensorModule::set_difficulty(netuid, start_diff);
SubtensorModule::set_min_difficulty(netuid, 1);
SubtensorModule::set_adjustment_interval(netuid, adjustment_interval);
SubtensorModule::set_target_registrations_per_interval(
netuid,
Expand Down Expand Up @@ -620,6 +622,7 @@ fn test_burn_adjustment_case_e() {
SubtensorModule::set_max_registrations_per_block(netuid, 10);
SubtensorModule::set_burn(netuid, burn_cost);
SubtensorModule::set_difficulty(netuid, start_diff);
SubtensorModule::set_min_difficulty(netuid, 1);
SubtensorModule::set_adjustment_interval(netuid, adjustment_interval);
SubtensorModule::set_target_registrations_per_interval(
netuid,
Expand Down Expand Up @@ -693,6 +696,7 @@ fn test_burn_adjustment_case_f() {
SubtensorModule::set_max_registrations_per_block(netuid, 10);
SubtensorModule::set_burn(netuid, burn_cost);
SubtensorModule::set_difficulty(netuid, start_diff);
SubtensorModule::set_min_difficulty(netuid, start_diff);
SubtensorModule::set_adjustment_interval(netuid, adjustment_interval);
SubtensorModule::set_target_registrations_per_interval(
netuid,
Expand Down Expand Up @@ -765,6 +769,7 @@ fn test_burn_adjustment_case_e_zero_registrations() {
SubtensorModule::set_max_registrations_per_block(netuid, 10);
SubtensorModule::set_burn(netuid, burn_cost);
SubtensorModule::set_difficulty(netuid, start_diff);
SubtensorModule::set_min_difficulty(netuid, 1);
SubtensorModule::set_adjustment_interval(netuid, adjustment_interval);
SubtensorModule::set_target_registrations_per_interval(
netuid,
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/tests/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn test_registration_difficulty_adjustment() {
let tempo: u16 = 1;
let modality: u16 = 1;
add_network(netuid, tempo, modality);
SubtensorModule::set_min_difficulty(netuid, 10000);
assert_eq!(SubtensorModule::get_difficulty_as_u64(netuid), 10000); // Check initial difficulty.
assert_eq!(SubtensorModule::get_last_adjustment_block(netuid), 0); // Last adjustment block starts at 0.
assert_eq!(SubtensorModule::get_registrations_this_block(netuid), 0); // No registrations this block.
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,5 @@ pub fn register_ok_neuron(
pub fn add_network(netuid: u16, tempo: u16, modality: u16) {
SubtensorModule::init_new_network(netuid, tempo);
SubtensorModule::set_network_registration_allowed(netuid, true);
SubtensorModule::set_network_pow_registration_allowed(netuid, true);
}
1 change: 1 addition & 0 deletions pallets/subtensor/tests/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ fn test_registration_disabled() {
//add network
add_network(netuid, tempo, 0);
SubtensorModule::set_network_registration_allowed(netuid, false);
SubtensorModule::set_network_pow_registration_allowed(netuid, false);

let result = SubtensorModule::register(
<<Test as Config>::RuntimeOrigin>::signed(hotkey_account_id),
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/tests/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ fn test_root_set_weights() {
299_999_997
);
}
let step = SubtensorModule::blocks_until_next_epoch(9, 1000, SubtensorModule::get_current_block_as_u64());
let step = SubtensorModule::blocks_until_next_epoch(10, 1000, SubtensorModule::get_current_block_as_u64());
step_block(step as u16);
assert_eq!(SubtensorModule::get_pending_emission(9), 0);
assert_eq!(SubtensorModule::get_pending_emission(10), 0);
});
}

Expand Down
32 changes: 32 additions & 0 deletions pallets/subtensor/tests/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,4 +1166,36 @@ fn test_sudo_set_network_lock_reduction_interval() {
to_be_set
);
});
}

#[test]
fn test_sudo_set_network_pow_registration_allowed() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
let to_be_set: bool = true;
add_network(netuid, 10, 0);

let init_value: bool = SubtensorModule::get_network_pow_registration_allowed(netuid);
assert_eq!(
SubtensorModule::sudo_set_network_pow_registration_allowed(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
netuid,
to_be_set
),
Err(DispatchError::BadOrigin.into())
);
assert_eq!(
SubtensorModule::get_network_pow_registration_allowed(netuid),
init_value
);
assert_ok!(SubtensorModule::sudo_set_network_pow_registration_allowed(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
));
assert_eq!(
SubtensorModule::get_network_pow_registration_allowed(netuid),
to_be_set
);
});
}