@@ -29,6 +29,7 @@ use crate::*;
2929mod v2;
3030mod v3;
3131mod v4;
32+ mod v5;
3233
3334/// A trait that allows version migrators to access the underlying pallet's
3435/// context, e.g., its Config trait.
@@ -53,13 +54,14 @@ pub enum StakingStorageVersion {
5354 V2_0_0 , // New Reward calculation, MaxCollatorCandidateStake
5455 V3_0_0 , // Update InflationConfig
5556 V4 , // Sort TopCandidates and parachain-stakings by amount
57+ V5 , // Remove SelectedCandidates, Count Candidates
5658}
5759
5860#[ cfg( feature = "try-runtime" ) ]
5961impl StakingStorageVersion {
6062 /// The latest storage version.
6163 fn latest ( ) -> Self {
62- Self :: V4
64+ Self :: V5
6365 }
6466}
6567
@@ -84,7 +86,8 @@ impl<T: Config> VersionMigratorTrait<T> for StakingStorageVersion {
8486 Self :: V1_0_0 => v2:: pre_migrate :: < T > ( ) ,
8587 Self :: V2_0_0 => v3:: pre_migrate :: < T > ( ) ,
8688 Self :: V3_0_0 => v4:: pre_migrate :: < T > ( ) ,
87- Self :: V4 => Err ( "Already on latest version v4." ) ,
89+ Self :: V4 => v5:: pre_migrate :: < T > ( ) ,
90+ Self :: V5 => Ok ( ( ) ) ,
8891 }
8992 }
9093
@@ -94,7 +97,8 @@ impl<T: Config> VersionMigratorTrait<T> for StakingStorageVersion {
9497 Self :: V1_0_0 => v2:: migrate :: < T > ( ) ,
9598 Self :: V2_0_0 => v3:: migrate :: < T > ( ) ,
9699 Self :: V3_0_0 => v4:: migrate :: < T > ( ) ,
97- Self :: V4 => Weight :: zero ( ) ,
100+ Self :: V4 => v5:: migrate :: < T > ( ) ,
101+ Self :: V5 => Weight :: zero ( ) ,
98102 }
99103 }
100104
@@ -106,7 +110,8 @@ impl<T: Config> VersionMigratorTrait<T> for StakingStorageVersion {
106110 Self :: V1_0_0 => v2:: post_migrate :: < T > ( ) ,
107111 Self :: V2_0_0 => v3:: post_migrate :: < T > ( ) ,
108112 Self :: V3_0_0 => v4:: post_migrate :: < T > ( ) ,
109- Self :: V4 => Err ( "Migration from v4 should have never happened in the first place." ) ,
113+ Self :: V4 => v5:: post_migrate :: < T > ( ) ,
114+ Self :: V5 => Ok ( ( ) ) ,
110115 }
111116 }
112117}
@@ -126,20 +131,16 @@ impl<T: Config> StakingStorageMigrator<T> {
126131 StakingStorageVersion :: V1_0_0 => Some ( StakingStorageVersion :: V2_0_0 ) ,
127132 StakingStorageVersion :: V2_0_0 => Some ( StakingStorageVersion :: V3_0_0 ) ,
128133 // Migration happens naturally, no need to point to the latest version
129- StakingStorageVersion :: V3_0_0 => None ,
130- StakingStorageVersion :: V4 => None ,
134+ StakingStorageVersion :: V3_0_0 => Some ( StakingStorageVersion :: V4 ) ,
135+ StakingStorageVersion :: V4 => Some ( StakingStorageVersion :: V5 ) ,
136+ StakingStorageVersion :: V5 => None ,
131137 }
132138 }
133139
134140 /// Checks whether the latest storage version deployed is lower than the
135141 /// latest possible.
136142 #[ cfg( feature = "try-runtime" ) ]
137143 pub ( crate ) fn pre_migrate ( ) -> Result < ( ) , & ' static str > {
138- ensure ! (
139- StorageVersion :: <T >:: get( ) < StakingStorageVersion :: latest( ) ,
140- "Already the latest storage version."
141- ) ;
142-
143144 // Don't need to check for any other pre_migrate, as in try-runtime it is also
144145 // called in the migrate() function. Same applies for post_migrate checks for
145146 // each version migrator.
@@ -198,35 +199,11 @@ mod tests {
198199
199200 use crate :: mock:: Test as TestRuntime ;
200201
201- #[ test]
202- fn ok_from_v1_migration ( ) {
203- let mut ext = mock:: ExtBuilder :: default ( )
204- . with_balances ( vec ! [ ( 1 , 100 ) , ( 2 , 100 ) ] )
205- . with_collators ( vec ! [ ( 1 , 100 ) , ( 2 , 100 ) ] )
206- . with_storage_version ( StakingStorageVersion :: V1_0_0 )
207- . build ( ) ;
208- ext. execute_with ( || {
209- #[ cfg( feature = "try-runtime" ) ]
210- assert ! (
211- StakingStorageMigrator :: <TestRuntime >:: pre_migrate( ) . is_ok( ) ,
212- "Storage pre-migrate from v1 should not fail."
213- ) ;
214-
215- StakingStorageMigrator :: < TestRuntime > :: migrate ( ) ;
216-
217- #[ cfg( feature = "try-runtime" ) ]
218- assert ! (
219- StakingStorageMigrator :: <TestRuntime >:: post_migrate( ) . is_ok( ) ,
220- "Storage post-migrate from v1 should not fail."
221- ) ;
222- } ) ;
223- }
224-
225202 #[ test]
226203 fn ok_from_default_migration ( ) {
227204 let mut ext = mock:: ExtBuilder :: default ( )
228- . with_balances ( vec ! [ ( 1 , 100 ) , ( 2 , 100 ) ] )
229- . with_collators ( vec ! [ ( 1 , 100 ) , ( 2 , 100 ) ] )
205+ . with_balances ( ( 0 .. 15 ) . into_iter ( ) . map ( |n| ( n , 120 ) ) . collect ( ) )
206+ . with_collators ( ( 0 .. 15 ) . into_iter ( ) . map ( |n| ( n , 100 ) ) . collect ( ) )
230207 . build ( ) ;
231208 ext. execute_with ( || {
232209 #[ cfg( feature = "try-runtime" ) ]
0 commit comments