diff --git a/pallets/subspace/src/registration.rs b/pallets/subspace/src/registration.rs index 989e454e5..0460a8d4c 100644 --- a/pallets/subspace/src/registration.rs +++ b/pallets/subspace/src/registration.rs @@ -85,7 +85,7 @@ impl Pallet { // adding the stake amount Self::do_add_stake(origin.clone(), netuid, module_key.clone(), stake_amount)?; - + // CONSTANT INITIAL BURN if min_burn > 0 { ensure!(stake_amount >= min_burn, Error::::NotEnoughStakeToRegister); @@ -229,8 +229,6 @@ impl Pallet { // use default parameters // - - let num_subnets: u16 = Self::num_subnets(); let max_subnets: u16 = Self::getglobal_max_allowed_subnets(); // if we have not reached the max number of subnets, then we can start a new one @@ -253,10 +251,7 @@ impl Pallet { params.name = name.clone(); let netuid = Self::add_subnet(params); Founder::::insert(netuid, founder_key.clone()); - - - - + Ok(()) } diff --git a/pallets/subspace/src/staking.rs b/pallets/subspace/src/staking.rs index bc3190caa..d1e81d356 100644 --- a/pallets/subspace/src/staking.rs +++ b/pallets/subspace/src/staking.rs @@ -125,8 +125,6 @@ impl Pallet { log::info!("StakeAdded( key:{:?}, stake_to_be_added:{:?} )", key, amount); Self::deposit_event(Event::StakeAdded(key, module_key, amount)); - - // --- 6. Ok and return. Ok(()) } diff --git a/pallets/subspace/src/step.rs b/pallets/subspace/src/step.rs index 553003c13..1b745b1ab 100644 --- a/pallets/subspace/src/step.rs +++ b/pallets/subspace/src/step.rs @@ -170,8 +170,6 @@ impl Pallet { incentive[*uid_i as usize] = I32F32::from_num(1.0); } } - - inplace_normalize(&mut incentive); // range: I32F32(0, 1) // ================================= diff --git a/pallets/subspace/src/subnet.rs b/pallets/subspace/src/subnet.rs index a773b9915..e94f83243 100644 --- a/pallets/subspace/src/subnet.rs +++ b/pallets/subspace/src/subnet.rs @@ -645,14 +645,11 @@ impl Pallet { // ==== Global Setters ==== // ======================== pub fn set_tempo(netuid: u16, tempo: u16) { - Tempo::::insert(netuid, tempo); + Tempo::::insert(netuid, tempo.max(100)); } pub fn set_founder_share(netuid: u16, mut founder_share: u16) { - if founder_share > 100 { - founder_share = 100; - } - FounderShare::::insert(netuid, founder_share); + FounderShare::::insert(netuid, founder_share.min(100)); } pub fn get_founder_share(netuid: u16) -> u16 { return FounderShare::::get(netuid) @@ -667,10 +664,7 @@ impl Pallet { } pub fn set_incentive_ratio(netuid: u16, mut incentive_ratio: u16) { - if incentive_ratio > 100 { - incentive_ratio = 100; - } - IncentiveRatio::::insert(netuid, incentive_ratio); + IncentiveRatio::::insert(netuid, incentive_ratio.min(100)); } pub fn get_founder(netuid: u16) -> T::AccountId { diff --git a/pallets/subspace/tests/test_burn.rs b/pallets/subspace/tests/test_burn.rs index 5c43bb646..89ffe70cc 100644 --- a/pallets/subspace/tests/test_burn.rs +++ b/pallets/subspace/tests/test_burn.rs @@ -58,7 +58,7 @@ fn test_burn() { incentives, emissions); - step_epoch(1); + step_epoch(netuid); let dividends = SubspaceModule::get_dividends(netuid); diff --git a/pallets/subspace/tests/test_step.rs b/pallets/subspace/tests/test_step.rs index 9477e1b1b..7da9bda5d 100644 --- a/pallets/subspace/tests/test_step.rs +++ b/pallets/subspace/tests/test_step.rs @@ -90,7 +90,7 @@ fn test_dividends_same_stake() { let stakes_before : Vec = SubspaceModule::get_stakes(netuid); - step_block(1); + step_epoch(netuid); let incentives: Vec = SubspaceModule::get_incentives(netuid); let dividends: Vec = SubspaceModule::get_dividends(netuid); let emissions: Vec = SubspaceModule::get_emissions(netuid); @@ -147,7 +147,7 @@ fn test_dividends_diff_stake() { let n_list: Vec = vec![10, 50, 100, 1000]; let blocks_per_epoch_list: u64 = 1; let stake_per_module: u64 = 10_000; - let tempo : u16 = 10; + let tempo : u16 = 100; // SETUP NETWORK for i in 0..n { @@ -238,7 +238,7 @@ fn test_pruning() { let n: u16 = 100; let blocks_per_epoch_list: u64 = 1; let stake_per_module: u64 = 10_000; - let tempo: u16 = 1; + let tempo: u16 = 100; // SETUP NETWORK register_n_modules(netuid, n, stake_per_module); @@ -308,11 +308,12 @@ fn test_lowest_priority_mechanism() { let n_list: Vec = vec![10, 50, 100, 1000]; let blocks_per_epoch_list: u64 = 1; let stake_per_module: u64 = 10_000; + let tempo : u16 = 100; // SETUP NETWORK register_n_modules(netuid, n, stake_per_module); - SubspaceModule::set_tempo(netuid, 1); + SubspaceModule::set_tempo(netuid, tempo); SubspaceModule::set_max_allowed_weights(netuid, n); SubspaceModule::set_min_allowed_weights(netuid, 0); @@ -334,7 +335,7 @@ fn test_lowest_priority_mechanism() { weight_values[prune_uid as usize] = 0; set_weights(netuid, keys[0], weight_uids.clone(), weight_values.clone()); - step_block(1); + step_block(tempo); let incentives: Vec = SubspaceModule::get_incentives(netuid); let dividends: Vec = SubspaceModule::get_dividends(netuid); let emissions: Vec = SubspaceModule::get_emissions(netuid); @@ -497,7 +498,7 @@ fn test_incentives() { let mut params = SubspaceModule::subnet_params(netuid); params.min_allowed_weights = 0; params.max_allowed_weights = n; - params.tempo = 1; + params.tempo = 100; let keys = SubspaceModule::get_keys(netuid); @@ -509,7 +510,7 @@ fn test_incentives() { let weight_values: Vec = [1, 1].to_vec(); set_weights(netuid, keys[0], weight_uids.clone(), weight_values.clone()); - step_block(1); + step_block(params.tempo); let incentives: Vec = SubspaceModule::get_incentives(netuid); let emissions: Vec = SubspaceModule::get_emissions(netuid); @@ -526,13 +527,13 @@ fn test_incentives() { set_weights(netuid, keys[0], weight_uids.clone(), weight_values.clone()); set_weights(netuid, keys[9], weight_uids.clone(), weight_values.clone()); - step_block(1); + step_block(params.tempo); let incentives: Vec = SubspaceModule::get_incentives(netuid); let emissions: Vec = SubspaceModule::get_emissions(netuid); // evaluate votees - let delta : u64 = 100; + let delta : u64 = 100 * params.tempo as u64; assert!(incentives[1] > 0); assert!(emissions[2] > 2 * emissions[1] - delta && @@ -561,7 +562,7 @@ fn test_trust() { let mut params = SubspaceModule::subnet_params(netuid); params.min_allowed_weights = 0; params.max_allowed_weights = n; - params.tempo = 1; + params.tempo = 100; params.trust_ratio = 100; SubspaceModule::set_subnet_params(netuid, params.clone()); @@ -579,7 +580,7 @@ fn test_trust() { let weight_uids: Vec = [1, 2].to_vec(); let weight_values: Vec = [1, 1].to_vec(); set_weights(netuid, keys[9], weight_uids.clone(), weight_values.clone()); - step_block(1); + step_block(params.tempo); let trust: Vec = SubspaceModule::get_trust(netuid); let emission : Vec = SubspaceModule::get_emissions(netuid); @@ -855,14 +856,16 @@ fn test_founder_share() { let founder_share = SubspaceModule::get_founder_share(netuid); let founder_ratio: f64 = founder_share as f64 / 100.0; + let subnet_params = SubspaceModule::subnet_params(netuid); + let founder_stake_before = SubspaceModule::get_stake_for_key(netuid, &founder_key); println!("founder_stake_before: {:?}", founder_stake_before); // vote to avoid key[0] as we want to see the key[0] burn step_epoch(netuid); - let total_emission = SubspaceModule::get_subnet_emission(netuid); - let expected_founder_share = (total_emission as f64 * founder_ratio) as u64; - let expected_emission = total_emission; + let total_emission = SubspaceModule::get_subnet_emission(netuid) * subnet_params.tempo as u64; + let expected_emission = total_emission as u64; + let expected_founder_share = (expected_emission as f64 * founder_ratio) as u64; let emissions = SubspaceModule::get_emissions(netuid); let dividends = SubspaceModule::get_dividends(netuid); let incentives = SubspaceModule::get_incentives(netuid); @@ -884,23 +887,23 @@ fn test_founder_share() { let calculated_founder_share = SubspaceModule::get_stake_for_key(netuid, &founder_key) - founder_stake_before - founder_emission; - let delta: u64 = 1000; + let delta: u64 = 100000; println!("expected_emission: {:?}", expected_emission); println!("total_emission: {:?}", total_emission); - assert!(expected_emission > calcualted_total_emission - delta ); - assert!(expected_emission < calcualted_total_emission + delta ); + assert!(expected_emission > calcualted_total_emission - delta , "expected_emission: {} != calcualted_total_emission: {}", expected_emission, calcualted_total_emission); + assert!(expected_emission < calcualted_total_emission + delta , "expected_emission: {} != calcualted_total_emission: {}", expected_emission, calcualted_total_emission); - println!("calculated_founder_share: {:?}", calculated_founder_share); println!("expected_founder_share: {:?}", expected_founder_share); - assert!(expected_founder_share > calculated_founder_share - delta ); - assert!(expected_founder_share < calculated_founder_share + delta ); - + assert!(expected_founder_share > calculated_founder_share - delta , "expected_founder_share: {} != calculated_founder_share: {}", expected_founder_share, calculated_founder_share); + assert!(expected_founder_share < calculated_founder_share + delta , "expected_founder_share: {} != calculated_founder_share: {}", expected_founder_share, calculated_founder_share); }); + + }