Skip to content

Commit ef2457d

Browse files
committed
also fix swap coldkey: needs test
1 parent 9969452 commit ef2457d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pallets/subtensor/src/swap/swap_coldkey.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ impl<T: Config> Pallet<T> {
169169
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
170170
}
171171

172-
// 4. Swap total coldkey stake.
172+
// 4. Swap LastAddStakeIncrease.
173+
for hotkey in StakingHotkeys::<T>::get(old_coldkey) {
174+
let last_add_stake_increase = LastAddStakeIncrease::<T>::get(&hotkey, old_coldkey);
175+
LastAddStakeIncrease::<T>::remove(&hotkey, old_coldkey);
176+
LastAddStakeIncrease::<T>::insert(&hotkey, new_coldkey, last_add_stake_increase);
177+
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 2));
178+
}
179+
180+
// 5. Swap total coldkey stake.
173181
// TotalColdkeyStake: MAP ( coldkey ) --> u64 | Total stake of the coldkey.
174182
let old_coldkey_stake: u64 = TotalColdkeyStake::<T>::get(old_coldkey);
175183
// Get the stake of the new coldkey.
@@ -183,7 +191,7 @@ impl<T: Config> Pallet<T> {
183191
);
184192
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
185193

186-
// 5. Swap StakingHotkeys.
194+
// 6. Swap StakingHotkeys.
187195
// StakingHotkeys: MAP ( coldkey ) --> Vec<hotkeys> | Hotkeys staking for the coldkey.
188196
let old_staking_hotkeys: Vec<T::AccountId> = StakingHotkeys::<T>::get(old_coldkey);
189197
let mut new_staking_hotkeys: Vec<T::AccountId> = StakingHotkeys::<T>::get(new_coldkey);
@@ -197,7 +205,7 @@ impl<T: Config> Pallet<T> {
197205
StakingHotkeys::<T>::insert(new_coldkey, new_staking_hotkeys);
198206
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
199207

200-
// 6. Swap hotkey owners.
208+
// 7. Swap hotkey owners.
201209
// Owner: MAP ( hotkey ) --> coldkey | Owner of the hotkey.
202210
// OwnedHotkeys: MAP ( coldkey ) --> Vec<hotkeys> | Hotkeys owned by the coldkey.
203211
let old_owned_hotkeys: Vec<T::AccountId> = OwnedHotkeys::<T>::get(old_coldkey);
@@ -216,7 +224,7 @@ impl<T: Config> Pallet<T> {
216224
OwnedHotkeys::<T>::insert(new_coldkey, new_owned_hotkeys);
217225
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
218226

219-
// 7. Transfer remaining balance.
227+
// 8. Transfer remaining balance.
220228
// Balance: MAP ( coldkey ) --> u64 | Balance of the coldkey.
221229
// Transfer any remaining balance from old_coldkey to new_coldkey
222230
let remaining_balance = Self::get_coldkey_balance(old_coldkey);

0 commit comments

Comments
 (0)