1616// You should have received a copy of the GNU General Public License
1717// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
19+ use crate :: params:: { MergeParams , Params } ;
1920use anyhow:: { Context , Result , anyhow, ensure} ;
2021use clap:: Parser ;
2122use ethexe_common:: {
2223 Announce , HashOf , SimpleBlockData ,
2324 db:: { AnnounceStorageRO , DBGlobals , GlobalsStorageRO , OnChainStorageRO } ,
25+ gear:: CANONICAL_QUARANTINE ,
2426} ;
2527use ethexe_db:: {
26- Database , RawDatabase , RocksDatabase ,
28+ Database , InitConfig , RawDatabase , RocksDatabase ,
2729 iterator:: { BlockNode , DatabaseIterator } ,
2830 verifier:: IntegrityVerifier ,
2931 visitor:: { self } ,
3032} ;
31- use ethexe_processor:: { Processor , ProcessorConfig } ;
33+ use ethexe_processor:: { DEFAULT_CHUNK_SIZE , Processor , ProcessorConfig } ;
3234use indicatif:: { ProgressBar , ProgressStyle } ;
3335use std:: { collections:: HashSet , path:: PathBuf } ;
3436
@@ -38,15 +40,13 @@ const PROGRESS_BAR_TEMPLATE: &str = "{spinner:.green} [{elapsed_precise}] [{wide
3840/// Run checks on ethexe database, see more in [`super::Command::Check`].
3941#[ derive( Debug , Parser ) ]
4042pub struct CheckCommand {
41- /// Path to database directory (including router addr subdirectory).
42- #[ arg( long) ]
43- pub db : PathBuf ,
44-
45- #[ arg( long, default_value = "2" ) ]
46- pub chunk_size : usize ,
43+ /// CLI parameters to be merged with file ones before execution.
44+ #[ clap( flatten) ]
45+ pub params : Params ,
4746
48- #[ arg( long, default_value = "4" ) ]
49- pub canonical_quarantine : u8 ,
47+ /// Override database location.
48+ #[ arg( long) ]
49+ pub db : Option < PathBuf > ,
5050
5151 /// Perform computations of announces, by default from start announce to latest computed announce.
5252 #[ arg( long, alias = "compute" ) ]
@@ -56,12 +56,21 @@ pub struct CheckCommand {
5656 #[ arg( long, alias = "integrity" ) ]
5757 pub integrity_check : bool ,
5858
59+ /// Perform migrations before checking the database.
60+ #[ arg( long) ]
61+ pub migrate : bool ,
62+
5963 /// Enable logging verbosity (debug level by default), disables progress bar.
6064 #[ arg( short, long) ]
6165 pub verbose : bool ,
6266}
6367
6468impl CheckCommand {
69+ pub fn with_params ( mut self , params : Params ) -> Self {
70+ self . params = self . params . merge ( params) ;
71+ self
72+ }
73+
6574 /// Execute the command.
6675 pub fn exec ( self ) -> Result < ( ) > {
6776 tokio:: runtime:: Builder :: new_multi_thread ( )
@@ -80,17 +89,48 @@ impl CheckCommand {
8089 self . integrity_check = true ;
8190 }
8291
83- let rocks_db = RocksDatabase :: open ( self . db ) . context ( "failed to open rocks database" ) ?;
84- let db = Database :: try_from_raw ( RawDatabase :: from_one ( & rocks_db) ) ?;
92+ let rocks_db = RocksDatabase :: open (
93+ self . db
94+ . or_else ( || self . params . node . as_ref ( ) . map ( |node| node. db_dir ( ) ) )
95+ . context ( "missing database path" ) ?,
96+ )
97+ . context ( "failed to open rocks database" ) ?;
98+ let raw_db = RawDatabase :: from_one ( & rocks_db) ;
99+
100+ let db = if self . migrate {
101+ let ethereum_config = self
102+ . params
103+ . ethereum
104+ . context ( "missing Ethereum-related configuration" ) ?
105+ . into_config ( ) ?;
106+
107+ ethexe_db:: initialize_db (
108+ InitConfig {
109+ ethereum_rpc : ethereum_config. rpc . clone ( ) ,
110+ router_address : ethereum_config. router_address ,
111+ slot_duration_secs : ethereum_config. block_time . as_secs ( ) ,
112+ } ,
113+ raw_db. overlaid ( ) ,
114+ )
115+ . await ?
116+ } else {
117+ Database :: try_from_raw ( raw_db) ?
118+ } ;
85119
86120 let globals = db. globals ( ) . clone ( ) ;
87121
122+ let node_params = self . params . node . unwrap_or_default ( ) ;
88123 let checker = Checker {
89124 db,
90125 globals,
91126 progress_bar : !self . verbose ,
92- chunk_size : self . chunk_size ,
93- canonical_quarantine : self . canonical_quarantine ,
127+ chunk_size : node_params
128+ . chunk_processing_threads
129+ . unwrap_or ( DEFAULT_CHUNK_SIZE )
130+ . get ( ) ,
131+ canonical_quarantine : node_params
132+ . canonical_quarantine
133+ . unwrap_or ( CANONICAL_QUARANTINE ) ,
94134 } ;
95135
96136 if self . integrity_check {
0 commit comments