Skip to content

Commit 6a2eeb6

Browse files
committed
make sure to keep old hotkey pending emissions
1 parent 12c4d1f commit 6a2eeb6

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pallets/subtensor/src/migrations/migrate_fix_pending_emission.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ fn swap_pending_emissions<T: Config>(
1818
PendingdHotkeyEmission::<T>::remove(old_hotkey);
1919
weight.saturating_accrue(T::DbWeight::get().writes(1));
2020

21+
// Get any existing pending emissions for the new hotkey
22+
let existing_new_pending_emissions = PendingdHotkeyEmission::<T>::get(new_hotkey);
23+
weight.saturating_accrue(T::DbWeight::get().reads(1));
24+
2125
// Add the pending emissions for the new hotkey
22-
PendingdHotkeyEmission::<T>::insert(new_hotkey, pending_emissions);
26+
PendingdHotkeyEmission::<T>::insert(
27+
new_hotkey,
28+
pending_emissions.saturating_add(existing_new_pending_emissions),
29+
);
2330
weight.saturating_accrue(T::DbWeight::get().writes(1));
2431

2532
weight
@@ -40,8 +47,8 @@ fn unstake_old_hotkey_and_move_to_pending<T: Config>(
4047
let null_account = DefaultAccount::<T>::get();
4148
weight.saturating_accrue(T::DbWeight::get().reads(1));
4249

43-
// Get the pending emissions for the new hotkey
44-
let pending_emissions = PendingdHotkeyEmission::<T>::get(new_hotkey);
50+
// Get the pending emissions for the OLD hotkey
51+
let pending_emissions_old: u64 = PendingdHotkeyEmission::<T>::get(old_hotkey);
4552
weight.saturating_accrue(T::DbWeight::get().reads(1));
4653

4754
// Get the stake for the 0x000 key
@@ -71,8 +78,17 @@ fn unstake_old_hotkey_and_move_to_pending<T: Config>(
7178
TotalStake::<T>::put(TotalStake::<T>::get().saturating_sub(null_stake));
7279
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
7380

74-
// Add stake to the pending emissions for the new hotkey
75-
PendingdHotkeyEmission::<T>::insert(new_hotkey, pending_emissions.saturating_add(null_stake));
81+
// Get the pending emissions for the NEW hotkey
82+
let pending_emissions_new: u64 = PendingdHotkeyEmission::<T>::get(new_hotkey);
83+
weight.saturating_accrue(T::DbWeight::get().reads(1));
84+
85+
// Add stake to the pending emissions for the new hotkey and the old hotkey
86+
PendingdHotkeyEmission::<T>::insert(
87+
new_hotkey,
88+
pending_emissions_new
89+
.saturating_add(pending_emissions_old)
90+
.saturating_add(null_stake),
91+
);
7692
weight.saturating_accrue(T::DbWeight::get().writes(1));
7793

7894
weight

0 commit comments

Comments
 (0)