Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix el bug #215

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions op-node/rollup/derive/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved
currentL2UnsafeHead = engineUnsafeHead
}
}
return currentL2UnsafeHead
}
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved
Loading