[nc-1756] jsonrpc enabling for clique and ibft (#91)

Chris Mckay 6 years ago committed by GitHub
parent fdd08a8820
commit 0d77c515b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java
  2. 4
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNodeConfig.java
  3. 5
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java
  4. 10
      consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueJsonRpcMethodsFactory.java
  5. 33
      consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/jsonrpc/CliqueRpcApis.java
  6. 22
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftJsonRpcMethodsFactory.java
  7. 33
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/jsonrpc/IbftRpcApis.java
  8. 2
      ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcTestMethodsFactory.java
  9. 29
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfiguration.java
  10. 5
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java
  11. 44
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java
  12. 47
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java
  13. 18
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfiguration.java
  14. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/AbstractEthJsonRpcHttpServiceTest.java
  15. 2
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcConfigurationTest.java
  16. 5
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  17. 3
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceTest.java
  18. 2
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketConfigurationTest.java
  19. 2
      pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java
  20. 8
      pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java
  21. 40
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  22. 35
      pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java

@ -18,7 +18,7 @@ import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.pantheonRpcDisabledNode;
import static tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNodeConfig.patheonNodeWithRpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode;

@ -15,7 +15,7 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.node;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import java.io.IOException;
@ -69,7 +69,7 @@ public class PantheonNodeConfig {
}
public static PantheonNodeConfig patheonNodeWithRpcApis(
final String name, final RpcApis... enabledRpcApis) {
final String name, final RpcApi... enabledRpcApis) {
final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig();
jsonRpcConfig.setRpcApis(Arrays.asList(enabledRpcApis));
final WebSocketConfiguration webSocketConfig = createWebSocketConfig();

@ -12,7 +12,8 @@
*/
package tech.pegasys.pantheon.tests.acceptance.dsl.node;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import java.io.File;
import java.io.IOException;
@ -93,7 +94,7 @@ public class ProcessPantheonNodeRunner implements PantheonNodeRunner {
waitForPortsFile(dataDir);
}
private String apiList(final Collection<RpcApis> rpcApis) {
private String apiList(final Collection<RpcApi> rpcApis) {
return String.join(",", rpcApis.stream().map(RpcApis::getValue).collect(Collectors.toList()));
}

@ -24,16 +24,23 @@ import tech.pegasys.pantheon.consensus.common.VoteProposer;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class CliqueJsonRpcMethodsFactory {
public Map<String, JsonRpcMethod> methods(final ProtocolContext<CliqueContext> context) {
public Map<String, JsonRpcMethod> methods(
final ProtocolContext<CliqueContext> context, final Collection<RpcApi> jsonRpcApis) {
final Map<String, JsonRpcMethod> rpcMethods = new HashMap<>();
if (!jsonRpcApis.contains(CliqueRpcApis.CLIQUE)) {
return rpcMethods;
}
final MutableBlockchain blockchain = context.getBlockchain();
final WorldStateArchive worldStateArchive = context.getWorldStateArchive();
final BlockchainQueries blockchainQueries =
@ -50,7 +57,6 @@ public class CliqueJsonRpcMethodsFactory {
final Propose proposeRpc = new Propose(voteProposer, jsonRpcParameter);
final Discard discardRpc = new Discard(voteProposer, jsonRpcParameter);
final Map<String, JsonRpcMethod> rpcMethods = new HashMap<>();
rpcMethods.put(cliqueGetSigners.getName(), cliqueGetSigners);
rpcMethods.put(cliqueGetSignersAtHash.getName(), cliqueGetSignersAtHash);
rpcMethods.put(proposeRpc.getName(), proposeRpc);

@ -0,0 +1,33 @@
/*
* Copyright 2018 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.
*/
package tech.pegasys.pantheon.consensus.clique.jsonrpc;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import java.util.Optional;
public class CliqueRpcApis {
public static final RpcApi CLIQUE = new RpcApi("CLIQUE");
public static final Optional<RpcApi> valueOf(final String name) {
if (name.equals(CLIQUE.getCliValue())) {
return Optional.of(CLIQUE);
} else {
return Optional.empty();
}
}
public static final String getName(final RpcApi rpcapi) {
return rpcapi.getCliValue();
}
}

@ -16,9 +16,11 @@ import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.jsonrpc.methods.IbftDiscardValidatorVote;
import tech.pegasys.pantheon.consensus.ibft.jsonrpc.methods.IbftProposeValidatorVote;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -26,16 +28,20 @@ public class IbftJsonRpcMethodsFactory {
private final JsonRpcParameter jsonRpcParameter = new JsonRpcParameter();
public Map<String, JsonRpcMethod> methods(final ProtocolContext<IbftContext> context) {
public Map<String, JsonRpcMethod> methods(
final ProtocolContext<IbftContext> context, final Collection<RpcApi> jsonRpcApis) {
final Map<String, JsonRpcMethod> rpcMethods = new HashMap<>();
// @formatter:off
addMethods(
rpcMethods,
new IbftProposeValidatorVote(
context.getConsensusState().getVoteProposer(), jsonRpcParameter),
new IbftDiscardValidatorVote(
context.getConsensusState().getVoteProposer(), jsonRpcParameter));
if (jsonRpcApis.contains(IbftRpcApis.IBFT)) {
// @formatter:off
addMethods(
rpcMethods,
new IbftProposeValidatorVote(
context.getConsensusState().getVoteProposer(), jsonRpcParameter),
new IbftDiscardValidatorVote(
context.getConsensusState().getVoteProposer(), jsonRpcParameter));
}
return rpcMethods;
}

@ -0,0 +1,33 @@
/*
* Copyright 2018 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.
*/
package tech.pegasys.pantheon.consensus.ibft.jsonrpc;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import java.util.Optional;
public class IbftRpcApis {
public static final RpcApi IBFT = new RpcApi("IBFT");
public static final Optional<RpcApi> valueOf(final String name) {
if (name.equals(IBFT.getCliValue())) {
return Optional.of(IBFT);
} else {
return Optional.empty();
}
}
public static final String getName(final RpcApi rpcapi) {
return rpcapi.getCliValue();
}
}

@ -95,6 +95,6 @@ public class JsonRpcTestMethodsFactory {
transactionPool,
miningCoordinator,
new HashSet<>(),
JsonRpcConfiguration.DEFAULT_JSON_RPC_APIS);
RpcApis.DEFAULT_JSON_RPC_APIS);
}
}

@ -12,6 +12,7 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@ -20,36 +21,23 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
public class JsonRpcConfiguration {
public static final String DEFAULT_JSON_RPC_HOST = "127.0.0.1";
public static final int DEFAULT_JSON_RPC_PORT = 8545;
public static final Collection<RpcApis> DEFAULT_JSON_RPC_APIS =
public static final Collection<RpcApi> DEFAULT_JSON_RPC_APIS =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);
private boolean enabled;
private int port;
private String host;
private Collection<String> corsAllowedDomains = Collections.emptyList();
private Collection<RpcApis> rpcApis;
public enum RpcApis {
DEBUG,
ETH,
MINER,
NET,
WEB3;
public String getValue() {
return this.name().toLowerCase();
}
}
private Collection<RpcApi> rpcApis;
public static JsonRpcConfiguration createDefault() {
final JsonRpcConfiguration config = new JsonRpcConfiguration();
config.setEnabled(false);
config.setPort(DEFAULT_JSON_RPC_PORT);
config.setHost(DEFAULT_JSON_RPC_HOST);
config.rpcApis = DEFAULT_JSON_RPC_APIS;
config.rpcApis = RpcApis.DEFAULT_JSON_RPC_APIS;
return config;
}
@ -89,14 +77,19 @@ public class JsonRpcConfiguration {
}
}
public Collection<RpcApis> getRpcApis() {
public Collection<RpcApi> getRpcApis() {
return rpcApis;
}
public void setRpcApis(final Collection<RpcApis> rpcApis) {
public void setRpcApis(final Collection<RpcApi> rpcApis) {
this.rpcApis = rpcApis;
}
public void addRpcApi(final RpcApi rpcApi) {
this.rpcApis = new ArrayList<>(rpcApis);
rpcApis.add(rpcApi);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)

@ -17,7 +17,6 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.AdminPeers;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.DebugStorageRangeAt;
@ -96,7 +95,7 @@ public class JsonRpcMethodsFactory {
final ProtocolSchedule<?> protocolSchedule,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApis> rpcApis,
final Collection<RpcApi> rpcApis,
final FilterManager filterManager) {
final BlockchainQueries blockchainQueries =
new BlockchainQueries(blockchain, worldStateArchive);
@ -125,7 +124,7 @@ public class JsonRpcMethodsFactory {
final TransactionPool transactionPool,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApis> rpcApis) {
final Collection<RpcApi> rpcApis) {
final Map<String, JsonRpcMethod> enabledMethods = new HashMap<>();
// @formatter:off
if (rpcApis.contains(RpcApis.ETH)) {

@ -0,0 +1,44 @@
/*
* Copyright 2018 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.
*/
package tech.pegasys.pantheon.ethereum.jsonrpc;
import com.google.common.base.Objects;
public class RpcApi {
private final String cliValue;
public RpcApi(final String cliValue) {
this.cliValue = cliValue;
}
public String getCliValue() {
return cliValue;
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final RpcApi rpcApi = (RpcApi) o;
return Objects.equal(cliValue, rpcApi.cliValue);
}
@Override
public int hashCode() {
return Objects.hashCode(cliValue);
}
}

@ -0,0 +1,47 @@
/*
* Copyright 2018 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.
*/
package tech.pegasys.pantheon.ethereum.jsonrpc;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
public class RpcApis {
public static final RpcApi ETH = new RpcApi("ETH");
public static final RpcApi DEBUG = new RpcApi("DEBUG");
public static final RpcApi MINER = new RpcApi("MINER");
public static final RpcApi NET = new RpcApi("NET");
public static final RpcApi WEB3 = new RpcApi("WEB3");
public static final Collection<RpcApi> DEFAULT_JSON_RPC_APIS = Arrays.asList(ETH, NET, WEB3);
public static final Optional<RpcApi> valueOf(final String name) {
if (name.equals(ETH.getCliValue())) {
return Optional.of(ETH);
} else if (name.equals(DEBUG.getCliValue())) {
return Optional.of(DEBUG);
} else if (name.equals(MINER.getCliValue())) {
return Optional.of(MINER);
} else if (name.equals(NET.getCliValue())) {
return Optional.of(NET);
} else if (name.equals(WEB3.getCliValue())) {
return Optional.of(WEB3);
} else {
return Optional.empty();
}
}
public static final String getValue(final RpcApi rpcapi) {
return rpcapi.getCliValue();
}
}

@ -12,8 +12,10 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc.websocket;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -21,16 +23,15 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
public class WebSocketConfiguration {
public static final String DEFAULT_WEBSOCKET_HOST = "127.0.0.1";
public static final int DEFAULT_WEBSOCKET_PORT = 8546;
public static final Collection<RpcApis> DEFAULT_WEBSOCKET_APIS =
public static final Collection<RpcApi> DEFAULT_WEBSOCKET_APIS =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);
private boolean enabled;
private int port;
private String host;
private Collection<RpcApis> rpcApis;
private Collection<RpcApi> rpcApis;
public static WebSocketConfiguration createDefault() {
final WebSocketConfiguration config = new WebSocketConfiguration();
@ -67,14 +68,19 @@ public class WebSocketConfiguration {
return port;
}
public Collection<RpcApis> getRpcApis() {
public Collection<RpcApi> getRpcApis() {
return rpcApis;
}
public void setRpcApis(final Collection<RpcApis> rpcApis) {
public void setRpcApis(final Collection<RpcApi> rpcApis) {
this.rpcApis = rpcApis;
}
public void addRpcApi(final RpcApi rpcApi) {
this.rpcApis = new ArrayList<>(rpcApis);
rpcApis.add(rpcApi);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)

@ -33,7 +33,6 @@ import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.db.DefaultMutableBlockchain;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterRepository;
@ -94,7 +93,7 @@ public abstract class AbstractEthJsonRpcHttpServiceTest {
protected final String NET_VERSION = "6986785976597";
protected static final Collection<RpcApis> JSON_RPC_APIS =
protected static final Collection<RpcApi> JSON_RPC_APIS =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);
protected MutableBlockchain blockchain;

@ -14,8 +14,6 @@ package tech.pegasys.pantheon.ethereum.jsonrpc;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import com.google.common.collect.Lists;
import org.junit.Test;

@ -21,7 +21,6 @@ import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries;
@ -142,7 +141,7 @@ public class JsonRpcHttpServiceRpcApisTest {
}
}
private JsonRpcConfiguration createJsonRpcConfigurationWithRpcApis(final RpcApis... rpcApis) {
private JsonRpcConfiguration createJsonRpcConfigurationWithRpcApis(final RpcApi... rpcApis) {
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault();
config.setCorsAllowedDomains(singletonList("*"));
config.setPort(0);
@ -152,7 +151,7 @@ public class JsonRpcHttpServiceRpcApisTest {
return config;
}
private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final RpcApis... rpcApis) {
private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final RpcApi... rpcApis) {
return createJsonRpcHttpServiceWithRpcApis(createJsonRpcConfigurationWithRpcApis(rpcApis));
}

@ -31,7 +31,6 @@ import tech.pegasys.pantheon.ethereum.core.Transaction;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.eth.EthProtocol;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockWithMetadata;
@ -88,7 +87,7 @@ public class JsonRpcHttpServiceTest {
protected static P2PNetwork peerDiscoveryMock;
protected static BlockchainQueries blockchainQueries;
protected static Synchronizer synchronizer;
protected static final Collection<RpcApis> JSON_RPC_APIS =
protected static final Collection<RpcApi> JSON_RPC_APIS =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);
protected final JsonRpcTestHelper testHelper = new JsonRpcTestHelper();

@ -14,7 +14,7 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.websocket;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import org.junit.Test;

@ -2,7 +2,7 @@ package tech.pegasys.pantheon;
// This file is generated via a gradle task and should not be edited directly.
public class PantheonInfo {
private static final String version = "pantheon/0.0.8-SNAPSHOT";
private static final String version = "pantheon/0.8.0-SNAPSHOT";
private PantheonInfo() {}

@ -25,9 +25,9 @@ import tech.pegasys.pantheon.ethereum.core.Synchronizer;
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.db.WorldStateArchive;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcHttpService;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcMethodsFactory;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterRepository;
@ -219,7 +219,7 @@ public class RunnerBuilder {
final TransactionPool transactionPool,
final AbstractMiningCoordinator<?, ?> miningCoordinator,
final Set<Capability> supportedCapabilities,
final Collection<RpcApis> jsonRpcApis,
final Collection<RpcApi> jsonRpcApis,
final FilterManager filterManager) {
final Map<String, JsonRpcMethod> methods =
new JsonRpcMethodsFactory()
@ -242,7 +242,7 @@ public class RunnerBuilder {
@SuppressWarnings("unchecked")
final ProtocolContext<CliqueContext> cliqueProtocolContext =
(ProtocolContext<CliqueContext>) context;
methods.putAll(new CliqueJsonRpcMethodsFactory().methods(cliqueProtocolContext));
methods.putAll(new CliqueJsonRpcMethodsFactory().methods(cliqueProtocolContext, jsonRpcApis));
}
if (context.getConsensusState() instanceof IbftContext) {
@ -250,7 +250,7 @@ public class RunnerBuilder {
@SuppressWarnings("unchecked")
final ProtocolContext<IbftContext> ibftProtocolContext =
(ProtocolContext<IbftContext>) context;
methods.putAll(new IbftJsonRpcMethodsFactory().methods(ibftProtocolContext));
methods.putAll(new IbftJsonRpcMethodsFactory().methods(ibftProtocolContext, jsonRpcApis));
}
return methods;
}

@ -17,6 +17,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
import tech.pegasys.pantheon.Runner;
import tech.pegasys.pantheon.RunnerBuilder;
import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty;
import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis;
import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis;
import tech.pegasys.pantheon.controller.PantheonController;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Address;
@ -25,7 +27,8 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration.Builder;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer;
import tech.pegasys.pantheon.util.BlockImporter;
@ -43,6 +46,9 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
import com.google.common.net.HostAndPort;
import io.vertx.core.Vertx;
@ -93,19 +99,23 @@ public class PantheonCommand implements Runnable {
private static final String CONFIG_FILE_OPTION_NAME = "--config";
public static class RpcApisEnumConverter implements ITypeConverter<RpcApis> {
public static class RpcApisConverter implements ITypeConverter<RpcApi> {
@Override
public RpcApis convert(final String s) throws RpcApisEnumConvertionException {
try {
return RpcApis.valueOf(s.trim().toUpperCase());
} catch (final IllegalArgumentException e) {
throw new RpcApisEnumConvertionException("Invalid value: " + s);
}
public RpcApi convert(final String name) throws RpcApisConversionException {
String uppercaseName = name.trim().toUpperCase();
return Stream.<Function<String, Optional<RpcApi>>>of(
RpcApis::valueOf, CliqueRpcApis::valueOf, IbftRpcApis::valueOf)
.map(f -> f.apply(uppercaseName))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElseThrow(() -> new RpcApisConversionException("Invalid value: " + name));
}
}
public static class RpcApisEnumConvertionException extends Exception {
RpcApisEnumConvertionException(final String s) {
public static class RpcApisConversionException extends Exception {
RpcApisConversionException(final String s) {
super(s);
}
}
@ -265,10 +275,11 @@ public class PantheonCommand implements Runnable {
paramLabel = "<api name>",
split = ",",
arity = "1..*",
converter = RpcApisEnumConverter.class,
converter = RpcApisConverter.class,
description = "Comma separated APIs to enable on JSON-RPC channel. default: ${DEFAULT-VALUE}"
)
private final Collection<RpcApis> rpcApis = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);
private final Collection<RpcApi> rpcApis =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT);
@Option(
names = {"--ws-enabled"},
@ -291,10 +302,11 @@ public class PantheonCommand implements Runnable {
paramLabel = "<api name>",
split = ",",
arity = "1..*",
converter = RpcApisEnumConverter.class,
converter = RpcApisConverter.class,
description = "Comma separated APIs to enable on WebSocket channel. default: ${DEFAULT-VALUE}"
)
private final Collection<RpcApis> wsApis = Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3);
private final Collection<RpcApi> wsApis =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT);
@Option(
names = {"--dev-mode"},

@ -28,6 +28,8 @@ import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.M
import tech.pegasys.pantheon.PantheonInfo;
import tech.pegasys.pantheon.cli.EthNetworkConfig.Builder;
import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis;
import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Wei;
@ -60,6 +62,20 @@ import org.mockito.ArgumentMatchers;
public class PantheonCommandTest extends CommandTestAbstract {
@Rule public final TemporaryFolder temp = new TemporaryFolder();
private static final JsonRpcConfiguration defaultJsonRpcConfiguration;
private static final WebSocketConfiguration defaultWebSocketConfiguration;
static {
final JsonRpcConfiguration rpcConf = JsonRpcConfiguration.createDefault();
rpcConf.addRpcApi(CliqueRpcApis.CLIQUE);
rpcConf.addRpcApi(IbftRpcApis.IBFT);
defaultJsonRpcConfiguration = rpcConf;
final WebSocketConfiguration websocketConf = WebSocketConfiguration.createDefault();
websocketConf.addRpcApi(CliqueRpcApis.CLIQUE);
websocketConf.addRpcApi(IbftRpcApis.IBFT);
defaultWebSocketConfiguration = websocketConf;
}
@Override
@Before
@ -109,8 +125,8 @@ public class PantheonCommandTest extends CommandTestAbstract {
eq("127.0.0.1"),
eq(30303),
eq(25),
eq(JsonRpcConfiguration.createDefault()),
eq(WebSocketConfiguration.createDefault()),
eq(defaultJsonRpcConfiguration),
eq(defaultWebSocketConfiguration),
any());
final ArgumentCaptor<MiningParameters> miningArg =
@ -214,12 +230,16 @@ public class PantheonCommandTest extends CommandTestAbstract {
jsonRpcConfiguration.setPort(5678);
jsonRpcConfiguration.setCorsAllowedDomains(Collections.emptyList());
jsonRpcConfiguration.setRpcApis(JsonRpcConfiguration.DEFAULT_JSON_RPC_APIS);
jsonRpcConfiguration.addRpcApi(CliqueRpcApis.CLIQUE);
jsonRpcConfiguration.addRpcApi(IbftRpcApis.IBFT);
final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
webSocketConfiguration.setEnabled(false);
webSocketConfiguration.setHost("9.10.11.12");
webSocketConfiguration.setPort(9101);
webSocketConfiguration.setRpcApis(WebSocketConfiguration.DEFAULT_WEBSOCKET_APIS);
webSocketConfiguration.addRpcApi(CliqueRpcApis.CLIQUE);
webSocketConfiguration.addRpcApi(IbftRpcApis.IBFT);
parseCommand("--config", configFile);
@ -268,6 +288,13 @@ public class PantheonCommandTest extends CommandTestAbstract {
final String configFile = Resources.getResource("partial_config.toml").getFile();
parseCommand("--config", configFile);
final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
jsonRpcConfiguration.addRpcApi(CliqueRpcApis.CLIQUE);
jsonRpcConfiguration.addRpcApi(IbftRpcApis.IBFT);
final WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
webSocketConfiguration.addRpcApi(CliqueRpcApis.CLIQUE);
webSocketConfiguration.addRpcApi(IbftRpcApis.IBFT);
verify(mockRunnerBuilder)
.build(
@ -278,8 +305,8 @@ public class PantheonCommandTest extends CommandTestAbstract {
eq("127.0.0.1"),
eq(30303),
eq(25),
eq(JsonRpcConfiguration.createDefault()),
eq(WebSocketConfiguration.createDefault()),
eq(jsonRpcConfiguration),
eq(webSocketConfiguration),
any());
verify(mockControllerBuilder).build(any(), any(), any(), eq(false), any(), eq(false));

Loading…
Cancel
Save