From 3a01bd766123ecd47193a90649c3415c8c75d452 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 28 Sep 2023 18:50:41 +1000 Subject: [PATCH] Validate bad block before new head check syncing 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 aca6ee9dc6b..716534e145a 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()); @@ -141,19 +154,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"))); - } - if (!isValidForkchoiceState( forkChoice.getSafeBlockHash(), forkChoice.getFinalizedBlockHash(), newHead)) { logForkchoiceUpdatedCall(INVALID, forkChoice);