From 3d786ca2e26f108b27e0ed40fefad72ba47a9860 Mon Sep 17 00:00:00 2001 From: camfairchild Date: Thu, 19 Dec 2024 16:38:46 -0500 Subject: [PATCH] chore: clippy --- .../subtensor/src/coinbase/run_coinbase.rs | 4 +- pallets/subtensor/src/tests/coinbase.rs | 15 +++--- pallets/subtensor/src/tests/mock.rs | 17 +++++-- pallets/subtensor/src/tests/staking.rs | 50 +++++++++++-------- pallets/subtensor/src/tests/swap_hotkey.rs | 2 +- 5 files changed, 53 insertions(+), 35 deletions(-) diff --git a/pallets/subtensor/src/coinbase/run_coinbase.rs b/pallets/subtensor/src/coinbase/run_coinbase.rs index 1ad5da31d..40eaaf8ce 100644 --- a/pallets/subtensor/src/coinbase/run_coinbase.rs +++ b/pallets/subtensor/src/coinbase/run_coinbase.rs @@ -456,7 +456,7 @@ impl Pallet { hotkey: &T::AccountId, netuid: u16, emission: u64, - current_block: u64, + _current_block: u64, emission_tuples: &mut BTreeMap<(T::AccountId, T::AccountId), Vec<(u16, u64)>>, ) { // Calculate the hotkey's share of the emission based on its delegation status @@ -474,7 +474,7 @@ impl Pallet { let mut total_alpha: I96F32 = I96F32::from_num(0); let mut contributions: Vec<(T::AccountId, I96F32, I96F32)> = Vec::new(); - let hotkey_tempo = HotkeyEmissionTempo::::get(); + let _hotkey_tempo = HotkeyEmissionTempo::::get(); // Calculate total global and alpha scores for all nominators for (nominator, nominator_alpha) in Alpha::::iter_prefix((hotkey, netuid)) { diff --git a/pallets/subtensor/src/tests/coinbase.rs b/pallets/subtensor/src/tests/coinbase.rs index ab62bc105..1c32e6770 100644 --- a/pallets/subtensor/src/tests/coinbase.rs +++ b/pallets/subtensor/src/tests/coinbase.rs @@ -1,11 +1,10 @@ -#![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)] -use super::mock::*; +#![allow(clippy::unwrap_used)] -use frame_support::assert_ok; -use sp_core::U256; -use substrate_fixed::types::I64F64; +use super::mock::*; +use crate::subnets::Mechanism; +use crate::*; -use crate::TargetStakesPerInterval; +use sp_core::{Get, U256}; // Test the ability to hash all sorts of hotkeys. #[test] @@ -321,7 +320,7 @@ fn test_run_coinbase_different_mechanisms() { // Check subnet-specific behavior let emission1 = EmissionValues::::get(netuid1); - let emission2 = EmissionValues::::get(netuid2); + //let emission2 = EmissionValues::::get(netuid2); // For stable mechanism (netuid1) assert_eq!( @@ -1639,7 +1638,7 @@ fn test_emission_with_registration_disabled_subnet() { increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 1000, netuid); // Configure emission rate for the subnet - // TODO (CAM) + EmissionValues::::insert(netuid, 10); assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10); // Verify initial emission state is zero diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 1aba0f28f..ba1746e23 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -217,7 +217,10 @@ impl CanVote for CanVoteToTriumvirate { } } -use crate::{CollectiveInterface, MemberManagement, StakeThreshold, TotalHotkeyStake}; +use crate::{ + CollectiveInterface, MemberManagement, StakeThreshold, TotalHotkeyAlpha, + TotalHotkeyColdkeyStakesThisInterval, +}; pub struct ManageSenateMembers; impl MemberManagement for ManageSenateMembers { fn add_member(account: &AccountId) -> DispatchResultWithPostInfo { @@ -806,8 +809,8 @@ pub fn wait_and_set_pending_children(netuid: u16) { #[allow(dead_code)] pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec: &[(u64, U256)]) { // Set minimum stake for setting children - let parent_total_stake_original = TotalHotkeyStake::::get(parent); - TotalHotkeyStake::::insert(parent, StakeThreshold::::get()); + let parent_total_stake_original = TotalHotkeyAlpha::::get(parent, netuid); + TotalHotkeyAlpha::::insert(parent, netuid, StakeThreshold::::get()); // Set initial parent-child relationship assert_ok!(SubtensorModule::do_schedule_children( @@ -817,7 +820,7 @@ pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec: child_vec.to_vec() )); wait_and_set_pending_children(netuid); - TotalHotkeyStake::::insert(parent, parent_total_stake_original); + TotalHotkeyAlpha::::insert(parent, netuid, parent_total_stake_original); } // Helper function to wait for the rate limit @@ -829,3 +832,9 @@ pub fn step_rate_limit(transaction_type: &TransactionType, netuid: u16) { // Step that many blocks step_block(limit as u16); } + +#[allow(dead_code)] +pub fn get_total_stakes_this_interval_for_coldkey_hotkey(coldkey: &U256, hotkey: &U256) -> u64 { + let (stakes_count, _) = TotalHotkeyColdkeyStakesThisInterval::::get(coldkey, hotkey); + stakes_count +} diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index fcbbd9170..b9515c2d3 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -555,17 +555,14 @@ fn test_add_stake_rate_limit_exceeded() { let hotkey_account_id = U256::from(561337); let coldkey_account_id = U256::from(61337); let netuid: u16 = 1; - let start_nonce: u64 = 0; - let tempo: u16 = 13; let max_stakes = 2; let block_number = 1; SubtensorModule::set_target_stakes_per_interval(max_stakes); - SubtensorModule::set_stakes_this_interval_for_coldkey_hotkey( - &coldkey_account_id, - &hotkey_account_id, - max_stakes, - block_number, + TotalHotkeyColdkeyStakesThisInterval::::insert( + hotkey_account_id, + coldkey_account_id, + (max_stakes, block_number), ); // block 2 @@ -573,20 +570,25 @@ fn test_add_stake_rate_limit_exceeded() { // stake 2 and 3 assert_ok!(SubtensorModule::add_stake( - <::RuntimeOrigin>::signed(coldkey), - hotkey, + <::RuntimeOrigin>::signed(coldkey_account_id), + hotkey_account_id, + netuid, 1, )); // remove should increase the counter assert_ok!(SubtensorModule::remove_stake( - <::RuntimeOrigin>::signed(coldkey), - hotkey, + <::RuntimeOrigin>::signed(coldkey_account_id), + hotkey_account_id, + netuid, 1, )); // counter should be increased, while the block should not be changed assert_eq!( - TotalHotkeyColdkeyStakesThisInterval::::get(coldkey, hotkey), + TotalHotkeyColdkeyStakesThisInterval::::get( + hotkey_account_id, + coldkey_account_id + ), (3, 1) ); @@ -604,7 +606,7 @@ fn test_add_stake_rate_limit_exceeded() { Error::::StakingRateLimitExceeded ); - let current_stakes = SubtensorModule::get_stakes_this_interval_for_coldkey_hotkey( + let current_stakes = get_total_stakes_this_interval_for_coldkey_hotkey( &coldkey_account_id, &hotkey_account_id, ); @@ -645,7 +647,7 @@ fn test_remove_stake_under_limit() { 1, )); - let current_unstakes = SubtensorModule::get_stakes_this_interval_for_coldkey_hotkey( + let current_unstakes = get_total_stakes_this_interval_for_coldkey_hotkey( &coldkey_account_id, &hotkey_account_id, ); @@ -667,8 +669,8 @@ fn test_remove_stake_rate_limit_exceeded() { SubtensorModule::set_target_stakes_per_interval(max_unstakes); TotalHotkeyColdkeyStakesThisInterval::::insert( - &coldkey_account_id, - &hotkey_account_id, + hotkey_account_id, + coldkey_account_id, (max_unstakes, block_number), ); @@ -2843,8 +2845,8 @@ fn test_mining_emission_drain() { let root_tempo = 9; // neet root epoch to happen before subnet tempo let subnet_tempo = 10; let hotkey_tempo = 20; - let stake = 100_000_000_000; - let miner_stake = 1_000_000_000; + let stake: u64 = 100_000_000_000; + let miner_stake: u64 = 1_000_000_000; // Add network, register hotkeys, and setup network parameters add_network(root_id, root_tempo, 0); @@ -2892,16 +2894,19 @@ fn test_mining_emission_drain() { assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(coldkey), validator, + netuid, stake )); assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(coldkey), miner, + netuid, miner_stake )); assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(nominator), miner, + netuid, stake )); // Make all stakes viable @@ -2971,8 +2976,8 @@ fn test_mining_emission_drain_with_validation() { let root_tempo = 9; // neet root epoch to happen before subnet tempo let subnet_tempo = 10; let hotkey_tempo = 20; - let stake = 100_000_000_000; - let half_stake = 50_000_000_000; + let stake = 100_000_000_000_u64; + let half_stake = 50_000_000_000_u64; // Add network, register hotkeys, and setup network parameters add_network(root_id, root_tempo, 0); @@ -3019,16 +3024,19 @@ fn test_mining_emission_drain_with_validation() { assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(coldkey), validator_miner1, + netuid, stake )); assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(coldkey), validator_miner2, + netuid, half_stake )); assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(nominator), validator_miner2, + netuid, half_stake )); // Make all stakes viable @@ -3144,11 +3152,13 @@ fn test_mining_emission_drain_validator_valiminer_miner() { assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(coldkey), validator, + netuid, stake )); assert_ok!(SubtensorModule::add_stake( RuntimeOrigin::signed(coldkey), validator_miner, + netuid, stake )); // Make all stakes viable diff --git a/pallets/subtensor/src/tests/swap_hotkey.rs b/pallets/subtensor/src/tests/swap_hotkey.rs index 30ed7202e..dd0db8246 100644 --- a/pallets/subtensor/src/tests/swap_hotkey.rs +++ b/pallets/subtensor/src/tests/swap_hotkey.rs @@ -1118,7 +1118,7 @@ fn test_hotkey_swap_stake_delta() { for &coldkey in coldkeys.iter() { Stake::::insert(old_hotkey, coldkey, 123 + coldkey.saturated_into::()); Alpha::::insert( - (old_hotkey, coldkey, netuid), + (old_hotkey, netuid, coldkey), 1234 + coldkey.saturated_into::(), );