Skip to content

Commit 6ca4b24

Browse files
committed
clippy
1 parent feb736e commit 6ca4b24

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

pallets/subtensor/src/migrations/migrate_kappa_map_to_default.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ use scale_info::prelude::string::String;
55

66
pub fn migrate_kappa_map_to_default<T: Config>() -> Weight {
77
let mig_name: Vec<u8> = b"kappa_map_to_default".to_vec();
8+
let mig_name_str = String::from_utf8_lossy(&mig_name);
89

910
// 1 read for the HasMigrationRun flag
1011
let mut total_weight = T::DbWeight::get().reads(1);
1112

1213
// Run once guard
1314
if HasMigrationRun::<T>::get(&mig_name) {
14-
log::info!(
15-
"Migration '{}' already executed - skipping",
16-
String::from_utf8_lossy(&mig_name)
17-
);
15+
log::info!("Migration '{mig_name_str}' already executed - skipping");
1816
return total_weight;
1917
}
2018

21-
log::info!("Running migration '{}'", String::from_utf8_lossy(&mig_name));
19+
log::info!("Running migration '{mig_name_str}'");
2220

2321
let target: u16 = DefaultKappa::<T>::get();
2422

@@ -29,32 +27,28 @@ pub fn migrate_kappa_map_to_default<T: Config>() -> Weight {
2927
let mut unchanged: u64 = 0;
3028

3129
for (netuid, current) in Kappa::<T>::iter() {
32-
visited += 1;
33-
reads += 1;
30+
visited = visited.saturating_add(1);
31+
reads = reads.saturating_add(1);
3432

3533
if current != target {
3634
Kappa::<T>::insert(netuid, target);
37-
writes += 1;
38-
updated += 1;
35+
writes = writes.saturating_add(1);
36+
updated = updated.saturating_add(1);
3937
} else {
40-
unchanged += 1;
38+
unchanged = unchanged.saturating_add(1);
4139
}
4240
}
4341

4442
total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(reads, writes));
4543

4644
log::info!(
47-
"Kappa migration summary: visited={visited}, updated={updated}, unchanged={unchanged}, target_default={}",
48-
target
45+
"Kappa migration summary: visited={visited}, updated={updated}, unchanged={unchanged}, target_default={target}"
4946
);
5047

5148
HasMigrationRun::<T>::insert(&mig_name, true);
5249
total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1));
5350

54-
log::info!(
55-
"Migration '{}' completed",
56-
String::from_utf8_lossy(&mig_name)
57-
);
51+
log::info!("Migration '{mig_name_str}' completed");
5852

5953
total_weight
6054
}

pallets/subtensor/src/tests/migration.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,33 +2179,37 @@ fn test_migrate_kappa_map_to_default() {
21792179
// 0. Constants / helpers
21802180
// ------------------------------
21812181
const MIG_NAME: &[u8] = b"kappa_map_to_default";
2182-
21832182
let default: u16 = DefaultKappa::<Test>::get();
2184-
let not_default: u16 = default.wrapping_add(1);
2183+
2184+
let not_default: u16 = if default == u16::MAX {
2185+
default.saturating_sub(1)
2186+
} else {
2187+
default.saturating_add(1)
2188+
};
21852189

21862190
// ------------------------------
2187-
// 1. Pre-state: seed non-default & default entries
2191+
// 1. Pre-state: seed using the correct key type (NetUid)
21882192
// ------------------------------
21892193
let n0: NetUid = 0u16.into();
21902194
let n1: NetUid = 1u16.into();
21912195
let n2: NetUid = 42u16.into();
21922196

2193-
Kappa::<Test>::insert(&n0, not_default);
2194-
Kappa::<Test>::insert(&n1, default);
2195-
Kappa::<Test>::insert(&n2, not_default);
2197+
Kappa::<Test>::insert(n0, not_default);
2198+
Kappa::<Test>::insert(n1, default);
2199+
Kappa::<Test>::insert(n2, not_default);
21962200

21972201
assert_eq!(
2198-
Kappa::<Test>::get(&n0),
2202+
Kappa::<Test>::get(n0),
21992203
not_default,
22002204
"precondition failed: Kappa[n0] should be non-default before migration"
22012205
);
22022206
assert_eq!(
2203-
Kappa::<Test>::get(&n1),
2207+
Kappa::<Test>::get(n1),
22042208
default,
22052209
"precondition failed: Kappa[n1] should be default before migration"
22062210
);
22072211
assert_eq!(
2208-
Kappa::<Test>::get(&n2),
2212+
Kappa::<Test>::get(n2),
22092213
not_default,
22102214
"precondition failed: Kappa[n2] should be non-default before migration"
22112215
);
@@ -2231,17 +2235,17 @@ fn test_migrate_kappa_map_to_default() {
22312235
);
22322236

22332237
assert_eq!(
2234-
Kappa::<Test>::get(&n0),
2238+
Kappa::<Test>::get(n0),
22352239
default,
22362240
"Kappa[n0] should be reset to the configured default"
22372241
);
22382242
assert_eq!(
2239-
Kappa::<Test>::get(&n1),
2243+
Kappa::<Test>::get(n1),
22402244
default,
22412245
"Kappa[n1] should remain at the configured default"
22422246
);
22432247
assert_eq!(
2244-
Kappa::<Test>::get(&n2),
2248+
Kappa::<Test>::get(n2),
22452249
default,
22462250
"Kappa[n2] should be reset to the configured default"
22472251
);

0 commit comments

Comments
 (0)