Skip to content

Commit ff23b6f

Browse files
constconst
authored andcommitted
fmt
1 parent 3c61aa8 commit ff23b6f

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

pallets/subtensor/src/migration.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub mod deprecated_loaded_emission_format {
2424
StorageMap<Pallet<T>, Identity, u16, Vec<(AccountIdOf<T>, u64)>, OptionQuery>;
2525
}
2626

27-
2827
/// Migrates and fixes the total coldkey stake.
2928
///
3029
/// This function iterates through all staking hotkeys, calculates the total stake for each coldkey,
@@ -33,7 +32,7 @@ pub mod deprecated_loaded_emission_format {
3332
///
3433
/// # Returns
3534
/// The weight of the migration process.
36-
pub fn do_migrate_fix_total_coldkey_stake<T: Config>() -> Weight{
35+
pub fn do_migrate_fix_total_coldkey_stake<T: Config>() -> Weight {
3736
// Initialize the weight with one read operation.
3837
let mut weight = T::DbWeight::get().reads(1);
3938

@@ -46,19 +45,19 @@ pub fn do_migrate_fix_total_coldkey_stake<T: Config>() -> Weight{
4645
// Calculate the total stake for the current coldkey.
4746
for hotkey in hotkey_vec {
4847
// Cant fail on retrieval.
49-
coldkey_stake_sum = coldkey_stake_sum.saturating_add(Stake::<T>::get(hotkey, coldkey.clone()));
48+
coldkey_stake_sum =
49+
coldkey_stake_sum.saturating_add(Stake::<T>::get(hotkey, coldkey.clone()));
5050
weight = weight.saturating_add(T::DbWeight::get().reads(1));
5151
}
5252
// Update the `TotalColdkeyStake` storage with the calculated stake sum.
5353
// Cant fail on insert.
54-
TotalColdkeyStake::<T>::insert( coldkey.clone(), coldkey_stake_sum );
54+
TotalColdkeyStake::<T>::insert(coldkey.clone(), coldkey_stake_sum);
5555
weight = weight.saturating_add(T::DbWeight::get().writes(1));
5656
}
5757
weight
5858
}
5959
// Public migrate function to be called by Lib.rs on upgrade.
6060
pub fn migrate_fix_total_coldkey_stake<T: Config>() -> Weight {
61-
6261
let current_storage_version: u16 = 7;
6362
let next_storage_version: u16 = 8;
6463

@@ -67,15 +66,15 @@ pub fn migrate_fix_total_coldkey_stake<T: Config>() -> Weight {
6766

6867
// Grab the current on-chain storage version.
6968
// Cant fail on retrieval.
70-
let onchain_version = Pallet::<T>::on_chain_storage_version();
69+
let onchain_version = Pallet::<T>::on_chain_storage_version();
7170

7271
// Only run this migration on storage version 6.
7372
if onchain_version == current_storage_version {
74-
weight = weight.saturating_add( do_migrate_fix_total_coldkey_stake::<T>() );
73+
weight = weight.saturating_add(do_migrate_fix_total_coldkey_stake::<T>());
7574
// Cant fail on insert.
76-
StorageVersion::new( next_storage_version ).put::<Pallet<T>>();
75+
StorageVersion::new(next_storage_version).put::<Pallet<T>>();
7776
weight.saturating_accrue(T::DbWeight::get().writes(1));
78-
}
77+
}
7978

8079
// Return the migration weight.
8180
weight

pallets/subtensor/tests/migration.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
mod mock;
44
use frame_support::assert_ok;
55
use frame_system::Config;
6-
use pallet_subtensor::*;
76
use mock::*;
7+
use pallet_subtensor::*;
88
use sp_core::U256;
99

1010
#[test]
@@ -278,12 +278,11 @@ fn test_migration_delete_subnet_21() {
278278
})
279279
}
280280

281-
282281
// SKIP_WASM_BUILD=1 RUST_LOG=info cargo test --test migration -- test_migrate_fix_total_coldkey_stake --exact --nocapture
283282
#[test]
284283
fn test_migrate_fix_total_coldkey_stake() {
285284
new_test_ext(1).execute_with(|| {
286-
let coldkey = U256::from(0);
285+
let coldkey = U256::from(0);
287286
TotalColdkeyStake::<Test>::insert(coldkey, 0);
288287
StakingHotkeys::<Test>::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]);
289288
Stake::<Test>::insert(U256::from(1), U256::from(0), 10000);
@@ -298,7 +297,7 @@ fn test_migrate_fix_total_coldkey_stake() {
298297
#[test]
299298
fn test_migrate_fix_total_coldkey_stake_value_already_in_total() {
300299
new_test_ext(1).execute_with(|| {
301-
let coldkey = U256::from(0);
300+
let coldkey = U256::from(0);
302301
TotalColdkeyStake::<Test>::insert(coldkey, 100000000);
303302
StakingHotkeys::<Test>::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]);
304303
Stake::<Test>::insert(U256::from(1), U256::from(0), 10000);
@@ -313,7 +312,7 @@ fn test_migrate_fix_total_coldkey_stake_value_already_in_total() {
313312
#[test]
314313
fn test_migrate_fix_total_coldkey_stake_no_entry() {
315314
new_test_ext(1).execute_with(|| {
316-
let coldkey = U256::from(0);
315+
let coldkey = U256::from(0);
317316
StakingHotkeys::<Test>::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]);
318317
Stake::<Test>::insert(U256::from(1), U256::from(0), 10000);
319318
Stake::<Test>::insert(U256::from(2), U256::from(0), 10000);
@@ -327,7 +326,7 @@ fn test_migrate_fix_total_coldkey_stake_no_entry() {
327326
#[test]
328327
fn test_migrate_fix_total_coldkey_stake_no_entry_in_hotkeys() {
329328
new_test_ext(1).execute_with(|| {
330-
let coldkey = U256::from(0);
329+
let coldkey = U256::from(0);
331330
TotalColdkeyStake::<Test>::insert(coldkey, 100000000);
332331
StakingHotkeys::<Test>::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]);
333332
pallet_subtensor::migration::do_migrate_fix_total_coldkey_stake::<Test>();
@@ -339,7 +338,7 @@ fn test_migrate_fix_total_coldkey_stake_no_entry_in_hotkeys() {
339338
#[test]
340339
fn test_migrate_fix_total_coldkey_stake_one_hotkey_stake_missing() {
341340
new_test_ext(1).execute_with(|| {
342-
let coldkey = U256::from(0);
341+
let coldkey = U256::from(0);
343342
TotalColdkeyStake::<Test>::insert(coldkey, 100000000);
344343
StakingHotkeys::<Test>::insert(coldkey, vec![U256::from(1), U256::from(2), U256::from(3)]);
345344
Stake::<Test>::insert(U256::from(1), U256::from(0), 10000);
@@ -348,5 +347,3 @@ fn test_migrate_fix_total_coldkey_stake_one_hotkey_stake_missing() {
348347
assert_eq!(TotalColdkeyStake::<Test>::get(coldkey), 20000);
349348
})
350349
}
351-
352-

pallets/subtensor/tests/swap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,4 +1886,4 @@ fn test_coldkey_delegations() {
18861886
assert_eq!(Stake::<Test>::get(delegate, new_coldkey), 100);
18871887
assert_eq!(Stake::<Test>::get(delegate, coldkey), 0);
18881888
});
1889-
}
1889+
}

0 commit comments

Comments
 (0)