@@ -60,54 +60,35 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
60
60
61
61
let components = components ( provider_factory. chain_spec ( ) ) ;
62
62
63
- let highest_static_file_block = provider_factory
64
- . static_file_provider ( )
65
- . get_highest_static_files ( )
66
- . max_block_num ( )
67
- . filter ( |highest_static_file_block| * highest_static_file_block > target) ;
68
-
69
- // Execute a pipeline unwind if the start of the range overlaps the existing static
70
- // files. If that's the case, then copy all available data from MDBX to static files, and
71
- // only then, proceed with the unwind.
72
- //
73
- // We also execute a pipeline unwind if `offline` is specified, because we need to only
74
- // unwind the data associated with offline stages.
75
- if highest_static_file_block. is_some ( ) || self . offline {
76
- if self . offline {
77
- info ! ( target: "reth::cli" , "Performing an unwind for offline-only data!" ) ;
78
- }
79
-
80
- if let Some ( highest_static_file_block) = highest_static_file_block {
81
- info ! ( target: "reth::cli" , ?target, ?highest_static_file_block, "Executing a pipeline unwind." ) ;
82
- } else {
83
- info ! ( target: "reth::cli" , ?target, "Executing a pipeline unwind." ) ;
84
- }
85
- info ! ( target: "reth::cli" , prune_config=?config. prune, "Using prune settings" ) ;
86
-
87
- // This will build an offline-only pipeline if the `offline` flag is enabled
88
- let mut pipeline =
89
- self . build_pipeline ( config, provider_factory, components. evm_config ( ) . clone ( ) ) ?;
63
+ // Sanity check that we have static files available to unwind to the target block.
64
+ let highest_static_file_block =
65
+ provider_factory. static_file_provider ( ) . get_highest_static_files ( ) . max_block_num ( ) ;
66
+ if highest_static_file_block
67
+ . filter ( |highest_static_file_block| * highest_static_file_block > target)
68
+ . is_none ( )
69
+ {
70
+ return Err ( eyre:: eyre!( "static files not available for target block {target}, highest is {highest_static_file_block:?}" ) ) ;
71
+ }
90
72
91
- // Move all applicable data from database to static files.
92
- pipeline. move_to_static_files ( ) ?;
73
+ if self . offline {
74
+ info ! ( target: "reth::cli" , "Performing an unwind for offline-only data!" ) ;
75
+ }
93
76
94
- pipeline. unwind ( target, None ) ?;
77
+ if let Some ( highest_static_file_block) = highest_static_file_block {
78
+ info ! ( target: "reth::cli" , ?target, ?highest_static_file_block, "Executing a pipeline unwind." ) ;
95
79
} else {
96
- info ! ( target: "reth::cli" , ?target, "Executing a database unwind." ) ;
97
- let provider = provider_factory. provider_rw ( ) ?;
80
+ info ! ( target: "reth::cli" , ?target, "Executing a pipeline unwind." ) ;
81
+ }
82
+ info ! ( target: "reth::cli" , prune_config=?config. prune, "Using prune settings" ) ;
98
83
99
- provider
100
- . remove_block_and_execution_above ( target )
101
- . map_err ( |err| eyre :: eyre! ( "Transaction error on unwind: {err}" ) ) ?;
84
+ // This will build an offline-only pipeline if the `offline` flag is enabled
85
+ let mut pipeline =
86
+ self . build_pipeline ( config , provider_factory , components . evm_config ( ) . clone ( ) ) ?;
102
87
103
- // update finalized block if needed
104
- let last_saved_finalized_block_number = provider. last_finalized_block_number ( ) ?;
105
- if last_saved_finalized_block_number. is_none_or ( |f| f > target) {
106
- provider. save_finalized_block_number ( target) ?;
107
- }
88
+ // Move all applicable data from database to static files.
89
+ pipeline. move_to_static_files ( ) ?;
108
90
109
- provider. commit ( ) ?;
110
- }
91
+ pipeline. unwind ( target, None ) ?;
111
92
112
93
info ! ( target: "reth::cli" , ?target, "Unwound blocks" ) ;
113
94
0 commit comments