diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java index 8532e6b1ddd..6f65dc5bd3d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java @@ -93,10 +93,27 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) forkChoice.getSafeBlockHash(), forkChoice.getFinalizedBlockHash()); + if (mergeCoordinator.isBadBlock(forkChoice.getHeadBlockHash())) { + logForkchoiceUpdatedCall(INVALID, forkChoice); + return new JsonRpcSuccessResponse( + requestId, + new EngineUpdateForkchoiceResult( + INVALID, + mergeCoordinator + .getLatestValidHashOfBadBlock(forkChoice.getHeadBlockHash()) + .orElse(Hash.ZERO), + null, + Optional.of(forkChoice.getHeadBlockHash() + " is an invalid block"))); + } + final Optional maybeNewHead = mergeCoordinator.getOrSyncHeadByHash( forkChoice.getHeadBlockHash(), forkChoice.getFinalizedBlockHash()); + if (maybeNewHead.isEmpty()) { + return syncingResponse(requestId, forkChoice); + } + ForkchoiceResult forkchoiceResult = null; if (!isValidForkchoiceState( forkChoice.getSafeBlockHash(), forkChoice.getFinalizedBlockHash(), maybeNewHead.get())) { @@ -143,22 +160,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) } } - if (mergeCoordinator.isBadBlock(forkChoice.getHeadBlockHash())) { - logForkchoiceUpdatedCall(INVALID, forkChoice); - return new JsonRpcSuccessResponse( - requestId, - new EngineUpdateForkchoiceResult( - INVALID, - mergeCoordinator - .getLatestValidHashOfBadBlock(forkChoice.getHeadBlockHash()) - .orElse(Hash.ZERO), - null, - Optional.of(forkChoice.getHeadBlockHash() + " is an invalid block"))); - } - - if (maybeNewHead.isEmpty()) { - return syncingResponse(requestId, forkChoice); - } final BlockHeader newHead = maybeNewHead.get(); if (maybePayloadAttributes.isPresent()) { Optional maybeError =