Skip to content

Commit

Permalink
Expose json rpc config to plugins through JsonRpcConfigurationService
Browse files Browse the repository at this point in the history
Signed-off-by: Antony Denyer <git@antonydenyer.co.uk>
  • Loading branch information
antonydenyer committed Aug 31, 2021
1 parent 625737a commit ca2f8cb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
32 changes: 25 additions & 7 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.BesuEvents;
import org.hyperledger.besu.plugin.services.JsonRpcConfigurationService;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.PermissioningService;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;
Expand Down Expand Up @@ -1113,7 +1114,7 @@ void setBannedNodeIds(final List<String> values) {
private Optional<TLSConfiguration> p2pTLSConfiguration;
private Collection<EnodeURL> staticNodes;
private BesuController besuController;
private BesuConfiguration pluginCommonConfiguration;
private final BesuCommandConfigurationService pluginCommonConfiguration;
private final Supplier<ObservableMetricsSystem> metricsSystem =
Suppliers.memoize(() -> MetricsSystemFactory.create(metricsConfiguration()));
private Vertx vertx;
Expand Down Expand Up @@ -1175,6 +1176,7 @@ protected BesuCommand(
this.privacyPluginPluginService = privacyPluginPluginService;
pluginCommonConfiguration = new BesuCommandConfigurationService();
besuPluginContext.addService(BesuConfiguration.class, pluginCommonConfiguration);
besuPluginContext.addService(JsonRpcConfigurationService.class, pluginCommonConfiguration);
this.pkiBlockCreationConfigProvider = pkiBlockCreationConfigProvider;
}

Expand Down Expand Up @@ -1230,11 +1232,6 @@ public void run() {
}
}

@VisibleForTesting
void setBesuConfiguration(final BesuConfiguration pluginCommonConfiguration) {
this.pluginCommonConfiguration = pluginCommonConfiguration;
}

private void addSubCommands(
final AbstractParseResultHandler<List<Object>> resultHandler, final InputStream in) {
commandLine.addSubcommand(
Expand Down Expand Up @@ -2687,7 +2684,8 @@ Level getLogLevel() {
return logLevel;
}

private class BesuCommandConfigurationService implements BesuConfiguration {
private class BesuCommandConfigurationService
implements BesuConfiguration, JsonRpcConfigurationService {

@Override
public Path getStoragePath() {
Expand All @@ -2706,6 +2704,26 @@ public int getDatabaseVersion() {
.getDataStorageFormat()
.getDatabaseVersion();
}

@Override
public boolean isJsonRpcEnabled() {
return isRpcHttpEnabled;
}

@Override
public int getJsonRpcPort() {
return rpcHttpPort;
}

@Override
public String getJsonRpcHost() {
return rpcHttpHost;
}

@Override
public Collection<String> getJsonRpcApis() {
return rpcHttpApis.stream().map(RpcApi::toString).collect(Collectors.toList());
}
}

private void instantiateSignatureAlgorithmFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.prometheus.MetricsConfiguration;
import org.hyperledger.besu.pki.config.PkiKeyStoreConfiguration;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;
import org.hyperledger.besu.plugin.services.StorageService;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageFactory;
Expand Down Expand Up @@ -145,7 +144,6 @@ public abstract class CommandTestAbstract {
@Mock protected RlpBlockImporter rlpBlockImporter;
@Mock protected StorageServiceImpl storageService;
@Mock protected SecurityModuleServiceImpl securityModuleService;
@Mock protected BesuConfiguration commonPluginConfiguration;
@Mock protected KeyValueStorageFactory rocksDBStorageFactory;
@Mock protected PrivacyKeyValueStorageFactory rocksDBSPrivacyStorageFactory;
@Mock protected PicoCLIOptions cliOptions;
Expand Down Expand Up @@ -353,8 +351,6 @@ protected TestBesuCommand parseCommand(final InputStream in, final String... arg
mockPkiBlockCreationConfigProvider);
besuCommands.add(besuCommand);

besuCommand.setBesuConfiguration(commonPluginConfiguration);

// parse using Ansi.OFF to be able to assert on non formatted output results
besuCommand.parse(
new RunLast().useOut(outPrintStream).useAnsi(Ansi.OFF),
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'zpv92JZmlU6gPifGcPG5ATE6Lv/ruWdJtjLk3EVXO4g='
knownHash = '0eGdR/xJa6srwpOpuqv4I7XNUUD/vooWpzlonfFerK0='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright ConsenSys AG.
*
* 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.plugin.services;

import java.util.Collection;

public interface JsonRpcConfigurationService extends BesuService {
/**
* has JSON-RPC been enabled
*
* @return has JSON-RPC been enabled
*/
boolean isJsonRpcEnabled();

/**
* Port JSON-RPC HTTP is listening on
*
* @return Port JSON-RPC HTTP is listening on
*/
int getJsonRpcPort();

/**
* The host that JSON-RPC HTTP is listening on
*
* @return Host that JSON-RPC HTTP is listening on
*/
String getJsonRpcHost();

/**
* The list of APIs enabled on JSON-RPC HTTP service
*
* @return list of APIs enabled on JSON-RPC HTTP service
*/
Collection<String> getJsonRpcApis();
}

0 comments on commit ca2f8cb

Please sign in to comment.