From 00853c2fcf9c58f183552528950b6929345f3d1d Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 28 Sep 2023 22:27:47 +1000 Subject: [PATCH] Validate bad block before new head check syncing (#5967) Signed-off-by: Gabriel-Trintinalia --- .../AbstractEngineForkchoiceUpdated.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 8e471e2a113..511300d1090 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,6 +93,19 @@ 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()); @@ -150,19 +163,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) return syncingResponse(requestId, forkChoice); } - 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"))); - } - maybePayloadAttributes.ifPresentOrElse( this::logPayload, () -> LOG.debug("Payload attributes are null"));