From f05401b78ece0f3751dd57da5f0f371b61222724 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:14:13 +0200 Subject: [PATCH] Don't write headBlockHash & co when FCU points to an old canonical block (#4650) --- eth/stagedsync/stage_headers.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index 4cd6e6e63..9b4bde039 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -332,22 +332,15 @@ func startHandlingForkChoice( if headerHash == canonicalHash { log.Info(fmt.Sprintf("[%s] Fork choice on previously known block", s.LogPrefix())) cfg.hd.BeaconRequestList.Remove(requestId) - rawdb.WriteForkchoiceHead(tx, forkChoice.HeadBlockHash) - canonical, err := safeAndFinalizedBlocksAreCanonical(forkChoice, s, tx, cfg) - if err != nil { - log.Warn(fmt.Sprintf("[%s] Fork choice err", s.LogPrefix()), "err", err) - return nil, err - } - if canonical { - return &privateapi.PayloadStatus{ - Status: remote.EngineStatus_VALID, - LatestValidHash: headerHash, - }, nil - } else { - return &privateapi.PayloadStatus{ - CriticalError: &privateapi.InvalidForkchoiceStateErr, - }, nil - } + // Per the Engine API spec: + // Client software MAY skip an update of the forkchoice state and MUST NOT begin a payload build process + // if forkchoiceState.headBlockHash references an ancestor of the head of canonical chain. + // In the case of such an event, client software MUST return + // {payloadStatus: {status: VALID, latestValidHash: forkchoiceState.headBlockHash, validationError: null}, payloadId: null}. + return &privateapi.PayloadStatus{ + Status: remote.EngineStatus_VALID, + LatestValidHash: headerHash, + }, nil } if cfg.memoryOverlay && headerHash == cfg.hd.GetNextForkHash() {