@@ -118,14 +118,9 @@ impl ValidatorSubmitter {
118118 true
119119 } ;
120120
121- let mut latest_seen_checkpoint_index = self
121+ let mut latest_seen_checkpoint = self
122122 . db
123- . retrieve_latest_checkpoint_index ( )
124- . unwrap_or_default ( )
125- . unwrap_or_default ( ) as u32 ;
126- let mut latest_seen_checkpoint_block_height = self
127- . db
128- . retrieve_latest_checkpoint_block_height ( )
123+ . retrieve_latest_checkpoint_info ( )
129124 . unwrap_or_default ( )
130125 . unwrap_or_default ( ) ;
131126
@@ -138,59 +133,40 @@ impl ValidatorSubmitter {
138133 } )
139134 . await ;
140135
141- if latest_checkpoint. index < latest_seen_checkpoint_index {
142- if let Some ( block_height) = latest_checkpoint. block_height {
143- if block_height >= latest_seen_checkpoint_block_height {
144- tracing:: error!(
145- ?latest_checkpoint,
146- ?latest_seen_checkpoint_index,
147- ?latest_seen_checkpoint_block_height,
148- "Latest checkpoint index is lower than previously seen, but has a block height equal or greater." ) ;
149-
150- let checkpoint = self . checkpoint ( & tree) ;
151- Self :: panic_with_reorg (
152- & self . reorg_reporter ,
153- & self . reorg_period ,
154- & self . checkpoint_syncer ,
155- tree. root ( ) ,
156- & latest_checkpoint,
157- & checkpoint,
158- )
159- . await ;
160- }
136+ if let Some ( block_height) = latest_checkpoint. block_height {
137+ if latest_checkpoint. index < latest_seen_checkpoint. checkpoint_index
138+ && block_height >= latest_seen_checkpoint. block_height
139+ {
140+ tracing:: error!(
141+ ?latest_checkpoint,
142+ ?latest_seen_checkpoint,
143+ "Latest checkpoint index is lower than previously seen, but has a block height equal or greater." ) ;
144+
145+ let checkpoint = self . checkpoint ( & tree) ;
146+ Self :: panic_with_reorg (
147+ & self . reorg_reporter ,
148+ & self . reorg_period ,
149+ & self . checkpoint_syncer ,
150+ tree. root ( ) ,
151+ & latest_checkpoint,
152+ & checkpoint,
153+ )
154+ . await ;
161155 }
162- }
163-
164- if latest_checkpoint. index > latest_seen_checkpoint_index {
165156 tracing:: debug!(
166- old_index = latest_seen_checkpoint_index ,
167- new_index = latest_checkpoint . index ,
157+ ?latest_checkpoint ,
158+ ?latest_seen_checkpoint ,
168159 "Updating latest seen checkpoint index"
169160 ) ;
170- latest_seen_checkpoint_index = latest_checkpoint. index ;
171- if let Err ( err) = self
172- . db
173- . store_latest_checkpoint_index ( latest_seen_checkpoint_index as u64 )
174- {
175- tracing:: error!( ?err, "Failed to store latest_checkpoint_index" ) ;
176- } ;
177- if let Some ( block_height) = latest_checkpoint. block_height {
178- if block_height < latest_seen_checkpoint_block_height {
179- tracing:: warn!(
180- checkpoint_index = latest_checkpoint. index,
181- checkpoint_block_height = block_height,
182- latest_seen_checkpoint_block_height,
183- "Receive a checkpoint with a higher index, but lower block height"
184- ) ;
185- }
186- latest_seen_checkpoint_block_height = block_height;
187- if let Err ( err) = self
188- . db
189- . store_latest_checkpoint_block_height ( latest_seen_checkpoint_block_height)
190- {
191- tracing:: error!( ?err, "Failed to store latest_checkpoint_block_height" ) ;
192- }
161+ if block_height < latest_seen_checkpoint. block_height {
162+ tracing:: warn!(
163+ ?latest_checkpoint,
164+ ?latest_seen_checkpoint,
165+ "Receive a checkpoint with a higher index, but lower block height"
166+ ) ;
193167 }
168+ latest_seen_checkpoint. block_height = block_height;
169+ latest_seen_checkpoint. checkpoint_index = latest_checkpoint. index ;
194170 }
195171
196172 self . metrics
@@ -344,13 +320,14 @@ impl ValidatorSubmitter {
344320 correctness_checkpoint : & CheckpointAtBlock ,
345321 incorrect_checkpoint : & Checkpoint ,
346322 ) {
347- let reorg_event = ReorgEvent :: new (
348- tree_root,
349- correctness_checkpoint. root ,
350- incorrect_checkpoint. index ,
351- chrono:: Utc :: now ( ) . timestamp ( ) as u64 ,
352- reorg_period. clone ( ) ,
353- ) ;
323+ let reorg_event = ReorgEvent {
324+ local_merkle_root : tree_root,
325+ local_checkpoint_index : incorrect_checkpoint. index ,
326+ canonical_merkle_root : correctness_checkpoint. root ,
327+ canonical_checkpoint_index : correctness_checkpoint. index ,
328+ unix_timestamp : chrono:: Utc :: now ( ) . timestamp ( ) as u64 ,
329+ reorg_period : reorg_period. clone ( ) ,
330+ } ;
354331 error ! (
355332 ?incorrect_checkpoint,
356333 ?correctness_checkpoint,
0 commit comments