@@ -12,9 +12,9 @@ use std::{
12
12
path:: { Path , PathBuf } ,
13
13
} ;
14
14
15
+ use :: eyre:: Result ;
15
16
use clap:: Parser ;
16
17
use cli:: { Cli , Command , ReconstructSource } ;
17
- use eyre:: Result ;
18
18
use processor:: snapshot:: {
19
19
exporter:: SnapshotExporter , importer:: SnapshotImporter , SnapshotBuilder ,
20
20
} ;
@@ -75,24 +75,29 @@ async fn main() -> Result<()> {
75
75
None => env:: current_dir ( ) ?. join ( storage:: DEFAULT_DB_NAME ) ,
76
76
} ;
77
77
78
- if let Some ( directory) = snapshot {
79
- tracing:: info!( "Trying to restore state from snapshot..." ) ;
80
- let importer = SnapshotImporter :: new ( PathBuf :: from ( directory) ) ;
81
- importer. run ( & db_path. clone ( ) ) . await ?;
82
- }
78
+ let snapshot_end_batch = match snapshot {
79
+ Some ( directory) => {
80
+ tracing:: info!( "Trying to restore state from snapshot..." ) ;
81
+ let importer = SnapshotImporter :: new ( PathBuf :: from ( directory) ) ;
82
+ let end_batch = importer. run ( & db_path. clone ( ) ) . await ?;
83
+ Some ( end_batch)
84
+ }
85
+ None => None ,
86
+ } ;
83
87
84
88
match source {
85
89
ReconstructSource :: L1 { l1_fetcher_options } => {
86
90
let fetcher_options = l1_fetcher_options. into ( ) ;
87
91
let processor = TreeProcessor :: new ( db_path. clone ( ) ) . await ?;
88
92
let fetcher = L1Fetcher :: new ( fetcher_options, Some ( processor. get_inner_db ( ) ) ) ?;
93
+
89
94
let ( tx, rx) = mpsc:: channel :: < CommitBlock > ( 5 ) ;
90
95
91
96
let processor_handle = tokio:: spawn ( async move {
92
97
processor. run ( rx) . await ;
93
98
} ) ;
94
99
95
- fetcher. run ( tx) . await ?;
100
+ fetcher. run ( tx, snapshot_end_batch ) . await ?;
96
101
processor_handle. await ?;
97
102
}
98
103
ReconstructSource :: File { file } => {
@@ -128,7 +133,7 @@ async fn main() -> Result<()> {
128
133
processor. run ( rx) . await ;
129
134
} ) ;
130
135
131
- fetcher. run ( tx) . await ?;
136
+ fetcher. run ( tx, None ) . await ?;
132
137
processor_handle. await ?;
133
138
134
139
tracing:: info!( "Successfully downloaded CommitBlocks to {}" , file) ;
@@ -159,7 +164,7 @@ async fn main() -> Result<()> {
159
164
let processor = SnapshotBuilder :: new ( db_path) ;
160
165
161
166
let mut fetcher_options: L1FetcherOptions = l1_fetcher_options. into ( ) ;
162
- if let Ok ( batch_number) = processor. get_latest_l1_batch_number ( ) {
167
+ if let Ok ( batch_number) = processor. get_latest_l1_block_number ( ) {
163
168
let batch_number = batch_number. as_u64 ( ) ;
164
169
if batch_number > ethereum:: GENESIS_BLOCK {
165
170
tracing:: info!(
@@ -176,18 +181,14 @@ async fn main() -> Result<()> {
176
181
processor. run ( rx) . await ;
177
182
} ) ;
178
183
179
- fetcher. run ( tx) . await ?;
184
+ fetcher. run ( tx, None ) . await ?;
180
185
processor_handle. await ?;
181
186
}
182
- Command :: ExportSnapshot {
183
- db_path,
184
- num_chunks,
185
- directory,
186
- } => {
187
+ Command :: ExportSnapshot { db_path, directory } => {
187
188
let export_path = Path :: new ( & directory) ;
188
189
std:: fs:: create_dir_all ( export_path) ?;
189
190
let exporter = SnapshotExporter :: new ( export_path, db_path) ?;
190
- exporter. export_snapshot ( num_chunks ) ?;
191
+ exporter. export_snapshot ( ) ?;
191
192
192
193
tracing:: info!( "Succesfully exported snapshot files to \" {directory}\" !" ) ;
193
194
}
0 commit comments