@@ -38,6 +38,10 @@ const (
3838 // under normal operation. A value of 2 means when head is at block N,
3939 // safe is at block N-2.
4040 SafeBlockLag = 2
41+ // FinalizedBlockLag is the number of blocks the finalized block lags behind head.
42+ // This is a temporary mock value until proper DA-based finalization is wired up.
43+ // A value of 3 means when head is at block N, finalized is at block N-3.
44+ FinalizedBlockLag = 3
4145)
4246
4347var (
@@ -419,12 +423,18 @@ func (c *EngineClient) setFinal(ctx context.Context, blockHash common.Hash, isFi
419423 return c .setFinalWithHeight (ctx , blockHash , 0 , isFinal )
420424}
421425
422- // setFinalWithHeight updates forkchoice state with optional safe block lagging.
423- // When isFinal=false and headHeight > SafeBlockLag, the safe block is automatically
424- // set to headHeight - SafeBlockLag blocks behind head.
426+ // setFinalWithHeight updates forkchoice state with safe and finalized block lagging.
427+ // When isFinal=false:
428+ // - Safe block is set to headHeight - SafeBlockLag (when headHeight > SafeBlockLag)
429+ // - Finalized block is set to headHeight - FinalizedBlockLag (when headHeight > FinalizedBlockLag)
430+ //
431+ // Note: The finalized lag is a temporary mock until proper DA-based finalization is wired up.
425432func (c * EngineClient ) setFinalWithHeight (ctx context.Context , blockHash common.Hash , headHeight uint64 , isFinal bool ) error {
426- var safeHash common.Hash
433+ var safeHash , finalizedHash common.Hash
427434 updateSafe := ! isFinal && headHeight > SafeBlockLag
435+ updateFinalized := ! isFinal && headHeight > FinalizedBlockLag
436+
437+ // Look up safe block hash
428438 if updateSafe {
429439 safeHeight := headHeight - SafeBlockLag
430440
@@ -446,6 +456,28 @@ func (c *EngineClient) setFinalWithHeight(ctx context.Context, blockHash common.
446456 }
447457 }
448458
459+ // Look up finalized block hash
460+ if updateFinalized {
461+ finalizedHeight := headHeight - FinalizedBlockLag
462+
463+ c .mu .Lock ()
464+ cachedFinalizedHash , ok := c .blockHashCache [finalizedHeight ]
465+ c .mu .Unlock ()
466+ if ok {
467+ finalizedHash = cachedFinalizedHash
468+ } else {
469+ var err error
470+ finalizedHash , _ , _ , _ , err = c .getBlockInfo (ctx , finalizedHeight )
471+ if err != nil {
472+ c .logger .Debug ().
473+ Uint64 ("finalizedHeight" , finalizedHeight ).
474+ Err (err ).
475+ Msg ("setFinalWithHeight: finalized block not found, skipping finalized update" )
476+ updateFinalized = false
477+ }
478+ }
479+ }
480+
449481 c .mu .Lock ()
450482 if isFinal {
451483 c .currentFinalizedBlockHash = blockHash
@@ -456,6 +488,9 @@ func (c *EngineClient) setFinalWithHeight(ctx context.Context, blockHash common.
456488 if updateSafe {
457489 c .currentSafeBlockHash = safeHash
458490 }
491+ if updateFinalized {
492+ c .currentFinalizedBlockHash = finalizedHash
493+ }
459494 }
460495 args := engine.ForkchoiceStateV1 {
461496 HeadBlockHash : c .currentHeadBlockHash ,
0 commit comments