Skip to content

Commit

Permalink
Merge branch 'main' into zkbesu
Browse files Browse the repository at this point in the history
  • Loading branch information
fab-10 committed Mar 25, 2024
2 parents b37f645 + bb9ba13 commit df45d38
Show file tree
Hide file tree
Showing 33 changed files with 216 additions and 121 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Transaction call object to accept both `input` and `data` field simultaneously if they are set to equal values [#6702](https://github.com/hyperledger/besu/pull/6702)
- `eth_call` for blob tx allows for empty `maxFeePerBlobGas` [#6731](https://github.com/hyperledger/besu/pull/6731)
- Extend error handling of plugin RPC methods [#6759](https://github.com/hyperledger/besu/pull/6759)
- Added engine_newPayloadV4 and engine_getPayloadV4 methods [#6783](https://github.com/hyperledger/besu/pull/6783)

### Bug fixes
- Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665)
Expand Down Expand Up @@ -442,7 +443,7 @@ https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/23.4.4/besu-23.4.4.z
- Early access - layered transaction pool implementation [#5290](https://github.com/hyperledger/besu/pull/5290)
- New RPC method `debug_getRawReceipts` [#5476](https://github.com/hyperledger/besu/pull/5476)
- Add TrieLogFactory plugin support [#5440](https://github.com/hyperledger/besu/pull/5440)
- Ignore `min-block-occupancy-ratio` option when on PoS networks, since in some cases, it prevents to have full blocks even if enough transactions are present [#5491](https://github.com/hyperledger/besu/pull/5491)
- Ignore `min-block-occupancy-ratio` option when on PoS networks, since in some cases, it prevents to have full blocks even if enough transactions are present [#5491](https://github.com/hyperledger/besu/pull/5491)

### Bug Fixes
- Fix eth_feeHistory response for the case in which blockCount is higher than highestBlock requested. [#5397](https://github.com/hyperledger/besu/pull/5397)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.provider.Arguments;

public class ExecutionEngineEip6110AcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/engine/eip6110/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/engine/eip6110/test-cases/";
public class ExecutionEnginePragueAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/engine/prague/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/engine/prague/test-cases/";

private static JsonRpcTestsContext testsContext;

public ExecutionEngineEip6110AcceptanceTest() {
public ExecutionEnginePragueAcceptanceTest() {
super(testsContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"londonBlock":0,
"terminalTotalDifficulty":0,
"cancunTime":0,
"experimentalEipsTime":20,
"pragueTime":20,
"clique": {
"period": 5,
"epoch": 30000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_getPayloadV6110",
"method": "engine_getPayloadV4",
"params": [
"0x282643b909febddf"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_newPayloadV6110",
"method": "engine_newPayloadV4",
"params": [
{
"parentHash": "0x45811fa27a100ce9035e5e086b9669275041a4ec0ebbd920be028fd7b0aa2356",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_newPayloadV6110",
"method": "engine_newPayloadV4",
"params": [
{
"parentHash": "0x1dd4f141551d53ce393845e2873754e43396101a8ebc0fd0eeb2e6798a591315",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"jsonrpc": "2.0",
"method": "engine_getPayloadV6110",
"method": "engine_getPayloadV4",
"params": [
"0x282643db882670cf"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public enum RpcMethod {
ENGINE_GET_PAYLOAD_V1("engine_getPayloadV1"),
ENGINE_GET_PAYLOAD_V2("engine_getPayloadV2"),
ENGINE_GET_PAYLOAD_V3("engine_getPayloadV3"),
ENGINE_GET_PAYLOAD_V6110("engine_getPayloadV6110"),
ENGINE_GET_PAYLOAD_V4("engine_getPayloadV4"),
ENGINE_NEW_PAYLOAD_V1("engine_newPayloadV1"),
ENGINE_NEW_PAYLOAD_V2("engine_newPayloadV2"),
ENGINE_NEW_PAYLOAD_V3("engine_newPayloadV3"),
ENGINE_NEW_PAYLOAD_V6110("engine_newPayloadV6110"),
ENGINE_NEW_PAYLOAD_V4("engine_newPayloadV4"),
ENGINE_FORKCHOICE_UPDATED_V1("engine_forkchoiceUpdatedV1"),
ENGINE_FORKCHOICE_UPDATED_V2("engine_forkchoiceUpdatedV2"),
ENGINE_FORKCHOICE_UPDATED_V3("engine_forkchoiceUpdatedV3"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext request) {
final Object result = function.apply(() -> request.getRequest().getParams());
return new JsonRpcSuccessResponse(request.getRequest().getId(), result);
} catch (final PluginRpcEndpointException ex) {
final JsonRpcError error = new JsonRpcError(ex.getRpcMethodError(), ex.getMessage());
LOG.error("Error calling plugin JSON-RPC endpoint", ex);
final JsonRpcError error = new JsonRpcError(ex.getRpcMethodError(), ex.getData());
LOG.debug("Error calling plugin JSON-RPC endpoint", ex);
return new JsonRpcErrorResponse(request.getRequest().getId(), error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
.filter(e -> e.getMethodName().startsWith("engine_"))
.filter(e -> !e.equals(ENGINE_EXCHANGE_CAPABILITIES))
.filter(e -> !e.equals(ENGINE_PREPARE_PAYLOAD_DEBUG))
.filter(e -> !e.getMethodName().endsWith("6110"))
.map(RpcMethod::getMethodName)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

import io.vertx.core.Vertx;

public class EngineGetPayloadV6110 extends AbstractEngineGetPayload {
public class EngineGetPayloadV4 extends AbstractEngineGetPayload {

private final Optional<ScheduledProtocolSpec.Hardfork> eip6110;
private final Optional<ScheduledProtocolSpec.Hardfork> prague;

public EngineGetPayloadV6110(
public EngineGetPayloadV4(
final Vertx vertx,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
Expand All @@ -50,12 +50,12 @@ public EngineGetPayloadV6110(
mergeMiningCoordinator,
blockResultFactory,
engineCallListener);
this.eip6110 = schedule.hardforkFor(s -> s.fork().name().equalsIgnoreCase("ExperimentalEips"));
this.prague = schedule.hardforkFor(s -> s.fork().name().equalsIgnoreCase("Prague"));
}

@Override
public String getName() {
return RpcMethod.ENGINE_GET_PAYLOAD_V6110.getMethodName();
return RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName();
}

@Override
Expand All @@ -66,22 +66,22 @@ protected JsonRpcResponse createResponse(

return new JsonRpcSuccessResponse(
request.getRequest().getId(),
blockResultFactory.payloadTransactionCompleteV6110(blockWithReceipts));
blockResultFactory.payloadTransactionCompleteV4(blockWithReceipts));
}

@Override
protected ValidationResult<RpcErrorType> validateForkSupported(final long blockTimestamp) {
if (protocolSchedule.isPresent()) {
if (eip6110.isPresent() && blockTimestamp >= eip6110.get().milestone()) {
if (prague.isPresent() && blockTimestamp >= prague.get().milestone()) {
return ValidationResult.valid();
} else {
return ValidationResult.invalid(
RpcErrorType.UNSUPPORTED_FORK,
"EIP-6110 configured to start at timestamp: " + eip6110.get().milestone());
"Prague configured to start at timestamp: " + prague.get().milestone());
}
} else {
return ValidationResult.invalid(
RpcErrorType.UNSUPPORTED_FORK, "Configuration error, no schedule for EIP-6110 fork set");
RpcErrorType.UNSUPPORTED_FORK, "Configuration error, no schedule for Prague fork set");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

import io.vertx.core.Vertx;

public class EngineNewPayloadV6110 extends AbstractEngineNewPayload {
public class EngineNewPayloadV4 extends AbstractEngineNewPayload {

private final Optional<ScheduledProtocolSpec.Hardfork> eip6110;
private final Optional<ScheduledProtocolSpec.Hardfork> prague;

public EngineNewPayloadV6110(
public EngineNewPayloadV4(
final Vertx vertx,
final ProtocolSchedule timestampSchedule,
final ProtocolContext protocolContext,
Expand All @@ -42,13 +42,12 @@ public EngineNewPayloadV6110(
final EngineCallListener engineCallListener) {
super(
vertx, timestampSchedule, protocolContext, mergeCoordinator, ethPeers, engineCallListener);
this.eip6110 =
timestampSchedule.hardforkFor(s -> s.fork().name().equalsIgnoreCase("ExperimentalEips"));
this.prague = timestampSchedule.hardforkFor(s -> s.fork().name().equalsIgnoreCase("prague"));
}

@Override
public String getName() {
return RpcMethod.ENGINE_NEW_PAYLOAD_V6110.getMethodName();
return RpcMethod.ENGINE_NEW_PAYLOAD_V4.getMethodName();
}

@Override
Expand All @@ -74,16 +73,16 @@ protected ValidationResult<RpcErrorType> validateParameters(
@Override
protected ValidationResult<RpcErrorType> validateForkSupported(final long blockTimestamp) {
if (protocolSchedule.isPresent()) {
if (eip6110.isPresent() && blockTimestamp >= eip6110.get().milestone()) {
if (prague.isPresent() && blockTimestamp >= prague.get().milestone()) {
return ValidationResult.valid();
} else {
return ValidationResult.invalid(
RpcErrorType.UNSUPPORTED_FORK,
"EIP-6110 configured to start at timestamp: " + eip6110.get().milestone());
"Prague configured to start at timestamp: " + prague.get().milestone());
}
} else {
return ValidationResult.invalid(
RpcErrorType.UNSUPPORTED_FORK, "Configuration error, no schedule for EIP-6110 fork set");
RpcErrorType.UNSUPPORTED_FORK, "Configuration error, no schedule for Prague fork set");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public EngineGetPayloadResultV3 payloadTransactionCompleteV3(
blobsBundleV1);
}

public EngineGetPayloadResultV6110 payloadTransactionCompleteV6110(
public EngineGetPayloadResultV4 payloadTransactionCompleteV4(
final BlockWithReceipts blockWithReceipts) {
final List<String> txs =
blockWithReceipts.getBlock().getBody().getTransactions().stream()
Expand All @@ -168,7 +168,7 @@ public EngineGetPayloadResultV6110 payloadTransactionCompleteV6110(

final BlobsBundleV1 blobsBundleV1 =
new BlobsBundleV1(blockWithReceipts.getBlock().getBody().getTransactions());
return new EngineGetPayloadResultV6110(
return new EngineGetPayloadResultV4(
blockWithReceipts.getHeader(),
txs,
blockWithReceipts.getBlock().getBody().getWithdrawals(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import org.apache.tuweni.bytes.Bytes32;

@JsonPropertyOrder({"executionPayload", "blockValue", "blobsBundle", "shouldOverrideBuilder"})
public class EngineGetPayloadResultV6110 {
public class EngineGetPayloadResultV4 {
protected final PayloadResult executionPayload;
private final String blockValue;
private final BlobsBundleV1 blobsBundle;
private final boolean shouldOverrideBuilder;

public EngineGetPayloadResultV6110(
public EngineGetPayloadResultV4(
final BlockHeader header,
final List<String> transactions,
final Optional<List<Withdrawal>> withdrawals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV2;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV3;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV6110;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV4;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV2;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV3;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV6110;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV4;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EnginePreparePayloadDebug;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineQosTimer;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
Expand Down Expand Up @@ -160,9 +160,9 @@ protected Map<String, JsonRpcMethod> create() {
protocolSchedule));
}

if (protocolSchedule.anyMatch(p -> p.spec().getName().equalsIgnoreCase("ExperimentalEips"))) {
if (protocolSchedule.anyMatch(p -> p.spec().getName().equalsIgnoreCase("prague"))) {
executionEngineApisSupported.add(
new EngineGetPayloadV6110(
new EngineGetPayloadV4(
consensusEngineServer,
protocolContext,
mergeCoordinator.get(),
Expand All @@ -171,7 +171,7 @@ protected Map<String, JsonRpcMethod> create() {
protocolSchedule));

executionEngineApisSupported.add(
new EngineNewPayloadV6110(
new EngineNewPayloadV4(
consensusEngineServer,
protocolSchedule,
protocolContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ protected void assertValidJsonRpcResult(final JsonObject json, final Object id)
}

protected void assertValidJsonRpcError(
final JsonObject json, final Object id, final int errorCode, final String errorMessage)
throws Exception {
final JsonObject json, final Object id, final int errorCode, final String errorMessage) {
assertValidJsonRpcError(json, id, errorCode, errorMessage, null);
}

protected void assertValidJsonRpcError(
final JsonObject json,
final Object id,
final int errorCode,
final String errorMessage,
final String data) {
// Check all expected fieldnames are set
final Set<String> fieldNames = json.fieldNames();
assertThat(fieldNames.size()).isEqualTo(3);
Expand All @@ -53,13 +61,19 @@ protected void assertValidJsonRpcError(
// Check error format
final JsonObject error = json.getJsonObject("error");
final Set<String> errorFieldNames = error.fieldNames();
assertThat(errorFieldNames.size()).isEqualTo(2);
assertThat(errorFieldNames.size()).isEqualTo(data == null ? 2 : 3);
assertThat(errorFieldNames.contains("code")).isTrue();
assertThat(errorFieldNames.contains("message")).isTrue();
if (data != null) {
assertThat(errorFieldNames.contains("data")).isTrue();
}

// Check error field values
assertThat(error.getInteger("code")).isEqualTo(errorCode);
assertThat(error.getString("message")).isEqualTo(errorMessage);
if (data != null) {
assertThat(error.getString("data")).isEqualTo(data);
}
}

protected void assertIdMatches(final JsonObject json, final Object expectedId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest;
import org.hyperledger.besu.plugin.services.rpc.RpcMethodError;

import java.util.Locale;
import java.util.Optional;

import io.vertx.core.json.JsonObject;
import okhttp3.RequestBody;
import okhttp3.Response;
Expand Down Expand Up @@ -127,6 +130,25 @@ public void methodErrorShouldReturnErrorResponse() throws Exception {
}
}

@Test
public void methodErrorWithDataShouldReturnErrorResponseWithDecodedData() throws Exception {
final var wrongParamContent =
"""
{"jsonrpc":"2.0","id":1,"method":"plugin_echo","params":["data"]}""";
try (var unused =
addRpcMethod(
"plugin_echo",
new PluginJsonRpcMethod("plugin_echo", PluginJsonRpcMethodTest::echoPluginRpcMethod))) {
final RequestBody body = RequestBody.create(wrongParamContent, JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
final JsonObject json = new JsonObject(resp.body().string());
testHelper.assertValidJsonRpcError(json, 1, -2, "Error with data: ABC", "abc");
}
}
}

@Test
public void unhandledExceptionShouldReturnInternalErrorResponse() throws Exception {
final var nullParam =
Expand Down Expand Up @@ -168,6 +190,29 @@ public String getMessage() {
}
});
}

if (input.toString().equals("data")) {
throw new PluginRpcEndpointException(
new RpcMethodError() {
@Override
public int getCode() {
return -2;
}

@Override
public String getMessage() {
return "Error with data";
}

@Override
public Optional<String> decodeData(final String data) {
// just turn everything uppercase
return Optional.of(data.toUpperCase(Locale.US));
}
},
"abc");
}

return input;
}
}
Loading

0 comments on commit df45d38

Please sign in to comment.