From 23b648d7ce88c9c4fe4804871681e7b322175d22 Mon Sep 17 00:00:00 2001
From: Giulio rebuffo <giulio.rebuffo@gmail.com>
Date: Tue, 17 May 2022 17:44:25 +0200
Subject: [PATCH] ops (#4183)

---
 ethdb/privateapi/ethbackend.go | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/ethdb/privateapi/ethbackend.go b/ethdb/privateapi/ethbackend.go
index d4b3f499c2..a1d5c1e796 100644
--- a/ethdb/privateapi/ethbackend.go
+++ b/ethdb/privateapi/ethbackend.go
@@ -456,12 +456,17 @@ func (s *EthBackendServer) EngineForkChoiceUpdatedV1(ctx context.Context, req *r
 			PayloadStatus: &remote.EnginePayloadStatus{Status: remote.EngineStatus_INVALID_TERMINAL_BLOCK},
 		}, nil
 	}
-	tx1.Rollback()
 
 	// TODO(yperbasis): Client software MAY skip an update of the forkchoice state and
 	// MUST NOT begin a payload build process if forkchoiceState.headBlockHash doesn't reference a leaf of the block tree
 	// (i.e. it references an old block).
 	// https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.6/src/engine/specification.md#specification-1
+	if rawdb.ReadHeadBlockHash(tx1) == forkChoice.HeadBlockHash {
+		return &remote.EngineForkChoiceUpdatedReply{
+			PayloadStatus: &remote.EnginePayloadStatus{Status: remote.EngineStatus_VALID},
+		}, nil
+	}
+	tx1.Rollback()
 
 	if s.stageLoopIsBusy() {
 		log.Trace("[ForkChoiceUpdated] stage loop is busy")
@@ -470,20 +475,14 @@ func (s *EthBackendServer) EngineForkChoiceUpdatedV1(ctx context.Context, req *r
 		}, nil
 	}
 
-	payloadStatus := PayloadStatus{
-		Status: remote.EngineStatus_VALID,
-	}
+	log.Trace("[ForkChoiceUpdated] sending forkChoiceMessage", "head", forkChoice.HeadBlockHash)
+	s.requestList.AddForkChoiceRequest(&forkChoice)
 
-	if (forkChoice.HeadBlockHash != common.Hash{} || forkChoice.HeadBlockHash != common.Hash{}) {
-		log.Trace("[ForkChoiceUpdated] sending forkChoiceMessage", "head", forkChoice.HeadBlockHash)
-		s.requestList.AddForkChoiceRequest(&forkChoice)
-
-		payloadStatus = <-s.statusCh
-		log.Trace("[ForkChoiceUpdated] got reply", "payloadStatus", payloadStatus)
+	payloadStatus := <-s.statusCh
+	log.Trace("[ForkChoiceUpdated] got reply", "payloadStatus", payloadStatus)
 
-		if payloadStatus.CriticalError != nil {
-			return nil, payloadStatus.CriticalError
-		}
+	if payloadStatus.CriticalError != nil {
+		return nil, payloadStatus.CriticalError
 	}
 
 	// No need for payload building
-- 
GitLab