Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated INVALID_TERMINAL_BLOCK with INVALID lvh 0x0 #3882

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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