Skip to content

Commit f95153e

Browse files
author
unconst
committed
add new test
1 parent c7a3238 commit f95153e

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ impl<T: Config> Pallet<T> {
353353
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid) {
354354
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
355355
// Increase stake for owner hotkey and coldkey.
356+
log::debug!("owner_hotkey: {:?} owner_coldkey: {:?}, owner_cut: {:?}", owner_hotkey, owner_coldkey, owner_cut);
356357
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
357358
&owner_hotkey,
358359
&owner_coldkey,
@@ -365,6 +366,7 @@ impl<T: Config> Pallet<T> {
365366
// Distribute mining incentives.
366367
for (hotkey, incentive) in incentives {
367368
// Increase stake for miner.
369+
log::debug!("incentives: hotkey: {:?}", incentive);
368370
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
369371
&hotkey.clone(),
370372
&Owner::<T>::get(hotkey.clone()),
@@ -376,21 +378,21 @@ impl<T: Config> Pallet<T> {
376378
// Distribute alpha divs.
377379
let _ = AlphaDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
378380
for (hotkey, mut alpha_divs) in alpha_dividends {
379-
log::debug!("hotkey: {:?} alpha_divs: {:?}", hotkey, alpha_divs);
380-
381381
// Get take prop
382382
let alpha_take: I96F32 =
383383
Self::get_hotkey_take_float(&hotkey).saturating_mul(alpha_divs);
384384
// Remove take prop from alpha_divs
385385
alpha_divs = alpha_divs.saturating_sub(alpha_take);
386386
// Give the validator their take.
387+
log::debug!("hotkey: {:?} alpha_take: {:?}", hotkey, alpha_take);
387388
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
388389
&hotkey,
389390
&Owner::<T>::get(hotkey.clone()),
390391
netuid,
391392
tou64!(alpha_take),
392393
);
393394
// Give all other nominators.
395+
log::debug!("hotkey: {:?} alpha_divs: {:?}", hotkey, alpha_divs);
394396
Self::increase_stake_for_hotkey_on_subnet(&hotkey.clone(), netuid, tou64!(alpha_divs));
395397
// Record dividends for this hotkey.
396398
AlphaDividendsPerSubnet::<T>::mutate(netuid, hotkey.clone(), |divs| {
@@ -401,19 +403,20 @@ impl<T: Config> Pallet<T> {
401403
// Distribute root tao divs.
402404
let _ = TaoDividendsPerSubnet::<T>::clear_prefix(netuid, u32::MAX, None);
403405
for (hotkey, mut root_tao) in tao_dividends {
404-
log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao);
405406
// Get take prop
406407
let tao_take: I96F32 = Self::get_hotkey_take_float(&hotkey).saturating_mul(root_tao);
407408
// Remove take prop from root_tao
408409
root_tao = root_tao.saturating_sub(tao_take);
409410
// Give the validator their take.
411+
log::debug!("hotkey: {:?} tao_take: {:?}", hotkey, tao_take);
410412
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
411413
&hotkey,
412414
&Owner::<T>::get(hotkey.clone()),
413415
Self::get_root_netuid(),
414416
tou64!(tao_take),
415417
);
416418
// Give rest to nominators.
419+
log::debug!("hotkey: {:?} root_tao: {:?}", hotkey, root_tao);
417420
Self::increase_stake_for_hotkey_on_subnet(
418421
&hotkey,
419422
Self::get_root_netuid(),

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,41 @@ fn test_drain_base_with_subnet_with_two_stakers_registered_and_root_different_am
724724
close(expected_root2.to_num::<u64>(), root_after2, 10);
725725
});
726726
}
727+
728+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_drain_alpha_childkey_parentkey --exact --show-output --nocapture
729+
#[test]
730+
fn test_drain_alpha_childkey_parentkey() {
731+
new_test_ext(1).execute_with(|| {
732+
let netuid: u16 = 1;
733+
add_network(netuid, 1, 0);
734+
let parent = U256::from(1);
735+
let child = U256::from(2);
736+
let coldkey = U256::from(3);
737+
let stake_before: u64 = 1_000_000_000;
738+
register_ok_neuron(netuid, child, coldkey, 0);
739+
SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
740+
&parent,
741+
&coldkey,
742+
netuid,
743+
stake_before,
744+
);
745+
mock_set_children_no_epochs(netuid, &parent, &[(u64::MAX, child)]);
746+
747+
// Childkey take is 10%
748+
ChildkeyTake::<Test>::insert(child, netuid, u16::MAX/10);
749+
750+
let pending_alpha: u64 = 1_000_000_000;
751+
SubtensorModule::drain_pending_emission(netuid, pending_alpha, 0, 0, 0);
752+
let parent_stake_after =
753+
SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid);
754+
let child_stake_after =
755+
SubtensorModule::get_stake_for_hotkey_on_subnet(&child, netuid);
756+
757+
// Child gets 10%, parent gets 90%
758+
let expected = I96F32::from_num(stake_before) + I96F32::from_num(pending_alpha) * I96F32::from_num(9.0 / 10.0);
759+
log::info!("expected: {:?}, parent_stake_after: {:?}", expected.to_num::<u64>(), parent_stake_after);
760+
close(expected.to_num::<u64>(), parent_stake_after, 10_000);
761+
let expected = I96F32::from_num(pending_alpha) / I96F32::from_num(10);
762+
close(expected.to_num::<u64>(), child_stake_after, 10_000);
763+
});
764+
}

0 commit comments

Comments
 (0)