Skip to content

Commit 3d786ca

Browse files
committed
chore: clippy
1 parent c13afe1 commit 3d786ca

File tree

5 files changed

+53
-35
lines changed

5 files changed

+53
-35
lines changed

Diff for: pallets/subtensor/src/coinbase/run_coinbase.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<T: Config> Pallet<T> {
456456
hotkey: &T::AccountId,
457457
netuid: u16,
458458
emission: u64,
459-
current_block: u64,
459+
_current_block: u64,
460460
emission_tuples: &mut BTreeMap<(T::AccountId, T::AccountId), Vec<(u16, u64)>>,
461461
) {
462462
// Calculate the hotkey's share of the emission based on its delegation status
@@ -474,7 +474,7 @@ impl<T: Config> Pallet<T> {
474474
let mut total_alpha: I96F32 = I96F32::from_num(0);
475475
let mut contributions: Vec<(T::AccountId, I96F32, I96F32)> = Vec::new();
476476

477-
let hotkey_tempo = HotkeyEmissionTempo::<T>::get();
477+
let _hotkey_tempo = HotkeyEmissionTempo::<T>::get();
478478

479479
// Calculate total global and alpha scores for all nominators
480480
for (nominator, nominator_alpha) in Alpha::<T>::iter_prefix((hotkey, netuid)) {

Diff for: pallets/subtensor/src/tests/coinbase.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]
2-
use super::mock::*;
1+
#![allow(clippy::unwrap_used)]
32

4-
use frame_support::assert_ok;
5-
use sp_core::U256;
6-
use substrate_fixed::types::I64F64;
3+
use super::mock::*;
4+
use crate::subnets::Mechanism;
5+
use crate::*;
76

8-
use crate::TargetStakesPerInterval;
7+
use sp_core::{Get, U256};
98

109
// Test the ability to hash all sorts of hotkeys.
1110
#[test]
@@ -321,7 +320,7 @@ fn test_run_coinbase_different_mechanisms() {
321320

322321
// Check subnet-specific behavior
323322
let emission1 = EmissionValues::<Test>::get(netuid1);
324-
let emission2 = EmissionValues::<Test>::get(netuid2);
323+
//let emission2 = EmissionValues::<Test>::get(netuid2);
325324

326325
// For stable mechanism (netuid1)
327326
assert_eq!(
@@ -1639,7 +1638,7 @@ fn test_emission_with_registration_disabled_subnet() {
16391638
increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 1000, netuid);
16401639

16411640
// Configure emission rate for the subnet
1642-
// TODO (CAM)
1641+
EmissionValues::<Test>::insert(netuid, 10);
16431642
assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10);
16441643

16451644
// Verify initial emission state is zero

Diff for: pallets/subtensor/src/tests/mock.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ impl CanVote<AccountId> for CanVoteToTriumvirate {
217217
}
218218
}
219219

220-
use crate::{CollectiveInterface, MemberManagement, StakeThreshold, TotalHotkeyStake};
220+
use crate::{
221+
CollectiveInterface, MemberManagement, StakeThreshold, TotalHotkeyAlpha,
222+
TotalHotkeyColdkeyStakesThisInterval,
223+
};
221224
pub struct ManageSenateMembers;
222225
impl MemberManagement<AccountId> for ManageSenateMembers {
223226
fn add_member(account: &AccountId) -> DispatchResultWithPostInfo {
@@ -806,8 +809,8 @@ pub fn wait_and_set_pending_children(netuid: u16) {
806809
#[allow(dead_code)]
807810
pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec: &[(u64, U256)]) {
808811
// Set minimum stake for setting children
809-
let parent_total_stake_original = TotalHotkeyStake::<Test>::get(parent);
810-
TotalHotkeyStake::<Test>::insert(parent, StakeThreshold::<Test>::get());
812+
let parent_total_stake_original = TotalHotkeyAlpha::<Test>::get(parent, netuid);
813+
TotalHotkeyAlpha::<Test>::insert(parent, netuid, StakeThreshold::<Test>::get());
811814

812815
// Set initial parent-child relationship
813816
assert_ok!(SubtensorModule::do_schedule_children(
@@ -817,7 +820,7 @@ pub fn mock_set_children(coldkey: &U256, parent: &U256, netuid: u16, child_vec:
817820
child_vec.to_vec()
818821
));
819822
wait_and_set_pending_children(netuid);
820-
TotalHotkeyStake::<Test>::insert(parent, parent_total_stake_original);
823+
TotalHotkeyAlpha::<Test>::insert(parent, netuid, parent_total_stake_original);
821824
}
822825

823826
// Helper function to wait for the rate limit
@@ -829,3 +832,9 @@ pub fn step_rate_limit(transaction_type: &TransactionType, netuid: u16) {
829832
// Step that many blocks
830833
step_block(limit as u16);
831834
}
835+
836+
#[allow(dead_code)]
837+
pub fn get_total_stakes_this_interval_for_coldkey_hotkey(coldkey: &U256, hotkey: &U256) -> u64 {
838+
let (stakes_count, _) = TotalHotkeyColdkeyStakesThisInterval::<Test>::get(coldkey, hotkey);
839+
stakes_count
840+
}

Diff for: pallets/subtensor/src/tests/staking.rs

+30-20
Original file line numberDiff line numberDiff line change
@@ -555,38 +555,40 @@ fn test_add_stake_rate_limit_exceeded() {
555555
let hotkey_account_id = U256::from(561337);
556556
let coldkey_account_id = U256::from(61337);
557557
let netuid: u16 = 1;
558-
let start_nonce: u64 = 0;
559-
let tempo: u16 = 13;
560558
let max_stakes = 2;
561559
let block_number = 1;
562560

563561
SubtensorModule::set_target_stakes_per_interval(max_stakes);
564-
SubtensorModule::set_stakes_this_interval_for_coldkey_hotkey(
565-
&coldkey_account_id,
566-
&hotkey_account_id,
567-
max_stakes,
568-
block_number,
562+
TotalHotkeyColdkeyStakesThisInterval::<Test>::insert(
563+
hotkey_account_id,
564+
coldkey_account_id,
565+
(max_stakes, block_number),
569566
);
570567

571568
// block 2
572569
step_block(1);
573570

574571
// stake 2 and 3
575572
assert_ok!(SubtensorModule::add_stake(
576-
<<Test as Config>::RuntimeOrigin>::signed(coldkey),
577-
hotkey,
573+
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
574+
hotkey_account_id,
575+
netuid,
578576
1,
579577
));
580578
// remove should increase the counter
581579
assert_ok!(SubtensorModule::remove_stake(
582-
<<Test as Config>::RuntimeOrigin>::signed(coldkey),
583-
hotkey,
580+
<<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id),
581+
hotkey_account_id,
582+
netuid,
584583
1,
585584
));
586585

587586
// counter should be increased, while the block should not be changed
588587
assert_eq!(
589-
TotalHotkeyColdkeyStakesThisInterval::<Test>::get(coldkey, hotkey),
588+
TotalHotkeyColdkeyStakesThisInterval::<Test>::get(
589+
hotkey_account_id,
590+
coldkey_account_id
591+
),
590592
(3, 1)
591593
);
592594

@@ -604,7 +606,7 @@ fn test_add_stake_rate_limit_exceeded() {
604606
Error::<Test>::StakingRateLimitExceeded
605607
);
606608

607-
let current_stakes = SubtensorModule::get_stakes_this_interval_for_coldkey_hotkey(
609+
let current_stakes = get_total_stakes_this_interval_for_coldkey_hotkey(
608610
&coldkey_account_id,
609611
&hotkey_account_id,
610612
);
@@ -645,7 +647,7 @@ fn test_remove_stake_under_limit() {
645647
1,
646648
));
647649

648-
let current_unstakes = SubtensorModule::get_stakes_this_interval_for_coldkey_hotkey(
650+
let current_unstakes = get_total_stakes_this_interval_for_coldkey_hotkey(
649651
&coldkey_account_id,
650652
&hotkey_account_id,
651653
);
@@ -667,8 +669,8 @@ fn test_remove_stake_rate_limit_exceeded() {
667669

668670
SubtensorModule::set_target_stakes_per_interval(max_unstakes);
669671
TotalHotkeyColdkeyStakesThisInterval::<Test>::insert(
670-
&coldkey_account_id,
671-
&hotkey_account_id,
672+
hotkey_account_id,
673+
coldkey_account_id,
672674
(max_unstakes, block_number),
673675
);
674676

@@ -2843,8 +2845,8 @@ fn test_mining_emission_drain() {
28432845
let root_tempo = 9; // neet root epoch to happen before subnet tempo
28442846
let subnet_tempo = 10;
28452847
let hotkey_tempo = 20;
2846-
let stake = 100_000_000_000;
2847-
let miner_stake = 1_000_000_000;
2848+
let stake: u64 = 100_000_000_000;
2849+
let miner_stake: u64 = 1_000_000_000;
28482850

28492851
// Add network, register hotkeys, and setup network parameters
28502852
add_network(root_id, root_tempo, 0);
@@ -2892,16 +2894,19 @@ fn test_mining_emission_drain() {
28922894
assert_ok!(SubtensorModule::add_stake(
28932895
RuntimeOrigin::signed(coldkey),
28942896
validator,
2897+
netuid,
28952898
stake
28962899
));
28972900
assert_ok!(SubtensorModule::add_stake(
28982901
RuntimeOrigin::signed(coldkey),
28992902
miner,
2903+
netuid,
29002904
miner_stake
29012905
));
29022906
assert_ok!(SubtensorModule::add_stake(
29032907
RuntimeOrigin::signed(nominator),
29042908
miner,
2909+
netuid,
29052910
stake
29062911
));
29072912
// Make all stakes viable
@@ -2971,8 +2976,8 @@ fn test_mining_emission_drain_with_validation() {
29712976
let root_tempo = 9; // neet root epoch to happen before subnet tempo
29722977
let subnet_tempo = 10;
29732978
let hotkey_tempo = 20;
2974-
let stake = 100_000_000_000;
2975-
let half_stake = 50_000_000_000;
2979+
let stake = 100_000_000_000_u64;
2980+
let half_stake = 50_000_000_000_u64;
29762981

29772982
// Add network, register hotkeys, and setup network parameters
29782983
add_network(root_id, root_tempo, 0);
@@ -3019,16 +3024,19 @@ fn test_mining_emission_drain_with_validation() {
30193024
assert_ok!(SubtensorModule::add_stake(
30203025
RuntimeOrigin::signed(coldkey),
30213026
validator_miner1,
3027+
netuid,
30223028
stake
30233029
));
30243030
assert_ok!(SubtensorModule::add_stake(
30253031
RuntimeOrigin::signed(coldkey),
30263032
validator_miner2,
3033+
netuid,
30273034
half_stake
30283035
));
30293036
assert_ok!(SubtensorModule::add_stake(
30303037
RuntimeOrigin::signed(nominator),
30313038
validator_miner2,
3039+
netuid,
30323040
half_stake
30333041
));
30343042
// Make all stakes viable
@@ -3144,11 +3152,13 @@ fn test_mining_emission_drain_validator_valiminer_miner() {
31443152
assert_ok!(SubtensorModule::add_stake(
31453153
RuntimeOrigin::signed(coldkey),
31463154
validator,
3155+
netuid,
31473156
stake
31483157
));
31493158
assert_ok!(SubtensorModule::add_stake(
31503159
RuntimeOrigin::signed(coldkey),
31513160
validator_miner,
3161+
netuid,
31523162
stake
31533163
));
31543164
// Make all stakes viable

Diff for: pallets/subtensor/src/tests/swap_hotkey.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ fn test_hotkey_swap_stake_delta() {
11181118
for &coldkey in coldkeys.iter() {
11191119
Stake::<Test>::insert(old_hotkey, coldkey, 123 + coldkey.saturated_into::<u64>());
11201120
Alpha::<Test>::insert(
1121-
(old_hotkey, coldkey, netuid),
1121+
(old_hotkey, netuid, coldkey),
11221122
1234 + coldkey.saturated_into::<u64>(),
11231123
);
11241124

0 commit comments

Comments
 (0)