1616// limitations under the License.
1717
1818use crate :: { build_executor, state_machine_call_with_proof, SharedParams , State , LOG_TARGET } ;
19- use frame_try_runtime:: UpgradeCheckSelect ;
2019use parity_scale_codec:: { Decode , Encode } ;
2120use sc_executor:: sp_wasm_interface:: HostFunctions ;
2221use sp_runtime:: traits:: { Block as BlockT , NumberFor } ;
@@ -30,18 +29,39 @@ pub struct OnRuntimeUpgradeCmd {
3029 #[ command( subcommand) ]
3130 pub state : State ,
3231
33- /// Select which optional checks to perform:
34- ///
35- /// - `all`: Perform all checks (default).
36- /// - `pre-and-post`: Perform pre- and post-upgrade checks.
37- /// - `try-state`: Perform the try-state checks.
38- /// - `none`: Perform no checks.
32+ /// Select which optional checks to perform.
3933 ///
4034 /// Performing any checks will potentially invalidate the measured PoV/Weight.
41- #[ clap( long, default_value = " All" , verbatim_doc_comment ) ]
35+ #[ clap( long, value_enum , default_value_t = UpgradeCheckSelect :: All ) ]
4236 pub checks : UpgradeCheckSelect ,
4337}
4438
39+ /// This is an adapter for [`frame_try_runtime::UpgradeCheckSelect`] since that does not implement
40+ /// `clap::ValueEnum`.
41+ #[ derive( clap:: ValueEnum , Debug , Clone , Copy ) ]
42+ #[ value( rename_all = "kebab-case" ) ]
43+ pub enum UpgradeCheckSelect {
44+ /// Perform no checks.
45+ None ,
46+ /// Perform all checks.
47+ All ,
48+ /// Perform pre- and post-upgrade checks.
49+ PreAndPost ,
50+ /// Perform the try-state checks.
51+ TryState ,
52+ }
53+
54+ impl From < UpgradeCheckSelect > for frame_try_runtime:: UpgradeCheckSelect {
55+ fn from ( x : UpgradeCheckSelect ) -> Self {
56+ match x {
57+ UpgradeCheckSelect :: None => Self :: None ,
58+ UpgradeCheckSelect :: All => Self :: All ,
59+ UpgradeCheckSelect :: PreAndPost => Self :: PreAndPost ,
60+ UpgradeCheckSelect :: TryState => Self :: TryState ,
61+ }
62+ }
63+ }
64+
4565pub ( crate ) async fn on_runtime_upgrade < Block , HostFns > (
4666 shared : SharedParams ,
4767 command : OnRuntimeUpgradeCmd ,
@@ -57,12 +77,13 @@ where
5777{
5878 let executor = build_executor ( & shared) ;
5979 let ext = command. state . into_ext :: < Block , HostFns > ( & shared, & executor, None ) . await ?;
80+ let checks: frame_try_runtime:: UpgradeCheckSelect = command. checks . into ( ) ;
6081
6182 let ( _, encoded_result) = state_machine_call_with_proof :: < Block , HostFns > (
6283 & ext,
6384 & executor,
6485 "TryRuntime_on_runtime_upgrade" ,
65- command . checks . encode ( ) . as_ref ( ) ,
86+ checks. encode ( ) . as_ref ( ) ,
6687 Default :: default ( ) , // we don't really need any extensions here.
6788 shared. export_proof ,
6889 ) ?;
0 commit comments