Skip to content

Commit 49d19b1

Browse files
author
Samuel Dare
committed
chore: lints
1 parent bda0c5a commit 49d19b1

File tree

6 files changed

+43
-51
lines changed

6 files changed

+43
-51
lines changed

justfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ clippy-fix:
3535
-A clippy::todo \
3636
-A clippy::unimplemented \
3737
-A clippy::indexing_slicing
38-
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
39-
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- \
40-
-A clippy::todo \
41-
-A clippy::unimplemented \
42-
-A clippy::indexing_slicing
38+
4339
fix:
4440
@echo "Running cargo fix..."
4541
cargo +{{RUSTV}} fix --workspace

pallets/subtensor/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,15 +1208,12 @@ pub mod pallet {
12081208
Owner::<T>::insert(hotkey.clone(), coldkey.clone());
12091209

12101210
// Update Owned map
1211-
let mut hotkeys = Owned::<T>::get(&coldkey);
1212-
if !hotkeys.contains(&hotkey) {
1211+
let mut hotkeys = Owned::<T>::get(coldkey);
1212+
if !hotkeys.contains(hotkey) {
12131213
hotkeys.push(hotkey.clone());
1214-
Owned::<T>::insert(
1215-
&coldkey,
1216-
hotkeys,
1217-
);
1214+
Owned::<T>::insert(coldkey, hotkeys);
12181215
}
1219-
1216+
12201217
TotalHotkeyStake::<T>::insert(hotkey.clone(), stake);
12211218
TotalColdkeyStake::<T>::insert(
12221219
coldkey.clone(),
@@ -1994,7 +1991,7 @@ pub mod pallet {
19941991
origin: OriginFor<T>,
19951992
old_coldkey: T::AccountId,
19961993
new_coldkey: T::AccountId,
1997-
) -> DispatchResultWithPostInfo {
1994+
) -> DispatchResultWithPostInfo {
19981995
Self::do_swap_coldkey(origin, &old_coldkey, &new_coldkey)
19991996
}
20001997

pallets/subtensor/src/migration.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,7 @@ pub fn migrate_populate_owned<T: Config>() -> Weight {
502502
}
503503
}
504504

505-
Owned::<T>::insert(
506-
&coldkey,
507-
hotkeys,
508-
);
505+
Owned::<T>::insert(&coldkey, hotkeys);
509506

510507
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 1));
511508
});

pallets/subtensor/src/staking.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,10 @@ impl<T: Config> Pallet<T> {
562562
Owner::<T>::insert(hotkey, coldkey);
563563

564564
// Update Owned map
565-
let mut hotkeys = Owned::<T>::get(&coldkey);
566-
if !hotkeys.contains(&hotkey) {
565+
let mut hotkeys = Owned::<T>::get(coldkey);
566+
if !hotkeys.contains(hotkey) {
567567
hotkeys.push(hotkey.clone());
568-
Owned::<T>::insert(
569-
&coldkey,
570-
hotkeys,
571-
);
568+
Owned::<T>::insert(coldkey, hotkeys);
572569
}
573570
}
574571
}

pallets/subtensor/src/swap.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,12 @@ impl<T: Config> Pallet<T> {
225225
Owner::<T>::insert(new_hotkey, coldkey.clone());
226226

227227
// Update Owned map
228-
let mut hotkeys = Owned::<T>::get(&coldkey);
229-
if !hotkeys.contains(&new_hotkey) {
228+
let mut hotkeys = Owned::<T>::get(coldkey);
229+
if !hotkeys.contains(new_hotkey) {
230230
hotkeys.push(new_hotkey.clone());
231231
}
232232
hotkeys.retain(|hk| *hk != *old_hotkey);
233-
Owned::<T>::insert(
234-
&coldkey,
235-
hotkeys,
236-
);
233+
Owned::<T>::insert(coldkey, hotkeys);
237234

238235
weight.saturating_accrue(T::DbWeight::get().writes(2));
239236
}
@@ -547,7 +544,7 @@ impl<T: Config> Pallet<T> {
547544
new_coldkey: &T::AccountId,
548545
weight: &mut Weight,
549546
) {
550-
// Find all hotkeys for this coldkey
547+
// Find all hotkeys for this coldkey
551548
let hotkeys = Owned::<T>::get(old_coldkey);
552549
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 0));
553550
for hotkey in hotkeys.iter() {
@@ -603,13 +600,10 @@ impl<T: Config> Pallet<T> {
603600
) {
604601
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 0));
605602
for hotkey in Owned::<T>::get(old_coldkey).iter() {
606-
let (stake, block) = TotalHotkeyColdkeyStakesThisInterval::<T>::get(&hotkey, old_coldkey);
603+
let (stake, block) =
604+
TotalHotkeyColdkeyStakesThisInterval::<T>::get(&hotkey, old_coldkey);
607605
TotalHotkeyColdkeyStakesThisInterval::<T>::remove(&hotkey, old_coldkey);
608-
TotalHotkeyColdkeyStakesThisInterval::<T>::insert(
609-
&hotkey,
610-
new_coldkey,
611-
(stake, block),
612-
);
606+
TotalHotkeyColdkeyStakesThisInterval::<T>::insert(&hotkey, new_coldkey, (stake, block));
613607
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
614608
}
615609
}
@@ -672,12 +666,12 @@ impl<T: Config> Pallet<T> {
672666
weight: &mut Weight,
673667
) {
674668
// Update Owned map with new coldkey
675-
let hotkeys = Owned::<T>::get(&old_coldkey);
669+
let hotkeys = Owned::<T>::get(old_coldkey);
676670
Owned::<T>::remove(old_coldkey);
677671
Owned::<T>::insert(new_coldkey, hotkeys);
678672
weight.saturating_accrue(T::DbWeight::get().reads_writes(0, 2));
679673
}
680-
674+
681675
/// Returns the cost of swapping a coldkey.
682676
///
683677
/// # Returns

