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
5 changes: 2 additions & 3 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,7 @@ pub mod pallet {
netuid: NetUid,
registration_allowed: bool,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;

ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::set_network_registration_allowed(
netuid,
registration_allowed,
Expand All @@ -633,7 +632,7 @@ pub mod pallet {
netuid: NetUid,
registration_allowed: bool,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

revert this

ensure_root(origin)?;

pallet_subtensor::Pallet::<T>::set_network_pow_registration_allowed(
netuid,
Expand Down
64 changes: 64 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,8 @@ 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(
Expand All @@ -996,6 +998,20 @@ 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(
<<Test as Config>::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(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
Expand All @@ -1008,6 +1024,54 @@ 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(
<<Test as Config>::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(
<<Test as Config>::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(
<<Test as Config>::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::*;

Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ pub mod pallet {
#[pallet::type_value]
/// Default value for registration allowed.
pub fn DefaultRegistrationAllowed<T: Config>() -> bool {
false
true
}
#[pallet::type_value]
/// Default value for network registered at.
Expand Down
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ mod hooks {
// Migrate ColdkeySwapScheduled structure to new format
.saturating_add(migrations::migrate_coldkey_swap_scheduled::migrate_coldkey_swap_scheduled::<T>())
// Fix the root subnet TAO storage value
.saturating_add(migrations::migrate_fix_root_subnet_tao::migrate_fix_root_subnet_tao::<T>());
.saturating_add(migrations::migrate_fix_root_subnet_tao::migrate_fix_root_subnet_tao::<T>())
// Fix the owner disable the registration
.saturating_add(migrations::migrate_set_registration_enable::migrate_set_registration_enable::<T>());
weight
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use alloc::string::String;

use frame_support::IterableStorageMap;
use frame_support::{traits::Get, weights::Weight};

use super::*;

pub fn migrate_set_registration_enable<T: Config>() -> 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::<T>::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<NetUid> = <NetworksAdded<T> as IterableStorageMap<NetUid, bool>>::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::<T>::get_network_pow_registration_allowed(*netuid) {
Pallet::<T>::set_network_pow_registration_allowed(*netuid, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));
}
Comment on lines +37 to +40
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this


if !Pallet::<T>::get_network_registration_allowed(*netuid) {
Pallet::<T>::set_network_registration_allowed(*netuid, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));
}
}

// Mark the migration as completed
HasMigrationRun::<T>::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
}
1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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;
Expand Down
8 changes: 6 additions & 2 deletions pallets/subtensor/src/subnets/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,19 @@ impl<T: Config> Pallet<T> {
Self::deposit_event(Event::SubnetIdentitySet(netuid_to_register));
}

// --- 16. Emit the NetworkAdded event.
// --- 16. Enable registration for new subnet
NetworkRegistrationAllowed::<T>::set(netuid_to_register, true);
NetworkPowRegistrationAllowed::<T>::set(netuid_to_register, true);

// --- 17. Emit the NetworkAdded event.
log::info!(
"NetworkAdded( netuid:{:?}, mechanism:{:?} )",
netuid_to_register,
mechid
);
Self::deposit_event(Event::NetworkAdded(netuid_to_register, mechid));

// --- 17. Return success.
// --- 18. Return success.
Ok(())
}

Expand Down
46 changes: 46 additions & 0 deletions pallets/subtensor/src/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,3 +907,49 @@ 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::<Test>::get(
MIGRATION_NAME.as_bytes().to_vec()
));

// Weight should be non-zero
assert!(!weight.is_zero(), "Migration weight should be non-zero");
});
}
16 changes: 16 additions & 0 deletions pallets/subtensor/src/tests/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ fn test_register_network_min_burn_at_default() {

// Check min burn is set to default
assert_eq!(MinBurn::<Test>::get(netuid), InitialMinBurn::get());

// Check registration allowed
assert!(NetworkRegistrationAllowed::<Test>::get(netuid));
assert!(NetworkPowRegistrationAllowed::<Test>::get(netuid));
});
}

Expand All @@ -245,6 +249,10 @@ 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::<Test>::get(netuid), *expected_symbol);

// Check registration allowed
assert!(NetworkRegistrationAllowed::<Test>::get(netuid));
assert!(NetworkPowRegistrationAllowed::<Test>::get(netuid));
}
});
}
Expand Down Expand Up @@ -272,6 +280,10 @@ 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::<Test>::get(netuid), *expected_symbol);

// Check registration allowed
assert!(NetworkRegistrationAllowed::<Test>::get(netuid));
assert!(NetworkPowRegistrationAllowed::<Test>::get(netuid));
}

// Swap some of the network symbol for the network 25 to network 51 symbol (not registered yet)
Expand Down Expand Up @@ -336,6 +348,10 @@ fn test_register_network_use_default_symbol_if_all_symbols_are_taken() {

// We expect the symbol to be the default symbol
assert_eq!(TokenSymbol::<Test>::get(netuid), *DEFAULT_SYMBOL);

// Check registration allowed
assert!(NetworkRegistrationAllowed::<Test>::get(netuid));
assert!(NetworkPowRegistrationAllowed::<Test>::get(netuid));
});
}
// cargo test --package pallet-subtensor --lib -- tests::subnet::test_subtoken_enable --exact --show-output
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: 286,
spec_version: 287,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading