1- use sc_cli:: RunCmd ;
1+ use sc_cli:: { GenericNumber , RunCmd } ;
22use structopt:: StructOpt ;
3+ use std:: { fmt:: Debug , str:: FromStr , sync:: Arc } ;
4+ use sp_runtime:: traits:: { Block as BlockT , Header as HeaderT } ;
5+ use sc_client_api:: { Backend , UsageProvider } ;
6+ use sc_cli:: { Result , CliConfiguration } ;
7+ use sc_cli:: { SharedParams , PruningParams } ;
8+ use sp_runtime:: traits:: Zero ;
39
410#[ derive( Debug , StructOpt ) ]
511pub struct Cli {
@@ -9,12 +15,6 @@ pub struct Cli {
915 #[ structopt( flatten) ]
1016 pub run : RunCmd ,
1117
12- // #[structopt(long = "request-base")]
13- // pub request_base: Option<String>,
14- //
15- // #[structopt(long = "ares-keys-file")]
16- // pub ares_keys_file: Option<String>,
17-
1818 #[ structopt( long = "warehouse" ) ]
1919 pub warehouse : Option < String > ,
2020
@@ -47,7 +47,62 @@ pub enum Subcommand {
4747 /// Revert the chain to a previous state.
4848 Revert ( sc_cli:: RevertCmd ) ,
4949
50+ /// Revert the chain to a previous state.
51+ ForceRevert ( ForceRevertCmd ) ,
52+
5053 /// The custom benchmark subcommmand benchmarking runtime pallets.
5154 #[ structopt( name = "benchmark" , about = "Benchmark runtime pallets." ) ]
5255 Benchmark ( frame_benchmarking_cli:: BenchmarkCmd ) ,
5356}
57+
58+
59+ /// The `revert` command used revert the chain to a previous state.
60+ #[ derive( Debug , StructOpt ) ]
61+ pub struct ForceRevertCmd {
62+
63+ /// Number of blocks to revert.
64+ #[ structopt( default_value = "256" ) ]
65+ pub num : GenericNumber ,
66+
67+ #[ allow( missing_docs) ]
68+ #[ structopt( flatten) ]
69+ pub shared_params : SharedParams ,
70+
71+ #[ allow( missing_docs) ]
72+ #[ structopt( flatten) ]
73+ pub pruning_params : PruningParams ,
74+ }
75+
76+ impl ForceRevertCmd {
77+ /// Run the revert command
78+ pub async fn run < B , BA , C > ( & self , client : Arc < C > , backend : Arc < BA > ) -> Result < ( ) >
79+ where
80+ B : BlockT ,
81+ BA : Backend < B > ,
82+ C : UsageProvider < B > ,
83+ <<<B as BlockT >:: Header as HeaderT >:: Number as FromStr >:: Err : Debug ,
84+ {
85+ let blocks = self . num . parse ( ) ?;
86+ // let force = self.force.parse().unwrap_or(false);
87+ // revert_chain(client, backend, blocks)?;
88+ let reverted = backend. revert ( blocks, true ) ?;
89+ let info = client. usage_info ( ) . chain ;
90+
91+ if reverted. 0 . is_zero ( ) {
92+ log:: info!( "There aren't any non-finalized blocks to force revert." ) ;
93+ } else {
94+ log:: info!( "Force reverted {} blocks. Best: #{} ({})" , reverted. 0 , info. best_number, info. best_hash) ;
95+ }
96+ Ok ( ( ) )
97+ }
98+ }
99+
100+ impl CliConfiguration for ForceRevertCmd {
101+ fn shared_params ( & self ) -> & SharedParams {
102+ & self . shared_params
103+ }
104+
105+ fn pruning_params ( & self ) -> Option < & PruningParams > {
106+ Some ( & self . pruning_params )
107+ }
108+ }
0 commit comments