Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Dec 19, 2024
1 parent c13afe1 commit 3d786ca
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl<T: Config> Pallet<T> {
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
Expand All @@ -474,7 +474,7 @@ impl<T: Config> Pallet<T> {
let mut total_alpha: I96F32 = I96F32::from_num(0);
let mut contributions: Vec<(T::AccountId, I96F32, I96F32)> = Vec::new();

let hotkey_tempo = HotkeyEmissionTempo::<T>::get();
let _hotkey_tempo = HotkeyEmissionTempo::<T>::get();

// Calculate total global and alpha scores for all nominators
for (nominator, nominator_alpha) in Alpha::<T>::iter_prefix((hotkey, netuid)) {
Expand Down
15 changes: 7 additions & 8 deletions pallets/subtensor/src/tests/coinbase.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -321,7 +320,7 @@ fn test_run_coinbase_different_mechanisms() {

// Check subnet-specific behavior
let emission1 = EmissionValues::<Test>::get(netuid1);
let emission2 = EmissionValues::<Test>::get(netuid2);
//let emission2 = EmissionValues::<Test>::get(netuid2);

// For stable mechanism (netuid1)
assert_eq!(
Expand Down Expand Up @@ -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::<Test>::insert(netuid, 10);
assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10);

// Verify initial emission state is zero
Expand Down
17 changes: 13 additions & 4 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ impl CanVote<AccountId> for CanVoteToTriumvirate {
}
}

use crate::{CollectiveInterface, MemberManagement, StakeThreshold, TotalHotkeyStake};
use crate::{
CollectiveInterface, MemberManagement, StakeThreshold, TotalHotkeyAlpha,
TotalHotkeyColdkeyStakesThisInterval,
};
pub struct ManageSenateMembers;
impl MemberManagement<AccountId> for ManageSenateMembers {
fn add_member(account: &AccountId) -> DispatchResultWithPostInfo {
Expand Down Expand Up @@ -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::<Test>::get(parent);
TotalHotkeyStake::<Test>::insert(parent, StakeThreshold::<Test>::get());
let parent_total_stake_original = TotalHotkeyAlpha::<Test>::get(parent, netuid);
TotalHotkeyAlpha::<Test>::insert(parent, netuid, StakeThreshold::<Test>::get());

// Set initial parent-child relationship
assert_ok!(SubtensorModule::do_schedule_children(
Expand All @@ -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::<Test>::insert(parent, parent_total_stake_original);
TotalHotkeyAlpha::<Test>::insert(parent, netuid, parent_total_stake_original);
}

// Helper function to wait for the rate limit
Expand All @@ -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::<Test>::get(coldkey, hotkey);
stakes_count
}
50 changes: 30 additions & 20 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,38 +555,40 @@ 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::<Test>::insert(
hotkey_account_id,
coldkey_account_id,
(max_stakes, block_number),
);

// block 2
step_block(1);

// stake 2 and 3
assert_ok!(SubtensorModule::add_stake(
<<Test as Config>::RuntimeOrigin>::signed(coldkey),
hotkey,
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id,
netuid,
1,
));
// remove should increase the counter
assert_ok!(SubtensorModule::remove_stake(
<<Test as Config>::RuntimeOrigin>::signed(coldkey),
hotkey,
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
hotkey_account_id,
netuid,
1,
));

// counter should be increased, while the block should not be changed
assert_eq!(
TotalHotkeyColdkeyStakesThisInterval::<Test>::get(coldkey, hotkey),
TotalHotkeyColdkeyStakesThisInterval::<Test>::get(
hotkey_account_id,
coldkey_account_id
),
(3, 1)
);

Expand All @@ -604,7 +606,7 @@ fn test_add_stake_rate_limit_exceeded() {
Error::<Test>::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,
);
Expand Down Expand Up @@ -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,
);
Expand All @@ -667,8 +669,8 @@ fn test_remove_stake_rate_limit_exceeded() {

SubtensorModule::set_target_stakes_per_interval(max_unstakes);
TotalHotkeyColdkeyStakesThisInterval::<Test>::insert(
&coldkey_account_id,
&hotkey_account_id,
hotkey_account_id,
coldkey_account_id,
(max_unstakes, block_number),
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/tests/swap_hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ fn test_hotkey_swap_stake_delta() {
for &coldkey in coldkeys.iter() {
Stake::<Test>::insert(old_hotkey, coldkey, 123 + coldkey.saturated_into::<u64>());
Alpha::<Test>::insert(
(old_hotkey, coldkey, netuid),
(old_hotkey, netuid, coldkey),
1234 + coldkey.saturated_into::<u64>(),
);

Expand Down

0 comments on commit 3d786ca

Please sign in to comment.