@@ -40,10 +40,6 @@ pub struct ImportConfig {
40
40
/// Result of an import operation.
41
41
#[ derive( Debug ) ]
42
42
pub struct ImportResult {
43
- /// Total number of blocks present in the database before the import started.
44
- pub starting_imported_blocks : usize ,
45
- /// Total number of transactions present in the database before the import started.
46
- pub starting_imported_txns : usize ,
47
43
/// Total number of blocks decoded from the file.
48
44
pub total_decoded_blocks : usize ,
49
45
/// Total number of transactions decoded from the file.
@@ -57,13 +53,8 @@ pub struct ImportResult {
57
53
impl ImportResult {
58
54
/// Returns true if all blocks and transactions were imported successfully.
59
55
pub fn is_complete ( & self ) -> bool {
60
- // Compare deltas so this works for fresh DBs (genesis present) and non-empty DBs alike.
61
- self . total_imported_blocks
62
- . saturating_sub ( self . starting_imported_blocks )
63
- . saturating_eq ( self . total_decoded_blocks ) &&
64
- self . total_imported_txns
65
- . saturating_sub ( self . starting_imported_txns )
66
- . saturating_eq ( self . total_decoded_txns )
56
+ self . total_decoded_blocks == self . total_imported_blocks &&
57
+ self . total_decoded_txns == self . total_imported_txns
67
58
}
68
59
}
69
60
100
91
let mut reader = ChunkedFileReader :: new ( path, import_config. chunk_len ) . await ?;
101
92
102
93
let provider = provider_factory. provider ( ) ?;
103
- let starting_imported_blocks = provider. tx_ref ( ) . entries :: < tables:: HeaderNumbers > ( ) ?;
104
- let starting_imported_txns = provider. tx_ref ( ) . entries :: < tables:: TransactionHashNumbers > ( ) ?;
94
+ let init_blocks = provider. tx_ref ( ) . entries :: < tables:: HeaderNumbers > ( ) ?;
95
+ let init_txns = provider. tx_ref ( ) . entries :: < tables:: TransactionHashNumbers > ( ) ?;
96
+ drop ( provider) ;
105
97
106
98
let mut total_decoded_blocks = 0 ;
107
99
let mut total_decoded_txns = 0 ;
@@ -139,7 +131,7 @@ where
139
131
debug ! ( target: "reth::import" , ?tip, "Tip manually set" ) ;
140
132
141
133
let latest_block_number =
142
- provider . get_stage_checkpoint ( StageId :: Finish ) ?. map ( |ch| ch. block_number ) ;
134
+ provider_factory . get_stage_checkpoint ( StageId :: Finish ) ?. map ( |ch| ch. block_number ) ;
143
135
tokio:: spawn ( reth_node_events:: node:: handle_events ( None , latest_block_number, events) ) ;
144
136
145
137
// Run pipeline
@@ -157,12 +149,12 @@ where
157
149
. expect ( "should have genesis" ) ;
158
150
}
159
151
160
- let total_imported_blocks = provider. tx_ref ( ) . entries :: < tables:: HeaderNumbers > ( ) ?;
161
- let total_imported_txns = provider. tx_ref ( ) . entries :: < tables:: TransactionHashNumbers > ( ) ?;
152
+ let provider = provider_factory. provider ( ) ?;
153
+ let total_imported_blocks = provider. tx_ref ( ) . entries :: < tables:: HeaderNumbers > ( ) ? - init_blocks;
154
+ let total_imported_txns =
155
+ provider. tx_ref ( ) . entries :: < tables:: TransactionHashNumbers > ( ) ? - init_txns;
162
156
163
157
let result = ImportResult {
164
- starting_imported_blocks,
165
- starting_imported_txns,
166
158
total_decoded_blocks,
167
159
total_decoded_txns,
168
160
total_imported_blocks,
0 commit comments