Skip to content

Commit

Permalink
Replace deprecated INVALID_TERMINAL_BLOCK with INVALID lvh 0x0 (#3882)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 authored May 23, 2022
1 parent 20daaf4 commit 5cdda94
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public enum EngineStatus {
INVALID,
SYNCING,
ACCEPTED,
INVALID_BLOCK_HASH,
INVALID_TERMINAL_BLOCK;
INVALID_BLOCK_HASH;
}

private final Vertx syncVertx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -34,7 +33,7 @@ public class EngineUpdateForkchoiceResult {
private final EnginePayloadStatusResult payloadStatus;
private final PayloadIdentifier payloadId;
static final EnumSet<EngineStatus> FORK_CHOICE_ENGINE_STATUS =
EnumSet.of(VALID, INVALID, SYNCING, INVALID_TERMINAL_BLOCK);
EnumSet.of(VALID, INVALID, SYNCING);

public EngineUpdateForkchoiceResult(
final EngineStatus status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -341,6 +340,15 @@ private EngineUpdateForkchoiceResult assertSuccessWithPayloadForForkchoiceResult
final Optional<EnginePayloadAttributesParameter> payloadParam,
final ForkchoiceResult forkchoiceResult,
final EngineStatus expectedStatus) {
return assertSuccessWithPayloadForForkchoiceResult(
payloadParam, forkchoiceResult, expectedStatus, Optional.empty());
}

private EngineUpdateForkchoiceResult assertSuccessWithPayloadForForkchoiceResult(
final Optional<EnginePayloadAttributesParameter> payloadParam,
final ForkchoiceResult forkchoiceResult,
final EngineStatus expectedStatus,
final Optional<Hash> maybeLatestValidHash) {

// result from mergeCoordinator has no new finalized, new head:
when(mergeCoordinator.updateForkChoice(
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down

0 comments on commit 5cdda94

Please sign in to comment.