diff --git a/.gitignore b/.gitignore index f90ee8f6bf..6866ee9af9 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ specs/*.json # Git merge/rebase artifacts *.orig + +# VSCode configuration +.vscode \ No newline at end of file diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index c6ba68e67a..cecf28659e 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -417,6 +417,9 @@ pub mod pallet { #[pallet::storage] // --- MAP ( netuid ) --> network_registration_allowed pub type NetworkRegistrationAllowed = StorageMap<_, Identity, u16, bool, ValueQuery, DefaultRegistrationAllowed>; + #[pallet::storage] // --- MAP ( netuid ) --> network_pow_allowed + pub type NetworkPowRegistrationAllowed = + StorageMap<_, Identity, u16, bool, ValueQuery, DefaultRegistrationAllowed>; #[pallet::storage] // --- MAP ( netuid ) --> block_created pub type NetworkRegisteredAt = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultNetworkRegisteredAt>; @@ -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. @@ -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))] @@ -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, netuid: u16, registration_allowed: bool) -> DispatchResult { + Self::do_sudo_set_network_pow_registration_allowed(origin, netuid, registration_allowed) + } } // ---- Subtensor helper functions. diff --git a/pallets/subtensor/src/registration.rs b/pallets/subtensor/src/registration.rs index 21c1ca1d22..f8f1664122 100644 --- a/pallets/subtensor/src/registration.rs +++ b/pallets/subtensor/src/registration.rs @@ -131,7 +131,7 @@ impl Pallet { // --- 3. Ensure the passed network allows registrations. ensure!( - Self::if_subnet_allows_registration(netuid), + Self::get_network_registration_allowed(netuid), Error::::RegistrationDisabled ); @@ -317,7 +317,7 @@ impl Pallet { // --- 3. Ensure the passed network allows registrations. ensure!( - Self::if_subnet_allows_registration(netuid), + Self::get_network_pow_registration_allowed(netuid), Error::::RegistrationDisabled ); diff --git a/pallets/subtensor/src/root.rs b/pallets/subtensor/src/root.rs index 2640c11101..801f2fda00 100644 --- a/pallets/subtensor/src/root.rs +++ b/pallets/subtensor/src/root.rs @@ -104,18 +104,6 @@ impl Pallet { return NetworksAdded::::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::::get(netuid); - } - // Returns a list of subnet netuid equal to total networks. // // diff --git a/pallets/subtensor/src/utils.rs b/pallets/subtensor/src/utils.rs index 12f043d357..f4fe9326a1 100644 --- a/pallets/subtensor/src/utils.rs +++ b/pallets/subtensor/src/utils.rs @@ -773,6 +773,28 @@ impl Pallet { Ok(()) } + pub fn get_network_pow_registration_allowed(netuid: u16) -> bool { + NetworkPowRegistrationAllowed::::get(netuid) + } + pub fn set_network_pow_registration_allowed(netuid: u16, registration_allowed: bool) { + NetworkPowRegistrationAllowed::::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::::get(netuid) } diff --git a/pallets/subtensor/tests/block_step.rs b/pallets/subtensor/tests/block_step.rs index 3081da5f10..837c9dbf0d 100644 --- a/pallets/subtensor/tests/block_step.rs +++ b/pallets/subtensor/tests/block_step.rs @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/pallets/subtensor/tests/difficulty.rs b/pallets/subtensor/tests/difficulty.rs index a64d722f95..45d3e6a05f 100644 --- a/pallets/subtensor/tests/difficulty.rs +++ b/pallets/subtensor/tests/difficulty.rs @@ -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. diff --git a/pallets/subtensor/tests/mock.rs b/pallets/subtensor/tests/mock.rs index fc756a0f76..db50f03d09 100644 --- a/pallets/subtensor/tests/mock.rs +++ b/pallets/subtensor/tests/mock.rs @@ -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); } diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index 75b408eef2..e1a672b107 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -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( <::RuntimeOrigin>::signed(hotkey_account_id), diff --git a/pallets/subtensor/tests/root.rs b/pallets/subtensor/tests/root.rs index 75cddec34f..ad7e0c9e78 100644 --- a/pallets/subtensor/tests/root.rs +++ b/pallets/subtensor/tests/root.rs @@ -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); }); } diff --git a/pallets/subtensor/tests/sudo.rs b/pallets/subtensor/tests/sudo.rs index fe4c9dee9f..9d8fd12f66 100644 --- a/pallets/subtensor/tests/sudo.rs +++ b/pallets/subtensor/tests/sudo.rs @@ -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( + <::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( + <::RuntimeOrigin>::root(), + netuid, + to_be_set + )); + assert_eq!( + SubtensorModule::get_network_pow_registration_allowed(netuid), + to_be_set + ); + }); } \ No newline at end of file