From e681f80c85408566edc6662745003f6f865e9270 Mon Sep 17 00:00:00 2001 From: Nicolas MASSART Date: Thu, 24 Jan 2019 10:27:56 +0100 Subject: [PATCH] NC-2104 Clique and iBFT should not be defined by default in RPC APIs (#635) fixes NC-2104 remove Clique and iBFT defaults and centralise default values As toString() is used to display default values in CLI description and this is not used anywhere else for RpcApi objects, it may have been used for debug long ago, but now we can use the simple string value as return from toString. Then we are able to use the DEFAULT_JSON_RPC_APIS constant as default value directly instead of hard coded defaults string in option that was probably used because previous toString was not outputting correct representation. It may be interesting to comment when some does this sort of hack. Signed-off-by: Adrian Sutton --- docs/Reference/Pantheon-CLI-Syntax.md | 4 ++-- .../pantheon/ethereum/jsonrpc/RpcApi.java | 3 +-- .../pegasys/pantheon/cli/PantheonCommand.java | 11 +++++------ .../pantheon/cli/PantheonCommandTest.java | 16 +--------------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/docs/Reference/Pantheon-CLI-Syntax.md b/docs/Reference/Pantheon-CLI-Syntax.md index 14904f3019..26d7c37e75 100644 --- a/docs/Reference/Pantheon-CLI-Syntax.md +++ b/docs/Reference/Pantheon-CLI-Syntax.md @@ -618,7 +618,7 @@ rpc-http-api=["ETH","NET","WEB3"] Comma-separated APIs to enable on the HTTP JSON-RPC channel. When you use this option, the `--rpc-http-enabled` option must also be specified. The available API options are: `ADMIN`, `ETH`, `NET`, `WEB3`, `CLIQUE`, `IBFT`, `DEBUG`, and `MINER`. -The default is: `ETH`, `NET`, `WEB3`, `CLIQUE`, `IBFT`. +The default is: `ETH`, `NET`, `WEB3`. !!!note :construction: IBFT is not currently supported. Support for IBFT is in active development. @@ -697,7 +697,7 @@ rpc-ws-api=["ETH","NET","WEB3"] Comma-separated APIs to enable on Websockets channel. When you use this option, the `--rpc-ws-enabled` option must also be specified. The available API options are: `ETH`, `NET`, `WEB3`, `CLIQUE`, `IBFT`, `DEBUG`, and `MINER`. -The default is: `ETH`, `NET`, `WEB3`, `CLIQUE`, `IBFT`. +The default is: `ETH`, `NET`, `WEB3`. !!!note :construction: IBFT is not currently supported. Support for IBFT is in active development. diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java index c5de2c7924..b758ac6343 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java @@ -12,7 +12,6 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc; -import com.google.common.base.MoreObjects; import com.google.common.base.Objects; public class RpcApi { @@ -45,6 +44,6 @@ public class RpcApi { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("cliValue", cliValue).toString(); + return cliValue; } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 79abeb231a..6bbc051439 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -17,6 +17,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath; import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT; +import static tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis.DEFAULT_JSON_RPC_APIS; import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_PORT; import static tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration.DEFAULT_WEBSOCKET_REFRESH_DELAY; import static tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer.DEFAULT_PORT; @@ -336,10 +337,9 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { split = ",", arity = "1..*", converter = RpcApisConverter.class, - description = "Comma separated APIs to enable on JSON-RPC channel. default: ${DEFAULT-VALUE}", - defaultValue = "ETH,NET,WEB3,CLIQUE,IBFT" + description = "Comma separated APIs to enable on JSON-RPC channel. default: ${DEFAULT-VALUE}" ) - private final Collection rpcHttpApis = null; + private final Collection rpcHttpApis = DEFAULT_JSON_RPC_APIS; @Option( names = {"--rpc-ws-enabled"}, @@ -371,10 +371,9 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { split = ",", arity = "1..*", converter = RpcApisConverter.class, - description = "Comma separated APIs to enable on WebSocket channel. default: ${DEFAULT-VALUE}", - defaultValue = "ETH,NET,WEB3,CLIQUE,IBFT" + description = "Comma separated APIs to enable on WebSocket channel. default: ${DEFAULT-VALUE}" ) - private final Collection rpcWsApis = null; + private final Collection rpcWsApis = DEFAULT_JSON_RPC_APIS; private Long rpcWsRefreshDelay; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index a8a2fa3030..c60dd33eb6 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -24,8 +24,6 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES; import tech.pegasys.pantheon.PantheonInfo; -import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; -import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; @@ -86,13 +84,9 @@ public class PantheonCommandTest extends CommandTestAbstract { 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; defaultMetricsConfiguration = MetricsConfiguration.createDefault(); @@ -109,7 +103,7 @@ public class PantheonCommandTest extends CommandTestAbstract { @Test public void callingHelpDisplaysDefaultRpcApisCorrectly() { parseCommand("--help"); - assertThat(commandOutput.toString()).contains("default: ETH,NET,WEB3,CLIQUE,IBFT"); + assertThat(commandOutput.toString()).contains("default: [ETH, NET, WEB3]"); assertThat(commandErrorOutput.toString()).isEmpty(); } @@ -256,16 +250,12 @@ public class PantheonCommandTest extends CommandTestAbstract { jsonRpcConfiguration.setPort(5678); jsonRpcConfiguration.setCorsAllowedDomains(Collections.emptyList()); jsonRpcConfiguration.setRpcApis(RpcApis.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); final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); metricsConfiguration.setEnabled(false); @@ -358,12 +348,8 @@ public class PantheonCommandTest extends CommandTestAbstract { parseCommand("--config-file", 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); final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();