Skip to content

Commit cadbe59

Browse files
author
Samuel Dare
committed
chore: conflicts, lints
1 parent 7518c55 commit cadbe59

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

justfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ 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
3843
fix:
3944
@echo "Running cargo fix..."
4045
cargo +{{RUSTV}} fix --workspace
@@ -46,5 +51,4 @@ lint:
4651
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
4752
just clippy-fix
4853
@echo "Running cargo clippy..."
49-
just clippy
50-
54+
just clippy

pallets/subtensor/src/swap.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ impl<T: Config> Pallet<T> {
4949
Error::<T>::HotKeySetTxRateLimitExceeded
5050
);
5151

52-
weight
53-
.saturating_accrue(T::DbWeight::get().reads((TotalNetworks::<T>::get() + 1u16) as u64));
52+
weight.saturating_accrue(
53+
T::DbWeight::get().reads((TotalNetworks::<T>::get().saturating_add(1u16)) as u64),
54+
);
5455

5556
let swap_cost = Self::get_hotkey_swap_cost();
5657
log::debug!("Swap cost: {:?}", swap_cost);
@@ -189,20 +190,20 @@ impl<T: Config> Pallet<T> {
189190
/// * `new_hotkey` - The new hotkey.
190191
/// * `weight` - The weight of the transaction.
191192
pub fn swap_stake(old_hotkey: &T::AccountId, new_hotkey: &T::AccountId, weight: &mut Weight) {
192-
let mut writes = 0;
193+
let mut writes: u64 = 0;
193194
let stakes: Vec<(T::AccountId, u64)> = Stake::<T>::iter_prefix(old_hotkey).collect();
194195
let stake_count = stakes.len() as u32;
195196

196197
for (coldkey, stake_amount) in stakes {
197198
Stake::<T>::insert(new_hotkey, &coldkey, stake_amount);
198-
writes += 1; // One write for insert
199+
writes = writes.saturating_add(1u64); // One write for insert
199200
}
200201

201202
// Clear the prefix for the old hotkey after transferring all stakes
202203
let _ = Stake::<T>::clear_prefix(old_hotkey, stake_count, None);
203-
writes += 1; // One write for clear_prefix
204+
writes = writes.saturating_add(1); // One write for insert; // One write for clear_prefix
204205

205-
*weight += T::DbWeight::get().writes(writes as u64);
206+
weight.saturating_accrue(T::DbWeight::get().writes(writes));
206207
}
207208

208209
/// Swaps the network membership status of the hotkey.
@@ -271,19 +272,19 @@ impl<T: Config> Pallet<T> {
271272
netuid_is_member: &[u16],
272273
weight: &mut Weight,
273274
) {
274-
let mut writes = 0;
275+
let mut writes: u64 = 0;
275276
for netuid in netuid_is_member {
276277
let keys: Vec<(u16, T::AccountId)> = Keys::<T>::iter_prefix(netuid).collect();
277278
for (uid, key) in keys {
278279
if key == *old_hotkey {
279280
log::info!("old hotkey found: {:?}", old_hotkey);
280281
Keys::<T>::insert(netuid, uid, new_hotkey.clone());
281282
}
282-
writes += 2;
283+
writes = writes.saturating_add(2u64);
283284
}
284285
}
285286
log::info!("writes: {:?}", writes);
286-
*weight += T::DbWeight::get().writes(writes as u64);
287+
weight.saturating_accrue(T::DbWeight::get().writes(writes));
287288
}
288289

289290
/// Swaps the loaded emission of the hotkey.
@@ -311,7 +312,7 @@ impl<T: Config> Pallet<T> {
311312
LoadedEmission::<T>::insert(netuid, emissions);
312313
}
313314
}
314-
*weight += T::DbWeight::get().writes(netuid_is_member.len() as u64);
315+
weight.saturating_accrue(T::DbWeight::get().writes(netuid_is_member.len() as u64));
315316
}
316317

317318
/// Swaps the UIDs of the hotkey.

pallets/subtensor/tests/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use frame_support::derive_impl;
33
use frame_support::dispatch::DispatchResultWithPostInfo;
44
use frame_support::weights::constants::RocksDbWeight;
55
use frame_support::{
6-
assert_ok, derive_impl,
6+
assert_ok,
77
dispatch::DispatchResultWithPostInfo,
88
parameter_types,
99
traits::{Everything, Hooks},

pallets/subtensor/tests/swap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]
2+
13
use codec::Encode;
24
use frame_support::weights::Weight;
35
use frame_support::{assert_err, assert_ok};

0 commit comments

Comments
 (0)