From cc05df521d1f120c1e2766c3251b7923f990cd7f Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 2 Jul 2025 12:36:12 -0500 Subject: [PATCH 1/2] Revert "fix owner disable registration" --- pallets/admin-utils/src/lib.rs | 5 +- pallets/admin-utils/src/tests/mod.rs | 64 ------------------- pallets/subtensor/src/lib.rs | 2 +- pallets/subtensor/src/macros/hooks.rs | 4 +- .../migrate_set_registration_enable.rs | 59 ----------------- pallets/subtensor/src/migrations/mod.rs | 1 - pallets/subtensor/src/subnets/subnet.rs | 8 +-- pallets/subtensor/src/tests/migration.rs | 46 ------------- pallets/subtensor/src/tests/subnet.rs | 16 ----- runtime/src/lib.rs | 2 +- 10 files changed, 8 insertions(+), 199 deletions(-) delete mode 100644 pallets/subtensor/src/migrations/migrate_set_registration_enable.rs diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 752b834c48..2968bd7728 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -605,7 +605,8 @@ pub mod pallet { netuid: NetUid, registration_allowed: bool, ) -> DispatchResult { - ensure_root(origin)?; + pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; + pallet_subtensor::Pallet::::set_network_registration_allowed( netuid, registration_allowed, @@ -632,7 +633,7 @@ pub mod pallet { netuid: NetUid, registration_allowed: bool, ) -> DispatchResult { - ensure_root(origin)?; + pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; pallet_subtensor::Pallet::::set_network_pow_registration_allowed( netuid, diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index cfac6310bf..260dc9f7c3 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -983,8 +983,6 @@ fn test_sudo_set_network_pow_registration_allowed() { let to_be_set: bool = true; add_network(netuid, 10); - let owner = SubtensorModule::get_subnet_owner(netuid); - let init_value: bool = SubtensorModule::get_network_pow_registration_allowed(netuid); assert_eq!( AdminUtils::sudo_set_network_pow_registration_allowed( @@ -998,20 +996,6 @@ fn test_sudo_set_network_pow_registration_allowed() { SubtensorModule::get_network_pow_registration_allowed(netuid), init_value ); - - assert_eq!( - AdminUtils::sudo_set_network_pow_registration_allowed( - <::RuntimeOrigin>::signed(owner), - netuid, - to_be_set - ), - Err(DispatchError::BadOrigin) - ); - assert_eq!( - SubtensorModule::get_network_pow_registration_allowed(netuid), - init_value - ); - assert_ok!(AdminUtils::sudo_set_network_pow_registration_allowed( <::RuntimeOrigin>::root(), netuid, @@ -1024,54 +1008,6 @@ fn test_sudo_set_network_pow_registration_allowed() { }); } -#[test] -fn test_sudo_set_network_registration_allowed() { - new_test_ext().execute_with(|| { - let netuid = NetUid::from(1); - let to_be_set: bool = true; - add_network(netuid, 10); - - let owner = SubtensorModule::get_subnet_owner(netuid); - - let init_value: bool = SubtensorModule::get_network_registration_allowed(netuid); - assert_eq!( - AdminUtils::sudo_set_network_registration_allowed( - <::RuntimeOrigin>::signed(U256::from(1)), - netuid, - to_be_set - ), - Err(DispatchError::BadOrigin) - ); - assert_eq!( - SubtensorModule::get_network_registration_allowed(netuid), - init_value - ); - - assert_eq!( - AdminUtils::sudo_set_network_registration_allowed( - <::RuntimeOrigin>::signed(owner), - netuid, - to_be_set - ), - Err(DispatchError::BadOrigin) - ); - assert_eq!( - SubtensorModule::get_network_registration_allowed(netuid), - init_value - ); - - assert_ok!(AdminUtils::sudo_set_network_registration_allowed( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - )); - assert_eq!( - SubtensorModule::get_network_registration_allowed(netuid), - to_be_set - ); - }); -} - mod sudo_set_nominator_min_required_stake { use super::*; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index e3d29175fa..dbd91fe25e 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -502,7 +502,7 @@ pub mod pallet { #[pallet::type_value] /// Default value for registration allowed. pub fn DefaultRegistrationAllowed() -> bool { - true + false } #[pallet::type_value] /// Default value for network registered at. diff --git a/pallets/subtensor/src/macros/hooks.rs b/pallets/subtensor/src/macros/hooks.rs index f067497efb..1f75abc01f 100644 --- a/pallets/subtensor/src/macros/hooks.rs +++ b/pallets/subtensor/src/macros/hooks.rs @@ -121,9 +121,7 @@ mod hooks { // Migrate ColdkeySwapScheduled structure to new format .saturating_add(migrations::migrate_coldkey_swap_scheduled::migrate_coldkey_swap_scheduled::()) // Fix the root subnet TAO storage value - .saturating_add(migrations::migrate_fix_root_subnet_tao::migrate_fix_root_subnet_tao::()) - // Fix the owner disable the registration - .saturating_add(migrations::migrate_set_registration_enable::migrate_set_registration_enable::()); + .saturating_add(migrations::migrate_fix_root_subnet_tao::migrate_fix_root_subnet_tao::()); weight } diff --git a/pallets/subtensor/src/migrations/migrate_set_registration_enable.rs b/pallets/subtensor/src/migrations/migrate_set_registration_enable.rs deleted file mode 100644 index d066ed6b74..0000000000 --- a/pallets/subtensor/src/migrations/migrate_set_registration_enable.rs +++ /dev/null @@ -1,59 +0,0 @@ -use alloc::string::String; - -use frame_support::IterableStorageMap; -use frame_support::{traits::Get, weights::Weight}; - -use super::*; - -pub fn migrate_set_registration_enable() -> Weight { - let migration_name = b"migrate_set_registration_enable".to_vec(); - - // Initialize the weight with one read operation. - let mut weight = T::DbWeight::get().reads(1); - - // Check if the migration has already run - if HasMigrationRun::::get(&migration_name) { - log::info!( - "Migration '{:?}' has already run. Skipping.", - String::from_utf8_lossy(&migration_name) - ); - return weight; - } - log::info!( - "Running migration '{}'", - String::from_utf8_lossy(&migration_name) - ); - - let netuids: Vec = as IterableStorageMap>::iter() - .map(|(netuid, _)| netuid) - .collect(); - weight = weight.saturating_add(T::DbWeight::get().reads(netuids.len() as u64)); - - for netuid in netuids.iter() { - if netuid.is_root() { - continue; - } - - if !Pallet::::get_network_pow_registration_allowed(*netuid) { - Pallet::::set_network_pow_registration_allowed(*netuid, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - - if !Pallet::::get_network_registration_allowed(*netuid) { - Pallet::::set_network_registration_allowed(*netuid, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - } - } - - // Mark the migration as completed - HasMigrationRun::::insert(&migration_name, true); - weight = weight.saturating_add(T::DbWeight::get().writes(1)); - - log::info!( - "Migration '{:?}' completed.", - String::from_utf8_lossy(&migration_name) - ); - - // Return the migration weight. - weight -} diff --git a/pallets/subtensor/src/migrations/mod.rs b/pallets/subtensor/src/migrations/mod.rs index 5a6b1094e2..35da283800 100644 --- a/pallets/subtensor/src/migrations/mod.rs +++ b/pallets/subtensor/src/migrations/mod.rs @@ -27,7 +27,6 @@ pub mod migrate_reset_max_burn; pub mod migrate_set_first_emission_block_number; pub mod migrate_set_min_burn; pub mod migrate_set_min_difficulty; -pub mod migrate_set_registration_enable; pub mod migrate_set_subtoken_enabled; pub mod migrate_stake_threshold; pub mod migrate_subnet_identities_to_v3; diff --git a/pallets/subtensor/src/subnets/subnet.rs b/pallets/subtensor/src/subnets/subnet.rs index dd8eeddcb0..70855c69a1 100644 --- a/pallets/subtensor/src/subnets/subnet.rs +++ b/pallets/subtensor/src/subnets/subnet.rs @@ -220,11 +220,7 @@ impl Pallet { Self::deposit_event(Event::SubnetIdentitySet(netuid_to_register)); } - // --- 16. Enable registration for new subnet - NetworkRegistrationAllowed::::set(netuid_to_register, true); - NetworkPowRegistrationAllowed::::set(netuid_to_register, true); - - // --- 17. Emit the NetworkAdded event. + // --- 16. Emit the NetworkAdded event. log::info!( "NetworkAdded( netuid:{:?}, mechanism:{:?} )", netuid_to_register, @@ -232,7 +228,7 @@ impl Pallet { ); Self::deposit_event(Event::NetworkAdded(netuid_to_register, mechid)); - // --- 18. Return success. + // --- 17. Return success. Ok(()) } diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 0e75a7cc92..c5cc8689cf 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -907,49 +907,3 @@ fn test_migrate_subnet_symbols() { assert!(!weight.is_zero(), "Migration weight should be non-zero"); }); } - -#[test] -fn test_migrate_set_registration_enable() { - new_test_ext(1).execute_with(|| { - const MIGRATION_NAME: &str = "migrate_set_registration_enable"; - - // Create 3 subnets - let netuids: [NetUid; 3] = [1.into(), 2.into(), 3.into()]; - for netuid in netuids.iter() { - add_network(*netuid, 1, 0); - // Set registration to false to simulate the need for migration - SubtensorModule::set_network_registration_allowed(*netuid, false); - SubtensorModule::set_network_pow_registration_allowed(*netuid, false); - } - - // Sanity check: registration is disabled before migration - for netuid in netuids.iter() { - assert!(!SubtensorModule::get_network_registration_allowed(*netuid)); - assert!(!SubtensorModule::get_network_pow_registration_allowed( - *netuid - )); - } - - // Run the migration - let weight = - crate::migrations::migrate_set_registration_enable::migrate_set_registration_enable::< - Test, - >(); - - // After migration, registration should be enabled for all subnets except root - for netuid in netuids.iter() { - assert!(SubtensorModule::get_network_registration_allowed(*netuid)); - assert!(SubtensorModule::get_network_pow_registration_allowed( - *netuid - )); - } - - // Migration should be marked as run - assert!(HasMigrationRun::::get( - MIGRATION_NAME.as_bytes().to_vec() - )); - - // Weight should be non-zero - assert!(!weight.is_zero(), "Migration weight should be non-zero"); - }); -} diff --git a/pallets/subtensor/src/tests/subnet.rs b/pallets/subtensor/src/tests/subnet.rs index e29018d80d..e9a29864fc 100644 --- a/pallets/subtensor/src/tests/subnet.rs +++ b/pallets/subtensor/src/tests/subnet.rs @@ -220,10 +220,6 @@ fn test_register_network_min_burn_at_default() { // Check min burn is set to default assert_eq!(MinBurn::::get(netuid), InitialMinBurn::get()); - - // Check registration allowed - assert!(NetworkRegistrationAllowed::::get(netuid)); - assert!(NetworkPowRegistrationAllowed::::get(netuid)); }); } @@ -249,10 +245,6 @@ fn test_register_network_use_symbol_for_subnet_if_available() { // Ensure the symbol correspond to the netuid has been set let expected_symbol = SYMBOLS.get(usize::from(u16::from(netuid))).unwrap(); assert_eq!(TokenSymbol::::get(netuid), *expected_symbol); - - // Check registration allowed - assert!(NetworkRegistrationAllowed::::get(netuid)); - assert!(NetworkPowRegistrationAllowed::::get(netuid)); } }); } @@ -280,10 +272,6 @@ fn test_register_network_use_next_available_symbol_if_symbol_for_subnet_is_taken // Ensure the symbol correspond to the netuid has been set let expected_symbol = SYMBOLS.get(usize::from(u16::from(netuid))).unwrap(); assert_eq!(TokenSymbol::::get(netuid), *expected_symbol); - - // Check registration allowed - assert!(NetworkRegistrationAllowed::::get(netuid)); - assert!(NetworkPowRegistrationAllowed::::get(netuid)); } // Swap some of the network symbol for the network 25 to network 51 symbol (not registered yet) @@ -348,10 +336,6 @@ fn test_register_network_use_default_symbol_if_all_symbols_are_taken() { // We expect the symbol to be the default symbol assert_eq!(TokenSymbol::::get(netuid), *DEFAULT_SYMBOL); - - // Check registration allowed - assert!(NetworkRegistrationAllowed::::get(netuid)); - assert!(NetworkPowRegistrationAllowed::::get(netuid)); }); } // cargo test --package pallet-subtensor --lib -- tests::subnet::test_subtoken_enable --exact --show-output diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 0d5d5fd04e..161287fdef 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -218,7 +218,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 287, + spec_version: 286, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 3ba5e30030b7f0e023ceada56c4fd31a00c58f4e Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Mon, 7 Jul 2025 12:09:14 -0300 Subject: [PATCH 2/2] bump spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6e244fce41..c2417cda5a 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -218,7 +218,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 289, + spec_version: 290, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,