diff --git a/pallets/admin-utils/src/tests/mod.rs b/pallets/admin-utils/src/tests/mod.rs index 3f24deb78..186831031 100644 --- a/pallets/admin-utils/src/tests/mod.rs +++ b/pallets/admin-utils/src/tests/mod.rs @@ -961,10 +961,7 @@ mod sudo_set_nominator_min_required_stake { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); assert_eq!(Balances::free_balance(cold1), 4); // Add stake cold2 --> hot1 (is delegation.) @@ -974,10 +971,7 @@ mod sudo_set_nominator_min_required_stake { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold2), 1); assert_eq!(Balances::free_balance(cold2), 4); // Add stake cold1 --> hot2 (non delegation.) @@ -987,10 +981,7 @@ mod sudo_set_nominator_min_required_stake { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold1), 1); assert_eq!(Balances::free_balance(cold1), 8); // Add stake cold2 --> hot2 (is delegation.) @@ -1000,10 +991,7 @@ mod sudo_set_nominator_min_required_stake { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold2), 1); assert_eq!(Balances::free_balance(cold2), 8); // Set min stake to 0 (noop) @@ -1011,44 +999,20 @@ mod sudo_set_nominator_min_required_stake { <::RuntimeOrigin>::root(), 0u64 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 1); + assert_eq!(Stake::::get(hot1, cold2), 1); + assert_eq!(Stake::::get(hot2, cold2), 1); // Set min nomination to 10: should clear (cold2, hot1) and (cold1, hot2). assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake( <::RuntimeOrigin>::root(), 10u64 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 0); + assert_eq!(Stake::::get(hot1, cold2), 0); + assert_eq!(Stake::::get(hot2, cold2), 1); // Balances have been added back into accounts. assert_eq!(Balances::free_balance(cold1), 9); diff --git a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs index b5e833aeb..46f7c5373 100644 --- a/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs +++ b/pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs @@ -204,10 +204,7 @@ impl Pallet { assert!(StakingHotkeys::::get(migration_ck_acct).contains(taostats_old_hk_acct)); - assert_eq!( - Self::get_stake_for_coldkey_and_hotkey(null_account, taostats_old_hk_acct), - 0 - ); + assert_eq!(Stake::::get(taostats_old_hk_acct, null_account), 0); // Check the total hotkey stake is the same assert_eq!( @@ -217,7 +214,7 @@ impl Pallet { ); let new_null_stake_taostats = - Self::get_stake_for_coldkey_and_hotkey(migration_ck_acct, taostats_old_hk_acct); + Stake::::get(taostats_old_hk_acct, migration_ck_acct); assert_eq!( new_null_stake_taostats, @@ -257,10 +254,7 @@ impl Pallet { assert!(StakingHotkeys::::get(migration_ck_acct).contains(datura_old_hk_acct)); - assert_eq!( - Self::get_stake_for_coldkey_and_hotkey(null_account, datura_old_hk_acct), - 0 - ); + assert_eq!(Stake::::get(datura_old_hk_acct, null_account), 0); // Check the total hotkey stake is the same assert_eq!( @@ -269,8 +263,7 @@ impl Pallet { .saturating_add(old.old_migration_stake_datura) ); - let new_null_stake_datura = - Self::get_stake_for_coldkey_and_hotkey(migration_ck_acct, datura_old_hk_acct); + let new_null_stake_datura = Stake::::get(datura_old_hk_acct, migration_ck_acct); assert_eq!( new_null_stake_datura, @@ -353,14 +346,8 @@ pub mod migration { .saturating_add(PendingdHotkeyEmission::::get(taostats_new_hk_acct)); Ok::<(u64, u64), sp_runtime::TryRuntimeError>(( - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - null_account, - taostats_old_hk_acct, - ), - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - migration_acct, - taostats_old_hk_acct, - ), + Stake::::get(taostats_old_hk_acct, null_account), + Stake::::get(taostats_old_hk_acct, migration_acct), )) } _ => { @@ -386,14 +373,8 @@ pub mod migration { .saturating_add(PendingdHotkeyEmission::::get(datura_new_hk_acct)); Ok::<(u64, u64), sp_runtime::TryRuntimeError>(( - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - null_account, - datura_old_hk_acct, - ), - crate::Pallet::::get_stake_for_coldkey_and_hotkey( - migration_acct, - datura_old_hk_acct, - ), + Stake::::get(datura_old_hk_acct, null_account), + Stake::::get(datura_old_hk_acct, migration_acct), )) } _ => { diff --git a/pallets/subtensor/src/rpc_info/delegate_info.rs b/pallets/subtensor/src/rpc_info/delegate_info.rs index be068bf68..c641ad8d9 100644 --- a/pallets/subtensor/src/rpc_info/delegate_info.rs +++ b/pallets/subtensor/src/rpc_info/delegate_info.rs @@ -119,8 +119,7 @@ impl Pallet { let mut delegates: Vec<(DelegateInfo, Compact)> = Vec::new(); for delegate in as IterableStorageMap>::iter_keys() { - let staked_to_this_delegatee = - Self::get_stake_for_coldkey_and_hotkey(&delegatee.clone(), &delegate.clone()); + let staked_to_this_delegatee = Stake::::get(&delegate, &delegatee); if staked_to_this_delegatee == 0 { continue; // No stake to this delegate } diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 1e223d4f8..facfb2605 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -41,12 +41,6 @@ impl Pallet { TotalColdkeyStake::::get(coldkey) } - // Returns the stake under the cold - hot pairing in the staking table. - // - pub fn get_stake_for_coldkey_and_hotkey(coldkey: &T::AccountId, hotkey: &T::AccountId) -> u64 { - Stake::::get(hotkey, coldkey) - } - pub fn get_target_stakes_per_interval() -> u64 { TargetStakesPerInterval::::get() } @@ -111,7 +105,7 @@ impl Pallet { /// # Returns /// True if the account has enough balance, false otherwise. pub fn has_enough_stake(coldkey: &T::AccountId, hotkey: &T::AccountId, decrement: u64) -> bool { - Self::get_stake_for_coldkey_and_hotkey(coldkey, hotkey) >= decrement + Stake::::get(hotkey, coldkey) >= decrement } /// Increases the stake on the hotkey account under its owning coldkey. diff --git a/pallets/subtensor/src/staking/remove_stake.rs b/pallets/subtensor/src/staking/remove_stake.rs index f5cf87bc7..7a101a8ae 100644 --- a/pallets/subtensor/src/staking/remove_stake.rs +++ b/pallets/subtensor/src/staking/remove_stake.rs @@ -81,7 +81,7 @@ impl Pallet { // If the stake is below the minimum, we clear the nomination from storage. // This only applies to nominator stakes. // If the coldkey does not own the hotkey, it's a nominator stake. - let new_stake = Self::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let new_stake = Stake::::get(&hotkey, &coldkey); Self::clear_small_nomination_if_required(&hotkey, &coldkey, new_stake); // Check if stake lowered below MinStake and remove Pending children if it did diff --git a/pallets/subtensor/src/tests/children.rs b/pallets/subtensor/src/tests/children.rs index fe22d58af..b6f6a9c2c 100644 --- a/pallets/subtensor/src/tests/children.rs +++ b/pallets/subtensor/src/tests/children.rs @@ -1823,8 +1823,7 @@ fn test_childkey_single_parent_emission() { } step_block(7200 + 1); // Check emission distribution - let parent_stake: u64 = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_parent, &parent); + let parent_stake: u64 = Stake::::get(parent, coldkey_parent); let parent_stake_on_subnet: u64 = SubtensorModule::get_stake_for_hotkey_on_subnet(&parent, netuid); @@ -1834,8 +1833,7 @@ fn test_childkey_single_parent_emission() { parent_stake_on_subnet ); - let child_stake: u64 = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_child, &child); + let child_stake: u64 = Stake::::get(child, coldkey_child); let child_stake_on_subnet: u64 = SubtensorModule::get_stake_for_hotkey_on_subnet(&child, netuid); @@ -1845,10 +1843,7 @@ fn test_childkey_single_parent_emission() { child_stake_on_subnet ); - let weight_setter_stake: u64 = SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_weight_setter, - &weight_setter, - ); + let weight_setter_stake: u64 = Stake::::get(weight_setter, coldkey_weight_setter); let weight_setter_stake_on_subnet: u64 = SubtensorModule::get_stake_for_hotkey_on_subnet(&weight_setter, netuid); @@ -1969,7 +1964,7 @@ fn test_childkey_multiple_parents_emission() { ]; for (coldkey, hotkey, name) in stakes.iter() { - let stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(coldkey, hotkey); + let stake = Stake::::get(hotkey, coldkey); let stake_on_subnet = SubtensorModule::get_stake_for_hotkey_on_subnet(hotkey, netuid); log::debug!( "{} stake: {:?}, {} stake on subnet: {:?}", @@ -1980,15 +1975,10 @@ fn test_childkey_multiple_parents_emission() { ); } - let parent1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_parent1, &parent1); - let parent2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_parent2, &parent2); - let child_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_child, &child); - let weight_setter_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_weight_setter, - &weight_setter, - ); + let parent1_stake = Stake::::get(parent1, coldkey_parent1); + let parent2_stake = Stake::::get(parent2, coldkey_parent2); + let child_stake = Stake::::get(child, coldkey_child); + let weight_setter_stake = Stake::::get(weight_setter, coldkey_weight_setter); assert!( parent1_stake > 200_000, diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index 8ba9e4c1d..a2baed44e 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -6,7 +6,7 @@ use sp_core::U256; use substrate_fixed::types::I64F64; use crate::{ - HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, TargetStakesPerInterval, + HotkeyEmissionTempo, PendingEmission, PendingdHotkeyEmission, Stake, TargetStakesPerInterval, }; // Test the ability to hash all sorts of hotkeys. @@ -312,9 +312,9 @@ fn test_coinbase_nominator_drainage_overflow() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); @@ -349,11 +349,9 @@ fn test_coinbase_nominator_drainage_overflow() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let hotkey_stake = Stake::::get(hotkey, coldkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", @@ -465,9 +463,9 @@ fn test_coinbase_nominator_drainage_no_deltas() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); @@ -498,11 +496,9 @@ fn test_coinbase_nominator_drainage_no_deltas() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let hotkey_stake = Stake::::get(hotkey, coldkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", @@ -608,14 +604,13 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator1_stake_before = Stake::::get(hotkey, nominator1); assert_eq!(nominator1_stake_before, 100 + 123); // The stake should include the added stake // 5. Set emission and verify initial states @@ -648,11 +643,9 @@ fn test_coinbase_nominator_drainage_with_positive_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let hotkey_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let hotkey_stake = Stake::::get(hotkey, coldkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", @@ -765,14 +758,13 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator_1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!(nominator_1_stake_before, 100 - 12); @@ -806,12 +798,10 @@ fn test_coinbase_nominator_drainage_with_negative_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", @@ -931,14 +921,13 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the unchanged from the initial stake assert_eq!(nominator1_stake_before, 100); @@ -969,12 +958,10 @@ fn test_coinbase_nominator_drainage_with_neutral_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", @@ -1075,11 +1062,9 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator1, &hotkey, 100); SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 100); - let initial_nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let initial_nominator1_stake = Stake::::get(hotkey, nominator1); let intial_total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let initial_nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let initial_nominator2_stake = Stake::::get(hotkey, nominator2); assert_eq!(initial_nominator1_stake, initial_nominator2_stake); // Initial stakes should be equal @@ -1107,14 +1092,13 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); - let nominator_1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!( nominator_1_stake_before, @@ -1151,12 +1135,10 @@ fn test_coinbase_nominator_drainage_with_net_positive_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", @@ -1274,11 +1256,9 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator1, &hotkey, 300); SubtensorModule::increase_stake_on_coldkey_hotkey_account(&nominator2, &hotkey, 300); - let initial_nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let initial_nominator1_stake = Stake::::get(hotkey, nominator1); let intial_total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let initial_nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let initial_nominator2_stake = Stake::::get(hotkey, nominator2); assert_eq!(initial_nominator1_stake, initial_nominator2_stake); // Initial stakes should be equal @@ -1307,15 +1287,14 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { // Log the stakes for hotkey, nominator1, and nominator2 log::debug!( "Initial stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}", - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey), - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey) + Stake::::get(hotkey, coldkey), + Stake::::get(hotkey, nominator1), + Stake::::get(hotkey, nominator2) ); log::debug!("Stakes added for nominators"); let total_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator_1_stake_before = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); + let nominator_1_stake_before = Stake::::get(hotkey, nominator1); // Notice that nominator1 stake is the new stake, including the removed stake assert_eq!( nominator_1_stake_before, @@ -1353,12 +1332,10 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() { log::debug!("After second block, pending emission drained"); // 8. Check final stakes - let delegate_stake = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey, &hotkey); + let delegate_stake = Stake::::get(hotkey, coldkey); let total_hotkey_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey); - let nominator1_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator1, &hotkey); - let nominator2_stake = - SubtensorModule::get_stake_for_coldkey_and_hotkey(&nominator2, &hotkey); + let nominator1_stake = Stake::::get(hotkey, nominator1); + let nominator2_stake = Stake::::get(hotkey, nominator2); log::debug!( "Final stakes - Hotkey: {}, Nominator1: {}, Nominator2: {}, Total Hotkey Stake: {}", diff --git a/pallets/subtensor/src/tests/migration.rs b/pallets/subtensor/src/tests/migration.rs index 0daba9744..7fe0bedb5 100644 --- a/pallets/subtensor/src/tests/migration.rs +++ b/pallets/subtensor/src/tests/migration.rs @@ -651,34 +651,19 @@ fn test_migrate_fix_pending_emissions() { assert_eq!(TotalStake::::get(), expected_total_issuance); // Check the total stake maps are updated following the migration (removal of old null_account stake entries) assert_eq!(TotalColdkeyStake::::get(null_account), 0); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(null_account, datura_old_hk_account), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - null_account, - taostats_old_hk_account - ), - 0 - ); + assert_eq!(Stake::::get(datura_old_hk_account, null_account), 0); + assert_eq!(Stake::::get(taostats_old_hk_account, null_account), 0); // Check staking hotkeys is updated assert_eq!(StakingHotkeys::::get(null_account), vec![]); // Check the migration key has stake with both *old* hotkeys assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - migration_account, - datura_old_hk_account - ), + Stake::::get(datura_old_hk_account, migration_account), null_stake_datura ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - migration_account, - taostats_old_hk_account - ), + Stake::::get(taostats_old_hk_account, migration_account), null_stake_tao_stats ); assert_eq!( diff --git a/pallets/subtensor/src/tests/senate.rs b/pallets/subtensor/src/tests/senate.rs index a0a2f81c6..27f0df6ef 100644 --- a/pallets/subtensor/src/tests/senate.rs +++ b/pallets/subtensor/src/tests/senate.rs @@ -14,7 +14,7 @@ use sp_runtime::{ BuildStorage, }; -use crate::{migrations, Error, Owner, SubnetworkN}; +use crate::{migrations, Error, Owner, Stake, SubnetworkN}; pub fn new_test_ext() -> sp_io::TestExternalities { sp_tracing::try_init_simple(); @@ -101,7 +101,7 @@ fn test_senate_join_works() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -167,7 +167,7 @@ fn test_senate_vote_works() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -329,7 +329,7 @@ fn test_senate_leave_works() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -396,7 +396,7 @@ fn test_senate_leave_vote_removal() { 100_000 )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), 99_999 ); assert_eq!( @@ -533,7 +533,7 @@ fn test_senate_not_leave_when_stake_removed() { stake_amount )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&staker_coldkey, &hotkey_account_id), + Stake::::get(hotkey_account_id, staker_coldkey), stake_amount - 1 // Need to account for ED ); assert_eq!( @@ -749,10 +749,7 @@ fn test_adjust_senate_events() { 1 // Will be more than the last one in the senate by stake (has 0 stake) )); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &replacement_hotkey_account_id - ), + Stake::::get(replacement_hotkey_account_id, coldkey_account_id), 1 ); assert_eq!( diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index 688800b4f..79d986288 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -1107,10 +1107,7 @@ fn test_has_enough_stake_yes() { SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 10000 ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey_id, &hotkey_id), - 10000 - ); + assert_eq!(Stake::::get(hotkey_id, coldkey_id), 10000); assert!(SubtensorModule::has_enough_stake( &coldkey_id, &hotkey_id, @@ -1147,10 +1144,7 @@ fn test_non_existent_account() { &(U256::from(0)), 10, ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&U256::from(0), &U256::from(0)), - 10 - ); + assert_eq!(Stake::::get(U256::from(0), U256::from(0)), 10); assert_eq!( SubtensorModule::get_total_stake_for_coldkey(&(U256::from(0))), 10 @@ -1245,22 +1239,10 @@ fn test_unstake_all_coldkeys_from_hotkey_account() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); // Vefify stake for all coldkeys is 0 - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0_id, &hotkey_id), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey1_id, &hotkey_id), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2_id, &hotkey_id), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey3_id, &hotkey_id), - 0 - ); + assert_eq!(Stake::::get(hotkey_id, coldkey0_id), 0); + assert_eq!(Stake::::get(hotkey_id, coldkey1_id), 0); + assert_eq!(Stake::::get(hotkey_id, coldkey2_id), 0); + assert_eq!(Stake::::get(hotkey_id, coldkey3_id), 0); // Verify free balance is correct for all coldkeys assert_eq!(Balances::free_balance(coldkey0_id), amount); @@ -1311,10 +1293,7 @@ fn test_unstake_all_coldkeys_from_hotkey_account_single_staker() { assert_eq!(SubtensorModule::get_total_stake_for_hotkey(&hotkey_id), 0); // Vefify stake for single coldkey is 0 - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey0_id, &hotkey_id), - 0 - ); + assert_eq!(Stake::::get(hotkey_id, coldkey0_id), 0); // Verify free balance is correct for single coldkey assert_eq!(Balances::free_balance(coldkey0_id), amount); @@ -1403,10 +1382,7 @@ fn test_clear_small_nominations() { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); assert_eq!(Balances::free_balance(cold1), 4); // Add stake cold2 --> hot1 (is delegation.) @@ -1416,10 +1392,7 @@ fn test_clear_small_nominations() { hot1, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); + assert_eq!(Stake::::get(hot1, cold2), 1); assert_eq!(Balances::free_balance(cold2), 4); // Add stake cold1 --> hot2 (non delegation.) @@ -1429,10 +1402,7 @@ fn test_clear_small_nominations() { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold1), 1); assert_eq!(Balances::free_balance(cold1), 8); // Add stake cold2 --> hot2 (is delegation.) @@ -1442,31 +1412,16 @@ fn test_clear_small_nominations() { hot2, 1 )); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot2, cold2), 1); assert_eq!(Balances::free_balance(cold2), 8); // Run clear all small nominations when min stake is zero (noop) SubtensorModule::set_nominator_min_required_stake(0); SubtensorModule::clear_small_nominations(); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 1); + assert_eq!(Stake::::get(hot1, cold2), 1); + assert_eq!(Stake::::get(hot2, cold2), 1); // Set min nomination to 10 let total_cold1_stake_before = TotalColdkeyStake::::get(cold1); @@ -1480,22 +1435,10 @@ fn test_clear_small_nominations() { // Run clear all small nominations (removes delegations under 10) SubtensorModule::clear_small_nominations(); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot1), - 1 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold1, &hot2), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot1), - 0 - ); - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&cold2, &hot2), - 1 - ); + assert_eq!(Stake::::get(hot1, cold1), 1); + assert_eq!(Stake::::get(hot2, cold1), 0); + assert_eq!(Stake::::get(hot1, cold2), 0); + assert_eq!(Stake::::get(hot2, cold2), 1); // Balances have been added back into accounts. assert_eq!(Balances::free_balance(cold1), 9); @@ -1621,7 +1564,7 @@ fn test_remove_stake_below_minimum_threshold() { // without unstaking all and removing the nomination. let total_hotkey_stake_before = SubtensorModule::get_total_stake_for_hotkey(&hotkey1); let bal_before = Balances::free_balance(coldkey2); - let staked_before = SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey1); + let staked_before = Stake::::get(hotkey1, coldkey2); let total_network_stake_before = SubtensorModule::get_total_stake(); let total_issuance_before = SubtensorModule::get_total_issuance(); // check the premise of the test is correct @@ -1633,10 +1576,7 @@ fn test_remove_stake_below_minimum_threshold() { )); // Has no stake now - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey(&coldkey2, &hotkey1), - 0 - ); + assert_eq!(Stake::::get(hotkey1, coldkey2), 0); let stake_removed = staked_before; // All stake was removed // Has the full balance assert_eq!(Balances::free_balance(coldkey2), bal_before + stake_removed); diff --git a/pallets/subtensor/src/tests/uids.rs b/pallets/subtensor/src/tests/uids.rs index 4310218d1..1c25a2ba8 100644 --- a/pallets/subtensor/src/tests/uids.rs +++ b/pallets/subtensor/src/tests/uids.rs @@ -255,24 +255,15 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { // Check stake on neuron assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account_id), stake_amount ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account1_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account1_id), stake_amount + 1 ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account2_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account2_id), stake_amount + 2 ); @@ -297,24 +288,15 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { // Check the stake is still on the coldkey accounts. assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account_id), stake_amount ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account1_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account1_id), stake_amount + 1 ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account2_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account2_id), stake_amount + 2 ); @@ -338,20 +320,11 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { )); // Check the stake is now on the free balance of the coldkey accounts. - assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account_id, - &hotkey_account_id - ), - 0 - ); + assert_eq!(Stake::::get(hotkey_account_id, coldkey_account_id), 0); assert_eq!(Balances::free_balance(coldkey_account_id), stake_amount); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account1_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account1_id), 0 ); assert_eq!( @@ -360,10 +333,7 @@ fn test_replace_neuron_multiple_subnets_unstake_all() { ); assert_eq!( - SubtensorModule::get_stake_for_coldkey_and_hotkey( - &coldkey_account2_id, - &hotkey_account_id - ), + Stake::::get(hotkey_account_id, coldkey_account2_id), 0 ); assert_eq!(