Engine RPC endpoint (#3470)

Code originally written by jflo on the merge branch.
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/3391/head
Fabio Di Fabio 3 years ago committed by GitHub
parent 1c39d48143
commit 435c9e388c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      CHANGELOG.md
  2. 12
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/BesuNode.java
  3. 3
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java
  4. 7
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfiguration.java
  5. 9
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/BesuNodeConfigurationBuilder.java
  6. 4
      acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/configuration/NodeConfiguration.java
  7. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/OpenTelemetryAcceptanceTest.java
  8. 7
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/plugins/RpcEndpointServicePluginTest.java
  9. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivCallAcceptanceTest.java
  10. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/contracts/PrivacyProxyTest.java
  11. 9
      besu/src/main/java/org/hyperledger/besu/Runner.java
  12. 62
      besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
  13. 40
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  14. 2
      besu/src/main/java/org/hyperledger/besu/cli/options/unstable/MergeOptions.java
  15. 80
      besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java
  16. 15
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  17. 1
      besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java
  18. 11
      besu/src/test/java/org/hyperledger/besu/cli/options/unstable/MergeConfigOptionsTest.java
  19. 2
      besu/src/test/resources/everything_config.toml
  20. 12
      config/src/main/java/org/hyperledger/besu/config/experimental/MergeConfigOptions.java
  21. 1
      ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcTestMethodsFactory.java
  22. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcConfiguration.java
  23. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java
  24. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcApis.java
  25. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/authentication/AuthenticationUtils.java
  26. 74
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/ConsensusBlockResult.java
  27. 35
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/OpaqueTransactionsResult.java
  28. 58
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ExecutionEngineJsonRpcMethods.java
  29. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java
  30. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java
  31. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java
  32. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceLoginTest.java
  33. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceParameterizedTest.java
  34. 3
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  35. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTestBase.java
  36. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsClientAuthTest.java
  37. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsMisconfigurationTest.java
  38. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTlsTest.java
  39. 13
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketRequestHandlerTest.java
  40. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketServiceLoginTest.java
  41. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/DefaultBlockchain.java

@ -5,17 +5,15 @@
### Additions and Improvements
- Allow optional RPC methods that bypass authentication [#3382](https://github.com/hyperledger/besu/pull/3382)
## 22.1.1
### Additions and Improvements
- Merge: extend block creation and mining to support The Merge [#3412](https://github.com/hyperledger/besu/pull/3412)
- Merge: backward sync [#3410](https://github.com/hyperledger/besu/pull/3410)
- Merge: Extend validateAndProcessBlock to return an error message in case of failure, so it can be returned to the caller of ExecutePayload API [#3411](https://github.com/hyperledger/besu/pull/3411)
- Merge: Persist latest finalized block [#2913](https://github.com/hyperledger/besu/issues/2913)
- Merge: Add PostMergeContext, and stop syncing after the swith to PoS [#3453](https://github.com/hyperledger/besu/pull/3453)
- Merge: Add header validation rules needed to validate The Merge blocks [#3454](https://github.com/hyperledger/besu/pull/3454)
- Merge: Add core components: controller builder, protocol scheduler, coordinator, block creator and processor. [#3461](https://github.com/hyperledger/besu/pull/3461)
- Execution layer (The Merge):
- Extend block creation and mining to support The Merge [#3412](https://github.com/hyperledger/besu/pull/3412)
- Backward sync [#3410](https://github.com/hyperledger/besu/pull/3410)
- Extend validateAndProcessBlock to return an error message in case of failure, so it can be returned to the caller of ExecutePayload API [#3411](https://github.com/hyperledger/besu/pull/3411)
- Persist latest finalized block [#2913](https://github.com/hyperledger/besu/issues/2913)
- Add PostMergeContext, and stop syncing after the swith to PoS [#3453](https://github.com/hyperledger/besu/pull/3453)
- Add header validation rules needed to validate The Merge blocks [#3454](https://github.com/hyperledger/besu/pull/3454)
- Add core components: controller builder, protocol scheduler, coordinator, block creator and processor. [#3461](https://github.com/hyperledger/besu/pull/3461)
- Execution specific RPC endpoint [#2914](https://github.com/hyperledger/besu/issues/2914), [#3350](https://github.com/hyperledger/besu/pull/3350)
### Bug Fixes

@ -325,7 +325,8 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
}
}
public Optional<Integer> getJsonRpcSocketPort() {
@Override
public Optional<Integer> getJsonRpcPort() {
if (isJsonRpcEnabled()) {
return Optional.of(Integer.valueOf(portsProperties.getProperty("json-rpc")));
} else {
@ -333,6 +334,15 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
}
}
@Override
public Optional<Integer> getEngineJsonRpcPort() {
if (isJsonRpcEnabled()) {
return Optional.of(Integer.valueOf(portsProperties.getProperty("engine-json-rpc")));
} else {
return Optional.empty();
}
}
@Override
public String getHostName() {
return LOCALHOST;

@ -187,6 +187,9 @@ public class ProcessBesuNodeRunner implements BesuNodeRunner {
params.add("--rpc-http-authentication-jwt-algorithm");
params.add(node.jsonRpcConfiguration().getAuthenticationAlgorithm().toString());
}
// TODO: properly handle engine rpc, set port to 0 to make tests pass
params.add("--engine-rpc-http-port");
params.add("0");
}
if (node.wsRpcEnabled()) {

@ -37,6 +37,7 @@ public class BesuNodeConfiguration {
private final Optional<Path> dataPath;
private final MiningParameters miningParameters;
private final JsonRpcConfiguration jsonRpcConfiguration;
private final Optional<JsonRpcConfiguration> engineRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
@ -68,6 +69,7 @@ public class BesuNodeConfiguration {
final Optional<Path> dataPath,
final MiningParameters miningParameters,
final JsonRpcConfiguration jsonRpcConfiguration,
final Optional<JsonRpcConfiguration> engineRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
@ -96,6 +98,7 @@ public class BesuNodeConfiguration {
this.name = name;
this.miningParameters = miningParameters;
this.jsonRpcConfiguration = jsonRpcConfiguration;
this.engineRpcConfiguration = engineRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
@ -136,6 +139,10 @@ public class BesuNodeConfiguration {
return jsonRpcConfiguration;
}
public Optional<JsonRpcConfiguration> getEngineRpcConfiguration() {
return engineRpcConfiguration;
}
public WebSocketConfiguration getWebSocketConfiguration() {
return webSocketConfiguration;
}

@ -57,6 +57,7 @@ public class BesuNodeConfigurationBuilder {
.minTransactionGasPrice(Wei.of(1000))
.build();
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private JsonRpcConfiguration engineRpcConfiguration = JsonRpcConfiguration.createEngineDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
@ -87,6 +88,7 @@ public class BesuNodeConfigurationBuilder {
// Check connections more frequently during acceptance tests to cut down on
// intermittent failures due to the fact that we're running over a real network
networkingConfiguration.setInitiateConnectionsFrequency(5);
engineRpcConfiguration.setPort(JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT);
}
public BesuNodeConfigurationBuilder name(final String name) {
@ -123,6 +125,12 @@ public class BesuNodeConfigurationBuilder {
return this;
}
public BesuNodeConfigurationBuilder engineJsonRpcConfiguration(
final JsonRpcConfiguration engineConfig) {
this.engineRpcConfiguration = engineConfig;
return this;
}
public BesuNodeConfigurationBuilder jsonRpcEnabled() {
this.jsonRpcConfiguration.setEnabled(true);
this.jsonRpcConfiguration.setPort(0);
@ -457,6 +465,7 @@ public class BesuNodeConfigurationBuilder {
dataPath,
miningParameters,
jsonRpcConfiguration,
Optional.of(engineRpcConfiguration),
webSocketConfiguration,
metricsConfiguration,
permissioningConfiguration,

@ -32,6 +32,10 @@ public interface NodeConfiguration {
Optional<Integer> getJsonRpcWebSocketPort();
Optional<Integer> getJsonRpcPort();
Optional<Integer> getEngineJsonRpcPort();
String getHostName();
boolean isJsonRpcEnabled();

@ -211,7 +211,7 @@ public class OpenTelemetryAcceptanceTest extends AcceptanceTestBase {
Call.Factory client = new TracingCallFactory(okClient, tracer);
Request request =
new Request.Builder()
.url("http://localhost:" + metricsNode.getJsonRpcSocketPort().get())
.url("http://localhost:" + metricsNode.getJsonRpcPort().get())
.post(
RequestBody.create(
"{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":255}",

@ -107,12 +107,7 @@ public class RpcEndpointServicePluginTest extends AcceptanceTestBase {
.newCall(
new Request.Builder()
.post(body)
.url(
"http://"
+ node.getHostName()
+ ":"
+ node.getJsonRpcSocketPort().get()
+ "/")
.url("http://" + node.getHostName() + ":" + node.getJsonRpcPort().get() + "/")
.build())
.execute()
.body()

@ -228,7 +228,7 @@ public class PrivCallAcceptanceTest extends ParameterizedEnclaveTestBase {
"http://"
+ minerNode.getBesu().getHostName()
+ ":"
+ minerNode.getBesu().getJsonRpcSocketPort().get());
+ minerNode.getBesu().getJsonRpcPort().get());
final String validContractAddress = eventEmitter.getContractAddress();
final String invalidContractAddress = constructInvalidString(validContractAddress);

@ -120,7 +120,7 @@ public class PrivacyProxyTest extends AcceptanceTestBase {
final HttpService httpService =
new HttpService(
"http://" + minerNode.getHostName() + ":" + minerNode.getJsonRpcSocketPort().get());
"http://" + minerNode.getHostName() + ":" + minerNode.getJsonRpcPort().get());
final Web3j web3j = Web3j.build(httpService);
// load the proxy contract, use it with another signer

@ -62,6 +62,7 @@ public class Runner implements AutoCloseable {
private final Optional<EthStatsService> ethStatsService;
private final Optional<GraphQLHttpService> graphQLHttp;
private final Optional<JsonRpcHttpService> jsonRpc;
private final Optional<JsonRpcHttpService> engineJsonRpc;
private final Optional<MetricsService> metrics;
private final Optional<Path> pidPath;
private final Optional<WebSocketService> websocketRpc;
@ -78,6 +79,7 @@ public class Runner implements AutoCloseable {
final NetworkRunner networkRunner,
final NatService natService,
final Optional<JsonRpcHttpService> jsonRpc,
final Optional<JsonRpcHttpService> engineJsonRpc,
final Optional<GraphQLHttpService> graphQLHttp,
final Optional<WebSocketService> websocketRpc,
final Optional<StratumServer> stratumServer,
@ -94,6 +96,7 @@ public class Runner implements AutoCloseable {
this.graphQLHttp = graphQLHttp;
this.pidPath = pidPath;
this.jsonRpc = jsonRpc;
this.engineJsonRpc = engineJsonRpc;
this.websocketRpc = websocketRpc;
this.metrics = metrics;
this.ethStatsService = ethStatsService;
@ -112,6 +115,7 @@ public class Runner implements AutoCloseable {
metrics.ifPresent(service -> waitForServiceToStart("metrics", service.start()));
jsonRpc.ifPresent(service -> waitForServiceToStart("jsonRpc", service.start()));
engineJsonRpc.ifPresent(service -> waitForServiceToStart("engineJsonRpc", service.start()));
graphQLHttp.ifPresent(service -> waitForServiceToStart("graphQLHttp", service.start()));
websocketRpc.ifPresent(service -> waitForServiceToStart("websocketRpc", service.start()));
stratumServer.ifPresent(server -> waitForServiceToStart("stratum", server.start()));
@ -142,6 +146,7 @@ public class Runner implements AutoCloseable {
public void stop() {
transactionPoolEvictionService.stop();
jsonRpc.ifPresent(service -> waitForServiceToStop("jsonRpc", service.stop()));
engineJsonRpc.ifPresent(service -> waitForServiceToStop("engineJsonRpc", service.stop()));
graphQLHttp.ifPresent(service -> waitForServiceToStop("graphQLHttp", service.stop()));
websocketRpc.ifPresent(service -> waitForServiceToStop("websocketRpc", service.stop()));
metrics.ifPresent(service -> waitForServiceToStop("metrics", service.stop()));
@ -304,6 +309,10 @@ public class Runner implements AutoCloseable {
return jsonRpc.map(service -> service.socketAddress().getPort());
}
public Optional<Integer> getEngineJsonRpcPort() {
return engineJsonRpc.map(service -> service.socketAddress().getPort());
}
public Optional<Integer> getGraphQLHttpPort() {
return graphQLHttp.map(service -> service.socketAddress().getPort());
}

@ -160,6 +160,7 @@ public class RunnerBuilder {
private String ethstatsUrl;
private String ethstatsContact;
private JsonRpcConfiguration jsonRpcConfiguration;
private Optional<JsonRpcConfiguration> engineJsonRpcConfiguration = Optional.empty();
private GraphQLConfiguration graphQLConfiguration;
private WebSocketConfiguration webSocketConfiguration;
private ApiConfiguration apiConfiguration;
@ -289,6 +290,12 @@ public class RunnerBuilder {
return this;
}
public RunnerBuilder engineJsonRpcConfiguration(
final JsonRpcConfiguration engineJsonRpcConfiguration) {
this.engineJsonRpcConfiguration = Optional.of(engineJsonRpcConfiguration);
return this;
}
public RunnerBuilder graphQLConfiguration(final GraphQLConfiguration graphQLConfiguration) {
this.graphQLConfiguration = graphQLConfiguration;
return this;
@ -552,10 +559,12 @@ public class RunnerBuilder {
AccountPermissioningController::getAccountLocalConfigPermissioningController);
Optional<JsonRpcHttpService> jsonRpcHttpService = Optional.empty();
Optional<JsonRpcHttpService> engineJsonRpcHttpService = Optional.empty();
if (jsonRpcConfiguration.isEnabled()) {
final Map<String, JsonRpcMethod> jsonRpcMethods =
final Map<String, JsonRpcMethod> allJsonRpcMethods =
jsonRpcMethods(
protocolSchedule,
context,
besuController,
peerNetwork,
blockchainQueries,
@ -576,6 +585,12 @@ public class RunnerBuilder {
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl);
final Map<String, JsonRpcMethod> nonEngineMethods =
allJsonRpcMethods.entrySet().stream()
.filter(entry -> !entry.getKey().toLowerCase().startsWith("engine"))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
jsonRpcHttpService =
Optional.of(
new JsonRpcHttpService(
@ -584,9 +599,48 @@ public class RunnerBuilder {
jsonRpcConfiguration,
metricsSystem,
natService,
jsonRpcMethods,
nonEngineMethods,
new HealthService(new LivenessCheck()),
new HealthService(new ReadinessCheck(peerNetwork, synchronizer))));
if (engineJsonRpcConfiguration.isPresent()) {
final Map<String, JsonRpcMethod> engineMethods =
jsonRpcMethods(
protocolSchedule,
context,
besuController,
peerNetwork,
blockchainQueries,
synchronizer,
transactionPool,
miningCoordinator,
metricsSystem,
supportedCapabilities,
engineJsonRpcConfiguration.get().getRpcApis(),
filterManager,
accountLocalConfigPermissioningController,
nodeLocalConfigPermissioningController,
privacyParameters,
engineJsonRpcConfiguration.get(),
webSocketConfiguration,
metricsConfiguration,
natService,
besuPluginContext.getNamedPlugins(),
dataDir,
rpcEndpointServiceImpl);
engineJsonRpcHttpService =
Optional.of(
new JsonRpcHttpService(
vertx,
dataDir,
engineJsonRpcConfiguration.orElse(JsonRpcConfiguration.createEngineDefault()),
metricsSystem,
natService,
engineMethods,
new HealthService(new LivenessCheck()),
new HealthService(new ReadinessCheck(peerNetwork, synchronizer))));
}
}
Optional<GraphQLHttpService> graphQLHttpService = Optional.empty();
@ -624,6 +678,7 @@ public class RunnerBuilder {
final Map<String, JsonRpcMethod> webSocketsJsonRpcMethods =
jsonRpcMethods(
protocolSchedule,
context,
besuController,
peerNetwork,
blockchainQueries,
@ -699,6 +754,7 @@ public class RunnerBuilder {
networkRunner,
natService,
jsonRpcHttpService,
engineJsonRpcHttpService,
graphQLHttpService,
webSocketService,
stratumServer,
@ -817,6 +873,7 @@ public class RunnerBuilder {
private Map<String, JsonRpcMethod> jsonRpcMethods(
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final BesuController besuController,
final P2PNetwork network,
final BlockchainQueries blockchainQueries,
@ -847,6 +904,7 @@ public class RunnerBuilder {
blockchainQueries,
synchronizer,
protocolSchedule,
protocolContext,
filterManager,
transactionPool,
miningCoordinator,

@ -24,6 +24,7 @@ import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
import static org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration.DEFAULT_GRAPHQL_HTTP_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.DEFAULT_RPC_APIS;
import static org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT;
@ -547,6 +548,13 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
arity = "1")
private final Integer rpcHttpPort = DEFAULT_JSON_RPC_PORT;
@Option(
names = {"--engine-rpc-http-port"},
paramLabel = MANDATORY_PORT_FORMAT_HELP,
description = "Port to provide consensus client APIS on (default: ${DEFAULT-VALUE})",
arity = "1")
private final Integer engineRpcHttpPort = DEFAULT_ENGINE_JSON_RPC_PORT;
@Option(
names = {"--rpc-http-max-active-connections"},
description =
@ -847,6 +855,15 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
defaultValue = "localhost,127.0.0.1")
private final JsonRPCAllowlistHostsProperty hostsAllowlist = new JsonRPCAllowlistHostsProperty();
@Option(
names = {"--engine-host-allowlist"},
paramLabel = "<hostname>[,<hostname>...]... or * or all",
description =
"Comma separated list of hostnames to allow for ENGINE API access, or * to accept any host (default: ${DEFAULT-VALUE})",
defaultValue = "localhost,127.0.0.1")
private final JsonRPCAllowlistHostsProperty engineHostsAllowlist =
new JsonRPCAllowlistHostsProperty();
@Option(
names = {"--host-whitelist"},
hidden = true,
@ -1172,6 +1189,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
private EthNetworkConfig ethNetworkConfig;
private JsonRpcConfiguration jsonRpcConfiguration;
private JsonRpcConfiguration engineJsonRpcConfiguration;
private GraphQLConfiguration graphQLConfiguration;
private WebSocketConfiguration webSocketConfiguration;
private ApiConfiguration apiConfiguration;
@ -1475,6 +1493,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
p2pPort,
graphQLConfiguration,
jsonRpcConfiguration,
engineJsonRpcConfiguration,
webSocketConfiguration,
apiConfiguration,
metricsConfiguration,
@ -1768,6 +1787,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
checkGoQuorumCompatibilityConfig(ethNetworkConfig);
jsonRpcConfiguration = jsonRpcConfiguration();
engineJsonRpcConfiguration = engineJsonRpcConfiguration();
p2pTLSConfiguration = p2pTLSConfigOptions.p2pTLSConfiguration(commandLine);
graphQLConfiguration = graphQLConfiguration();
webSocketConfiguration = webSocketConfiguration();
@ -1931,6 +1951,24 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
return graphQLConfiguration;
}
private JsonRpcConfiguration engineJsonRpcConfiguration() {
final JsonRpcConfiguration engineConfig = JsonRpcConfiguration.createDefault();
engineConfig.setEnabled(isRpcHttpEnabled);
engineConfig.setHost(rpcHttpHost);
engineConfig.setPort(engineRpcHttpPort);
engineConfig.setMaxActiveConnections(rpcHttpMaxConnections);
engineConfig.setCorsAllowedDomains(rpcHttpCorsAllowedOrigins);
engineConfig.setRpcApis(Arrays.asList("ENGINE", "ETH"));
engineConfig.setHostsAllowlist(engineHostsAllowlist);
engineConfig.setAuthenticationEnabled(isRpcHttpAuthenticationEnabled);
engineConfig.setAuthenticationCredentialsFile(rpcHttpAuthenticationCredentialsFile());
engineConfig.setAuthenticationPublicKeyFile(rpcHttpAuthenticationPublicKeyFile);
engineConfig.setAuthenticationAlgorithm(rpcHttpAuthenticationAlgorithm);
engineConfig.setTlsConfiguration(rpcHttpTlsConfiguration());
engineConfig.setHttpTimeoutSec(unstableRPCOptions.getHttpTimeoutSec());
return engineConfig;
}
private JsonRpcConfiguration jsonRpcConfiguration() {
checkRpcTlsClientAuthOptionsDependencies();
checkRpcTlsOptionsDependencies();
@ -2526,6 +2564,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
final int p2pListenPort,
final GraphQLConfiguration graphQLConfiguration,
final JsonRpcConfiguration jsonRpcConfiguration,
final JsonRpcConfiguration engineJsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final ApiConfiguration apiConfiguration,
final MetricsConfiguration metricsConfiguration,
@ -2560,6 +2599,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
.networkingConfiguration(unstableNetworkingOptions.toDomainObject())
.graphQLConfiguration(graphQLConfiguration)
.jsonRpcConfiguration(jsonRpcConfiguration)
.engineJsonRpcConfiguration(engineJsonRpcConfiguration)
.webSocketConfiguration(webSocketConfiguration)
.apiConfiguration(apiConfiguration)
.pidPath(pidPath)

@ -40,7 +40,7 @@ public class MergeOptions implements Options {
return new MergeOptions();
}
public Boolean isMergeEnabled() {
static Boolean isMergeEnabled() {
return mergeEnabled;
}

@ -21,10 +21,12 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.config.experimental.MergeConfigOptions;
import org.hyperledger.besu.consensus.common.bft.BftEventQueue;
import org.hyperledger.besu.consensus.common.bft.network.PeerConnectionTracker;
import org.hyperledger.besu.consensus.common.bft.protocol.BftProtocolManager;
import org.hyperledger.besu.consensus.ibft.protocol.IbftSubProtocol;
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.crypto.KeyPairSecurityModule;
import org.hyperledger.besu.crypto.NodeKey;
@ -56,9 +58,11 @@ import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.nat.NatMethod;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.stream.Stream;
@ -209,4 +213,80 @@ public final class RunnerBuilderTest {
.contains(UInt64.valueOf(2 + i));
}
}
@Test
public void whenEngineApiAddedListensOnDefaultPort() {
JsonRpcConfiguration jrpc = JsonRpcConfiguration.createDefault();
jrpc.setEnabled(true);
JsonRpcConfiguration engine = JsonRpcConfiguration.createEngineDefault();
EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
when(mockMainnet.getNetworkId()).thenReturn(BigInteger.ONE);
MergeConfigOptions.setMergeEnabled(true);
when(besuController.getMiningCoordinator()).thenReturn(mock(MergeMiningCoordinator.class));
final Runner runner =
new RunnerBuilder()
.discovery(true)
.p2pListenInterface("0.0.0.0")
.p2pListenPort(30303)
.p2pAdvertisedHost("127.0.0.1")
.p2pEnabled(true)
.natMethod(NatMethod.NONE)
.besuController(besuController)
.ethNetworkConfig(mockMainnet)
.metricsSystem(mock(ObservableMetricsSystem.class))
.permissioningService(mock(PermissioningServiceImpl.class))
.jsonRpcConfiguration(jrpc)
.engineJsonRpcConfiguration(engine)
.graphQLConfiguration(mock(GraphQLConfiguration.class))
.webSocketConfiguration(mock(WebSocketConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.storageProvider(mock(KeyValueStorageProvider.class))
.forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
.build();
assertThat(runner.getJsonRpcPort()).isPresent();
assertThat(runner.getEngineJsonRpcPort()).isPresent();
}
@Test
public void noEngineApiNoServiceForMethods() {
JsonRpcConfiguration defaultPlusEng = JsonRpcConfiguration.createDefault();
defaultPlusEng.setEnabled(true);
EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
when(mockMainnet.getNetworkId()).thenReturn(BigInteger.ONE);
MergeConfigOptions.setMergeEnabled(true);
when(besuController.getMiningCoordinator()).thenReturn(mock(MergeMiningCoordinator.class));
final Runner runner =
new RunnerBuilder()
.discovery(true)
.p2pListenInterface("0.0.0.0")
.p2pListenPort(30303)
.p2pAdvertisedHost("127.0.0.1")
.p2pEnabled(true)
.natMethod(NatMethod.NONE)
.besuController(besuController)
.ethNetworkConfig(mockMainnet)
.metricsSystem(mock(ObservableMetricsSystem.class))
.permissioningService(mock(PermissioningServiceImpl.class))
.jsonRpcConfiguration(defaultPlusEng)
.graphQLConfiguration(mock(GraphQLConfiguration.class))
.webSocketConfiguration(mock(WebSocketConfiguration.class))
.metricsConfiguration(mock(MetricsConfiguration.class))
.vertx(Vertx.vertx())
.dataDir(dataDir.getRoot().toPath())
.storageProvider(mock(KeyValueStorageProvider.class))
.forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
.build();
assertThat(runner.getJsonRpcPort()).isPresent();
assertThat(runner.getEngineJsonRpcPort()).isEmpty();
}
}

@ -27,6 +27,7 @@ import static org.hyperledger.besu.cli.config.NetworkName.RINKEBY;
import static org.hyperledger.besu.cli.config.NetworkName.ROPSTEN;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ENGINE;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ETH;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.NET;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.PERM;
@ -1928,6 +1929,20 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void rpcApisSupportsEngine() {
parseCommand("--rpc-http-api", "ENGINE", "--rpc-http-enabled");
verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();
assertThat(jsonRpcConfigArgumentCaptor.getValue().getRpcApis())
.containsExactlyInAnyOrder(ENGINE.name());
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void rpcApisPropertyIgnoresDuplicatesAndMustBeUsed() {
parseCommand("--rpc-http-api", "ETH,NET,NET", "--rpc-http-enabled");

@ -264,6 +264,7 @@ public abstract class CommandTestAbstract {
when(mockRunnerBuilder.natManagerServiceName(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.natMethodFallbackEnabled(anyBoolean())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.jsonRpcConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.engineJsonRpcConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.graphQLConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.webSocketConfiguration(any())).thenReturn(mockRunnerBuilder);
when(mockRunnerBuilder.apiConfiguration(any())).thenReturn(mockRunnerBuilder);

@ -15,7 +15,6 @@
package org.hyperledger.besu.cli.options.unstable;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import org.hyperledger.besu.config.experimental.MergeConfigOptions;
@ -33,7 +32,7 @@ public class MergeConfigOptionsTest {
@Test
public void shouldBeDisabledByDefault() {
// disabledByDefault
assertThat(MergeOptions.create().isMergeEnabled()).isFalse();
assertThat(MergeOptions.isMergeEnabled()).isFalse();
}
@Test
@ -54,8 +53,10 @@ public class MergeConfigOptionsTest {
}
@Test
public void shouldThrowOnReconfigure() {
assertThatThrownBy(() -> MergeConfigOptions.setMergeEnabled(false))
.isInstanceOf(RuntimeException.class);
public void shouldRefuseToDisableMergeOnceSet() {
MergeConfigOptions.setMergeEnabled(true);
assertThat(MergeConfigOptions.isMergeEnabled()).isTrue();
MergeConfigOptions.setMergeEnabled(false);
assertThat(MergeConfigOptions.isMergeEnabled()).isTrue();
}
}

@ -43,6 +43,7 @@ remote-connections-max-percentage=60
random-peer-priority-enabled=false
host-whitelist=["all"]
host-allowlist=["all"]
engine-host-allowlist=["all"]
required-blocks=["8675309=123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"]
discovery-dns-url="enrtree://AM5FCQLWIZX2QFPNJAP7VUERCCRNGRHWZG3YYHIUV7BVDQ5FDPRT2@nodes.example.org"
@ -57,6 +58,7 @@ network-id=303
rpc-http-enabled=false
rpc-http-host="5.6.7.8"
rpc-http-port=5678
engine-rpc-http-port=5679
rpc-http-max-active-connections=100
rpc-http-api=["DEBUG","ETH"]
rpc-http-apis=["DEBUG","ETH"]

@ -14,22 +14,20 @@
*/
package org.hyperledger.besu.config.experimental;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
/** For now there is a static config that is driven by a command line option. */
public class MergeConfigOptions {
private static Optional<Boolean> mergeEnabled = Optional.empty();
private static final AtomicBoolean mergeEnabled = new AtomicBoolean(false);
public static void setMergeEnabled(final boolean bool) {
if (!mergeEnabled.isPresent()) {
mergeEnabled = Optional.of(bool);
} else if (mergeEnabled.get() != bool) {
throw new RuntimeException("Refusing to re-configure already configured merge feature");
if (!mergeEnabled.get()) {
mergeEnabled.set(bool);
}
}
public static boolean isMergeEnabled() {
return mergeEnabled.orElse(false);
return mergeEnabled.get();
}
public static void doIfMergeEnabled(final Runnable mergeDo) {

@ -164,6 +164,7 @@ public class JsonRpcTestMethodsFactory {
blockchainQueries,
synchronizer,
importer.getProtocolSchedule(),
context,
filterManager,
transactionPool,
miningCoordinator,

@ -34,6 +34,7 @@ import com.google.common.base.MoreObjects;
public class JsonRpcConfiguration {
private static final String DEFAULT_JSON_RPC_HOST = "127.0.0.1";
public static final int DEFAULT_JSON_RPC_PORT = 8545;
public static final int DEFAULT_ENGINE_JSON_RPC_PORT = 8550;
public static final int DEFAULT_MAX_ACTIVE_CONNECTIONS = 80;
private boolean enabled;
@ -62,6 +63,16 @@ public class JsonRpcConfiguration {
return config;
}
public static JsonRpcConfiguration createEngineDefault() {
final JsonRpcConfiguration config = createDefault();
config.setPort(DEFAULT_ENGINE_JSON_RPC_PORT);
List<String> engineMethodGroup = new ArrayList<>();
engineMethodGroup.add(RpcApis.ENGINE.name());
engineMethodGroup.add(RpcApis.ETH.name());
config.setRpcApis(engineMethodGroup);
return config;
}
private JsonRpcConfiguration() {}
public boolean isEnabled() {

@ -779,7 +779,7 @@ public class JsonRpcHttpService {
private Optional<JsonRpcError> validateMethodAvailability(final JsonRpcRequest request) {
final String name = request.getMethod();
LOG.debug("JSON-RPC request -> {}", name);
LOG.debug("JSON-RPC request -> {} {}", name, request.getParams());
final JsonRpcMethod method = rpcMethods.get(name);

@ -33,6 +33,7 @@ public enum RpcApis {
GOQUORUM,
CLIQUE,
IBFT,
ENGINE,
QBFT;
public static final List<String> DEFAULT_RPC_APIS = Arrays.asList("ETH", "NET", "WEB3");

@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright Hyperledger Besu contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at

@ -0,0 +1,74 @@
/*
* Copyright Hyperledger Besu contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.JsonNode;
@JsonPropertyOrder({
"number",
"blockHash",
"mixHash",
"parentHash",
"nonce",
"sha3Uncles",
"logsBloom",
"transactionsRoot",
"stateRoot",
"receiptsRoot",
"miner",
"difficulty",
"totalDifficulty",
"extraData",
"baseFee",
"size",
"gasLimit",
"gasUsed",
"timestamp",
"uncles",
"transactions"
})
public class ConsensusBlockResult extends BlockResult {
private final List<String> opaqueTransactions;
public ConsensusBlockResult(
final BlockHeader header,
final List<String> transactions,
final List<JsonNode> ommers,
final Difficulty totalDifficulty,
final int size,
final boolean includeCoinbase) {
super(header, null, ommers, totalDifficulty, size, includeCoinbase);
this.opaqueTransactions = transactions;
}
@Override
@JsonGetter(value = "blockHash")
public String getHash() {
return hash;
}
@JsonGetter(value = "transactions")
public List<String> getOpaqueTransactions() {
return opaqueTransactions;
}
}

@ -0,0 +1,35 @@
/*
* Copyright Hyperledger Besu contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;
import java.util.Set;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonValue;
public class OpaqueTransactionsResult implements TransactionResult {
private final Set<String> transactionInfoResults;
public OpaqueTransactionsResult(final Set<String> transactionInfoSet) {
transactionInfoResults =
transactionInfoSet.stream().map(String::new).collect(Collectors.toSet());
}
@JsonValue
public Set<String> getResults() {
return transactionInfoResults;
}
}

@ -0,0 +1,58 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineExecutePayload;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineForkchoiceUpdated;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayload;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator;
import java.util.Map;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
public class ExecutionEngineJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final BlockResultFactory blockResultFactory = new BlockResultFactory();
private final MergeMiningCoordinator mergeCoordinator;
private final ProtocolContext protocolContext;
ExecutionEngineJsonRpcMethods(
final MiningCoordinator miningCoordinator, final ProtocolContext protocolContext) {
this.mergeCoordinator = (MergeMiningCoordinator) miningCoordinator;
this.protocolContext = protocolContext;
}
@Override
protected String getApiGroup() {
return RpcApis.ENGINE.name();
}
@Override
protected Map<String, JsonRpcMethod> create() {
Vertx syncVertx = Vertx.vertx(new VertxOptions().setWorkerPoolSize(1));
return mapOf(
new EngineGetPayload(syncVertx, protocolContext, blockResultFactory),
new EngineExecutePayload(syncVertx, protocolContext, mergeCoordinator),
new EngineForkchoiceUpdated(syncVertx, protocolContext, mergeCoordinator));
}
}

@ -15,6 +15,8 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.experimental.MergeConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -55,6 +57,7 @@ public class JsonRpcMethodsFactory {
final BlockchainQueries blockchainQueries,
final Synchronizer synchronizer,
final ProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final FilterManager filterManager,
final TransactionPool transactionPool,
final MiningCoordinator miningCoordinator,
@ -124,6 +127,14 @@ public class JsonRpcMethodsFactory {
new TxPoolJsonRpcMethods(transactionPool),
new PluginsJsonRpcMethods(namedPlugins));
// TODO: Implement engine-specific json-rpc endpoint rather than including consensus here
// https://github.com/hyperledger/besu/issues/2914
MergeConfigOptions.doIfMergeEnabled(
() ->
enabled.putAll(
new ExecutionEngineJsonRpcMethods(miningCoordinator, protocolContext)
.create(rpcApis)));
for (final JsonRpcMethods apiGroup : availableApiGroups) {
enabled.putAll(apiGroup.create(rpcApis));
}

@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterIdGenerator;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
@ -127,6 +128,7 @@ public abstract class AbstractJsonRpcHttpServiceTest {
protected Map<String, JsonRpcMethod> getRpcMethods(
final JsonRpcConfiguration config, final BlockchainSetupUtil blockchainSetupUtil) {
final ProtocolContext protocolContext = mock(ProtocolContext.class);
final Synchronizer synchronizerMock = mock(Synchronizer.class);
final P2PNetwork peerDiscoveryMock = mock(P2PNetwork.class);
final TransactionPool transactionPoolMock = mock(TransactionPool.class);
@ -170,6 +172,7 @@ public abstract class AbstractJsonRpcHttpServiceTest {
blockchainQueries,
synchronizerMock,
blockchainSetupUtil.getProtocolSchedule(),
protocolContext,
filterManager,
transactionPoolMock,
miningCoordinatorMock,

@ -20,6 +20,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -105,6 +106,7 @@ public class JsonRpcHttpServiceHostAllowlistTest {
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright Hyperledger Besu contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
@ -22,6 +22,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.AuthenticationUtils;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
@ -135,6 +136,7 @@ public class JsonRpcHttpServiceLoginTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(genesisConfigOptions),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright Hyperledger Besu contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at

@ -21,6 +21,7 @@ import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -203,6 +204,7 @@ public class JsonRpcHttpServiceRpcApisTest {
blockchainQueries,
mock(Synchronizer.class),
ProtocolScheduleFixture.MAINNET,
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),
@ -300,6 +302,7 @@ public class JsonRpcHttpServiceRpcApisTest {
blockchainQueries,
mock(Synchronizer.class),
ProtocolScheduleFixture.MAINNET,
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -19,6 +19,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -113,6 +114,7 @@ public class JsonRpcHttpServiceTestBase {
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID),
EvmConfiguration.DEFAULT),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -120,6 +121,7 @@ public class JsonRpcHttpServiceTlsClientAuthTest {
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -108,6 +109,7 @@ public class JsonRpcHttpServiceTlsMisconfigurationTest {
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -110,6 +111,7 @@ public class JsonRpcHttpServiceTlsTest {
synchronizer,
MainnetProtocolSchedule.fromConfig(
new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID)),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -145,6 +145,17 @@ public class WebSocketRequestHandlerTest {
@Test
public void handlerBatchRequestContainingErrorsShouldRespondWithBatchErrors(
final TestContext context) {
ServerWebSocket websocketMock = mock(ServerWebSocket.class);
when(websocketMock.textHandlerID()).thenReturn(UUID.randomUUID().toString());
WebSocketRequestHandler handleBadCalls =
new WebSocketRequestHandler(
vertx,
methods,
mock(EthScheduler.class),
TimeoutOptions.defaultOptions().getTimeoutSeconds());
final Async async = context.async();
final JsonObject requestJson =
@ -161,7 +172,7 @@ public class WebSocketRequestHandlerTest {
when(websocketMock.writeFrame(argThat(this::isFinalFrame))).then(completeOnLastFrame(async));
handler.handle(websocketMock, arrayJson.toString());
handleBadCalls.handle(websocketMock, arrayJson.toString());
async.awaitSuccess(WebSocketRequestHandlerTest.VERTX_AWAIT_TIMEOUT_MILLIS);

@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright Hyperledger Besu contributors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
@ -23,6 +23,7 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcHttpService;
@ -163,6 +164,7 @@ public class WebSocketServiceLoginTest {
blockchainQueries,
synchronizer,
MainnetProtocolSchedule.fromConfig(genesisConfigOptions),
mock(ProtocolContext.class),
mock(FilterManager.class),
mock(TransactionPool.class),
mock(PoWMiningCoordinator.class),

@ -20,6 +20,7 @@ import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import org.hyperledger.besu.config.experimental.MergeConfigOptions;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
@ -142,7 +143,13 @@ public class DefaultBlockchain implements MutableBlockchain {
() -> chainHeadOmmerCount);
this.reorgLoggingThreshold = reorgLoggingThreshold;
this.blockChoiceRule = heaviestChainBlockChoiceRule;
// TODO: FROMRAYONISM, need to account for fixed total difficulty
this.blockChoiceRule =
MergeConfigOptions.isMergeEnabled()
? // always regard the new block as "worse" because we don't reorg anymore; the
// consensus node tells us what the head is through `setHead`
(newBlockHeader, currentBlockHeader) -> -1
: heaviestChainBlockChoiceRule;
}
public static MutableBlockchain createMutable(

Loading…
Cancel
Save