diff --git a/CHANGELOG.md b/CHANGELOG.md index 97097514670..e91e001fd86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 22.4.2 +### Additions and Improvements +- Engine API Update: Replace deprecated INVALID_TERMINAL_BLOCK with INVALID last valid hash 0x0 [#3882](https://github.com/hyperledger/besu/pull/3882) + ### Bug Fixes - Stop backward sync if genesis block has been reached [#3869](https://github.com/hyperledger/besu/pull/3869) - Deprecate experimental merge flag and engine-rpc-enabled flag [#3875](https://github.com/hyperledger/besu/pull/3875) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/ExecutionEngineJsonRpcMethod.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/ExecutionEngineJsonRpcMethod.java index 05263a84985..85022820cdf 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/ExecutionEngineJsonRpcMethod.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/ExecutionEngineJsonRpcMethod.java @@ -34,8 +34,7 @@ public enum EngineStatus { INVALID, SYNCING, ACCEPTED, - INVALID_BLOCK_HASH, - INVALID_TERMINAL_BLOCK; + INVALID_BLOCK_HASH; } private final Vertx syncVertx; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java index e1d7f4713a0..30df6a33ba1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_TERMINAL_BLOCK; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID; import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda; @@ -107,8 +106,8 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) return new JsonRpcSuccessResponse( requestId, new EngineUpdateForkchoiceResult( - INVALID_TERMINAL_BLOCK, - null, + INVALID, + Hash.ZERO, null, Optional.of(newHead.get() + " did not descend from terminal block"))); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java index 111da2e2787..4e2502d28ae 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java @@ -17,7 +17,6 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.ACCEPTED; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_BLOCK_HASH; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_TERMINAL_BLOCK; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID; import static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda; @@ -165,7 +164,10 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) // TODO: post-merge cleanup if (!mergeCoordinator.latestValidAncestorDescendsFromTerminal(newBlockHeader)) { - return respondWith(requestContext.getRequest().getId(), null, INVALID_TERMINAL_BLOCK); + return respondWithInvalid( + requestContext.getRequest().getId(), + Hash.ZERO, + newBlockHeader.getHash() + " did not descend from terminal block"); } final var latestValidAncestor = mergeCoordinator.getLatestValidAncestor(newBlockHeader); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineUpdateForkchoiceResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineUpdateForkchoiceResult.java index 0ca4f92f5f5..f560d295094 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineUpdateForkchoiceResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineUpdateForkchoiceResult.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_TERMINAL_BLOCK; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID; @@ -34,7 +33,7 @@ public class EngineUpdateForkchoiceResult { private final EnginePayloadStatusResult payloadStatus; private final PayloadIdentifier payloadId; static final EnumSet FORK_CHOICE_ENGINE_STATUS = - EnumSet.of(VALID, INVALID, SYNCING, INVALID_TERMINAL_BLOCK); + EnumSet.of(VALID, INVALID, SYNCING); public EngineUpdateForkchoiceResult( final EngineStatus status, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java index 4e32f315f60..d441b781d65 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java @@ -16,7 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_TERMINAL_BLOCK; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID; import static org.mockito.ArgumentMatchers.any; @@ -101,14 +100,14 @@ public void shouldReturnSyncingIfMissingNewHead() { } @Test - public void shouldReturnInvalidTerminalBlock() { + public void shouldReturnInvalidOnBadTerminalBlock() { BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader(); when(blockchain.getBlockHeader(any())).thenReturn(Optional.of(mockHeader)); when(mergeCoordinator.latestValidAncestorDescendsFromTerminal(mockHeader)).thenReturn(false); when(mergeCoordinator.isDescendantOf(any(), any())).thenReturn(true); assertSuccessWithPayloadForForkchoiceResult( - Optional.empty(), mock(ForkchoiceResult.class), INVALID_TERMINAL_BLOCK); + Optional.empty(), mock(ForkchoiceResult.class), INVALID, Optional.of(Hash.ZERO)); } @Test @@ -341,6 +340,15 @@ private EngineUpdateForkchoiceResult assertSuccessWithPayloadForForkchoiceResult final Optional payloadParam, final ForkchoiceResult forkchoiceResult, final EngineStatus expectedStatus) { + return assertSuccessWithPayloadForForkchoiceResult( + payloadParam, forkchoiceResult, expectedStatus, Optional.empty()); + } + + private EngineUpdateForkchoiceResult assertSuccessWithPayloadForForkchoiceResult( + final Optional payloadParam, + final ForkchoiceResult forkchoiceResult, + final EngineStatus expectedStatus, + final Optional maybeLatestValidHash) { // result from mergeCoordinator has no new finalized, new head: when(mergeCoordinator.updateForkChoice( @@ -364,7 +372,7 @@ private EngineUpdateForkchoiceResult assertSuccessWithPayloadForForkchoiceResult } } else { // assert null latest valid and payload identifier: - assertThat(res.getPayloadStatus().getLatestValidHash()).isEmpty(); + assertThat(res.getPayloadStatus().getLatestValidHash()).isEqualTo(maybeLatestValidHash); assertThat(res.getPayloadId()).isNull(); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java index d47637dc968..1c9803cda96 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java @@ -18,7 +18,6 @@ import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.ACCEPTED; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_BLOCK_HASH; -import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID_TERMINAL_BLOCK; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID; import static org.mockito.ArgumentMatchers.any; @@ -164,7 +163,7 @@ public void shouldReturnSuccessOnAlreadyPresent() { } @Test - public void shouldReturnInvalidTerminalBlock() { + public void shouldReturnInvalidOnBadTerminalBlock() { BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader(); when(blockchain.getBlockByHash(any())).thenReturn(Optional.empty()); @@ -177,8 +176,8 @@ public void shouldReturnInvalidTerminalBlock() { var resp = resp(mockPayload(mockHeader, Collections.emptyList())); EnginePayloadStatusResult res = fromSuccessResp(resp); - assertThat(res.getLatestValidHash()).isEmpty(); - assertThat(res.getStatusAsString()).isEqualTo(INVALID_TERMINAL_BLOCK.name()); + assertThat(res.getLatestValidHash()).isEqualTo(Optional.of(Hash.ZERO)); + assertThat(res.getStatusAsString()).isEqualTo(INVALID.name()); } @Test