@@ -169,7 +169,20 @@ 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 StakeDeltaSinceLastEmissionDrain
173+ for hotkey in StakingHotkeys :: < T > :: get ( old_coldkey) {
174+ let old_stake_delta = StakeDeltaSinceLastEmissionDrain :: < T > :: get ( & hotkey, old_coldkey) ;
175+ let new_stake_delta = StakeDeltaSinceLastEmissionDrain :: < T > :: get ( & hotkey, new_coldkey) ;
176+ StakeDeltaSinceLastEmissionDrain :: < T > :: insert (
177+ & hotkey,
178+ new_coldkey,
179+ new_stake_delta. saturating_add ( old_stake_delta) ,
180+ ) ;
181+ StakeDeltaSinceLastEmissionDrain :: < T > :: remove ( & hotkey, old_coldkey) ;
182+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
183+ }
184+
185+ // 5. Swap total coldkey stake.
173186 // TotalColdkeyStake: MAP ( coldkey ) --> u64 | Total stake of the coldkey.
174187 let old_coldkey_stake: u64 = TotalColdkeyStake :: < T > :: get ( old_coldkey) ;
175188 // Get the stake of the new coldkey.
@@ -183,7 +196,7 @@ impl<T: Config> Pallet<T> {
183196 ) ;
184197 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
185198
186- // 5 . Swap StakingHotkeys.
199+ // 6 . Swap StakingHotkeys.
187200 // StakingHotkeys: MAP ( coldkey ) --> Vec<hotkeys> | Hotkeys staking for the coldkey.
188201 let old_staking_hotkeys: Vec < T :: AccountId > = StakingHotkeys :: < T > :: get ( old_coldkey) ;
189202 let mut new_staking_hotkeys: Vec < T :: AccountId > = StakingHotkeys :: < T > :: get ( new_coldkey) ;
@@ -197,7 +210,7 @@ impl<T: Config> Pallet<T> {
197210 StakingHotkeys :: < T > :: insert ( new_coldkey, new_staking_hotkeys) ;
198211 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
199212
200- // 6 . Swap hotkey owners.
213+ // 7 . Swap hotkey owners.
201214 // Owner: MAP ( hotkey ) --> coldkey | Owner of the hotkey.
202215 // OwnedHotkeys: MAP ( coldkey ) --> Vec<hotkeys> | Hotkeys owned by the coldkey.
203216 let old_owned_hotkeys: Vec < T :: AccountId > = OwnedHotkeys :: < T > :: get ( old_coldkey) ;
@@ -216,7 +229,7 @@ impl<T: Config> Pallet<T> {
216229 OwnedHotkeys :: < T > :: insert ( new_coldkey, new_owned_hotkeys) ;
217230 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads_writes ( 2 , 2 ) ) ;
218231
219- // 7 . Transfer remaining balance.
232+ // 8 . Transfer remaining balance.
220233 // Balance: MAP ( coldkey ) --> u64 | Balance of the coldkey.
221234 // Transfer any remaining balance from old_coldkey to new_coldkey
222235 let remaining_balance = Self :: get_coldkey_balance ( old_coldkey) ;
0 commit comments