@@ -148,22 +148,20 @@ pub fn do_migrate_fix_pending_emission<T: Config>() -> Weight {
148
148
/// Required so we can read values in the v0 storage format during the migration.
149
149
#[ cfg( feature = "try-runtime" ) ]
150
150
mod v0 {
151
- use frame_support:: storage_alias;
152
151
use subtensor_macros:: freeze_struct;
153
152
154
- #[ freeze_struct( "7adbed79987ae83d " ) ]
153
+ #[ freeze_struct( "2228babfc0580c62 " ) ]
155
154
#[ derive( codec:: Encode , codec:: Decode , Clone , PartialEq , Debug ) ]
156
155
pub struct OldStorage {
157
156
pub total_issuance_before : u64 ,
157
+ pub total_stake_before : u64 ,
158
158
pub expected_taostats_new_hk_pending_emission : u64 ,
159
159
pub expected_datura_new_hk_pending_emission : u64 ,
160
+ pub old_migration_stake_taostats : u64 ,
160
161
pub old_null_stake_taostats : u64 ,
162
+ pub old_migration_stake_datura : u64 ,
161
163
pub old_null_stake_datura : u64 ,
162
164
}
163
-
164
- /// V0 type for [`crate::Value`].
165
- #[ storage_alias]
166
- pub type Value < T : crate :: Config > = StorageValue < crate :: Pallet < T > , OldStorage > ;
167
165
}
168
166
169
167
impl < T : Config > Pallet < T > {
@@ -184,7 +182,9 @@ impl<T: Config> Pallet<T> {
184
182
let old = old_storage;
185
183
let null_stake_total = old
186
184
. old_null_stake_taostats
187
- . saturating_add ( old. old_null_stake_datura ) ;
185
+ . saturating_add ( old. old_null_stake_datura )
186
+ . saturating_add ( old. old_migration_stake_taostats )
187
+ . saturating_add ( old. old_migration_stake_datura ) ;
188
188
189
189
match (
190
190
taostats_old_hk_account,
@@ -209,10 +209,19 @@ impl<T: Config> Pallet<T> {
209
209
0
210
210
) ;
211
211
212
+ // Check the total hotkey stake is the same
213
+ assert_eq ! (
214
+ TotalHotkeyStake :: <T >:: get( taostats_old_hk_acct) ,
215
+ old. old_null_stake_taostats + old. old_migration_stake_taostats
216
+ ) ;
217
+
212
218
let new_null_stake_taostats =
213
219
Self :: get_stake_for_coldkey_and_hotkey ( migration_ck_acct, taostats_old_hk_acct) ;
214
220
215
- assert_eq ! ( new_null_stake_taostats, old. old_null_stake_taostats) ;
221
+ assert_eq ! (
222
+ new_null_stake_taostats,
223
+ old. old_null_stake_taostats + old. old_migration_stake_taostats
224
+ ) ;
216
225
}
217
226
_ => {
218
227
log:: warn!( "Failed to get account id from ss58 for taostats hotkeys" ) ;
@@ -251,10 +260,19 @@ impl<T: Config> Pallet<T> {
251
260
0
252
261
) ;
253
262
263
+ // Check the total hotkey stake is the same
264
+ assert_eq ! (
265
+ TotalHotkeyStake :: <T >:: get( datura_old_hk_acct) ,
266
+ old. old_null_stake_datura + old. old_migration_stake_datura
267
+ ) ;
268
+
254
269
let new_null_stake_datura =
255
270
Self :: get_stake_for_coldkey_and_hotkey ( migration_ck_acct, datura_old_hk_acct) ;
256
271
257
- assert_eq ! ( new_null_stake_datura, old. old_null_stake_datura) ;
272
+ assert_eq ! (
273
+ new_null_stake_datura,
274
+ old. old_null_stake_datura + old. old_migration_stake_datura
275
+ ) ;
258
276
}
259
277
_ => {
260
278
log:: warn!( "Failed to get account id from ss58 for datura hotkeys" ) ;
@@ -278,10 +296,11 @@ impl<T: Config> Pallet<T> {
278
296
279
297
// Check the total issuance is the SAME following migration (no TAO issued)
280
298
let expected_total_issuance = old. total_issuance_before ;
299
+ let expected_total_stake = old. total_stake_before ;
281
300
assert_eq ! ( Self :: get_total_issuance( ) , expected_total_issuance) ;
282
301
283
302
// Check total stake is the SAME following the migration (no new TAO staked)
284
- assert_eq ! ( TotalStake :: <T >:: get( ) , expected_total_issuance ) ;
303
+ assert_eq ! ( TotalStake :: <T >:: get( ) , expected_total_stake ) ;
285
304
// Check the total stake maps are updated following the migration (removal of old null_account stake entries)
286
305
assert_eq ! ( TotalColdkeyStake :: <T >:: get( null_account) , 0 ) ;
287
306
@@ -303,7 +322,11 @@ pub mod migration {
303
322
304
323
#[ cfg( feature = "try-runtime" ) ]
305
324
fn get_old_storage_values < T : Config > ( ) -> Result < v0:: OldStorage , sp_runtime:: TryRuntimeError > {
325
+ log:: info!( "Getting old storage values for migration" ) ;
326
+
306
327
let null_account = & DefaultAccount :: < T > :: get ( ) ;
328
+ let migration_coldkey = "5GeRjQYsobRWFnrbBmGe5ugme3rfnDVF69N45YtdBpUFsJG8" ;
329
+ let migration_account = & get_account_id_from_ss58 :: < T > ( migration_coldkey) ;
307
330
308
331
let taostats_old_hotkey = "5Hddm3iBFD2GLT5ik7LZnT3XJUnRnN8PoeCFgGQgawUVKNm8" ;
309
332
let taostats_new_hotkey = "5GKH9FPPnWSUoeeTJp19wVtd84XqFW4pyK2ijV2GsFbhTrP1" ;
@@ -314,20 +337,27 @@ pub mod migration {
314
337
let total_issuance_before = crate :: Pallet :: < T > :: get_total_issuance ( ) ;
315
338
let mut expected_taostats_new_hk_pending_emission: u64 = 0 ;
316
339
let mut expected_datura_new_hk_pending_emission: u64 = 0 ;
317
- let old_null_stake_taostats: u64 = match ( taostats_old_hk_account, taostats_new_hk_account)
318
- {
319
- ( Ok ( taostats_old_hk_acct) , Ok ( taostats_new_hk_acct) ) => {
340
+ let ( old_null_stake_taostats, old_migration_stake_taostats) = match (
341
+ taostats_old_hk_account,
342
+ taostats_new_hk_account,
343
+ migration_account,
344
+ ) {
345
+ ( Ok ( taostats_old_hk_acct) , Ok ( taostats_new_hk_acct) , Ok ( migration_acct) ) => {
320
346
expected_taostats_new_hk_pending_emission =
321
347
expected_taostats_new_hk_pending_emission
322
348
. saturating_add ( PendingdHotkeyEmission :: < T > :: get ( taostats_old_hk_acct) )
323
349
. saturating_add ( PendingdHotkeyEmission :: < T > :: get ( taostats_new_hk_acct) ) ;
324
350
325
- Ok :: < u64 , sp_runtime:: TryRuntimeError > (
351
+ Ok :: < ( u64 , u64 ) , sp_runtime:: TryRuntimeError > ( (
326
352
crate :: Pallet :: < T > :: get_stake_for_coldkey_and_hotkey (
327
353
null_account,
328
354
taostats_old_hk_acct,
329
355
) ,
330
- )
356
+ crate :: Pallet :: < T > :: get_stake_for_coldkey_and_hotkey (
357
+ migration_acct,
358
+ taostats_old_hk_acct,
359
+ ) ,
360
+ ) )
331
361
}
332
362
_ => {
333
363
log:: warn!( "Failed to get account id from ss58 for taostats hotkeys" ) ;
@@ -341,33 +371,48 @@ pub mod migration {
341
371
let datura_old_hk_account = & get_account_id_from_ss58 :: < T > ( datura_old_hotkey) ;
342
372
let datura_new_hk_account = & get_account_id_from_ss58 :: < T > ( datura_new_hotkey) ;
343
373
344
- let old_null_stake_datura: u64 = match ( datura_old_hk_account, datura_new_hk_account) {
345
- ( Ok ( datura_old_hk_acct) , Ok ( datura_new_hk_acct) ) => {
374
+ let ( old_null_stake_datura, old_migration_stake_datura) = match (
375
+ datura_old_hk_account,
376
+ datura_new_hk_account,
377
+ migration_account,
378
+ ) {
379
+ ( Ok ( datura_old_hk_acct) , Ok ( datura_new_hk_acct) , Ok ( migration_acct) ) => {
346
380
expected_datura_new_hk_pending_emission = expected_datura_new_hk_pending_emission
347
381
. saturating_add ( PendingdHotkeyEmission :: < T > :: get ( datura_old_hk_acct) )
348
382
. saturating_add ( PendingdHotkeyEmission :: < T > :: get ( datura_new_hk_acct) ) ;
349
383
350
- Ok :: < u64 , sp_runtime:: TryRuntimeError > (
384
+ Ok :: < ( u64 , u64 ) , sp_runtime:: TryRuntimeError > ( (
351
385
crate :: Pallet :: < T > :: get_stake_for_coldkey_and_hotkey (
352
386
null_account,
353
387
datura_old_hk_acct,
354
388
) ,
355
- )
389
+ crate :: Pallet :: < T > :: get_stake_for_coldkey_and_hotkey (
390
+ migration_acct,
391
+ datura_old_hk_acct,
392
+ ) ,
393
+ ) )
356
394
}
357
395
_ => {
358
396
log:: warn!( "Failed to get account id from ss58 for datura hotkeys" ) ;
359
397
Err ( "Failed to get account id from ss58 for datura hotkeys" . into ( ) )
360
398
}
361
399
} ?;
362
400
401
+ let total_stake_before: u64 = crate :: Pallet :: < T > :: get_total_stake ( ) ;
402
+
363
403
let result = v0:: OldStorage {
364
404
total_issuance_before,
405
+ total_stake_before,
365
406
expected_taostats_new_hk_pending_emission,
366
407
expected_datura_new_hk_pending_emission,
408
+ old_migration_stake_taostats,
367
409
old_null_stake_taostats,
410
+ old_migration_stake_datura,
368
411
old_null_stake_datura,
369
412
} ;
370
413
414
+ log:: info!( "Got old storage values for migration" ) ;
415
+
371
416
Ok ( result)
372
417
}
373
418
@@ -378,10 +423,18 @@ pub mod migration {
378
423
use codec:: Encode ;
379
424
380
425
// Get the old storage values
381
- let old_storage = get_old_storage_values :: < T > ( ) ?;
426
+ match get_old_storage_values :: < T > ( ) {
427
+ Ok ( old_storage) => {
428
+ log:: info!( "Successfully got old storage values for migration" ) ;
429
+ let encoded = old_storage. encode ( ) ;
382
430
383
- // Return it as an encoded `Vec<u8>`
384
- Ok ( old_storage. encode ( ) )
431
+ Ok ( encoded)
432
+ }
433
+ Err ( e) => {
434
+ log:: error!( "Failed to get old storage values for migration: {:?}" , e) ;
435
+ Err ( "Failed to get old storage values for migration" . into ( ) )
436
+ }
437
+ }
385
438
}
386
439
387
440
// Runs the migrate function for the fix_pending_emission migration
@@ -430,21 +483,14 @@ pub mod migration {
430
483
fn post_upgrade ( state : Vec < u8 > ) -> Result < ( ) , sp_runtime:: TryRuntimeError > {
431
484
use codec:: Decode ;
432
485
433
- let maybe_old_value =
434
- Option :: < v0:: OldStorage > :: decode ( & mut & state[ ..] ) . map_err ( |_| {
486
+ let old_storage : v0 :: OldStorage =
487
+ v0:: OldStorage :: decode ( & mut & state[ ..] ) . map_err ( |_| {
435
488
sp_runtime:: TryRuntimeError :: Other ( "Failed to decode old value from storage" )
436
489
} ) ?;
437
490
438
- match maybe_old_value {
439
- Some ( old_value) => {
440
- // Verify that all null stake invariants are satisfied after the migration
441
- crate :: Pallet :: < T > :: check_null_stake_invariants ( old_value) ?;
442
- }
443
- None => {
444
- log:: warn!( "Failed to decode old value from storage" ) ;
445
- return Err ( "Failed to decode old value from storage" . into ( ) ) ;
446
- }
447
- } ;
491
+ // Verify that all null stake invariants are satisfied after the migration
492
+ crate :: Pallet :: < T > :: check_null_stake_invariants ( old_storage) ?;
493
+
448
494
Ok ( ( ) )
449
495
}
450
496
}
0 commit comments