Skip to content

Commit f037dbc

Browse files
committed
Filter migration StakingHotkey by non-zero stakes, bump spec version
1 parent dbea365 commit f037dbc

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

pallets/subtensor/src/migration.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -560,29 +560,31 @@ pub fn migrate_populate_staking_hotkeys<T: Config>() -> Weight {
560560
let mut storage_writes: u64 = 0;
561561

562562
// Iterate through all Owner entries
563-
Stake::<T>::iter().for_each(|(hotkey, coldkey, _stake)| {
563+
Stake::<T>::iter().for_each(|(hotkey, coldkey, stake)| {
564564
storage_reads = storage_reads.saturating_add(1); // Read from Owner storage
565-
let mut hotkeys = StakingHotkeys::<T>::get(&coldkey);
566-
storage_reads = storage_reads.saturating_add(1); // Read from StakingHotkeys storage
567-
568-
// Add the hotkey if it's not already in the vector
569-
if !hotkeys.contains(&hotkey) {
570-
hotkeys.push(hotkey);
571-
keys_touched = keys_touched.saturating_add(1);
572-
573-
// Update longest hotkey vector info
574-
if longest_hotkey_vector < hotkeys.len() {
575-
longest_hotkey_vector = hotkeys.len();
576-
longest_coldkey = Some(coldkey.clone());
565+
if stake > 0 {
566+
let mut hotkeys = StakingHotkeys::<T>::get(&coldkey);
567+
storage_reads = storage_reads.saturating_add(1); // Read from StakingHotkeys storage
568+
569+
// Add the hotkey if it's not already in the vector
570+
if !hotkeys.contains(&hotkey) {
571+
hotkeys.push(hotkey);
572+
keys_touched = keys_touched.saturating_add(1);
573+
574+
// Update longest hotkey vector info
575+
if longest_hotkey_vector < hotkeys.len() {
576+
longest_hotkey_vector = hotkeys.len();
577+
longest_coldkey = Some(coldkey.clone());
578+
}
579+
580+
// Update the StakingHotkeys storage
581+
StakingHotkeys::<T>::insert(&coldkey, hotkeys);
582+
storage_writes = storage_writes.saturating_add(1); // Write to StakingHotkeys storage
577583
}
578-
579-
// Update the StakingHotkeys storage
580-
StakingHotkeys::<T>::insert(&coldkey, hotkeys);
581-
storage_writes = storage_writes.saturating_add(1); // Write to StakingHotkeys storage
584+
585+
// Accrue weight for reads and writes
586+
weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1));
582587
}
583-
584-
// Accrue weight for reads and writes
585-
weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 1));
586588
});
587589

588590
// Log migration results

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
139139
// `spec_version`, and `authoring_version` are the same between Wasm and native.
140140
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
141141
// the compatible custom types.
142-
spec_version: 158,
142+
spec_version: 159,
143143
impl_version: 1,
144144
apis: RUNTIME_API_VERSIONS,
145145
transaction_version: 1,

0 commit comments

Comments
 (0)