@@ -4356,3 +4356,140 @@ fn test_root_children_enable_subnet_owner_set_weights() {
43564356 ) ) ;
43574357 } ) ;
43584358}
4359+
4360+ // Test that register_network automatically schedules root validators as parents of the
4361+ // subnet owner, enabling the owner to set weights after cooldown.
4362+ // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::children::test_register_network_schedules_root_validators --exact --show-output --nocapture
4363+ #[ test]
4364+ fn test_register_network_schedules_root_validators ( ) {
4365+ new_test_ext ( 1 ) . execute_with ( || {
4366+ // --- Setup root network and root validators ---
4367+ let root_val_coldkey_1 = U256 :: from ( 100 ) ;
4368+ let root_val_hotkey_1 = U256 :: from ( 101 ) ;
4369+ let root_val_coldkey_2 = U256 :: from ( 200 ) ;
4370+ let root_val_hotkey_2 = U256 :: from ( 201 ) ;
4371+
4372+ add_network ( NetUid :: ROOT , 1 , 0 ) ;
4373+
4374+ // Root validators need to be registered on some subnet before root_register.
4375+ // Create a bootstrap subnet for that purpose.
4376+ let bootstrap_netuid = NetUid :: from ( 1 ) ;
4377+ add_network ( bootstrap_netuid, 1 , 0 ) ;
4378+ register_ok_neuron ( bootstrap_netuid, root_val_hotkey_1, root_val_coldkey_1, 0 ) ;
4379+ register_ok_neuron ( bootstrap_netuid, root_val_hotkey_2, root_val_coldkey_2, 0 ) ;
4380+
4381+ assert_ok ! ( SubtensorModule :: root_register(
4382+ RuntimeOrigin :: signed( root_val_coldkey_1) ,
4383+ root_val_hotkey_1,
4384+ ) ) ;
4385+ assert_ok ! ( SubtensorModule :: root_register(
4386+ RuntimeOrigin :: signed( root_val_coldkey_2) ,
4387+ root_val_hotkey_2,
4388+ ) ) ;
4389+
4390+ // Give root validators significant stake on root and bootstrap subnet
4391+ let root_stake = AlphaBalance :: from ( 1_000_000_000 ) ;
4392+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
4393+ & root_val_hotkey_1,
4394+ & root_val_coldkey_1,
4395+ NetUid :: ROOT ,
4396+ root_stake,
4397+ ) ;
4398+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
4399+ & root_val_hotkey_2,
4400+ & root_val_coldkey_2,
4401+ NetUid :: ROOT ,
4402+ root_stake,
4403+ ) ;
4404+
4405+ // --- Minimize cooldown so pending children activate quickly ---
4406+ assert_ok ! ( SubtensorModule :: set_pending_childkey_cooldown(
4407+ RuntimeOrigin :: root( ) ,
4408+ 0 ,
4409+ ) ) ;
4410+
4411+ // --- Set a high stake threshold ---
4412+ let high_threshold = 500_000_000u64 ;
4413+ SubtensorModule :: set_stake_threshold ( high_threshold) ;
4414+
4415+ // --- Register a new subnet (this should automatically call do_set_root_validators_for_subnet) ---
4416+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
4417+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
4418+ let lock_cost = SubtensorModule :: get_network_lock_cost ( ) ;
4419+ SubtensorModule :: add_balance_to_coldkey_account ( & subnet_owner_coldkey, lock_cost. into ( ) ) ;
4420+ TotalIssuance :: < Test > :: mutate ( |total| {
4421+ * total = total. saturating_add ( lock_cost) ;
4422+ } ) ;
4423+ assert_ok ! ( SubtensorModule :: register_network(
4424+ RuntimeOrigin :: signed( subnet_owner_coldkey) ,
4425+ subnet_owner_hotkey,
4426+ ) ) ;
4427+
4428+ // Determine the netuid that was just created
4429+ let netuid: NetUid = ( TotalNetworks :: < Test > :: get ( ) . saturating_sub ( 1 ) ) . into ( ) ;
4430+ assert_eq ! (
4431+ SubnetOwnerHotkey :: <Test >:: get( netuid) ,
4432+ subnet_owner_hotkey,
4433+ "Subnet owner hotkey should be set"
4434+ ) ;
4435+
4436+ // Root validators need stake on the new subnet for child stake inheritance to work
4437+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
4438+ & root_val_hotkey_1,
4439+ & root_val_coldkey_1,
4440+ netuid,
4441+ root_stake,
4442+ ) ;
4443+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
4444+ & root_val_hotkey_2,
4445+ & root_val_coldkey_2,
4446+ netuid,
4447+ root_stake,
4448+ ) ;
4449+
4450+ // --- Verify pending children were scheduled during registration ---
4451+ assert ! (
4452+ PendingChildKeys :: <Test >:: contains_key( netuid, root_val_hotkey_1) ,
4453+ "Root validator 1 should have pending children on the new subnet"
4454+ ) ;
4455+ assert ! (
4456+ PendingChildKeys :: <Test >:: contains_key( netuid, root_val_hotkey_2) ,
4457+ "Root validator 2 should have pending children on the new subnet"
4458+ ) ;
4459+
4460+ // --- Activate pending children ---
4461+ step_block ( 1 ) ;
4462+ SubtensorModule :: do_set_pending_children ( netuid) ;
4463+
4464+ // --- Verify child-parent relationships ---
4465+ let children_1 = SubtensorModule :: get_children ( & root_val_hotkey_1, netuid) ;
4466+ assert_eq ! (
4467+ children_1,
4468+ vec![ ( u64 :: MAX , subnet_owner_hotkey) ] ,
4469+ "Root validator 1 should have subnet owner as child"
4470+ ) ;
4471+ let children_2 = SubtensorModule :: get_children ( & root_val_hotkey_2, netuid) ;
4472+ assert_eq ! (
4473+ children_2,
4474+ vec![ ( u64 :: MAX , subnet_owner_hotkey) ] ,
4475+ "Root validator 2 should have subnet owner as child"
4476+ ) ;
4477+
4478+ // --- Verify subnet owner can now set weights ---
4479+ SubtensorModule :: set_weights_set_rate_limit ( netuid, 0 ) ;
4480+ SubtensorModule :: set_commit_reveal_weights_enabled ( netuid, false ) ;
4481+ let version_key = SubtensorModule :: get_weights_version_key ( netuid) ;
4482+
4483+ assert ! (
4484+ SubtensorModule :: check_weights_min_stake( & subnet_owner_hotkey, netuid) ,
4485+ "Subnet owner should have enough inherited stake to set weights"
4486+ ) ;
4487+ assert_ok ! ( SubtensorModule :: set_weights(
4488+ RuntimeOrigin :: signed( subnet_owner_hotkey) ,
4489+ netuid,
4490+ vec![ 0 ] ,
4491+ vec![ u16 :: MAX ] ,
4492+ version_key
4493+ ) ) ;
4494+ } ) ;
4495+ }
0 commit comments