@@ -3238,225 +3238,3 @@ fn test_rank_trust_incentive_calculation_with_parent_child() {
32383238 } ) ;
32393239}
32403240
3241- /// Test normal operation of childkey take
3242- ///
3243- /// This test verifies the correct distribution of rewards between child and parents.
3244- ///
3245- /// # Test Steps:
3246- /// 1. Initialize test environment with a child and multiple parents
3247- /// 2. Set childkey take to 9% (4915 when normalized to u16::MAX)
3248- /// 3. Set up network parameters and register all neurons
3249- /// 4. Set initial stakes for all neurons
3250- /// 5. Run an epoch and process emissions
3251- /// 6. Calculate expected reward distribution
3252- /// 7. Compare actual distribution with expected distribution
3253- ///
3254- /// # Expected Results:
3255- /// - Child should keep 9% of the rewards
3256- /// - Remaining 91% should be distributed among parents proportional to their stake
3257- /// - Total distributed rewards should equal total emissions
3258-
3259- /// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test children -- test_normal_childkey_take_operation --exact --nocapture
3260-
3261- // #[test]
3262- // fn test_normal_childkey_take_operation() {
3263- // new_test_ext(1).execute_with(|| {
3264- // let netuid: u16 = 1;
3265- // let num_neurons: u16 = 5;
3266-
3267- // // Create hotkeys and coldkeys
3268- // let child_coldkey = U256::from(100);
3269- // let child_hotkey = U256::from(0);
3270- // let parent_coldkey = U256::from(101);
3271- // let parent_hotkey = U256::from(1);
3272- // let validator_coldkeys: Vec<U256> = (102..105).map(U256::from).collect();
3273- // let validator_hotkeys: Vec<U256> = (2..5).map(U256::from).collect();
3274-
3275- // // Set childkey take to 9% (4915 when normalized to u16::MAX)
3276- // let childkey_take: u16 = 4915;
3277-
3278- // // Set up network parameters and register neurons
3279- // add_network(netuid, num_neurons, 0);
3280- // SubtensorModule::set_max_registrations_per_block(netuid, 1000);
3281- // SubtensorModule::set_target_registrations_per_interval(netuid, 1000);
3282- // SubtensorModule::set_weights_set_rate_limit(netuid, 0);
3283- // SubtensorModule::set_hotkey_emission_tempo(10);
3284-
3285- // register_ok_neuron(netuid, child_hotkey, child_coldkey, 0);
3286- // register_ok_neuron(netuid, parent_hotkey, parent_coldkey, 0);
3287- // for (&hotkey, &coldkey) in validator_hotkeys.iter().zip(validator_coldkeys.iter()) {
3288- // register_ok_neuron(netuid, hotkey, coldkey, 0);
3289- // }
3290-
3291- // // Set initial stakes
3292- // let child_stake: u64 = 1_000_000;
3293- // let parent_stake: u64 = 2_000_000;
3294- // let validator_stakes: Vec<u64> = vec![3_000_000, 4_000_000, 5_000_000];
3295-
3296- // SubtensorModule::add_balance_to_coldkey_account(&child_coldkey, child_stake);
3297- // SubtensorModule::increase_stake_on_coldkey_hotkey_account(
3298- // &child_coldkey,
3299- // &child_hotkey,
3300- // child_stake,
3301- // );
3302-
3303- // SubtensorModule::add_balance_to_coldkey_account(&parent_coldkey, parent_stake);
3304- // SubtensorModule::increase_stake_on_coldkey_hotkey_account(
3305- // &parent_coldkey,
3306- // &parent_hotkey,
3307- // parent_stake,
3308- // );
3309-
3310- // for (i, (&hotkey, &coldkey)) in validator_hotkeys
3311- // .iter()
3312- // .zip(validator_coldkeys.iter())
3313- // .enumerate()
3314- // {
3315- // SubtensorModule::add_balance_to_coldkey_account(&coldkey, validator_stakes[i]);
3316- // SubtensorModule::increase_stake_on_coldkey_hotkey_account(
3317- // &coldkey,
3318- // &hotkey,
3319- // validator_stakes[i],
3320- // );
3321- // }
3322-
3323- // // Set up parent-child relationship
3324- // assert_ok!(SubtensorModule::do_set_children(
3325- // RuntimeOrigin::signed(parent_coldkey),
3326- // parent_hotkey,
3327- // netuid,
3328- // vec![(u64::MAX, child_hotkey)]
3329- // ));
3330-
3331- // // Set childkey take
3332- // assert_ok!(SubtensorModule::do_set_childkey_take(
3333- // child_coldkey,
3334- // child_hotkey,
3335- // childkey_take,
3336- // netuid
3337- // ));
3338-
3339- // // Set weights
3340- // let all_uids: Vec<u16> = (0..num_neurons).collect();
3341- // let weights: Vec<u16> = vec![u16::MAX / num_neurons; num_neurons as usize];
3342-
3343- // step_block(2); // Step to ensure weights are set
3344-
3345- // for &hotkey in std::iter::once(&parent_hotkey).chain(validator_hotkeys.iter()) {
3346- // assert_ok!(SubtensorModule::set_weights(
3347- // RuntimeOrigin::signed(hotkey),
3348- // netuid,
3349- // all_uids.clone(),
3350- // weights.clone(),
3351- // 0
3352- // ));
3353- // }
3354-
3355- // // Run epoch and process emissions
3356- // let rao_emission: u64 = 1_000_000_000;
3357- // let emission = SubtensorModule::epoch(netuid, rao_emission);
3358-
3359- // // Store initial stakes
3360- // let initial_stakes: Vec<u64> = [child_hotkey, parent_hotkey]
3361- // .iter()
3362- // .chain(validator_hotkeys.iter())
3363- // .map(|&hotkey| SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid))
3364- // .collect();
3365-
3366- // log::info!("Initial stakes:");
3367- // log::info!("Child: {}", initial_stakes[0]);
3368- // log::info!("Parent: {}", initial_stakes[1]);
3369- // for (i, &stake) in initial_stakes.iter().skip(2).enumerate() {
3370- // log::info!("Validator {}: {}", i, stake);
3371- // }
3372-
3373- // // Accumulate emissions
3374- // for (hotkey, mining_emission, validator_emission) in emission {
3375- // SubtensorModule::accumulate_hotkey_emission(
3376- // &hotkey,
3377- // netuid,
3378- // validator_emission,
3379- // mining_emission,
3380- // );
3381- // }
3382-
3383- // // Check pending emissions before distribution
3384- // log::info!("\nPending emissions before distribution:");
3385- // let pending_emissions: Vec<u64> = [child_hotkey, parent_hotkey]
3386- // .iter()
3387- // .chain(validator_hotkeys.iter())
3388- // .map(|&hotkey| SubtensorModule::get_pending_hotkey_emission(&hotkey))
3389- // .collect();
3390-
3391- // log::info!("Child: {}", pending_emissions[0]);
3392- // log::info!("Parent: {}", pending_emissions[1]);
3393- // for (i, &emission) in pending_emissions.iter().skip(2).enumerate() {
3394- // log::info!("Validator {}: {}", i, emission);
3395- // }
3396-
3397- // let total_pending_emission: u64 = pending_emissions.iter().sum();
3398- // log::info!("Total pending emission: {}", total_pending_emission);
3399-
3400- // log::info!("\nChildkey take: {}", childkey_take);
3401-
3402- // // Step block to trigger emission distribution
3403- // step_block(11);
3404-
3405- // // Calculate actual rewards
3406- // let final_stakes: Vec<u64> = [child_hotkey, parent_hotkey]
3407- // .iter()
3408- // .chain(validator_hotkeys.iter())
3409- // .map(|&hotkey| SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid))
3410- // .collect();
3411-
3412- // let rewards: Vec<u64> = final_stakes
3413- // .iter()
3414- // .zip(initial_stakes.iter())
3415- // .map(|(&final_stake, &initial_stake)| final_stake - initial_stake)
3416- // .collect();
3417-
3418- // log::info!("\nRewards:");
3419- // log::info!("Child reward: {}", rewards[0]);
3420- // log::info!("Parent reward: {}", rewards[1]);
3421- // for (i, &reward) in rewards.iter().skip(2).enumerate() {
3422- // log::info!("Validator {} reward: {}", i, reward);
3423- // }
3424-
3425- // // Verify total distributed rewards
3426- // let total_distributed: u64 = rewards.iter().sum();
3427- // log::info!("\nTotal distributed: {}", total_distributed);
3428- // log::info!("Total emission: {}", total_pending_emission);
3429-
3430- // assert!(
3431- // (total_distributed as i64 - total_pending_emission as i64).abs() <= 10,
3432- // "Total distributed rewards mismatch: distributed {} vs emission {}",
3433- // total_distributed,
3434- // total_pending_emission
3435- // );
3436-
3437- // // Check that PendingdHotkeyEmission is cleared after distribution
3438- // for &hotkey in [child_hotkey, parent_hotkey]
3439- // .iter()
3440- // .chain(validator_hotkeys.iter())
3441- // {
3442- // assert_eq!(
3443- // SubtensorModule::get_pending_hotkey_emission(&hotkey),
3444- // 0,
3445- // "Pending emission not cleared for hotkey {:?}",
3446- // hotkey
3447- // );
3448- // }
3449-
3450- // // Verify childkey take
3451- // let child_reward = rewards[0];
3452- // let expected_child_reward =
3453- // (total_pending_emission as u128 * childkey_take as u128 / u16::MAX as u128) as u64;
3454- // log::info!("\nExpected child reward: {}", expected_child_reward);
3455- // assert!(
3456- // (child_reward as i64 - expected_child_reward as i64).abs() <= 1,
3457- // "Child reward mismatch: actual {} vs expected {}",
3458- // child_reward,
3459- // expected_child_reward
3460- // );
3461- // });
3462- // }
0 commit comments