From bb6b1a4831499c5931bd62fcf666c85e9698a451 Mon Sep 17 00:00:00 2001 From: Krish Date: Fri, 5 Jul 2024 12:23:41 +0800 Subject: [PATCH 1/4] fix: fix el bug --- op-node/rollup/derive/engine_controller.go | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/op-node/rollup/derive/engine_controller.go b/op-node/rollup/derive/engine_controller.go index f73ce21891..a6b054919e 100644 --- a/op-node/rollup/derive/engine_controller.go +++ b/op-node/rollup/derive/engine_controller.go @@ -293,6 +293,17 @@ func (e *EngineController) checkForkchoiceUpdatedStatus(status eth.ExecutePayloa return status == eth.ExecutionValid } +// checkUpdateUnsafeHead checks if we can update current unsafeHead for op-node +func (e *EngineController) checkUpdateUnsafeHead(status eth.ExecutePayloadStatus) bool { + if e.syncMode == sync.ELSync { + if e.syncStatus == syncStatusStartedEL || e.syncStatus == syncStatusWillStartEL { + return false + } + return true + } + return status == eth.ExecutionValid +} + // TryUpdateEngine attempts to update the engine with the current forkchoice state of the rollup node, // this is a no-op if the nodes already agree on the forkchoice state. func (e *EngineController) TryUpdateEngine(ctx context.Context) error { @@ -329,8 +340,9 @@ func (e *EngineController) InsertUnsafePayload(ctx context.Context, envelope *et // Check if there is a finalized head once when doing EL sync. If so, transition to CL sync if e.syncStatus == syncStatusWillStartEL { b, err := e.engine.L2BlockRefByLabel(ctx, eth.Finalized) + currentUnsafe := e.GetCurrentUnsafeHead(ctx) isTransitionBlock := e.rollupCfg.Genesis.L2.Number != 0 && b.Hash == e.rollupCfg.Genesis.L2.Hash - isGapSyncNeeded := ref.Number-e.UnsafeL2Head().Number > uint64(e.elTriggerGap) + isGapSyncNeeded := ref.Number-currentUnsafe.Number > uint64(e.elTriggerGap) if errors.Is(err, ethereum.NotFound) || isTransitionBlock || isGapSyncNeeded { e.syncStatus = syncStatusStartedEL e.log.Info("Starting EL sync") @@ -385,12 +397,16 @@ func (e *EngineController) InsertUnsafePayload(ctx context.Context, envelope *et return NewTemporaryError(fmt.Errorf("cannot prepare unsafe chain for new payload: new - %v; parent: %v; err: %w", payload.ID(), payload.ParentID(), eth.ForkchoiceUpdateErr(fcRes.PayloadStatus))) } - e.SetUnsafeHead(ref) + e.needFCUCall = false + if e.checkUpdateUnsafeHead(fcRes.PayloadStatus.Status) { + e.SetUnsafeHead(ref) + } if e.syncStatus == syncStatusFinishedELButNotFinalized { e.log.Info("Finished EL sync", "sync_duration", e.clock.Since(e.elStart), "finalized_block", ref.ID().String()) e.syncStatus = syncStatusFinishedEL + e.SetUnsafeHead(ref) } return nil @@ -468,3 +484,15 @@ func (e *EngineController) TryBackupUnsafeReorg(ctx context.Context) (bool, erro func (e *EngineController) ResetBuildingState() { e.resetBuildingState() } + +func (e *EngineController) GetCurrentUnsafeHead(ctx context.Context) eth.L2BlockRef { + currentL2UnsafeHead := e.UnsafeL2Head() + if currentL2UnsafeHead.Number == 0 { + //derivation stage not finished yet + engineUnsafeHead, err := e.engine.L2BlockRefByLabel(ctx, eth.Unsafe) + if err == nil { + currentL2UnsafeHead = engineUnsafeHead + } + } + return currentL2UnsafeHead +} From 28bd4e22c239447c43e6544f1ad95d7e8df8bfb3 Mon Sep 17 00:00:00 2001 From: Krish Date: Wed, 10 Jul 2024 01:23:35 +0700 Subject: [PATCH 2/4] chore: add error logs when cannot get latest unsafe from geth --- op-node/rollup/derive/engine_controller.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/op-node/rollup/derive/engine_controller.go b/op-node/rollup/derive/engine_controller.go index a6b054919e..25fd4c1a5f 100644 --- a/op-node/rollup/derive/engine_controller.go +++ b/op-node/rollup/derive/engine_controller.go @@ -490,7 +490,9 @@ func (e *EngineController) GetCurrentUnsafeHead(ctx context.Context) eth.L2Block if currentL2UnsafeHead.Number == 0 { //derivation stage not finished yet engineUnsafeHead, err := e.engine.L2BlockRefByLabel(ctx, eth.Unsafe) - if err == nil { + if err != nil { + log.Error("cannot get unsafe head from engine") + } else { currentL2UnsafeHead = engineUnsafeHead } } From 6ee71ecfb3de38cd005d34c383f8ef2c283431d3 Mon Sep 17 00:00:00 2001 From: Owen <103096885+owen-reorg@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:14:25 +0800 Subject: [PATCH 3/4] Update op-node/rollup/derive/engine_controller.go --- op-node/rollup/derive/engine_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op-node/rollup/derive/engine_controller.go b/op-node/rollup/derive/engine_controller.go index 840728fb2a..cbe61fde44 100644 --- a/op-node/rollup/derive/engine_controller.go +++ b/op-node/rollup/derive/engine_controller.go @@ -551,7 +551,7 @@ func (e *EngineController) GetCurrentUnsafeHead(ctx context.Context) eth.L2Block } } return currentL2UnsafeHead - +} // getCurrentL2Info returns the current finalized, safe and unsafe heads of the execution engine. func (e *EngineController) getCurrentL2Info(ctx context.Context) (*sync.FindHeadsResult, error) { finalized, err := e.engine.L2BlockRefByLabel(ctx, eth.Finalized) From b05eaa3b82e34f14920295a04b7909b819c26a69 Mon Sep 17 00:00:00 2001 From: Owen <103096885+owen-reorg@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:14:52 +0800 Subject: [PATCH 4/4] Update op-node/rollup/derive/engine_controller.go --- op-node/rollup/derive/engine_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/op-node/rollup/derive/engine_controller.go b/op-node/rollup/derive/engine_controller.go index cbe61fde44..555728a5ea 100644 --- a/op-node/rollup/derive/engine_controller.go +++ b/op-node/rollup/derive/engine_controller.go @@ -552,6 +552,7 @@ func (e *EngineController) GetCurrentUnsafeHead(ctx context.Context) eth.L2Block } return currentL2UnsafeHead } + // getCurrentL2Info returns the current finalized, safe and unsafe heads of the execution engine. func (e *EngineController) getCurrentL2Info(ctx context.Context) (*sync.FindHeadsResult, error) { finalized, err := e.engine.L2BlockRefByLabel(ctx, eth.Finalized)