pallets/subtensor/tests/swap.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,10 @@ fn test_do_swap_coldkey_success() {
10631063
// Setup initial state
10641064
add_network(netuid, 13, 0);
10651065
register_ok_neuron(netuid, hotkey, old_coldkey, 0);
1066-
SubtensorModule::add_balance_to_coldkey_account(&old_coldkey, stake_amount + swap_cost + free_balance);
1066+
SubtensorModule::add_balance_to_coldkey_account(
1067+
&old_coldkey,
1068+
stake_amount + swap_cost + free_balance,
1069+
);
10671070

10681071
// Add stake to the neuron
10691072
assert_ok!(SubtensorModule::add_stake(
@@ -1072,20 +1075,22 @@ fn test_do_swap_coldkey_success() {
10721075
stake_amount
10731076
));
10741077

1075-
log::info!("TotalColdkeyStake::<Test>::get(old_coldkey): {:?}", TotalColdkeyStake::<Test>::get(old_coldkey));
1076-
log::info!("Stake::<Test>::get(old_coldkey, hotkey): {:?}", Stake::<Test>::get(hotkey, old_coldkey));
1078+
log::info!(
1079+
"TotalColdkeyStake::<Test>::get(old_coldkey): {:?}",
1080+
TotalColdkeyStake::<Test>::get(old_coldkey)
1081+
);
1082+
log::info!(
1083+
"Stake::<Test>::get(old_coldkey, hotkey): {:?}",
1084+
Stake::<Test>::get(hotkey, old_coldkey)
1085+
);
10771086

10781087
// Verify initial stake
10791088
assert_eq!(TotalColdkeyStake::<Test>::get(old_coldkey), stake_amount);
10801089
assert_eq!(Stake::<Test>::get(hotkey, old_coldkey), stake_amount);
10811090

1082-
10831091
assert_eq!(Owned::<Test>::get(old_coldkey), vec![hotkey]);
10841092
assert!(!Owned::<Test>::contains_key(new_coldkey));
10851093

1086-
1087-
1088-
10891094
// Get coldkey free balance before swap
10901095
let balance = SubtensorModule::get_coldkey_balance(&old_coldkey);
10911096
assert_eq!(balance, free_balance + swap_cost);
@@ -1107,14 +1112,20 @@ fn test_do_swap_coldkey_success() {
11071112
assert!(!Owned::<Test>::contains_key(old_coldkey));
11081113

11091114
// Verify balance transfer
1110-
assert_eq!(SubtensorModule::get_coldkey_balance(&new_coldkey), balance - swap_cost);
1115+
assert_eq!(
1116+
SubtensorModule::get_coldkey_balance(&new_coldkey),
1117+
balance - swap_cost
1118+
);
11111119
assert_eq!(SubtensorModule::get_coldkey_balance(&old_coldkey), 0);
11121120

11131121
// Verify event emission
1114-
System::assert_last_event(Event::ColdkeySwapped {
1115-
old_coldkey: old_coldkey,
1116-
new_coldkey: new_coldkey,
1117-
}.into());
1122+
System::assert_last_event(
1123+
Event::ColdkeySwapped {
1124+
old_coldkey,
1125+
new_coldkey,
1126+
}
1127+
.into(),
1128+
);
11181129
});
11191130
}
11201131

@@ -1255,7 +1266,7 @@ fn test_swap_owner_for_coldkey() {
12551266
Owner::<Test>::insert(hotkey1, old_coldkey);
12561267
Owner::<Test>::insert(hotkey2, old_coldkey);
12571268

1258-
// Initialize Owned map
1269+
// Initialize Owned map
12591270
Owned::<Test>::insert(old_coldkey, vec![hotkey1, hotkey2]);
12601271

12611272
// Perform the swap

0 commit comments

Comments
 (0)