Skip to content

Commit a2969f8

Browse files
committed
Merge branch 'main' into nonclaim-into-main
2 parents 913231b + d4d8182 commit a2969f8

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ impl<T: Config> Pallet<T> {
249249
BlocksSinceLastStep::<T>::mutate(netuid, |total| *total = total.saturating_add(1));
250250
}
251251
}
252+
253+
// --- 8. Apply pending childkeys of this subnet for the next epoch
254+
for netuid in subnets.iter() {
255+
Self::do_set_pending_children(*netuid);
256+
}
252257
}
253258

254259
pub fn drain_pending_emission(

pallets/subtensor/src/tests/children.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,3 +3923,108 @@ fn test_dynamic_parent_child_relationships() {
39233923
// Child2 stake (874,826) > Child1 stake (778,446)
39243924
});
39253925
}
3926+
3927+
// Test that revoking childkeys does not require minimum stake
3928+
#[test]
3929+
fn test_revoke_child_no_min_stake_check() {
3930+
new_test_ext(1).execute_with(|| {
3931+
let coldkey = U256::from(1);
3932+
let parent = U256::from(2);
3933+
let child = U256::from(3);
3934+
let netuid: u16 = 1;
3935+
let proportion: u64 = 1000;
3936+
3937+
// Add network and register hotkey
3938+
add_network(netuid, 13, 0);
3939+
register_ok_neuron(netuid, parent, coldkey, 0);
3940+
3941+
// Set minimum stake for setting children
3942+
let parent_total_stake_original = TotalHotkeyStake::<Test>::get(parent);
3943+
StakeThreshold::<Test>::put(1_000_000_000_000);
3944+
TotalHotkeyStake::<Test>::insert(parent, StakeThreshold::<Test>::get());
3945+
3946+
// Schedule parent-child relationship
3947+
assert_ok!(SubtensorModule::do_schedule_children(
3948+
RuntimeOrigin::signed(coldkey),
3949+
parent,
3950+
netuid,
3951+
vec![(proportion, child)],
3952+
));
3953+
3954+
// Ensure the childkeys are not yet applied
3955+
let children_before = SubtensorModule::get_children(&parent, netuid);
3956+
assert_eq!(children_before, vec![]);
3957+
3958+
wait_and_set_pending_children(netuid);
3959+
TotalHotkeyStake::<Test>::insert(parent, parent_total_stake_original);
3960+
3961+
// Ensure the childkeys are applied
3962+
let children_after = SubtensorModule::get_children(&parent, netuid);
3963+
assert_eq!(children_after, vec![(proportion, child)]);
3964+
3965+
// Reduce the stake below required threshold
3966+
TotalHotkeyStake::<Test>::insert(parent, StakeThreshold::<Test>::get() - 1);
3967+
3968+
// Bypass tx rate limit
3969+
SubtensorModule::set_last_transaction_block_on_subnet(
3970+
&parent,
3971+
netuid,
3972+
&TransactionType::SetChildren,
3973+
0,
3974+
);
3975+
3976+
// Schedule parent-child relationship revokation
3977+
assert_ok!(SubtensorModule::do_schedule_children(
3978+
RuntimeOrigin::signed(coldkey),
3979+
parent,
3980+
netuid,
3981+
vec![],
3982+
));
3983+
3984+
wait_and_set_pending_children(netuid);
3985+
TotalHotkeyStake::<Test>::insert(parent, parent_total_stake_original);
3986+
3987+
// Ensure the childkeys are revoked
3988+
let children_after = SubtensorModule::get_children(&parent, netuid);
3989+
assert_eq!(children_after, vec![]);
3990+
});
3991+
}
3992+
3993+
// Test that setting childkeys works even if subnet registration is disabled
3994+
#[test]
3995+
fn test_do_set_child_registration_disabled() {
3996+
new_test_ext(1).execute_with(|| {
3997+
let coldkey = U256::from(1);
3998+
let parent = U256::from(2);
3999+
let child = U256::from(3);
4000+
let netuid: u16 = 1;
4001+
let proportion: u64 = 1000;
4002+
4003+
// Add network and register hotkey
4004+
add_network(netuid, 13, 0);
4005+
register_ok_neuron(netuid, parent, coldkey, 0);
4006+
4007+
// Set minimum stake for setting children
4008+
let parent_total_stake_original = TotalHotkeyStake::<Test>::get(parent);
4009+
StakeThreshold::<Test>::put(1_000_000_000_000);
4010+
TotalHotkeyStake::<Test>::insert(parent, StakeThreshold::<Test>::get());
4011+
4012+
// Disable subnet registrations
4013+
NetworkRegistrationAllowed::<Test>::insert(netuid, false);
4014+
4015+
// Schedule parent-child relationship
4016+
assert_ok!(SubtensorModule::do_schedule_children(
4017+
RuntimeOrigin::signed(coldkey),
4018+
parent,
4019+
netuid,
4020+
vec![(proportion, child)],
4021+
));
4022+
4023+
wait_and_set_pending_children(netuid);
4024+
TotalHotkeyStake::<Test>::insert(parent, parent_total_stake_original);
4025+
4026+
// Ensure the childkeys are applied
4027+
let children_after = SubtensorModule::get_children(&parent, netuid);
4028+
assert_eq!(children_after, vec![(proportion, child)]);
4029+
});
4030+
}

0 commit comments

Comments
 (0)