@@ -222,11 +222,19 @@ func (f *finalizer) updateFlushIDs(newPendingFlushID, newStoredFlushID uint64) {
222
222
223
223
func (f * finalizer ) checkL1InfoTreeUpdate (ctx context.Context ) {
224
224
firstL1InfoRootUpdate := true
225
+ skipFirstSleep := true
225
226
226
227
for {
228
+ if skipFirstSleep {
229
+ skipFirstSleep = false
230
+ } else {
231
+ time .Sleep (f .cfg .L1InfoTreeCheckInterval .Duration )
232
+ }
233
+
227
234
lastL1BlockNumber , err := f .etherman .GetLatestBlockNumber (ctx )
228
235
if err != nil {
229
236
log .Errorf ("error getting latest L1 block number, error: %v" , err )
237
+ continue
230
238
}
231
239
232
240
maxBlockNumber := uint64 (0 )
@@ -246,9 +254,30 @@ func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
246
254
}
247
255
248
256
if firstL1InfoRootUpdate || l1InfoRoot .L1InfoTreeIndex > f .lastL1InfoTree .L1InfoTreeIndex {
249
- firstL1InfoRootUpdate = false
257
+ log .Infof ("received new L1InfoRoot, l1InfoTreeIndex: %d, l1InfoTreeRoot: %s, l1Block: %d" ,
258
+ l1InfoRoot .L1InfoTreeIndex , l1InfoRoot .L1InfoTreeRoot , l1InfoRoot .BlockNumber )
250
259
251
- log .Debugf ("received new L1InfoRoot. L1InfoTreeIndex: %d" , l1InfoRoot .L1InfoTreeIndex )
260
+ // Sanity check l1BlockState (l1InfoRoot.BlockNumber) blockhash matches blockhash on ethereum. We skip it if l1InfoRoot.BlockNumber == 0 (empty tree)
261
+ if l1InfoRoot .BlockNumber > 0 {
262
+ l1BlockState , err := f .stateIntf .GetBlockByNumber (ctx , l1InfoRoot .BlockNumber , nil )
263
+ if err != nil {
264
+ log .Errorf ("error getting L1 block %d from the state, error: %v" , l1InfoRoot .BlockNumber , err )
265
+ continue
266
+ }
267
+
268
+ l1BlockEth , err := f .etherman .HeaderByNumber (ctx , new (big.Int ).SetUint64 (l1InfoRoot .BlockNumber ))
269
+ if err != nil {
270
+ log .Errorf ("error getting L1 block %d from ethereum, error: %v" , l1InfoRoot .BlockNumber , err )
271
+ continue
272
+ }
273
+ if l1BlockState .BlockHash != l1BlockEth .Hash () {
274
+ log .Warnf ("skipping use of l1InfoTreeIndex %d, L1 block %d blockhash %s doesn't match blockhash on ethereum %s (L1 reorg?)" ,
275
+ l1InfoRoot .L1InfoTreeIndex , l1InfoRoot .BlockNumber , l1BlockState .BlockHash , l1BlockEth .Hash ())
276
+ continue
277
+ }
278
+ }
279
+
280
+ firstL1InfoRootUpdate = false
252
281
253
282
f .lastL1InfoTreeMux .Lock ()
254
283
f .lastL1InfoTree = l1InfoRoot
@@ -261,8 +290,6 @@ func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
261
290
f .lastL1InfoTreeCond .L .Unlock ()
262
291
}
263
292
}
264
-
265
- time .Sleep (f .cfg .L1InfoTreeCheckInterval .Duration )
266
293
}
267
294
}
268
295
0 commit comments