Skip to content

Commit

Permalink
chore: conflicts, lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Dare committed Jul 2, 2024
1 parent 7518c55 commit cadbe59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ clippy-fix:
-A clippy::todo \
-A clippy::unimplemented \
-A clippy::indexing_slicing
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- \
-A clippy::todo \
-A clippy::unimplemented \
-A clippy::indexing_slicing
fix:
@echo "Running cargo fix..."
cargo +{{RUSTV}} fix --workspace
Expand All @@ -46,5 +51,4 @@ lint:
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
just clippy-fix
@echo "Running cargo clippy..."
just clippy

just clippy
21 changes: 11 additions & 10 deletions pallets/subtensor/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ impl<T: Config> Pallet<T> {
Error::<T>::HotKeySetTxRateLimitExceeded
);

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

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

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

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

*weight += T::DbWeight::get().writes(writes as u64);
weight.saturating_accrue(T::DbWeight::get().writes(writes));
}

/// Swaps the network membership status of the hotkey.
Expand Down Expand Up @@ -271,19 +272,19 @@ impl<T: Config> Pallet<T> {
netuid_is_member: &[u16],
weight: &mut Weight,
) {
let mut writes = 0;
let mut writes: u64 = 0;
for netuid in netuid_is_member {
let keys: Vec<(u16, T::AccountId)> = Keys::<T>::iter_prefix(netuid).collect();
for (uid, key) in keys {
if key == *old_hotkey {
log::info!("old hotkey found: {:?}", old_hotkey);
Keys::<T>::insert(netuid, uid, new_hotkey.clone());
}
writes += 2;
writes = writes.saturating_add(2u64);
}
}
log::info!("writes: {:?}", writes);
*weight += T::DbWeight::get().writes(writes as u64);
weight.saturating_accrue(T::DbWeight::get().writes(writes));
}

/// Swaps the loaded emission of the hotkey.
Expand Down Expand Up @@ -311,7 +312,7 @@ impl<T: Config> Pallet<T> {
LoadedEmission::<T>::insert(netuid, emissions);
}
}
*weight += T::DbWeight::get().writes(netuid_is_member.len() as u64);
weight.saturating_accrue(T::DbWeight::get().writes(netuid_is_member.len() as u64));
}

/// Swaps the UIDs of the hotkey.
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use frame_support::derive_impl;
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::weights::constants::RocksDbWeight;
use frame_support::{
assert_ok, derive_impl,
assert_ok,
dispatch::DispatchResultWithPostInfo,
parameter_types,
traits::{Everything, Hooks},
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/tests/swap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]

use codec::Encode;
use frame_support::weights::Weight;
use frame_support::{assert_err, assert_ok};
Expand Down

0 comments on commit cadbe59

Please sign in to comment.