Skip to content

Commit

Permalink
check badblock before all else
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
jflo committed Oct 17, 2023
1 parent 395c33a commit 7f0d334
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockHeader> 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())) {
Expand Down Expand Up @@ -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<JsonRpcErrorResponse> maybeError =
Expand Down

0 comments on commit 7f0d334

Please sign in to comment.