@@ -19,9 +19,7 @@ use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade, weights::Weight
19
19
20
20
// NOTE: This must be used alongside the account whose balance is expected to be inactive.
21
21
// Generally this will be used for the XCM teleport checking account.
22
- pub struct MigrateToTrackInactive < T : Config , A : Get < T :: AccountId > > (
23
- sp_std:: marker:: PhantomData < ( T , A ) > ,
24
- ) ;
22
+ pub struct MigrateToTrackInactive < T , A > ( PhantomData < ( T , A ) > ) ;
25
23
impl < T : Config , A : Get < T :: AccountId > > OnRuntimeUpgrade for MigrateToTrackInactive < T , A > {
26
24
fn on_runtime_upgrade ( ) -> Weight {
27
25
let current_version = Pallet :: < T > :: current_storage_version ( ) ;
@@ -32,20 +30,35 @@ impl<T: Config, A: Get<T::AccountId>> OnRuntimeUpgrade for MigrateToTrackInactiv
32
30
Pallet :: < T > :: deactivate ( b) ;
33
31
current_version. put :: < Pallet < T > > ( ) ;
34
32
log:: info!( target: "runtime::balances" , "Storage to version {:?}" , current_version) ;
35
- T :: DbWeight :: get ( ) . reads_writes ( 3 , 3 )
33
+ T :: DbWeight :: get ( ) . reads_writes ( 4 , 3 )
36
34
} else {
37
35
log:: info!( target: "runtime::balances" , "Migration did not execute. This probably should be removed" ) ;
38
36
T :: DbWeight :: get ( ) . reads ( 2 )
39
37
}
40
38
}
39
+ }
41
40
42
- #[ cfg( feature = "try-runtime" ) ]
43
- fn pre_upgrade ( ) -> Result < Vec < u8 > , & ' static str > {
44
- Ok ( vec ! [ ] )
45
- }
41
+ // NOTE: This must be used alongside the account whose balance is expected to be inactive.
42
+ // Generally this will be used for the XCM teleport checking account.
43
+ pub struct MigrateManyToTrackInactive < T , A > ( PhantomData < ( T , A ) > ) ;
44
+ impl < T : Config , A : Get < Vec < T :: AccountId > > > OnRuntimeUpgrade for MigrateManyToTrackInactive < T , A > {
45
+ fn on_runtime_upgrade ( ) -> Weight {
46
+ let current_version = Pallet :: < T > :: current_storage_version ( ) ;
47
+ let onchain_version = Pallet :: < T > :: on_chain_storage_version ( ) ;
46
48
47
- #[ cfg( feature = "try-runtime" ) ]
48
- fn post_upgrade ( total : Vec < u8 > ) -> Result < ( ) , & ' static str > {
49
- Ok ( ( ) )
49
+ if onchain_version == 0 && current_version == 1 {
50
+ let accounts = A :: get ( ) ;
51
+ let total = accounts
52
+ . iter ( )
53
+ . map ( |a| Pallet :: < T > :: total_balance ( a) )
54
+ . fold ( T :: Balance :: zero ( ) , |a, e| a. saturating_add ( e) ) ;
55
+ Pallet :: < T > :: deactivate ( total) ;
56
+ current_version. put :: < Pallet < T > > ( ) ;
57
+ log:: info!( target: "runtime::balances" , "Storage to version {:?}" , current_version) ;
58
+ T :: DbWeight :: get ( ) . reads_writes ( 3 + accounts. len ( ) as u64 , 3 )
59
+ } else {
60
+ log:: info!( target: "runtime::balances" , "Migration did not execute. This probably should be removed" ) ;
61
+ T :: DbWeight :: get ( ) . reads ( 2 )
62
+ }
50
63
}
51
64
}
0 commit comments