@@ -57,26 +57,9 @@ pub mod versioned {
57
57
}
58
58
59
59
pub mod v8 {
60
- use super :: * ;
61
-
62
- #[ derive( Decode ) ]
63
- pub struct OldCommission < T : Config > {
64
- pub current : Option < ( Perbill , T :: AccountId ) > ,
65
- pub max : Option < Perbill > ,
66
- pub change_rate : Option < CommissionChangeRate < BlockNumberFor < T > > > ,
67
- pub throttle_from : Option < BlockNumberFor < T > > ,
68
- }
69
-
70
- #[ derive( Decode ) ]
71
- pub struct OldBondedPoolInner < T : Config > {
72
- pub commission : OldCommission < T > ,
73
- pub member_counter : u32 ,
74
- pub points : BalanceOf < T > ,
75
- pub roles : PoolRoles < T :: AccountId > ,
76
- pub state : PoolState ,
77
- }
60
+ use super :: { v7:: V7BondedPoolInner , * } ;
78
61
79
- impl < T : Config > OldBondedPoolInner < T > {
62
+ impl < T : Config > V7BondedPoolInner < T > {
80
63
fn migrate_to_v8 ( self ) -> BondedPoolInner < T > {
81
64
BondedPoolInner {
82
65
commission : Commission {
@@ -104,7 +87,7 @@ pub mod v8 {
104
87
105
88
fn on_runtime_upgrade ( ) -> Weight {
106
89
let mut translated = 0u64 ;
107
- BondedPools :: < T > :: translate :: < OldBondedPoolInner < T > , _ > ( |_key, old_value| {
90
+ BondedPools :: < T > :: translate :: < V7BondedPoolInner < T > , _ > ( |_key, old_value| {
108
91
translated. saturating_inc ( ) ;
109
92
Some ( old_value. migrate_to_v8 ( ) )
110
93
} ) ;
@@ -128,16 +111,58 @@ pub mod v8 {
128
111
///
129
112
/// WARNING: This migration works under the assumption that the [`BondedPools`] cannot be inflated
130
113
/// arbitrarily. Otherwise this migration could fail due to too high weight.
131
- mod v7 {
114
+ pub ( crate ) mod v7 {
132
115
use super :: * ;
133
116
117
+ #[ derive( Encode , Decode , MaxEncodedLen , TypeInfo , DebugNoBound , PartialEq , Clone ) ]
118
+ #[ codec( mel_bound( T : Config ) ) ]
119
+ #[ scale_info( skip_type_params( T ) ) ]
120
+ pub struct V7Commission < T : Config > {
121
+ pub current : Option < ( Perbill , T :: AccountId ) > ,
122
+ pub max : Option < Perbill > ,
123
+ pub change_rate : Option < CommissionChangeRate < BlockNumberFor < T > > > ,
124
+ pub throttle_from : Option < BlockNumberFor < T > > ,
125
+ }
126
+
127
+ #[ derive( Encode , Decode , MaxEncodedLen , TypeInfo , DebugNoBound , PartialEq , Clone ) ]
128
+ #[ codec( mel_bound( T : Config ) ) ]
129
+ #[ scale_info( skip_type_params( T ) ) ]
130
+ pub struct V7BondedPoolInner < T : Config > {
131
+ pub commission : V7Commission < T > ,
132
+ pub member_counter : u32 ,
133
+ pub points : BalanceOf < T > ,
134
+ pub roles : PoolRoles < T :: AccountId > ,
135
+ pub state : PoolState ,
136
+ }
137
+
138
+ #[ allow( dead_code) ]
139
+ #[ derive( RuntimeDebugNoBound ) ]
140
+ #[ cfg_attr( feature = "std" , derive( Clone , PartialEq ) ) ]
141
+ pub struct V7BondedPool < T : Config > {
142
+ /// The identifier of the pool.
143
+ id : PoolId ,
144
+ /// The inner fields.
145
+ inner : V7BondedPoolInner < T > ,
146
+ }
147
+
148
+ impl < T : Config > V7BondedPool < T > {
149
+ fn bonded_account ( & self ) -> T :: AccountId {
150
+ Pallet :: < T > :: create_bonded_account ( self . id )
151
+ }
152
+ }
153
+
154
+ // NOTE: We cannot put a V7 prefix here since that would change the storage key.
155
+ #[ frame_support:: storage_alias]
156
+ pub type BondedPools < T : Config > =
157
+ CountedStorageMap < Pallet < T > , Twox64Concat , PoolId , V7BondedPoolInner < T > > ;
158
+
134
159
pub struct VersionUncheckedMigrateV6ToV7 < T > ( sp_std:: marker:: PhantomData < T > ) ;
135
160
impl < T : Config > VersionUncheckedMigrateV6ToV7 < T > {
136
161
fn calculate_tvl_by_total_stake ( ) -> BalanceOf < T > {
137
162
BondedPools :: < T > :: iter ( )
138
163
. map ( |( id, inner) | {
139
164
T :: Staking :: total_stake (
140
- & BondedPool { id, inner : inner. clone ( ) } . bonded_account ( ) ,
165
+ & V7BondedPool { id, inner : inner. clone ( ) } . bonded_account ( ) ,
141
166
)
142
167
. unwrap_or_default ( )
143
168
} )
0 commit comments