Skip to content

Commit

Permalink
allow upgrade whether websockets enabled or not (#4019)
Browse files Browse the repository at this point in the history
* allow upgrade whether websockets enabled or not

Signed-off-by: Justin Florentine <[email protected]>

Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
jflo and macfarla committed Jun 30, 2022
1 parent 68c8438 commit 3baa4da
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
11 changes: 7 additions & 4 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ public Runner build() {
new HealthService(new ReadinessCheck(peerNetwork, synchronizer))));
}

final SubscriptionManager subscriptionManager =
createSubscriptionManager(vertx, transactionPool, blockchainQueries);

Optional<JsonRpcService> engineJsonRpcService = Optional.empty();
if (engineJsonRpcConfiguration.isPresent() && engineJsonRpcConfiguration.get().isEnabled()) {
final Map<String, JsonRpcMethod> engineMethods =
Expand Down Expand Up @@ -669,6 +672,9 @@ public Runner build() {
? webSocketConfiguration
: WebSocketConfiguration.createEngineDefault();

final WebSocketMethodsFactory websocketMethodsFactory =
new WebSocketMethodsFactory(subscriptionManager, engineMethods);

engineJsonRpcService =
Optional.of(
new JsonRpcService(
Expand All @@ -677,7 +683,7 @@ public Runner build() {
engineJsonRpcConfiguration.orElse(JsonRpcConfiguration.createEngineDefault()),
metricsSystem,
natService,
engineMethods,
websocketMethodsFactory.methods(),
Optional.ofNullable(engineSocketConfig),
besuController.getProtocolManager().ethContext().getScheduler(),
authToUse,
Expand Down Expand Up @@ -743,9 +749,6 @@ public Runner build() {
dataDir,
rpcEndpointServiceImpl);

final SubscriptionManager subscriptionManager =
createSubscriptionManager(vertx, transactionPool, blockchainQueries);

createLogsSubscriptionService(
context.getBlockchain(),
context.getWorldStateArchive(),
Expand Down
43 changes: 43 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,49 @@ public void whenEngineApiAddedWebSocketReadyOnSamePort() {
assertThat(runner.getEngineJsonRpcPort()).isPresent();
}

@Test
public void whenEngineApiAddedEthSubscribeAvailable() {
WebSocketConfiguration wsRpc = WebSocketConfiguration.createDefault();
wsRpc.setEnabled(true);
EthNetworkConfig mockMainnet = mock(EthNetworkConfig.class);
when(mockMainnet.getNetworkId()).thenReturn(BigInteger.ONE);
MergeConfigOptions.setMergeEnabled(true);
when(besuController.getMiningCoordinator()).thenReturn(mock(MergeMiningCoordinator.class));
JsonRpcConfiguration engineConf = JsonRpcConfiguration.createEngineDefault();
engineConf.setEnabled(true);

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(JsonRpcConfiguration.createDefault())
.engineJsonRpcConfiguration(engineConf)
.webSocketConfiguration(wsRpc)
.jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class))
.graphQLConfiguration(mock(GraphQLConfiguration.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.getEngineJsonRpcPort()).isPresent();
runner.startExternalServices();
// assert that rpc method collection has eth_subscribe in it.
runner.stop();
}

@Test
public void noEngineApiNoServiceForMethods() {
JsonRpcConfiguration defaultRpcConfig = JsonRpcConfiguration.createDefault();
Expand Down

0 comments on commit 3baa4da

Please sign in to comment.