From 5cdda94ab10ad1902b45a7f8da6490e6f30ffbc3 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Mon, 23 May 2022 14:39:16 +0200 Subject: [PATCH] Replace deprecated INVALID_TERMINAL_BLOCK with INVALID lvh 0x0 (#3882) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 3 +++ .../methods/ExecutionEngineJsonRpcMethod.java | 3 +-- .../methods/engine/EngineForkchoiceUpdated.java | 5 ++--- .../methods/engine/EngineNewPayload.java | 6 ++++-- .../results/EngineUpdateForkchoiceResult.java | 3 +-- .../engine/EngineForkchoiceUpdatedTest.java | 16 ++++++++++++---- .../methods/engine/EngineNewPayloadTest.java | 7 +++---- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9709751467..e91e001fd8 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 05263a8498..85022820cd 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 abstract class ExecutionEngineJsonRpcMethod implements JsonRpcMethod { 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 e1d7f4713a..30df6a33ba 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 class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod { 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 111da2e278..4e2502d28a 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 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; 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 class EngineNewPayload extends ExecutionEngineJsonRpcMethod { // 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 0ca4f92f5f..f560d29509 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 4e32f315f6..d441b781d6 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 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; 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 class EngineForkchoiceUpdatedTest { } @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 @@ public class EngineForkchoiceUpdatedTest { 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 @@ public class EngineForkchoiceUpdatedTest { } } 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 d47637dc96..1c9803cda9 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.assertj.core.api.Assertions.assertThat; 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 class EngineNewPayloadTest { } @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 class EngineNewPayloadTest { 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