From 39063332e6f405b086f1068ecbf3a31bd0d967d5 Mon Sep 17 00:00:00 2001 From: Nicolas MASSART Date: Tue, 22 Jan 2019 15:44:54 +0100 Subject: [PATCH 1/5] fixes NC-2104 As toString() is used to display default values in CLI description and this is not used anywhere else for RpcApi objects, it may have benn 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. --- .../pegasys/pantheon/ethereum/jsonrpc/RpcApi.java | 2 +- .../tech/pegasys/pantheon/cli/PantheonCommand.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) 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..f194bb87d9 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 @@ -45,6 +45,6 @@ public int hashCode() { @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 e48ecad7be..78ed1c9767 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -17,12 +17,14 @@ 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; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; +import java.util.Collections; import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; @@ -336,10 +338,9 @@ public static class RpcApisConversionException extends Exception { 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 +372,9 @@ public static class RpcApisConversionException extends Exception { 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; From e5bbd37464c3d4ba0ecb2222595b969eabb7dae0 Mon Sep 17 00:00:00 2001 From: Nicolas MASSART Date: Tue, 22 Jan 2019 15:54:32 +0100 Subject: [PATCH 2/5] 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 benn 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. --- docs/Reference/Pantheon-CLI-Syntax.md | 4 ++-- .../pantheon/ethereum/jsonrpc/RpcApi.java | 1 - .../pegasys/pantheon/cli/PantheonCommand.java | 1 - .../pantheon/cli/PantheonCommandTest.java | 16 +--------------- 4 files changed, 3 insertions(+), 19 deletions(-) diff --git a/docs/Reference/Pantheon-CLI-Syntax.md b/docs/Reference/Pantheon-CLI-Syntax.md index 147ef70e74..9d1d67b67b 100644 --- a/docs/Reference/Pantheon-CLI-Syntax.md +++ b/docs/Reference/Pantheon-CLI-Syntax.md @@ -622,7 +622,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. @@ -701,7 +701,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 f194bb87d9..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 { 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 78ed1c9767..be8a850114 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -24,7 +24,6 @@ import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.DEFAULT_METRICS_PORT; import static tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration.createDefault; -import java.util.Collections; import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; 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 0b46af7481..7c106eaa00 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 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.Wei; @@ -84,13 +82,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(); @@ -107,7 +101,7 @@ public void callingHelpSubCommandMustDisplayUsage() { @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(); } @@ -254,16 +248,12 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException 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); @@ -356,12 +346,8 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce 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(); From 559d176500b7cdb2747efaeaefbb55819c8f1569 Mon Sep 17 00:00:00 2001 From: Nicolas MASSART Date: Tue, 22 Jan 2019 21:31:46 +0100 Subject: [PATCH 3/5] fixes NC-2026 adds a `--network` option instead of separated options Networks are now defined using a `--network` option that takes the cas insensitive name of an enum values as input : MAINNET, OTTOMAN, RINKEBY, ROPSTEN, GOERLI, DEV These presets are a set of network-id, genesis file and boonodes list. If the `--private-genesis-file` is provided with a valid JSON genesis file, Pantheon consider that none of these predefined networks are used and requires user to also set the `--network-id` and `--bootnodes` options. However you can also just override the `--network-id` and `--bootnodes` for a predefined network without having to provide a genesis file. --- docs/Reference/Pantheon-CLI-Syntax.md | 178 +++++++++--------- .../pantheon/cli/DefaultCommandValues.java | 2 +- .../pantheon/cli/EthNetworkConfig.java | 12 ++ .../pegasys/pantheon/cli/NetworkName.java | 3 +- .../pegasys/pantheon/cli/PantheonCommand.java | 127 ++++++------- .../pantheon/cli/StandaloneCommand.java | 7 +- .../pantheon/cli/PantheonCommandTest.java | 142 +++++++++++--- .../src/test/resources/complete_config.toml | 1 + .../src/test/resources/everything_config.toml | 9 +- 9 files changed, 284 insertions(+), 197 deletions(-) diff --git a/docs/Reference/Pantheon-CLI-Syntax.md b/docs/Reference/Pantheon-CLI-Syntax.md index 9d1d67b67b..ee9f53e2f5 100644 --- a/docs/Reference/Pantheon-CLI-Syntax.md +++ b/docs/Reference/Pantheon-CLI-Syntax.md @@ -125,72 +125,12 @@ The path to the Pantheon data directory. The default is the `/build/distribution ### dev-mode !!!important - This option is deprecated in favor of the new `--network` option. - It will be completely removed in the 0.9 release. - -```bash tab="Syntax" ---dev-mode -``` - -```bash tab="Example Configuration File" -dev-mode=true -``` - -Set this option to `true` to run in development mode. -For example, specify this option to perform CPU mining more easily in a private test network. -In development mode, a custom genesis configuration specifies the chain ID. -When using this option, also set the [`--network-id`](#network-id) option to the network you use for development. -Default is `false`. - - -!!!note - The [`--dev-mode`](#dev-mode) option overrides the [`--genesis`](#genesis) option. If both are specified, the development mode configuration is used. - - -### genesis-file - -```bash tab="Syntax" ---genesis-file= -``` - -```bash tab="Example Command Line" ---genesis-file=/home/me/me_node/customGenesisFile.json -``` - -```bash tab="Example Configuration File" -genesis-file="/home/me/me_node/customGenesisFile.json" -``` - -The path to the genesis file. The default is the embedded genesis file for the Ethereum mainnet. -When using this option, it is recommended to also set the [`--network-id`](#network-id) option. - -!!!note - This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#custom-genesis-file). - -!!!note - The [`--genesis`](#genesis) option is overridden by the [`--dev-mode`](#dev-mode) option. - If both are specified, the specified genesis file is ignored and the development mode configuration used. - + This option was removed in favor of the new [`--network`](#network) option. ### goerli !!!important - This option is deprecated in favor of the new `--network` option. - It will be completely removed in the 0.9 release. - -```bash tab="Syntax" ---goerli -``` - -```bash tab="Example Configuration File" -goerli=true -``` - -Uses the Goerli test network. Default is false. - -!!!note - This option is only available from v0.8.3. - + This option was removed in favor of the new [`--network`](#network) option. ### host-whitelist @@ -367,11 +307,49 @@ min-gas-price="1337" The minimum price that a transaction offers for it to be included in a mined block. The default is 1000. -### network-id +### network -!!!important - This option is deprecated in favor of the new `--network` option. - It will be completely removed in the 0.9 release. +```bash tab="Syntax" +--network= +``` + +```bash tab="Example Command Line" +--network=rinkeby +``` + +```bash tab="Example Configuration File" +network="rinkeby" +``` + +Known network predefined configuration. +The default is `mainnet`. + +Possible values are : + +`mainnet` +: Main Ethereum network + +`rinkeby` +: PoA test network using Clique _(only compatible with some clients)_. + +`ropsten` +: PoA test network using Aura _(only compatible with some clients)_. + +`goerli` +: PoA test network using Clique _(compatible with most clients)_. + +`ottoman` +: iBFT 1.0 test network. Pantheon can only synchronise on it but can't validate. + This network configuration doesn't include a genesis file. You have to define + the genesis with your own using [`--private-genesis-file`](#private-genesis-file) option. + +`dev` +: PoW development network with a very low difficulty to enable local CPU mining. + +!!!note + Values are case insensitive, so either `mainnet` or `MAINNET` works. + +### network-id ```bash tab="Syntax" --network-id= @@ -386,7 +364,15 @@ network-id="8675309" ``` P2P network identifier. -The default is set to mainnet with value `1`. + +This option is used in two cases : + +1. **optional**, if you want to override your current [`--network`](#network) option's network id. +1. **required**, if you used the [`--private-genesis-file`](#private-genesis-file) option. + +There's no default value for this option as this value is either required when using +[`--private-genesis-file`](#private-genesis-file) or already defined by the +[`--network`](#network) option predefined configuration. ### no-discovery @@ -454,18 +440,7 @@ Not intended for use with mainnet or public testnets. ### ottoman !!!important - This option is deprecated in favor of the new `--network` option. - It will be completely removed in the 0.9 release. - -```bash tab="Syntax" ---ottoman -``` - -```bash tab="Example Configuration File" -ottoman=true -``` - -Synchronize against the Ottoman test network. This is only useful if you are using an IBFT genesis file. The default is `false`. + This option was removed in favor of the new [`--network`](#network) option. !!!note :construction: IBFT is not currently supported. Support for IBFT is in active development. @@ -512,23 +487,48 @@ The default is 30303. !!!note This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#exposing-ports). -### rinkeby +### private-genesis-file + +Genesis file is used to create a custom network. + +!!!tip + If you need to use one of the well-known networks like Ethereum MainNet, you should use + the [`--network`](#network) option instead. -!!!important - This option is deprecated in favor of the new `--network` option. - It will be completely removed in the 0.9 release. - ```bash tab="Syntax" ---rinkeby +--private-genesis-file= +``` + +```bash tab="Example Command Line" +--private-genesis-file=/home/me/me_node/customGenesisFile.json ``` ```bash tab="Example Configuration File" -rinkeby=true +private-genesis-file="/home/me/me_node/customGenesisFile.json" ``` -Uses the Rinkeby test network. -Default is `false`. - +The path to the genesis file. There's no default for this option. + +!!!important + The [`--private-genesis-file`](#private-genesis-file) option overrides the genesis file + defined in the preset configuration of [`--network`](#network) option. + If both are specified, the [`--private-genesis-file`](#private-genesis-file) option file is + taken in account and the known network one is ignored. + + When using this option, it is required to also set the [`--network-id`](#network-id) + and [`--bootnodes`](#bootnodes) options because using a custom genesis file implies that we don't use + network id and bootnodes of the known network because it would be incompatible with the one we run. + + Error messages at runtime are displayed to remind these options requirements. + +!!!note + This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#custom-genesis-file). + + +### rinkeby + +!!!important + This option was removed in favor of the new [`--network`](#network) option. ### ropsten diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java index 1917063cca..7884426e27 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java @@ -35,7 +35,7 @@ interface DefaultCommandValues { String DEFAULT_DATA_DIR_PATH = "./build/data"; String MANDATORY_INTEGER_FORMAT_HELP = ""; String MANDATORY_MODE_FORMAT_HELP = ""; - String MANDATORY_NETWORK_FORMAT_HELP = ""; + String MANDATORY_NETWORK_FORMAT_HELP = ""; String MANDATORY_NODE_ID_FORMAT_HELP = ""; Wei DEFAULT_MIN_TRANSACTION_GAS_PRICE = Wei.of(1000); BytesValue DEFAULT_EXTRA_DATA = BytesValue.EMPTY; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java index d16d2cd973..ca08904420 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collection; import java.util.Objects; @@ -33,10 +34,13 @@ public class EthNetworkConfig { private static final int RINKEBY_NETWORK_ID = 4; private static final int ROPSTEN_NETWORK_ID = 3; private static final int GOERLI_NETWORK_ID = 6284; + private static final int DEV_NETWORK_ID = 2018; + private static final int OTTOMAN_NETWORK_ID = 5; private static final String MAINNET_GENESIS = "mainnet.json"; private static final String RINKEBY_GENESIS = "rinkeby.json"; private static final String ROPSTEN_GENESIS = "ropsten.json"; private static final String GOERLI_GENESIS = "goerli.json"; + private static final String DEV_GENESIS = "dev.json"; private final String genesisConfig; private final int networkId; private final Collection bootNodes; @@ -113,6 +117,14 @@ public static EthNetworkConfig goerli() { jsonConfig(GOERLI_GENESIS), GOERLI_NETWORK_ID, GOERLI_BOOTSTRAP_NODES); } + public static EthNetworkConfig dev() { + return new EthNetworkConfig(jsonConfig(DEV_GENESIS), DEV_NETWORK_ID, new ArrayList<>()); + } + + public static EthNetworkConfig ottoman() { + return new EthNetworkConfig("", OTTOMAN_NETWORK_ID, new ArrayList<>()); + } + private static String jsonConfig(final String resourceName) { try { URI uri = Resources.getResource(resourceName).toURI(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java index 12ec370726..9096cea429 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java @@ -17,5 +17,6 @@ public enum NetworkName { OTTOMAN, RINKEBY, ROPSTEN, - GOERLI + GOERLI, + DEV } 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 be8a850114..bcc057d077 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -60,7 +60,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Optional; @@ -235,44 +234,6 @@ public static class RpcApisConversionException extends Exception { ) private final NetworkName network = MAINNET; - /** @deprecated Deprecated in favour of --network option */ - @Deprecated - // Boolean option to indicate if the client have to sync against the ottoman test network - // (see https://github.com/ethereum/EIPs/issues/650). - @Option( - names = {"--ottoman"}, - description = - "Synchronize against the Ottoman test network, only useful if using an iBFT genesis file" - + " - see https://github.com/ethereum/EIPs/issues/650 (default: ${DEFAULT-VALUE})" - ) - private final Boolean syncWithOttoman = false; - - /** @deprecated Deprecated in favour of --network option */ - @Deprecated - @Option( - names = {"--rinkeby"}, - description = - "Use the Rinkeby test network" - + " - see https://github.com/ethereum/EIPs/issues/225 (default: ${DEFAULT-VALUE})" - ) - private final Boolean rinkeby = false; - - /** @deprecated Deprecated in favour of --network option */ - @Deprecated - @Option( - names = {"--ropsten"}, - description = "Use the Ropsten test network (default: ${DEFAULT-VALUE})" - ) - private final Boolean ropsten = false; - - /** @deprecated Deprecated in favour of --network option */ - @Deprecated - @Option( - names = {"--goerli"}, - description = "Use the Goerli test network (default: ${DEFAULT-VALUE})" - ) - private final Boolean goerli = false; - @Option( names = {"--p2p-host"}, paramLabel = MANDATORY_HOST_FORMAT_HELP, @@ -290,12 +251,10 @@ public static class RpcApisConversionException extends Exception { ) private final Integer p2pPort = DEFAULT_PORT; - /** @deprecated Deprecated in favour of --network option */ - @Deprecated @Option( names = {"--network-id"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - description = "P2P network identifier (default: ${DEFAULT-VALUE})", + description = "P2P network identifier", arity = "1" ) private final Integer networkId = null; @@ -431,16 +390,6 @@ private Long configureRefreshDelay(final Long refreshDelay) { ) private final JsonRPCWhitelistHostsProperty hostsWhitelist = new JsonRPCWhitelistHostsProperty(); - /** @deprecated Deprecated in favour of --network option */ - @Deprecated - @Option( - names = {"--dev-mode"}, - description = - "set during development to have a custom genesis with specific chain id " - + "and reduced difficulty to enable CPU mining (default: ${DEFAULT-VALUE})." - ) - private final Boolean isDevMode = false; - @Option( names = {"--logging", "-l"}, paramLabel = "", @@ -525,6 +474,8 @@ public void parse( final CommandLine commandLine = new CommandLine(this); + commandLine.setCaseInsensitiveEnumValuesAllowed(true); + standaloneCommands = new StandaloneCommand(); if (isFullInstantiation()) { @@ -572,13 +523,8 @@ public void run() { "Unable to mine without a valid coinbase. Either disable mining (remove --miner-enabled)" + "or specify the beneficiary of mining (via --miner-coinbase
)"); } - if (trueCount(ropsten, rinkeby, goerli) > 1) { - throw new ParameterException( - new CommandLine(this), - "Unable to connect to multiple networks simultaneously. Specify one of --ropsten, --rinkeby or --goerli"); - } - final EthNetworkConfig ethNetworkConfig = ethNetworkConfig(); + final EthNetworkConfig ethNetworkConfig = ethNetworkConfig(network); PermissioningConfiguration permissioningConfiguration = permissioningConfiguration(); ensureAllBootnodesAreInWhitelist(ethNetworkConfig, permissioningConfiguration); @@ -618,20 +564,16 @@ private void ensureAllBootnodesAreInWhitelist( } } - private static int trueCount(final Boolean... b) { - return (int) Arrays.stream(b).filter(bool -> bool).count(); - } - PantheonController buildController() { try { return controllerBuilder .synchronizerConfiguration(buildSyncConfig()) .homePath(dataDir()) - .ethNetworkConfig(ethNetworkConfig()) - .syncWithOttoman(syncWithOttoman) + .ethNetworkConfig(ethNetworkConfig(network)) + .syncWithOttoman(NetworkName.OTTOMAN.equals(network)) .miningParameters( new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled)) - .devMode(isDevMode) + .devMode(NetworkName.DEV.equals(network)) .nodePrivateKeyFile(getNodePrivateKeyFile()) .metricsSystem(metricsSystem) .build(); @@ -758,17 +700,36 @@ private InetAddress autoDiscoverDefaultIP() { return autoDiscoveredDefaultIP; } - private EthNetworkConfig ethNetworkConfig() { + private EthNetworkConfig ethNetworkConfig(final NetworkName network) { final EthNetworkConfig predefinedNetworkConfig; - if (rinkeby) { - predefinedNetworkConfig = EthNetworkConfig.rinkeby(); - } else if (ropsten) { - predefinedNetworkConfig = EthNetworkConfig.ropsten(); - } else if (goerli) { - predefinedNetworkConfig = EthNetworkConfig.goerli(); - } else { - predefinedNetworkConfig = EthNetworkConfig.mainnet(); + + switch (network) { + case ROPSTEN: + predefinedNetworkConfig = EthNetworkConfig.ropsten(); + break; + case RINKEBY: + predefinedNetworkConfig = EthNetworkConfig.rinkeby(); + break; + case OTTOMAN: + predefinedNetworkConfig = EthNetworkConfig.ottoman(); + if (genesisFile() == null) { + throw new ParameterException( + new CommandLine(this), + "A genesis file must be defined with --private-genesis-file option to use Ottoman network."); + } + break; + case GOERLI: + predefinedNetworkConfig = EthNetworkConfig.goerli(); + break; + case DEV: + predefinedNetworkConfig = EthNetworkConfig.dev(); + break; + case MAINNET: + default: + predefinedNetworkConfig = EthNetworkConfig.mainnet(); + break; } + return updateNetworkConfig(predefinedNetworkConfig); } @@ -776,6 +737,24 @@ private EthNetworkConfig updateNetworkConfig(final EthNetworkConfig ethNetworkCo final EthNetworkConfig.Builder builder = new EthNetworkConfig.Builder(ethNetworkConfig); if (genesisFile() != null) { builder.setGenesisConfig(genesisConfig()); + // if we use a custom genesis, it means that we are not in any of the known networks and even + // if + // some properties of our ustom network are the same as one of the known networks, we can't + // connect to the same bootnodes or with the same network-id. We then ensure that these two + // options are set. + if (networkId == null && bootstrapNodes == null) { + throw new ParameterException( + new CommandLine(this), + "--network-id and --bootnodes option must be defined if --private-genesis-file option is used."); + } else if (networkId == null) { + throw new ParameterException( + new CommandLine(this), + "--network-id option must be defined if --private-genesis-file option is used."); + } else if (bootstrapNodes == null) { + throw new ParameterException( + new CommandLine(this), + "--bootnodes option must be defined if --private-genesis-file option is used."); + } } if (networkId != null) { builder.setNetworkId(networkId); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java index a7b99bf508..54db9f535f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java @@ -37,13 +37,14 @@ class StandaloneCommand implements DefaultCommandValues { // Genesis file path with null default option if the option // is not defined on command line as this default is handled by Runner - // to use mainnet json file from resources - // NOTE: we have no control over default value here. + // to use mainnet json file from resources as indicated in the + // default network option + // Then we have no control over genesis default value here. @CommandLine.Option( names = {"--private-genesis-file"}, paramLabel = MANDATORY_FILE_FORMAT_HELP, description = - "The path to genesis file. Setting this will also override --chain option to be CUSTOM" + "The path to genesis file. Setting this option makes --chain option ignored and requires --network-id to be set." ) final File genesisFile = null; } 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 7c106eaa00..b811d3ea1b 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -281,6 +281,7 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException final EthNetworkConfig networkConfig = new EthNetworkConfig.Builder(EthNetworkConfig.mainnet()) + .setNetworkId(42) .setGenesisConfig(GENESIS_CONFIG_TESTDATA) .setBootNodes(nodes) .build(); @@ -291,8 +292,6 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException // TODO: Re-enable as per NC-1057/NC-1681 // verify(mockSyncConfBuilder).syncMode(ArgumentMatchers.eq(SyncMode.FAST)); - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); } @@ -455,7 +454,8 @@ public void genesisPathOptionMustBeUsed() throws Exception { final ArgumentCaptor networkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); - parseCommand("--private-genesis-file", genesisFile.toString()); + parseCommand( + "--private-genesis-file", genesisFile.toString(), "--bootnodes", "--network-id", "42"); verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); @@ -466,6 +466,52 @@ public void genesisPathOptionMustBeUsed() throws Exception { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void genesisPathOptionRequiresNetworkIdAndBootnodesOptions() throws Exception { + assumeTrue(isFullInstantiation()); + + final Path genesisFile = createFakeGenesisFile(); + + parseCommand("--private-genesis-file", genesisFile.toString()); + + verifyZeroInteractions(mockControllerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains( + "--network-id and --bootnodes option must be defined if --private-genesis-file option is used."); + } + + @Test + public void genesisPathOptionRequiresNetworkIdOptions() throws Exception { + assumeTrue(isFullInstantiation()); + + final Path genesisFile = createFakeGenesisFile(); + + parseCommand("--private-genesis-file", genesisFile.toString(), "--bootnodes"); + + verifyZeroInteractions(mockControllerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains("--network-id option must be defined if --private-genesis-file option is used."); + } + + @Test + public void genesisPathOptionRequiresBootnodesOptions() throws Exception { + assumeTrue(isFullInstantiation()); + + final Path genesisFile = createFakeGenesisFile(); + + parseCommand("--private-genesis-file", genesisFile.toString(), "--network-id", "42"); + + verifyZeroInteractions(mockControllerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains("--bootnodes option must be defined if --private-genesis-file option is used."); + } + @Test public void genesisPathDisabledUnderDocker() { System.setProperty("pantheon.docker", "true"); @@ -726,7 +772,7 @@ public void nodesWhitelistOptionWhichDoesNotIncludeBootnodesMustDisplayError() { @Test public void ropstenWithNodesWhitelistOptionWhichDoesIncludeRopstenBootnodesMustNotDisplayError() { - parseCommand("--ropsten", "--nodes-whitelist", String.join(",", ropstenBootnodes)); + parseCommand("--network", "ropsten", "--nodes-whitelist", String.join(",", ropstenBootnodes)); verify(mockRunnerBuilder) .permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture()); @@ -749,7 +795,7 @@ public void ropstenWithNodesWhitelistOptionWhichDoesIncludeRopstenBootnodesMustN @Test public void ropstenWithNodesWhitelistOptionWhichDoesNotIncludeRopstenBootnodesMustDisplayError() { - parseCommand("--ropsten", "--nodes-whitelist", String.join(",", validENodeStrings)); + parseCommand("--network", "ropsten", "--nodes-whitelist", String.join(",", validENodeStrings)); verifyZeroInteractions(mockRunnerBuilder); @@ -1369,33 +1415,66 @@ public void miningParametersAreCaptured() throws Exception { @Test public void devModeOptionMustBeUsed() throws Exception { - parseCommand("--dev-mode"); + parseCommand("--network", "dev"); + + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); verify(mockControllerBuilder).devMode(eq(true)); + verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.dev()); + assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); } @Test - public void rinkebyValuesAreUsed() throws Exception { - parseCommand("--rinkeby"); + public void ottomanModeOptionMustBeUsed() throws Exception { + final Path genesisFile = createFakeGenesisFile(); + + int networkIdOptionValue = 42; + + parseCommand( + "--network", + "ottoman", + "--private-genesis-file", + genesisFile.toString(), + "--bootnodes", + "--network-id", + String.valueOf(networkIdOptionValue)); final ArgumentCaptor networkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); + verify(mockControllerBuilder).syncWithOttoman(eq(true)); verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); + assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo("genesis_config"); + assertThat(networkArg.getValue().getBootNodes()).isEmpty(); + assertThat(networkArg.getValue().getNetworkId()).isEqualTo(networkIdOptionValue); + assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.rinkeby()); } @Test - public void ropstenValuesAreUsed() throws Exception { - parseCommand("--ropsten"); + public void ottomanModeOptionRequiresGenesisFile() throws Exception { + parseCommand("--network", "ottoman"); + + verifyZeroInteractions(mockControllerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains( + "A genesis file must be defined with --private-genesis-file option to use Ottoman network."); + } + + @Test + public void rinkebyValuesAreUsed() throws Exception { + parseCommand("--network", "rinkeby"); final ArgumentCaptor networkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -1403,14 +1482,15 @@ public void ropstenValuesAreUsed() throws Exception { verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.rinkeby()); + assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.ropsten()); } @Test - public void goerliValuesAreUsed() throws Exception { - parseCommand("--goerli"); + public void ropstenValuesAreUsed() throws Exception { + parseCommand("--network", "ropsten"); final ArgumentCaptor networkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -1418,19 +1498,26 @@ public void goerliValuesAreUsed() throws Exception { verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.ropsten()); + assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.goerli()); } @Test - public void noSeveralNetworkOptions() { - parseCommand("--goerli", "--rinkeby"); + public void goerliValuesAreUsed() throws Exception { + parseCommand("--network", "goerli"); - verifyZeroInteractions(mockRunnerBuilder); + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); + + verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); + verify(mockControllerBuilder).build(); + + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.goerli()); assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).contains("Unable to connect to multiple networks"); + assertThat(commandErrorOutput.toString()).isEmpty(); } @Test @@ -1443,12 +1530,23 @@ public void goerliValuesCanBeOverridden() throws Exception { networkValuesCanBeOverridden("goerli"); } + @Test + public void ropstenValuesCanBeOverridden() throws Exception { + networkValuesCanBeOverridden("ropsten"); + } + + @Test + public void devValuesCanBeOverridden() throws Exception { + networkValuesCanBeOverridden("dev"); + } + private void networkValuesCanBeOverridden(final String network) throws Exception { final Path genesisFile = createFakeGenesisFile(); parseCommand( - "--" + network, + "--network", + network, "--network-id", - "1", + "1234567", "--bootnodes", String.join(",", validENodeStrings), "--private-genesis-file", @@ -1465,7 +1563,7 @@ private void networkValuesCanBeOverridden(final String network) throws Exception assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo("genesis_config"); assertThat(networkArg.getValue().getBootNodes()) .isEqualTo(Stream.of(validENodeStrings).map(URI::create).collect(Collectors.toList())); - assertThat(networkArg.getValue().getNetworkId()).isEqualTo(1); + assertThat(networkArg.getValue().getNetworkId()).isEqualTo(1234567); } @Test diff --git a/pantheon/src/test/resources/complete_config.toml b/pantheon/src/test/resources/complete_config.toml index 394f8217c5..8ac8e97a17 100644 --- a/pantheon/src/test/resources/complete_config.toml +++ b/pantheon/src/test/resources/complete_config.toml @@ -23,6 +23,7 @@ metrics-port=309 # chain private-genesis-file="~/genesis.json" # Path +network-id=42 sync-mode="fast"# should be FAST or FULL (or fast or full) ottoman=false # true means using ottoman testnet if genesys file uses iBFT diff --git a/pantheon/src/test/resources/everything_config.toml b/pantheon/src/test/resources/everything_config.toml index fe1e47fda3..24a38533ee 100644 --- a/pantheon/src/test/resources/everything_config.toml +++ b/pantheon/src/test/resources/everything_config.toml @@ -33,12 +33,7 @@ host-whitelist=["all"] network="MAINNET" private-genesis-file="~/genesis.json" #sync-mode="fast" -ottoman=false -ropsten=false -goerli=false -network-id=303 -rinkeby=false -dev-mode=false +network-id=42 # JSON-RPC rpc-http-enabled=false @@ -63,7 +58,7 @@ metrics-port=309 # Mining miner-enabled=false miner-coinbase="0x0000000000000000000000000000000000000002" -miner-extra-data="Protocol Engineering Group And SYStems" +miner-extra-data="0x444F4E27542050414E4943202120484F444C2C20484F444C2C20484F444C2021" min-gas-price="1" # Permissioning From 9f7d478b8bbd2dca71e1117b994d6d7aeb2ac343 Mon Sep 17 00:00:00 2001 From: Nicolas MASSART Date: Thu, 24 Jan 2019 18:06:42 +0100 Subject: [PATCH 4/5] fixes NC-2026 adds a `--network` option instead of separated options Networks are now defined using a `--network` option that takes the cas insensitive name of an enum values as input : MAINNET, RINKEBY, ROPSTEN, GOERLI, DEV These presets are a set of network-id, genesis file and boonodes list. If the `--genesis-file` is provided with a valid JSON genesis file, Pantheon uses it instead of the default network. An empty bootnodes list is then the default value and network id is the chain id found in the genesis file. `--network-id` and `--bootnodes` options can override these defaults. You can of course also override the `--network-id` and `--bootnodes` for a predefined known network (using `--network`). Also fixes NC-2189 renaming --private-genesis-file to --genesis-file Updated a lot of doc according to the options changes --- .../dsl/node/ThreadPantheonNodeRunner.java | 7 +- .../Accounts-for-Testing.md | 12 +- docs/Configuring-Pantheon/Logging.md | 27 ++- .../NetworkID-And-ChainID.md | 18 +- docs/Configuring-Pantheon/Networking.md | 4 +- .../Passing-JVM-Options.md | 2 +- .../Testing-Developing-Nodes.md | 24 +-- .../Using-Configuration-File.md | 20 ++- docs/Consensus-Protocols/Clique.md | 33 ++-- docs/Consensus-Protocols/IBFT.md | 6 +- docs/Getting-Started/Run-Docker-Image.md | 37 ++-- docs/Getting-Started/Starting-Pantheon.md | 57 ++++--- docs/Reference/JSON-RPC-API-Methods.md | 4 +- docs/Reference/Pantheon-CLI-Syntax.md | 80 +++------ docs/Reference/Using-JSON-RPC-API.md | 4 +- docs/Tutorials/Create-Private-Network.md | 34 ++-- docs/Using-Pantheon/Debugging.md | 4 +- .../pantheon/cli/EthNetworkConfig.java | 45 ++--- .../pegasys/pantheon/cli/NetworkName.java | 1 - .../pegasys/pantheon/cli/PantheonCommand.java | 106 ++++++------ .../pantheon/cli/StandaloneCommand.java | 4 +- .../pantheon/cli/PantheonCommandTest.java | 161 +++++++++--------- .../src/test/resources/complete_config.toml | 2 +- .../src/test/resources/everything_config.toml | 2 +- 24 files changed, 348 insertions(+), 346 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index 15079ebe66..91466c8a8e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.tests.acceptance.dsl.node; -import static tech.pegasys.pantheon.cli.EthNetworkConfig.mainnet; +import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; @@ -55,7 +55,10 @@ public void startNode(final PantheonNode node) { final PantheonControllerBuilder builder = new PantheonControllerBuilder(); final EthNetworkConfig ethNetworkConfig = node.ethNetworkConfig() - .orElse(new EthNetworkConfig.Builder(mainnet()).setNetworkId(NETWORK_ID).build()); + .orElse( + new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(MAINNET)) + .setNetworkId(NETWORK_ID) + .build()); final PantheonController pantheonController; try { pantheonController = diff --git a/docs/Configuring-Pantheon/Accounts-for-Testing.md b/docs/Configuring-Pantheon/Accounts-for-Testing.md index 3ed5609ff2..a6beeaf5ab 100644 --- a/docs/Configuring-Pantheon/Accounts-for-Testing.md +++ b/docs/Configuring-Pantheon/Accounts-for-Testing.md @@ -3,11 +3,13 @@ description: Ethereum accounts used for testing only on private network # Accounts for Testing -You can use existing accounts for testing by including them in the genesis file for a private network. Alternatively, Pantheon provides predefined accounts in development mode. +You can use existing accounts for testing by including them in the genesis file for a private network. +Alternatively, Pantheon provides predefined accounts in development mode. ## Development Mode - When you start Pantheon with the [`--dev-mode`](/Reference/Pantheon-CLI-Syntax/#dev-mode) command line option, the `dev.json` genesis file is used by default. + When you start Pantheon with the [`--network=dev`](../Reference/Pantheon-CLI-Syntax.md#network) + command line option, the `dev.json` genesis file is used by default. The `dev.json` genesis file defines the accounts below that can be used for testing. @@ -15,6 +17,8 @@ You can use existing accounts for testing by including them in the genesis file ## Genesis File -To use existing test accounts, specify the accounts and balances in a genesis file for your test network. For an example of defining accounts in the genesis file, refer to [`dev.json`](https://github.com/PegaSysEng/pantheon/blob/master/config/src/main/resources/dev.json). +To use existing test accounts, specify the accounts and balances in a genesis file for your test network. +For an example of defining accounts in the genesis file, refer to [`dev.json`](https://github.com/PegaSysEng/pantheon/blob/master/config/src/main/resources/dev.json). -Use the [`--genesis`](/Reference/Pantheon-CLI-Syntax/#genesis) command line option to start Pantheon with the genesis file defining the existing accounts. +Use the [`--genesis-file`](../Reference/Pantheon-CLI-Syntax.md#genesis-file) command line option to +start Pantheon with the genesis file defining the existing accounts. diff --git a/docs/Configuring-Pantheon/Logging.md b/docs/Configuring-Pantheon/Logging.md index 57b29f4870..6c58a6e108 100644 --- a/docs/Configuring-Pantheon/Logging.md +++ b/docs/Configuring-Pantheon/Logging.md @@ -15,11 +15,16 @@ Pantheon uses Log4J2 for logging. There are two methods to configure logging beh ## Basic Log Level Setting -Use the [`--logging`](../Reference/Pantheon-CLI-Syntax.md#logging) command line option to specify the logging verbosity. The [`--logging`](../Reference/Pantheon-CLI-Syntax.md#logging) option changes the volume of events displayed in the log. +Use the [`--logging`](../Reference/Pantheon-CLI-Syntax.md#logging) command line option to specify +the logging verbosity. The [`--logging`](../Reference/Pantheon-CLI-Syntax.md#logging) option changes +the volume of events displayed in the log. ## Advanced Custom Logging -You can provide your own logging configuration using the standard Log4J2 configuration mechanisms. For example, the following Log4J2 configuration is the same as the [default configuration](https://github.com/PegaSysEng/pantheon/blob/master/pantheon/src/main/resources/log4j2.xml) except logging of stack traces for exceptions is excluded. +You can provide your own logging configuration using the standard Log4J2 configuration mechanisms. +For example, the following Log4J2 configuration is the same as the +[default configuration](https://github.com/PegaSysEng/pantheon/blob/master/pantheon/src/main/resources/log4j2.xml) +except logging of stack traces for exceptions is excluded. ```xml tab="log4j2.xml" @@ -41,12 +46,18 @@ You can provide your own logging configuration using the standard Log4J2 configu ``` -To use your custom configuration, set the environment variable `LOG4J_CONFIGURATION_FILE` to the location of your configuration file. +To use your custom configuration, set the environment variable `LOG4J_CONFIGURATION_FILE` to the +location of your configuration file. -If you have more specific requirements, you can create your own [log4j2 configuration](https://logging.apache.org/log4j/2.x/manual/configuration.html). +If you have more specific requirements, you can create your own +[log4j2 configuration](https://logging.apache.org/log4j/2.x/manual/configuration.html). -For Bash-based executions, you can set the variable for only the scope of the program execution by setting it before starting Pantheon. For example, to set the debug logging and start Pantheon connected to the Rinkeby testnet: +For Bash-based executions, you can set the variable for only the scope of the program execution by +setting it before starting Pantheon. -```bash -$ LOG4J_CONFIGURATION_FILE=./debug.xml bin/pantheon --rinkeby -``` \ No newline at end of file +!!!example + To set the debug logging and start Pantheon connected to the Rinkeby testnet: + + ```bash + $ LOG4J_CONFIGURATION_FILE=./debug.xml bin/pantheon --network=rinkeby + ``` \ No newline at end of file diff --git a/docs/Configuring-Pantheon/NetworkID-And-ChainID.md b/docs/Configuring-Pantheon/NetworkID-And-ChainID.md index bc6a186243..e087a7ad6f 100644 --- a/docs/Configuring-Pantheon/NetworkID-And-ChainID.md +++ b/docs/Configuring-Pantheon/NetworkID-And-ChainID.md @@ -3,11 +3,21 @@ description: Pantheon network ID and chain ID implementation # Network ID and Chain ID -Ethereum networks have a **network ID** and a **chain ID**. The network ID is specified using the [`--network-id`](../Reference/Pantheon-CLI-Syntax.md#network-id) option and the chain ID is specified in the genesis file. +Ethereum networks have a **network ID** and a **chain ID**. The network ID can be specified using the +[`--network-id`](../Reference/Pantheon-CLI-Syntax.md#network-id) option and the chain ID is specified +in the genesis file. -For most networks including mainnet and the public testnets, the network ID and the chain ID are the same. +For most networks including MainNet and the public testnets, the network ID and the chain ID are the +same and Pantheon network id default values are defined according to the genesis chain id value. -The network ID is automatically set by Pantheon when connecting to the Ethereum mainnet ==1==, Rinkeby ==4==, and Ropsten ==3==. +The network ID is then automatically set by Pantheon to the chain id when connecting to the Ethereum networks: -When using the [`--dev-mode`](../Reference/Pantheon-CLI-Syntax.md#dev-mode) or [`--genesis`](../Reference/Pantheon-CLI-Syntax.md#genesis) options, specify the network ID using the [`--network-id`](../Reference/Pantheon-CLI-Syntax.md#network-id) option. +- **MainNet:** chain-id ==1==, network-id ==1== +- **Rinkeby:** chain-id ==4==, network-id ==4== +- **Ropsten:** chain-id ==3==, network-id ==3== +- **Dev:** chain-id ==2018==, network-id ==2018== + +When using the [`--network=dev`](../Reference/Pantheon-CLI-Syntax.md#network) or +[`--genesis-file`](../Reference/Pantheon-CLI-Syntax.md#genesis-file) options, you can override the +network ID using the [`--network-id`](../Reference/Pantheon-CLI-Syntax.md#network-id) option. diff --git a/docs/Configuring-Pantheon/Networking.md b/docs/Configuring-Pantheon/Networking.md index 884034f854..ffc8a6deac 100644 --- a/docs/Configuring-Pantheon/Networking.md +++ b/docs/Configuring-Pantheon/Networking.md @@ -20,7 +20,9 @@ If connections are not getting through the firewalls, ensure the peer discovery ## Peer Discovery Port -The [`--p2p-listen`](../Reference/Pantheon-CLI-Syntax.md#p2p-listen) option specifies the host and port on which P2P peer discovery listens. The default is ==127.0.0.1:30303==. +The [`--p2p-host`](../Reference/Pantheon-CLI-Syntax.md#p2p-host) and [`--p2p-port`](../Reference/Pantheon-CLI-Syntax.md#p2p-port) +options specifies the host and port on which P2P peer discovery listens. The default is ==127.0.0.1== +for host and ==30303== for port. ## Limiting Peers diff --git a/docs/Configuring-Pantheon/Passing-JVM-Options.md b/docs/Configuring-Pantheon/Passing-JVM-Options.md index fdcdfa2a5a..482c718267 100644 --- a/docs/Configuring-Pantheon/Passing-JVM-Options.md +++ b/docs/Configuring-Pantheon/Passing-JVM-Options.md @@ -12,5 +12,5 @@ For Bash-based executions, you can set the variable for only the scope of the pr !!! example ```bash $ PANTHEON_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 \ - $ bin/pantheon --rinkeby + $ bin/pantheon --network=rinkeby ``` \ No newline at end of file diff --git a/docs/Configuring-Pantheon/Testing-Developing-Nodes.md b/docs/Configuring-Pantheon/Testing-Developing-Nodes.md index 08672e4200..0b4a0e2866 100644 --- a/docs/Configuring-Pantheon/Testing-Developing-Nodes.md +++ b/docs/Configuring-Pantheon/Testing-Developing-Nodes.md @@ -21,41 +21,45 @@ To start a bootnode for a private network: !!! example ```bash - pantheon --genesis=privateNetworkGenesis.json --datadir=nodeDataDir export-pub-key bootnode + pantheon --genesis-file=privateNetworkGenesis.json --data-path=nodeDataPath export-pub-key bootnode ``` - Where `privateNetworkGenesis.json` and `nodeDataDir` are changed to the relevant values for + Where `privateNetworkGenesis.json` and `nodeDataPath` are changed to the relevant values for your private network. The node public key is exported to the `bootnode` file. 2. Start the bootnode, specifying: - * No arguments for the [`--bootnodes` option](../Reference/Pantheon-CLI-Syntax.md#bootnodes) because this is the bootnode. - * Network ID for your private network. * Genesis file and data directory as in the previous step. !!! example ``` - pantheon --bootnodes --genesis=privateNetworkGenesis.json --datadir=nodeDataDir --network-id 123 + pantheon --genesis-file=privateNetworkGenesis.json --data-path=nodeDataPath ``` -To specify this bootnode for another node, the enode URL for the `--bootnodes` option is `enode://@` where: +To specify this bootnode for another node, the enode URL for the [`--bootnodes`](../Reference/Pantheon-CLI-Syntax.md#bootnodes) +option is `enode://@` where: * `` is the node public key written to the specified file (`bootnode` in the above example) excluding the initial 0x. -* `` is the host and port the bootnode is listening on for P2P peer discovery. Specified by the `--p2p-listen` option for the bootnode (default is `127.0.0.1:30303`). +* `` is the host and port the bootnode is listening on for P2P peer discovery. +Specified by the [`--p2p-host` option](../Reference/Pantheon-CLI-Syntax.md#p2p-host) and +[`--p2p-port` option](../Reference/Pantheon-CLI-Syntax.md#p2p-port) option for the bootnode +(default host is `127.0.0.1` and port is `30303`). !!! example - If the `--p2p-listen` option is not specified and the node public key exported is `0xc35c3ec90a8a51fd5703594c6303382f3ae6b2ecb9589bab2c04b3794f2bc3fc2631dabb0c08af795787a6c004d8f532230ae6e9925cbbefb0b28b79295d615f` + If the [`--p2p-host`](../Reference/Pantheon-CLI-Syntax.md#p2p-host) or [`--p2p-port`](../Reference/Pantheon-CLI-Syntax.md#p2p-port) options are not specified and the node public key exported is `0xc35c3ec90a8a51fd5703594c6303382f3ae6b2ecb9589bab2c04b3794f2bc3fc2631dabb0c08af795787a6c004d8f532230ae6e9925cbbefb0b28b79295d615f` The enode URL is: `enode://c35c3ec90a8a51fd5703594c6303382f3ae6b2ecb9589bab2c04b3794f2bc3fc2631dabb0c08af795787a6c004d8f532230ae6e9925cbbefb0b28b79295d615f@127.0.0.1:30303` !!! info - The default host and port for P2P peer discovery is `127.0.0.1:30303`. Use the `--p2p-listen` option to specify a host and port. + The default host and port for P2P peer discovery is `127.0.0.1:30303`. + Use the [`--p2p-host`](../Reference/Pantheon-CLI-Syntax.md#p2p-host) and + [`--p2p-port`](../Reference/Pantheon-CLI-Syntax.md#p2p-port) option to specify a host and port. To start a node specifying the bootnode for P2P discovery: !!! example ```bash - pantheon --genesis=privateNetworkGenesis.json --datadir=nodeDataDir --p2p-listen=127.0.0.1:30301 --network-id=123 --bootnodes=enode://c35c3ec90a8a51fd5703594c6303382f3ae6b2ecb99bab2c04b3794f2bc3fc2631dabb0c08af795787a6c004d8f532230ae6e9925cbbefb0b28b79295d615f@127.0.0.1:30303 + pantheon --genesis-file=privateNetworkGenesis.json --data-path=nodeDataPath --p2p-host=127.0.0.1 --p2p-port=30301 --network-id=123 --bootnodes=enode://c35c3ec90a8a51fd5703594c6303382f3ae6b2ecb99bab2c04b3794f2bc3fc2631dabb0c08af795787a6c004d8f532230ae6e9925cbbefb0b28b79295d615f@127.0.0.1:30303 ``` \ No newline at end of file diff --git a/docs/Configuring-Pantheon/Using-Configuration-File.md b/docs/Configuring-Pantheon/Using-Configuration-File.md index 676c3b1070..0f02cb5816 100644 --- a/docs/Configuring-Pantheon/Using-Configuration-File.md +++ b/docs/Configuring-Pantheon/Using-Configuration-File.md @@ -3,7 +3,7 @@ To specify command line options in a file, use a TOML configuration file. The configuration file can be saved and reused across node startups. To specify the configuration file, -use the [`--config` option](../Reference/Pantheon-CLI-Syntax.md#config). +use the [`--config-file` option](../Reference/Pantheon-CLI-Syntax.md#config). To override an option specified in the configuration file, specify the same option on the command line. When an option is specified in both places, Pantheon is started with the command line value. @@ -25,17 +25,23 @@ Specific differences between the command line and the TOML file format are: !!!example "Example TOML configuration file" ```toml # Valid TOML config file - datadir="~/pantheondata" # Path + data-path="~/pantheondata" # Path # Network bootnodes=["enode://001@123:4567", "enode://002@123:4567", "enode://003@123:4567"] - p2p-listen="1.2.3.4:1234" # IP:port + + p2p-host="1.2.3.4" + p2p-port=1234 max-peers=42 - rpc-listen="5.6.7.8:5678" # IP:port - ws-listen="9.10.11.12:9101" # IP:port + + rpc-http-host="5.6.7.8" + rpc-http-port=5678 + + rpc-ws-host="9.10.11.12" + rpc-ws-port=9101 # Chain - genesis="~/genesis.json" # Path to the custom genesis file + genesis-file="~/genesis.json" # Path to the custom genesis file # Mining miner-enabled=true @@ -44,5 +50,5 @@ Specific differences between the command line and the TOML file format are: !!!example "Starting Pantheon with a Configuration File" ```bash - pantheon --config=/home/me/me_node/config.toml + pantheon --config-file=/home/me/me_node/config.toml ``` diff --git a/docs/Consensus-Protocols/Clique.md b/docs/Consensus-Protocols/Clique.md index b2999a2d02..e6141673db 100644 --- a/docs/Consensus-Protocols/Clique.md +++ b/docs/Consensus-Protocols/Clique.md @@ -5,13 +5,17 @@ source: rinkeby.json # Clique -Pantheon implements the Clique Proof-of-Authority (PoA) consensus protocol. Clique is used by the Rinkeby testnet and can be used for private networks. +Pantheon implements the Clique Proof-of-Authority (PoA) consensus protocol. Clique is used by the +Rinkeby testnet and can be used for private networks. -In Clique networks, transactions and blocks are validated by approved accounts, known as signers. Signers take turns to create the next block. Existing signers propose and vote to add or remove signers. +In Clique networks, transactions and blocks are validated by approved accounts, known as signers. +Signers take turns to create the next block. Existing signers propose and vote to add or remove signers. ## Genesis File -To use Clique in a private network, Pantheon requires a Clique genesis file. When connecting to Rinkeby, Pantheon uses the [`rinkeby.json`](https://github.com/PegaSysEng/pantheon/blob/master/config/src/main/resources/rinkeby.json) genesis file in the `/pantheon/config/src/main/resources` directory. +To use Clique in a private network, Pantheon requires a Clique genesis file. When connecting to Rinkeby, +Pantheon uses the [`rinkeby.json`](https://github.com/PegaSysEng/pantheon/blob/master/config/src/main/resources/rinkeby.json) +genesis file in the `/pantheon/config/src/main/resources` directory. A PoA genesis file defines properties specific to Clique: @@ -37,14 +41,17 @@ The properties specific to Clique are: * `epoch` - Number of blocks after which to reset all votes. * `extraData` - Initial signers are specified after the 32 bytes reserved for vanity data. -To connect to the Rinkeby testnet, start Pantheon with the [`--rinkeby`](../Reference/Pantheon-CLI-Syntax.md#rinkeby) command line option. To start a node on a Clique private network, use the [`--genesis`](../Reference/Pantheon-CLI-Syntax.md#genesis`) option to specify the custom genesis file. +To connect to the Rinkeby testnet, start Pantheon with the [`--network=rinkeby`](../Reference/Pantheon-CLI-Syntax.md#network) +command line option. To start a node on a Clique private network, use the +[`--genesis-file`](../Reference/Pantheon-CLI-Syntax.md#genesis-file) option to specify the custom genesis file. ## Adding and Removing Signers To propose adding or removing signers using the JSON-RPC methods, enable the HTTP interface -using [`--rpc-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-enabled) or WebSockets interface using -[`--ws-enabled`](../Reference/Pantheon-CLI-Syntax.md#ws-enabled). If also using the [`--rpc-api`](../Reference/Pantheon-CLI-Syntax.md#rpc-api) - or [`--ws-api`](../Reference/Pantheon-CLI-Syntax.md#ws-api) options, include `CLIQUE`. +using [`--rpc-http-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-enabled) or WebSockets interface using +[`--rpc-ws-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-enabled). If also using the +[`--rpc-api`](../Reference/Pantheon-CLI-Syntax.md#rpc-api) +or [`--ws-api`](../Reference/Pantheon-CLI-Syntax.md#ws-api) options, include `CLIQUE`. The JSON-RPC methods to add or remove signers are: @@ -60,9 +67,11 @@ To propose adding a signer, call `clique_propose` specifying the address of the When the next block is created by the signer, a vote is added to the block for the proposed signer. -When more than half of the existing signers propose adding the signer and their votes have been distributed in blocks, the signer is added and can begin signing blocks. +When more than half of the existing signers propose adding the signer and their votes have been +distributed in blocks, the signer is added and can begin signing blocks. -Use `clique_getSigners` to return a list of the signers and to confirm that your proposed signer has been added. +Use `clique_getSigners` to return a list of the signers and to confirm that your proposed signer has +been added. !!! example "JSON-RPC clique_getSigners Request Example" ```bash curl -X POST --data '{"jsonrpc":"2.0","method":"clique_getSigners","params":["latest"], "id":1}' @@ -74,11 +83,13 @@ To discard your proposal after confirming the signer was added, call `clique_dis curl -X POST --data '{"jsonrpc":"2.0","method":"clique_discard","params":["0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73"], "id":1}' ``` -The process for removing a signer is the same as adding a signer except you specify `false` as the second parameter of `clique_propose`. +The process for removing a signer is the same as adding a signer except you specify `false` as the +second parameter of `clique_propose`. ### Epoch Transition -At each epoch transition, all pending votes collected from received blocks are discarded. Existing proposals remain in effect and signers re-add their vote the next time they create a block. +At each epoch transition, all pending votes collected from received blocks are discarded. +Existing proposals remain in effect and signers re-add their vote the next time they create a block. Define the number of blocks between epoch transitions in the genesis file. diff --git a/docs/Consensus-Protocols/IBFT.md b/docs/Consensus-Protocols/IBFT.md index 6e8341de82..245a88f598 100644 --- a/docs/Consensus-Protocols/IBFT.md +++ b/docs/Consensus-Protocols/IBFT.md @@ -71,13 +71,13 @@ Properties that have specific values in IBFT 2.0 genesis files are: * `difficulty` - `0x1` * `mixHash` - `0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365` for Istanbul block identification. -To start a node on an IBFT 2.0 private network, use the [`--genesis`](../Reference/Pantheon-CLI-Syntax.md#genesis`) option to specify the custom genesis file. +To start a node on an IBFT 2.0 private network, use the [`--genesis-file`](../Reference/Pantheon-CLI-Syntax.md#genesis-file`) option to specify the custom genesis file. ## Adding and Removing Validators To propose adding or removing validators using the JSON-RPC methods, enable the HTTP interface -using [`--rpc-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-enabled) or WebSockets interface using -[`--ws-enabled`](../Reference/Pantheon-CLI-Syntax.md#ws-enabled). If also using the [`--rpc-api`](../Reference/Pantheon-CLI-Syntax.md#rpc-api) +using [`--rpc-http-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-enabled) or WebSockets interface using +[`--rpc-ws-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-enabled). If also using the [`--rpc-api`](../Reference/Pantheon-CLI-Syntax.md#rpc-api) or [`--ws-api`](../Reference/Pantheon-CLI-Syntax.md#ws-api) options, include `IBFT`. The JSON-RPC methods to add or remove validators are: diff --git a/docs/Getting-Started/Run-Docker-Image.md b/docs/Getting-Started/Run-Docker-Image.md index c97af780d0..e4acdf8087 100644 --- a/docs/Getting-Started/Run-Docker-Image.md +++ b/docs/Getting-Started/Run-Docker-Image.md @@ -47,29 +47,32 @@ docker run pegasyseng/pantheon:latest !!!attention You cannot use the following Pantheon command line options when running Pantheon from the Docker image: - * [`--datadir`](../Reference/Pantheon-CLI-Syntax.md#datadir), see [Persisting Data](#persisting-data) - * [`--config`](../Reference/Pantheon-CLI-Syntax.md#config), see [Custom Configuration File](#custom-configuration-file) - * [`--genesis`](../Reference/Pantheon-CLI-Syntax.md#genesis), see [Custom Genesis File](#custom-genesis-file). - * [`--rpc-listen`](../Reference/Pantheon-CLI-Syntax.md#rpc-listen), [`--p2plisten`](../Reference/Pantheon-CLI-Syntax.md#p2plisten), [`--ws-listen`](../Reference/Pantheon-CLI-Syntax.md#ws-listen), see [Exposing Ports](#exposing-ports) + * [`--data-path`](../Reference/Pantheon-CLI-Syntax.md#data-path), see [Persisting Data](#persisting-data) + * [`--config-file`](../Reference/Pantheon-CLI-Syntax.md#config), see [Custom Configuration File](#custom-configuration-file) + * [`--genesis-file`](../Reference/Pantheon-CLI-Syntax.md#genesis-file), see [Custom Genesis File](#custom-genesis-file). + * [`--rpc-http-host`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-host) and [`--rpc-http-port`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-port), + [`--p2p-host`](../Reference/Pantheon-CLI-Syntax.md#p2p-host) and [`--p2p-port`](../Reference/Pantheon-CLI-Syntax.md#p2p-port), + [`--rpc-ws-host`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-host) and [`--rpc-ws-port`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-port), + see [Exposing Ports](#exposing-ports) All other [Pantheon command line options](/Reference/Pantheon-CLI-Syntax) work in the same way as when Pantheon is installed locally. ### Data Directory -Specify a Docker volume for the data directory. This is the equivalent of specifying the [`--datadir`](../Reference/Pantheon-CLI-Syntax.md#datadir) option. +Specify a Docker volume for the data directory. This is the equivalent of specifying the [`--data-path`](../Reference/Pantheon-CLI-Syntax.md#data-path) option. To run Pantheon specifying a volume for the data directory: ```bash -docker run --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest +docker run --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest ``` -Where `` is the volume to which the data is saved. +Where `` is the volume to which the data is saved. ### Custom Configuration File -Specify a custom configuration file to provide a file containing key/value pairs for command line options. This is the equivalent of specifying the [`--config`](../Reference/Pantheon-CLI-Syntax.md#config) option. +Specify a custom configuration file to provide a file containing key/value pairs for command line options. This is the equivalent of specifying the [`--config-file`](../Reference/Pantheon-CLI-Syntax.md#config-file) option. To run Pantheon specifying a custom configuration file: ```bash @@ -85,7 +88,7 @@ Where `myconf.toml` is your custom configuration file and `path` is the absolute ### Custom Genesis File -Specify a custom genesis file to configure the blockchain. This is equivalent to specifying the `--genesis` option. +Specify a custom genesis file to configure the blockchain. This is equivalent to specifying the `--genesis-file` option. To run Pantheon specifying a custom genesis file: ```bash @@ -102,18 +105,18 @@ Where `mygenesis.json` is your custom configuration file and `path` is the absol ### Exposing Ports Expose ports for P2P peer discovery, JSON-RPC service, and WebSockets. This is required to use the -defaults ports or specify different ports (the equivalent of specifying the [`--rpc-listen`](../Reference/Pantheon-CLI-Syntax.md#rpc-listen), -[`--p2p-listen`](../Reference/Pantheon-CLI-Syntax.md#p2p-listen), [`--ws-listen`](../Reference/Pantheon-CLI-Syntax.md#ws-listen) options). +defaults ports or specify different ports (the equivalent of specifying the [`--rpc-http-port`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-port), +[`--p2p-port`](../Reference/Pantheon-CLI-Syntax.md#p2p-port), [`--rpc-ws-port`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-port) options). To run Pantheon exposing local ports for access: ```bash -$ docker run -p :8545 -p :8546 -p :30303 pegasyseng/pantheon:latest --rpc-enabled --ws-enabled +$ docker run -p :8545 -p :8546 -p :30303 pegasyseng/pantheon:latest --rpc-http-enabled --rpc-ws-enabled ``` !!!example To enable RPC calls to http://127.0.0.1:8545 and P2P discovery on http://127.0.0.1:13001: ```bash - docker run -p 8545:8545 -p 13001:30303 pegasyseng/pantheon:latest --rpc-enabled + docker run -p 8545:8545 -p 13001:30303 pegasyseng/pantheon:latest --rpc-http-enabled ``` ## Starting Pantheon @@ -128,7 +131,7 @@ docker run -p 30303:30303 --mount type=bind,source=/,target=/ To run a node on mainnet with the HTTP JSON-RPC service enabled: ```bash -docker run -p 8545:8545 -p 30303:30303 --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest --rpc-enabled +docker run -p 8545:8545 -p 30303:30303 --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest --rpc-http-enabled ``` ## Run a Node on Ropsten Testnet @@ -137,21 +140,21 @@ Save a local copy of the [Ropsten genesis file](https://github.com/PegaSysEng/pa To run a node on Ropsten: ```bash -docker run -p 30303:30303 --mount type=bind,source=/,target=/var/lib/pantheon --mount type=bind,source=//ropsten.json,target=/etc/pantheon/genesis.json pegasyseng/pantheon:latest --network-id=3 --bootnodes=enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303,enode://94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09@192.81.208.223:30303 +docker run -p 30303:30303 --mount type=bind,source=/,target=/var/lib/pantheon --network=ropsten ``` ## Run a Node on Rinkeby Testnet To run a node on Rinkeby: ```bash -docker run -p 30303:30303 --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest --rinkeby +docker run -p 30303:30303 --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest --network=rinkeby ``` ## Run a Node for Testing To run a node that mines blocks at a rate suitable for testing purposes with WebSockets enabled: ```bash -docker run -p 8546:8546 --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest --dev-mode --bootnodes= --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-cors-origins "all" --ws-enabled +docker run -p 8546:8546 --mount type=bind,source=/,target=/var/lib/pantheon pegasyseng/pantheon:latest --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-http-cors-origins "all" --rpc-ws-enabled --network=dev ``` ## Stopping Pantheon and Cleaning up Resources diff --git a/docs/Getting-Started/Starting-Pantheon.md b/docs/Getting-Started/Starting-Pantheon.md index d2c2c14707..4aadb323cd 100644 --- a/docs/Getting-Started/Starting-Pantheon.md +++ b/docs/Getting-Started/Starting-Pantheon.md @@ -13,7 +13,7 @@ Nodes can connect to the Ethereum mainnet, public testnets such as Ropsten, or p ## Local Block Data When connecting to a network other than the network previously connected to, you must either delete the local block data -or use the [`--datadir`](../Reference/Pantheon-CLI-Syntax.md#datadir) option to specify a different data directory. +or use the [`--data-path`](../Reference/Pantheon-CLI-Syntax.md#data-path) option to specify a different data directory. To delete the local block data, delete the `database` directory in the `pantheon/build/distribution/pantheon-` directory. @@ -22,16 +22,18 @@ To delete the local block data, delete the `database` directory in the `pantheon Pantheon specifies the genesis configuration, and sets the network ID and bootnodes when connecting to [Mainnet](#run-a-node-on-ethereum-mainnet), [Goerli](#run-a-node-on-goerli-testnet), [Rinkeby](#run-a-node-on-rinkeby-testnet), and [Ropsten](#run-a-node-on-ropsten-testnet). -When [`--dev-mode`](../Reference/Pantheon-CLI-Syntax.md#dev-mode) is specified, Pantheon uses the development mode genesis configuration. +When [`--network=dev`](../Reference/Pantheon-CLI-Syntax.md#network) is specified, Pantheon uses the +development mode genesis configuration associated to a low difficulty. +The default bootnodes setting for dev network is to have an empty bootnodes list. The genesis files defining the genesis configurations are in the [Pantheon source files](https://github.com/PegaSysEng/pantheon/tree/master/config/src/main/resources). To define a genesis configuration, create a genesis file (for example, `genesis.json`) and specify the file -using the [`--genesis`](../Reference/Pantheon-CLI-Syntax.md#genesis) option. +using the [`--genesis-file`](../Reference/Pantheon-CLI-Syntax.md#genesis-file) option. ## Confirm Node is Running -If you have started Pantheon with the [`--rpc-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-enabled) option, use [cURL](https://curl.haxx.se/) to +If you have started Pantheon with the [`--rpc-http-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-enabled) option, use [cURL](https://curl.haxx.se/) to call [JSON-RPC API methods](../Reference/JSON-RPC-API-Methods.md) to confirm the node is running. !!!example @@ -67,63 +69,66 @@ call [JSON-RPC API methods](../Reference/JSON-RPC-API-Methods.md) to confirm the To run a node that mines blocks at a rate suitable for testing purposes: ```bash -pantheon --dev-mode --network-id="2018" --bootnodes --miner-enabled --miner-coinbase=0xfe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-cors-origins="all" --host-whitelist="all" --ws-enabled --rpc-enabled --datadir=/tmp/tmpDatdir +pantheon --network=dev --miner-enabled --miner-coinbase=0xfe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-http-cors-origins="all" --host-whitelist="all" --rpc-rpc-ws-enabled --rpc-http-enabled --data-path=/tmp/tmpDatdir ``` -Alternatively, use the following [configuration file](../Configuring-Pantheon/Using-Configuration-File.md) and `--bootnodes` on the command line to start a node with the same options as above: +Alternatively, use the following [configuration file](../Configuring-Pantheon/Using-Configuration-File.md) +on the command line to start a node with the same options as above: ```toml -dev-mode=true -network-id="2018" +network="dev" miner-enabled=true miner-coinbase="0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" rpc-cors-origins=["all"] host-whitelist=["all"] -ws-enabled=true -rpc-enabled=true -datadir="/tmp/tmpDatadir" +rpc-ws-enabled=true +rpc-http-enabled=true +data-path="/tmp/tmpdata-path" ``` -## Run a Node on Ropsten Testnet - !!!note - From v0.8.2, use the [`--ropsten` option](../Reference/Pantheon-CLI-Syntax.md#options) - instead of the following options. For v0.8.1, use the following options. + `--network` option is new from 0.9 + +## Run a Node on Ropsten Testnet To run a node on Ropsten: ```bash -pantheon --network-id=3 --genesis=/pantheon/ethereum/core/src/main/resources/ropsten.json --bootnodes=enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303,enode://94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09@192.81.208.223:30303 +pantheon --network=ropsten ``` To run a node on Ropsten with the HTTP JSON-RPC service enabled and allow Remix to access the node: ```bash -pantheon --rpc-enabled --rpc-cors-origins "http://remix.ethereum.org" --network-id=3 --genesis=/pantheon/ethereum/core/src/main/resources/ropsten.json --bootnodes=enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303,enode://94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09@192.81.208.223:30303 +pantheon --network=ropsten --rpc-http-enabled --rpc-http-cors-origins "http://remix.ethereum.org" ``` -Where `` is the path to the `/pantheon` directory. - +!!!note + `--network` option is new from 0.9 + ## Run a Node on Rinkeby Testnet To run a node on Rinkeby specifying a data directory: ```bash -pantheon --rinkeby --datadir=/rinkebyDataDir +pantheon --network=rinkeby --data-path=/ ``` -Where `` and `` are the path and directory where the Rinkeby chain data is to be saved. +Where `` and `` are the path and directory where the Rinkeby chain data is to be saved. + +!!!note + `--network` option is new from 0.9 ## Run a Node on Goerli Testnet To run a node on [Goerli](https://github.com/goerli/testnet) specifying a data directory: ```bash -pantheon --goerli --datadir=/ +pantheon --network=goerli --data-path=/ ``` -Where `` and `` are the path and directory where the Goerli chain data is to be saved. +Where `` and `` are the path and directory where the Goerli chain data is to be saved. !!!note - This option is only available from v0.8.3. + `--network` option is new from 0.9 ## Run a Node on Ethereum Mainnet @@ -133,8 +138,8 @@ To run a node on the Ethereum mainnet: pantheon ``` -To run a node on mainnet with the HTTP JSON-RPC service enabled: +To run a node on mainnet with the HTTP JSON-RPC service enabled and available for localhost only: ```bash -pantheon --rpc-enabled +pantheon --rpc-http-enabled ``` diff --git a/docs/Reference/JSON-RPC-API-Methods.md b/docs/Reference/JSON-RPC-API-Methods.md index 70e978ff1d..295e8c5569 100644 --- a/docs/Reference/JSON-RPC-API-Methods.md +++ b/docs/Reference/JSON-RPC-API-Methods.md @@ -320,7 +320,7 @@ You can get the Ethereum account address from a client such as MetaMask or Ether !!!example ```bash - $ bin/pantheon --miner-coinbase="0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" --rpc-enabled + $ bin/pantheon --miner-coinbase="0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" --rpc-http-enabled ``` **Parameters** @@ -2062,7 +2062,7 @@ Lists the validators defined in the specified block. ### ibft_proposeValidatorVote -Proposes [adding or removing a validator]((../Consensus-Protocols/IBFT.md#adding-and-removing-validators)) with the specified address. +Proposes [adding or removing a validator](../Consensus-Protocols/IBFT.md#adding-and-removing-validators)) with the specified address. **Parameters** diff --git a/docs/Reference/Pantheon-CLI-Syntax.md b/docs/Reference/Pantheon-CLI-Syntax.md index 79e8238cbd..88b85cb24f 100644 --- a/docs/Reference/Pantheon-CLI-Syntax.md +++ b/docs/Reference/Pantheon-CLI-Syntax.md @@ -79,12 +79,16 @@ bootnodes=["enode://c35c3...d615f@1.2.3.4:30303","enode://f42c13...fc456@1.2.3.5 List of comma-separated enode URLs for P2P discovery bootstrap. -When connecting to mainnet or public testnets, the default is a predefined list of enode URLs. -Specify bootnodes when connecting to a [private network](../Configuring-Pantheon/Testing-Developing-Nodes.md#bootnodes). +When connecting to MainNet or public testnets, the default is a predefined list of enode URLs. + +On custom networks defined by [`--genesis-file`](#genesis-file) option, +an empty list of bootnodes is defined by default unless you define custom bootnodes as described in +[private network documentation](../Configuring-Pantheon/Testing-Developing-Nodes.md#bootnodes). !!! note - Specifying a node is a [bootnode](../Configuring-Pantheon/Testing-Developing-Nodes.md#bootnodes) - must be done on the command line not in a [configuration file](../Configuring-Pantheon/Using-Configuration-File.md). + Specifying that a node is a [bootnode](../Configuring-Pantheon/Testing-Developing-Nodes.md#bootnodes) + must be done on the command line using [`--bootnodes`](#bootnodes) option without value, + not in a [configuration file](../Configuring-Pantheon/Using-Configuration-File.md). ### config-file @@ -93,7 +97,7 @@ Specify bootnodes when connecting to a [private network](../Configuring-Pantheon ``` ```bash tab="Example Command Line" ---config=/home/me/me_node/config.toml +--config-file=/home/me/me_node/config.toml ``` The path to the [TOML configuration file](../Configuring-Pantheon/Using-Configuration-File.md). @@ -329,20 +333,15 @@ Possible values are : `mainnet` : Main Ethereum network +`ropsten` +: PoW test network similar to current main Ethereum network. + `rinkeby` : PoA test network using Clique _(only compatible with some clients)_. -`ropsten` -: PoA test network using Aura _(only compatible with some clients)_. - `goerli` : PoA test network using Clique _(compatible with most clients)_. -`ottoman` -: Enables accepting of blocks in an IBFT 1.0 network. - This network configuration doesn't include a genesis file. You have to define - the genesis with your own using [`--private-genesis-file`](#private-genesis-file) option. - `dev` : PoW development network with a very low difficulty to enable local CPU mining. @@ -365,14 +364,8 @@ network-id="8675309" P2P network identifier. -This option is used in two cases : - -1. **optional**, if you want to override your current [`--network`](#network) option's network id. -1. **required**, if you used the [`--private-genesis-file`](#private-genesis-file) option. - -There's no default value for this option as this value is either required when using -[`--private-genesis-file`](#private-genesis-file) or already defined by the -[`--network`](#network) option predefined configuration. +This option can be used to override your current network id. +The default value is the current network chain id which is defined in the genesis file. ### no-discovery @@ -440,11 +433,8 @@ Not intended for use with mainnet or public testnets. ### ottoman !!!important - This option was removed in favor of the new [`--network`](#network) option. - -!!!note - A Pantheon node cannot be a validator in an IBFT 1.0 network. Pantheon implements [IBFT 2.0](../Consensus-Protocols/IBFT.md). - + This version is not supporting IBFT Ottoman test network anymore. + ### p2p-host ```bash tab="Syntax" @@ -487,39 +477,34 @@ The default is 30303. !!!note This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#exposing-ports). -### private-genesis-file +### genesis-file Genesis file is used to create a custom network. !!!tip If you need to use one of the well-known networks like Ethereum MainNet, you should use - the [`--network`](#network) option instead. + the [`--network`](#network) option instead as all nodes of a same network have to define the + exact same genesis parameters. ```bash tab="Syntax" ---private-genesis-file= +--genesis-file= ``` ```bash tab="Example Command Line" ---private-genesis-file=/home/me/me_node/customGenesisFile.json +--genesis-file=/home/me/me_node/customGenesisFile.json ``` ```bash tab="Example Configuration File" -private-genesis-file="/home/me/me_node/customGenesisFile.json" +genesis-file="/home/me/me_node/customGenesisFile.json" ``` The path to the genesis file. There's no default for this option. !!!important - The [`--private-genesis-file`](#private-genesis-file) option overrides the genesis file + The [`--genesis-file`](#genesis-file) option overrides the genesis file defined in the preset configuration of [`--network`](#network) option. - If both are specified, the [`--private-genesis-file`](#private-genesis-file) option file is + If both are specified, the [`--genesis-file`](#genesis-file) option file is taken in account and the known network one is ignored. - - When using this option, it is required to also set the [`--network-id`](#network-id) - and [`--bootnodes`](#bootnodes) options because using a custom genesis file implies that we don't use - network id and bootnodes of the known network because it would be incompatible with the one we run. - - Error messages at runtime are displayed to remind these options requirements. !!!note This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#custom-genesis-file). @@ -533,22 +518,7 @@ The path to the genesis file. There's no default for this option. ### ropsten !!!important - This option is deprecated in favor of the new `--network` option. - It will be completely removed in the 0.9 release. - -```bash tab="Syntax" ---ropsten -``` - -```bash tab="Example Configuration File" -ropsten=true -``` - -Uses the Ropsten test network. -Default is `false`. - -!!!note - This option is only available only from v0.8.2. For v0.8.1, refer to [Starting Pantheon](../Getting-Started/Starting-Pantheon.md#run-a-node-on-ropsten-testnet). + This option was removed in favor of the new [`--network`](#network) option. ### rpc-http-enabled diff --git a/docs/Reference/Using-JSON-RPC-API.md b/docs/Reference/Using-JSON-RPC-API.md index 6080f0ca9d..b3748cf722 100644 --- a/docs/Reference/Using-JSON-RPC-API.md +++ b/docs/Reference/Using-JSON-RPC-API.md @@ -33,8 +33,8 @@ In this reference, the placeholder `` and `` means an endpoint (IP address and port) of the JSON-RPC service of a Pantheon node respectively for http endpoint and for WebSocket endpoint. -To activate JSON-RPC using http or WebSocket, see [`--rpc-listen`](../Reference/Pantheon-CLI-Syntax.md#rpc-listen) -and [`--ws-listen`](../Reference/Pantheon-CLI-Syntax.md#ws-listen) options in the CLI documentation. +To activate JSON-RPC using http or WebSocket, see [`--rpc-http-enabled`](../Reference/Pantheon-CLI-Syntax.md#rpc-http-enabled) +and [`--rpc-ws-listen`](../Reference/Pantheon-CLI-Syntax.md#rpc-ws-listen) options in the CLI documentation. The transport attributes are: diff --git a/docs/Tutorials/Create-Private-Network.md b/docs/Tutorials/Create-Private-Network.md index cb879bf080..3264f23a48 100644 --- a/docs/Tutorials/Create-Private-Network.md +++ b/docs/Tutorials/Create-Private-Network.md @@ -35,11 +35,11 @@ Create directories for your private network, each of the three nodes, and a data ```bash Private-Network/ ├── Node-1 -│   ├── Node-1-Datadir +│   ├── Node-1-data-path ├── Node-2 -│   ├── Node-2-Datadir +│   ├── Node-2-data-path └── Node-3 - ├── Node-3-Datadir + ├── Node-3-data-path ``` ### 2. Create Genesis File @@ -89,17 +89,17 @@ In the `Node-1` directory, use the [`export-pub-key` subcommand](../Reference/Pa the [node public key](../Configuring-Pantheon/Node-Keys.md) to the specified file (`publicKeyNode1` in this example): ```bash tab="MacOS" -pantheon --datadir=Node-1-Datadir --genesis=../privateNetworkGenesis.json export-pub-key Node-1-Datadir/publicKeyNode1 +pantheon --data-path=Node-1-data-path --genesis-file=../privateNetworkGenesis.json export-pub-key Node-1-data-path/publicKeyNode1 ``` ```bash tab="Windows" -pantheon --datadir=Node-1-Datadir --genesis=..\privateNetworkGenesis.json export-pub-key Node-1-Datadir\publicKeyNode1 +pantheon --data-path=Node-1-data-path --genesis-file=..\privateNetworkGenesis.json export-pub-key Node-1-data-path\publicKeyNode1 ``` Your node 1 directory now contains: ```bash ├── Node-1 -    ├── Node-1-Datadir +    ├── Node-1-data-path ├── database       ├── key       ├── publicKeyNode1 @@ -114,14 +114,14 @@ Start Node-1 specifying: * No arguments for the [`--bootnodes` option](../Reference/Pantheon-CLI-Syntax.md#bootnodes) because this is your bootnode. * Mining is enabled and the account to which mining rewards are paid using the [`--miner-enabled`](../Reference/Pantheon-CLI-Syntax.md#miner-enabled) and [`--miner-coinbase` options](../Reference/Pantheon-CLI-Syntax.md#miner-coinbase). -* JSON-RPC API is enabled using the [`--rpc-enabled` option](../Reference/Pantheon-CLI-Syntax.md#rpc-enabled). +* JSON-RPC API is enabled using the [`--rpc-http-enabled` option](../Reference/Pantheon-CLI-Syntax.md#rpc-http-enabled). ```bash tab="MacOS" -pantheon --datadir=Node-1-Datadir --genesis=../privateNetworkGenesis.json --bootnodes --network-id 123 --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-enabled +pantheon --data-path=Node-1-data-path --genesis-file=../privateNetworkGenesis.json --bootnodes --network-id 123 --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-http-enabled ``` ```bash tab="Windows" -pantheon --datadir=Node-1-Datadir --genesis=..\privateNetworkGenesis.json --bootnodes --network-id 123 --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-enabled +pantheon --data-path=Node-1-data-path --genesis-file=..\privateNetworkGenesis.json --bootnodes --network-id 123 --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 --rpc-http-enabled ``` !!! info @@ -144,31 +144,31 @@ The enode URL is `enode://@` where: Start another terminal, change to the `Node-2` directory and start Node-2 specifying: -* Different port to Node-1 for P2P peer discovery using the [`--p2p-listen` option](../Reference/Pantheon-CLI-Syntax.md#p2p-listen). +* Different port to Node-1 for P2P peer discovery using the [`--p2p-port` option](../Reference/Pantheon-CLI-Syntax.md#p2p-port). * Enode URL for Node-1 using the [`--bootnodes` option](../Reference/Pantheon-CLI-Syntax.md#bootnodes). -* Data directory for Node-2 using the [`--datadir` option](../Reference/Pantheon-CLI-Syntax.md#datadir). +* Data directory for Node-2 using the [`--data-path` option](../Reference/Pantheon-CLI-Syntax.md#data-path). * Genesis file and network ID as for Node-1. ```bash tab="MacOS" -pantheon --datadir=Node-2-Datadir --genesis=../privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-listen=127.0.0.1:30304 +pantheon --data-path=Node-2-data-path --genesis-file=../privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-port=30304 ``` ```bash tab="Windows" -pantheon --datadir=Node-2-Datadir --genesis=..\privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-listen=127.0.0.1:30304 +pantheon --data-path=Node-2-data-path --genesis-file=..\privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-port=30304 ``` Start another terminal, change to the `Node-3` directory and start Node-3 specifying: * Different port to Node-1 and Node-2 for P2P peer discovery. - * Data directory for Node-3 using the [`--datadir` option](../Reference/Pantheon-CLI-Syntax.md#datadir). + * Data directory for Node-3 using the [`--data-path` option](../Reference/Pantheon-CLI-Syntax.md#data-path). * Bootnode, genesis file, and network ID as for Node-2. ```bash tab="MacOS" -pantheon --datadir=Node-3-Datadir --genesis=../privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-listen=127.0.0.1:30305 +pantheon --data-path=Node-3-data-path --genesis-file=../privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-port30305 ``` ```bash tab="Windows" -pantheon --datadir=Node-3-Datadir --genesis=..\privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-listen=127.0.0.1:30305 +pantheon --data-path=Node-3-data-path --genesis-file=..\privateNetworkGenesis.json --bootnodes="enode://@127.0.0.1:30303" --network-id 123 --p2p-port=30305 ``` ### 6. Confirm Private Network is Working @@ -199,7 +199,7 @@ Send transactions using `eth_sendRawTransaction` to [send ether or, deploy or in Use the [JSON-RPC API](../Reference/Using-JSON-RPC-API.md). -Start a node with the `--ws-enabled` option and use the [RPC Pub/Sub API](../Using-Pantheon/RPC-PubSub.md). +Start a node with the `--rpc-ws-enabled` option and use the [RPC Pub/Sub API](../Using-Pantheon/RPC-PubSub.md). ## Stop Nodes diff --git a/docs/Using-Pantheon/Debugging.md b/docs/Using-Pantheon/Debugging.md index ce4bd86f16..b1bfada1b1 100644 --- a/docs/Using-Pantheon/Debugging.md +++ b/docs/Using-Pantheon/Debugging.md @@ -56,8 +56,8 @@ block of the `prometheus.yml` file: a single node for testing with metrics enabled: ```bash tab="Example" - pantheon --dev-mode --network-id="2018" --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 - --rpc-cors-origins="all" --rpc-enabled --metrics-enabled + pantheon --network=dev --miner-enabled --miner-coinbase fe3b557e8fb62b89f4916b721be55ceb828dbd73 + --rpc-http-cors-origins="all" --rpc-http-enabled --metrics-enabled ``` 4. In another terminal, run Prometheus specifying the `prometheus.yml` file: diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java index ca08904420..b546477123 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java @@ -35,7 +35,6 @@ public class EthNetworkConfig { private static final int ROPSTEN_NETWORK_ID = 3; private static final int GOERLI_NETWORK_ID = 6284; private static final int DEV_NETWORK_ID = 2018; - private static final int OTTOMAN_NETWORK_ID = 5; private static final String MAINNET_GENESIS = "mainnet.json"; private static final String RINKEBY_GENESIS = "rinkeby.json"; private static final String ROPSTEN_GENESIS = "ropsten.json"; @@ -97,32 +96,24 @@ public String toString() { + '}'; } - public static EthNetworkConfig mainnet() { - return new EthNetworkConfig( - jsonConfig(MAINNET_GENESIS), MAINNET_NETWORK_ID, MAINNET_BOOTSTRAP_NODES); - } - - public static EthNetworkConfig rinkeby() { - return new EthNetworkConfig( - jsonConfig(RINKEBY_GENESIS), RINKEBY_NETWORK_ID, RINKEBY_BOOTSTRAP_NODES); - } - - public static EthNetworkConfig ropsten() { - return new EthNetworkConfig( - jsonConfig(ROPSTEN_GENESIS), ROPSTEN_NETWORK_ID, ROPSTEN_BOOTSTRAP_NODES); - } - - public static EthNetworkConfig goerli() { - return new EthNetworkConfig( - jsonConfig(GOERLI_GENESIS), GOERLI_NETWORK_ID, GOERLI_BOOTSTRAP_NODES); - } - - public static EthNetworkConfig dev() { - return new EthNetworkConfig(jsonConfig(DEV_GENESIS), DEV_NETWORK_ID, new ArrayList<>()); - } - - public static EthNetworkConfig ottoman() { - return new EthNetworkConfig("", OTTOMAN_NETWORK_ID, new ArrayList<>()); + public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) { + switch (networkName) { + case ROPSTEN: + return new EthNetworkConfig( + jsonConfig(ROPSTEN_GENESIS), ROPSTEN_NETWORK_ID, ROPSTEN_BOOTSTRAP_NODES); + case RINKEBY: + return new EthNetworkConfig( + jsonConfig(RINKEBY_GENESIS), RINKEBY_NETWORK_ID, RINKEBY_BOOTSTRAP_NODES); + case GOERLI: + return new EthNetworkConfig( + jsonConfig(GOERLI_GENESIS), GOERLI_NETWORK_ID, GOERLI_BOOTSTRAP_NODES); + case DEV: + return new EthNetworkConfig(jsonConfig(DEV_GENESIS), DEV_NETWORK_ID, new ArrayList<>()); + case MAINNET: + default: + return new EthNetworkConfig( + jsonConfig(MAINNET_GENESIS), MAINNET_NETWORK_ID, MAINNET_BOOTSTRAP_NODES); + } } private static String jsonConfig(final String resourceName) { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java index 9096cea429..45e4158550 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java @@ -14,7 +14,6 @@ public enum NetworkName { MAINNET, - OTTOMAN, RINKEBY, ROPSTEN, GOERLI, 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 30dc303671..503bb47e18 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -29,6 +29,7 @@ import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; import tech.pegasys.pantheon.cli.custom.EnodeToURIPropertyConverter; import tech.pegasys.pantheon.cli.custom.JsonRPCWhitelistHostsProperty; +import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.consensus.clique.jsonrpc.CliqueRpcApis; import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftRpcApis; import tech.pegasys.pantheon.controller.KeyPairUtil; @@ -72,6 +73,7 @@ import com.google.common.net.HostAndPort; import com.google.common.net.HostSpecifier; import io.vertx.core.Vertx; +import io.vertx.core.json.DecodeException; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.config.Configurator; import picocli.CommandLine; @@ -184,7 +186,7 @@ public static class RpcApisConversionException extends Exception { arity = "0..*", converter = EnodeToURIPropertyConverter.class ) - private final Collection bootstrapNodes = null; + private final Collection bootNodes = null; @Option( names = {"--max-peers"}, @@ -254,7 +256,8 @@ public static class RpcApisConversionException extends Exception { @Option( names = {"--network-id"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - description = "P2P network identifier", + description = + "P2P network identifier. (default: the selected network chain id or custom genesis chain id)", arity = "1" ) private final Integer networkId = null; @@ -552,7 +555,7 @@ public void run() { Configurator.setAllLevels("", logLevel); } - if (!p2pEnabled && (bootstrapNodes != null && !bootstrapNodes.isEmpty())) { + if (!p2pEnabled && (bootNodes != null && !bootNodes.isEmpty())) { throw new ParameterException( new CommandLine(this), "Unable to specify bootnodes if p2p is disabled."); } @@ -565,7 +568,7 @@ public void run() { + "or specify the beneficiary of mining (via --miner-coinbase
)"); } - final EthNetworkConfig ethNetworkConfig = ethNetworkConfig(network); + final EthNetworkConfig ethNetworkConfig = updateNetworkConfig(network); final PermissioningConfiguration permissioningConfiguration = permissioningConfiguration(); ensureAllBootnodesAreInWhitelist(ethNetworkConfig, permissioningConfiguration); @@ -610,8 +613,8 @@ PantheonController buildController() { return controllerBuilder .synchronizerConfiguration(buildSyncConfig()) .homePath(dataDir()) - .ethNetworkConfig(ethNetworkConfig(network)) - .syncWithOttoman(NetworkName.OTTOMAN.equals(network)) + .ethNetworkConfig(updateNetworkConfig(network)) + .syncWithOttoman(false) // ottoman feature is still there but it's now removed from CLI .miningParameters( new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled)) .devMode(NetworkName.DEV.equals(network)) @@ -753,67 +756,56 @@ private InetAddress autoDiscoverDefaultIP() { return autoDiscoveredDefaultIP; } - private EthNetworkConfig ethNetworkConfig(final NetworkName network) { - final EthNetworkConfig predefinedNetworkConfig; - - switch (network) { - case ROPSTEN: - predefinedNetworkConfig = EthNetworkConfig.ropsten(); - break; - case RINKEBY: - predefinedNetworkConfig = EthNetworkConfig.rinkeby(); - break; - case OTTOMAN: - predefinedNetworkConfig = EthNetworkConfig.ottoman(); - if (genesisFile() == null) { + private EthNetworkConfig updateNetworkConfig(final NetworkName network) { + final EthNetworkConfig.Builder builder = + new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(network)); + + // custom genesis file use comes with specific default values for the genesis file itself + // but also for the network id and the bootnodes list. + File genesisFile = genesisFile(); + if (genesisFile != null) { + builder.setGenesisConfig(genesisConfig()); + + if (networkId == null) { + // if no network id option is defined on the CLI we have to set a default value from the + // genesis file. + // We do the genesis parsing only in this case as we already have network id constants + // for known networks to speed up the process. + // Also we have to parse the genesis as we don't already have a parsed version at this + // stage. + // If no chain id is found in the genesis as it's an optional, we use mainnet network id. + try { + GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig()); + builder.setNetworkId( + genesisConfigFile + .getConfigOptions() + .getChainId() + .orElse(EthNetworkConfig.getNetworkConfig(MAINNET).getNetworkId())); + } catch (DecodeException e) { throw new ParameterException( new CommandLine(this), - "A genesis file must be defined with --private-genesis-file option to use Ottoman network."); + String.format("Unable to parse genesis file %s.", genesisFile), + e); } - break; - case GOERLI: - predefinedNetworkConfig = EthNetworkConfig.goerli(); - break; - case DEV: - predefinedNetworkConfig = EthNetworkConfig.dev(); - break; - case MAINNET: - default: - predefinedNetworkConfig = EthNetworkConfig.mainnet(); - break; - } - return updateNetworkConfig(predefinedNetworkConfig); - } + } - private EthNetworkConfig updateNetworkConfig(final EthNetworkConfig ethNetworkConfig) { - final EthNetworkConfig.Builder builder = new EthNetworkConfig.Builder(ethNetworkConfig); - if (genesisFile() != null) { - builder.setGenesisConfig(genesisConfig()); - // if we use a custom genesis, it means that we are not in any of the known networks and even - // if - // some properties of our ustom network are the same as one of the known networks, we can't - // connect to the same bootnodes or with the same network-id. We then ensure that these two - // options are set. - if (networkId == null && bootstrapNodes == null) { - throw new ParameterException( - new CommandLine(this), - "--network-id and --bootnodes option must be defined if --private-genesis-file option is used."); - } else if (networkId == null) { - throw new ParameterException( - new CommandLine(this), - "--network-id option must be defined if --private-genesis-file option is used."); - } else if (bootstrapNodes == null) { - throw new ParameterException( - new CommandLine(this), - "--bootnodes option must be defined if --private-genesis-file option is used."); + if (bootNodes == null) { + // We default to an empty bootnodes list if the option is not provided on CLI because + // mainnet bootnodes won't work as the default value for a custom genesis, + // so it's better to have an empty list as default value that forces to create a custom one + // than a useless one that may make user think that it can work when it can't. + builder.setBootNodes(new ArrayList<>()); } } + if (networkId != null) { builder.setNetworkId(networkId); } - if (bootstrapNodes != null) { - builder.setBootNodes(bootstrapNodes); + + if (bootNodes != null) { + builder.setBootNodes(bootNodes); } + return builder.build(); } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java index 54db9f535f..cd7dc14070 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java @@ -41,10 +41,10 @@ class StandaloneCommand implements DefaultCommandValues { // default network option // Then we have no control over genesis default value here. @CommandLine.Option( - names = {"--private-genesis-file"}, + names = {"--genesis-file"}, paramLabel = MANDATORY_FILE_FORMAT_HELP, description = - "The path to genesis file. Setting this option makes --chain option ignored and requires --network-id to be set." + "The path to genesis file. Setting this option makes --network option ignored and requires --network-id to be set." ) final File genesisFile = null; } 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 ff8b83c76f..6376528b75 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -21,9 +21,15 @@ import static org.mockito.ArgumentMatchers.isNotNull; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; +import static tech.pegasys.pantheon.cli.NetworkName.DEV; +import static tech.pegasys.pantheon.cli.NetworkName.GOERLI; +import static tech.pegasys.pantheon.cli.NetworkName.MAINNET; +import static tech.pegasys.pantheon.cli.NetworkName.RINKEBY; +import static tech.pegasys.pantheon.cli.NetworkName.ROPSTEN; import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES; import tech.pegasys.pantheon.PantheonInfo; +import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; @@ -52,6 +58,7 @@ import java.util.stream.Stream; import com.google.common.io.Resources; +import io.vertx.core.json.JsonObject; import net.consensys.cava.toml.Toml; import net.consensys.cava.toml.TomlParseResult; import org.apache.commons.text.StringEscapeUtils; @@ -62,6 +69,7 @@ import picocli.CommandLine; public class PantheonCommandTest extends CommandTestAbstract { + private final String ORION_URI = "http://1.2.3.4:5555"; private final String VALID_NODE_ID = "6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"; @@ -69,7 +77,12 @@ public class PantheonCommandTest extends CommandTestAbstract { private static final JsonRpcConfiguration defaultJsonRpcConfiguration; private static final WebSocketConfiguration defaultWebSocketConfiguration; private static final MetricsConfiguration defaultMetricsConfiguration; - private static final String GENESIS_CONFIG_TESTDATA = "genesis_config"; + private static final int GENESIS_CONFIG_TEST_CHAINID = 3141592; + private static final JsonObject GENESIS_VALID_JSON = + (new JsonObject()) + .put("config", (new JsonObject()).put("chainId", GENESIS_CONFIG_TEST_CHAINID)); + private static final JsonObject GENESIS_INVALID_DATA = + (new JsonObject()).put("config", new JsonObject()); private final String[] validENodeStrings = { "enode://" + VALID_NODE_ID + "@192.168.0.1:4567", @@ -237,7 +250,7 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException assumeTrue(isFullInstantiation()); final URL configFile = Resources.getResource("complete_config.toml"); - final Path genesisFile = createFakeGenesisFile(); + final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); final String updatedConfig = Resources.toString(configFile, UTF_8) .replace("~/genesis.json", escapeTomlString(genesisFile.toString())); @@ -282,9 +295,9 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException assertThat(uriListArgumentCaptor.getValue()).isEqualTo(nodes); final EthNetworkConfig networkConfig = - new EthNetworkConfig.Builder(EthNetworkConfig.mainnet()) + new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(MAINNET)) .setNetworkId(42) - .setGenesisConfig(GENESIS_CONFIG_TESTDATA) + .setGenesisConfig(encodeJsonGenesis(GENESIS_VALID_JSON)) .setBootNodes(nodes) .build(); verify(mockControllerBuilder).homePath(eq(Paths.get("~/pantheondata"))); @@ -452,66 +465,81 @@ public void dataDirDefaultedUnderDocker() { public void genesisPathOptionMustBeUsed() throws Exception { assumeTrue(isFullInstantiation()); - final Path genesisFile = createFakeGenesisFile(); + final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); final ArgumentCaptor networkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); - parseCommand( - "--private-genesis-file", genesisFile.toString(), "--bootnodes", "--network-id", "42"); + parseCommand("--genesis-file", genesisFile.toString()); verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); - assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo("genesis_config"); + assertThat(networkArg.getValue().getGenesisConfig()) + .isEqualTo(encodeJsonGenesis(GENESIS_VALID_JSON)); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); } @Test - public void genesisPathOptionRequiresNetworkIdAndBootnodesOptions() throws Exception { + public void defaultNetworkIdAndBootnodesForCustomNetworkOptions() throws Exception { assumeTrue(isFullInstantiation()); - final Path genesisFile = createFakeGenesisFile(); + final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); - parseCommand("--private-genesis-file", genesisFile.toString()); + parseCommand("--genesis-file", genesisFile.toString()); - verifyZeroInteractions(mockControllerBuilder); + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); + + verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); + verify(mockControllerBuilder).build(); + + assertThat(networkArg.getValue().getGenesisConfig()) + .isEqualTo(encodeJsonGenesis(GENESIS_VALID_JSON)); + assertThat(networkArg.getValue().getBootNodes()).isEmpty(); + assertThat(networkArg.getValue().getNetworkId()).isEqualTo(GENESIS_CONFIG_TEST_CHAINID); assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains( - "--network-id and --bootnodes option must be defined if --private-genesis-file option is used."); + assertThat(commandErrorOutput.toString()).isEmpty(); } @Test - public void genesisPathOptionRequiresNetworkIdOptions() throws Exception { + public void defaultNetworkIdForInvalidGenesisMustBeMainnetNetworkId() throws Exception { assumeTrue(isFullInstantiation()); - final Path genesisFile = createFakeGenesisFile(); + final Path genesisFile = createFakeGenesisFile(GENESIS_INVALID_DATA); - parseCommand("--private-genesis-file", genesisFile.toString(), "--bootnodes"); + parseCommand("--genesis-file", genesisFile.toString()); - verifyZeroInteractions(mockControllerBuilder); + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains("--network-id option must be defined if --private-genesis-file option is used."); - } + verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); + verify(mockControllerBuilder).build(); - @Test - public void genesisPathOptionRequiresBootnodesOptions() throws Exception { - assumeTrue(isFullInstantiation()); + assertThat(networkArg.getValue().getGenesisConfig()) + .isEqualTo(encodeJsonGenesis(GENESIS_INVALID_DATA)); - final Path genesisFile = createFakeGenesisFile(); + // assertThat(networkArg.getValue().getNetworkId()) + // .isEqualTo(EthNetworkConfig.getNetworkConfig(MAINNET).getNetworkId()); - parseCommand("--private-genesis-file", genesisFile.toString(), "--network-id", "42"); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } - verifyZeroInteractions(mockControllerBuilder); + @Test + public void predefinedNetworkIdsMustBeEqualToChainIds() { + // check the network id against the one in mainnet genesis config + // it implies that EthNetworkConfig.mainnet().getNetworkId() returns a value equals to the chain + // id + // in this network genesis file. - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains("--bootnodes option must be defined if --private-genesis-file option is used."); + GenesisConfigFile genesisConfigFile = + GenesisConfigFile.fromConfig(EthNetworkConfig.getNetworkConfig(MAINNET).getGenesisConfig()); + assertThat(genesisConfigFile.getConfigOptions().getChainId().isPresent()).isTrue(); + assertThat(genesisConfigFile.getConfigOptions().getChainId().getAsInt()) + .isEqualTo(EthNetworkConfig.getNetworkConfig(MAINNET).getNetworkId()); } @Test @@ -1474,54 +1502,12 @@ public void devModeOptionMustBeUsed() throws Exception { verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.dev()); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(DEV)); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); } - @Test - public void ottomanModeOptionMustBeUsed() throws Exception { - final Path genesisFile = createFakeGenesisFile(); - - int networkIdOptionValue = 42; - - parseCommand( - "--network", - "ottoman", - "--private-genesis-file", - genesisFile.toString(), - "--bootnodes", - "--network-id", - String.valueOf(networkIdOptionValue)); - - final ArgumentCaptor networkArg = - ArgumentCaptor.forClass(EthNetworkConfig.class); - - verify(mockControllerBuilder).syncWithOttoman(eq(true)); - verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); - verify(mockControllerBuilder).build(); - - assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo("genesis_config"); - assertThat(networkArg.getValue().getBootNodes()).isEmpty(); - assertThat(networkArg.getValue().getNetworkId()).isEqualTo(networkIdOptionValue); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void ottomanModeOptionRequiresGenesisFile() throws Exception { - parseCommand("--network", "ottoman"); - - verifyZeroInteractions(mockControllerBuilder); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains( - "A genesis file must be defined with --private-genesis-file option to use Ottoman network."); - } - @Test public void rinkebyValuesAreUsed() throws Exception { parseCommand("--network", "rinkeby"); @@ -1532,7 +1518,7 @@ public void rinkebyValuesAreUsed() throws Exception { verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.rinkeby()); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(RINKEBY)); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -1548,7 +1534,7 @@ public void ropstenValuesAreUsed() throws Exception { verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.ropsten()); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(ROPSTEN)); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -1564,7 +1550,7 @@ public void goerliValuesAreUsed() throws Exception { verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); - assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.goerli()); + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(GOERLI)); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -1591,7 +1577,7 @@ public void devValuesCanBeOverridden() throws Exception { } private void networkValuesCanBeOverridden(final String network) throws Exception { - final Path genesisFile = createFakeGenesisFile(); + final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); parseCommand( "--network", network, @@ -1599,7 +1585,7 @@ private void networkValuesCanBeOverridden(final String network) throws Exception "1234567", "--bootnodes", String.join(",", validENodeStrings), - "--private-genesis-file", + "--genesis-file", genesisFile.toString()); final ArgumentCaptor networkArg = @@ -1610,7 +1596,8 @@ private void networkValuesCanBeOverridden(final String network) throws Exception assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(networkArg.getValue().getGenesisConfig()).isEqualTo("genesis_config"); + assertThat(networkArg.getValue().getGenesisConfig()) + .isEqualTo(encodeJsonGenesis(GENESIS_VALID_JSON)); assertThat(networkArg.getValue().getBootNodes()) .isEqualTo(Stream.of(validENodeStrings).map(URI::create).collect(Collectors.toList())); assertThat(networkArg.getValue().getNetworkId()).isEqualTo(1234567); @@ -1626,7 +1613,7 @@ public void fullCLIOptionsNotShownWhenInDockerContainer() { assertThat(commandOutput.toString()).doesNotContain("--config-file"); assertThat(commandOutput.toString()).doesNotContain("--data-path"); - assertThat(commandOutput.toString()).doesNotContain("--private-genesis-file"); + assertThat(commandOutput.toString()).doesNotContain("--genesis-file"); assertThat(commandErrorOutput.toString()).isEmpty(); } @@ -1638,7 +1625,7 @@ public void fullCLIOptionsShownWhenNotInDockerContainer() { assertThat(commandOutput.toString()).contains("--config-file"); assertThat(commandOutput.toString()).contains("--data-path"); - assertThat(commandOutput.toString()).contains("--private-genesis-file"); + assertThat(commandOutput.toString()).contains("--genesis-file"); assertThat(commandErrorOutput.toString()).isEmpty(); } @@ -1681,12 +1668,16 @@ public void mustVerifyPrivacyIsDisabled() throws IOException { assertThat(orionArg.getValue().isEnabled()).isEqualTo(false); } - private Path createFakeGenesisFile() throws IOException { + private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException { final Path genesisFile = Files.createTempFile("genesisFile", ""); - Files.write(genesisFile, "genesis_config".getBytes(UTF_8)); + Files.write(genesisFile, encodeJsonGenesis(jsonGenesis).getBytes(UTF_8)); return genesisFile; } + private String encodeJsonGenesis(final JsonObject jsonGenesis) { + return jsonGenesis.encodePrettily(); + } + private boolean isFullInstantiation() { return !Boolean.getBoolean("pantheon.docker"); } diff --git a/pantheon/src/test/resources/complete_config.toml b/pantheon/src/test/resources/complete_config.toml index 8ac8e97a17..70f54141ab 100644 --- a/pantheon/src/test/resources/complete_config.toml +++ b/pantheon/src/test/resources/complete_config.toml @@ -22,7 +22,7 @@ metrics-host="8.6.7.5" metrics-port=309 # chain -private-genesis-file="~/genesis.json" # Path +genesis-file="~/genesis.json" # Path network-id=42 sync-mode="fast"# should be FAST or FULL (or fast or full) ottoman=false # true means using ottoman testnet if genesys file uses iBFT diff --git a/pantheon/src/test/resources/everything_config.toml b/pantheon/src/test/resources/everything_config.toml index 075fe990a0..ef80aa7110 100644 --- a/pantheon/src/test/resources/everything_config.toml +++ b/pantheon/src/test/resources/everything_config.toml @@ -31,7 +31,7 @@ host-whitelist=["all"] # chain network="MAINNET" -private-genesis-file="~/genesis.json" +genesis-file="~/genesis.json" sync-mode="fast" network-id=303 From 95df04b71a1138db8af4b76d4a2c70a92c68682b Mon Sep 17 00:00:00 2001 From: Nicolas MASSART Date: Fri, 25 Jan 2019 11:39:47 +0100 Subject: [PATCH 5/5] fixes NC-2026 makes `--network` and `--genesis-file` options exclusives User have no reason to set `--network` and `--genesis-file` options at the same time that would lead to misunderstandings so we raise an error to prevent both options to be defined at the same time on the command line. Also fixes review feedbacks comments for the PR. --- .../NetworkID-And-ChainID.md | 2 +- docs/Getting-Started/Starting-Pantheon.md | 12 --- docs/Reference/Pantheon-CLI-Syntax.md | 95 +++++++------------ .../pegasys/pantheon/cli/PantheonCommand.java | 30 ++++-- .../pantheon/cli/PantheonCommandTest.java | 29 ++++-- 5 files changed, 80 insertions(+), 88 deletions(-) diff --git a/docs/Configuring-Pantheon/NetworkID-And-ChainID.md b/docs/Configuring-Pantheon/NetworkID-And-ChainID.md index e087a7ad6f..1e9351211c 100644 --- a/docs/Configuring-Pantheon/NetworkID-And-ChainID.md +++ b/docs/Configuring-Pantheon/NetworkID-And-ChainID.md @@ -10,7 +10,7 @@ in the genesis file. For most networks including MainNet and the public testnets, the network ID and the chain ID are the same and Pantheon network id default values are defined according to the genesis chain id value. -The network ID is then automatically set by Pantheon to the chain id when connecting to the Ethereum networks: +The network ID is automatically set by Pantheon to the chain ID when connecting to the Ethereum networks: - **MainNet:** chain-id ==1==, network-id ==1== - **Rinkeby:** chain-id ==4==, network-id ==4== diff --git a/docs/Getting-Started/Starting-Pantheon.md b/docs/Getting-Started/Starting-Pantheon.md index 4aadb323cd..4a89b8d1c8 100644 --- a/docs/Getting-Started/Starting-Pantheon.md +++ b/docs/Getting-Started/Starting-Pantheon.md @@ -85,9 +85,6 @@ rpc-http-enabled=true data-path="/tmp/tmpdata-path" ``` -!!!note - `--network` option is new from 0.9 - ## Run a Node on Ropsten Testnet To run a node on Ropsten: @@ -101,9 +98,6 @@ To run a node on Ropsten with the HTTP JSON-RPC service enabled and allow Remix ```bash pantheon --network=ropsten --rpc-http-enabled --rpc-http-cors-origins "http://remix.ethereum.org" ``` - -!!!note - `--network` option is new from 0.9 ## Run a Node on Rinkeby Testnet @@ -114,9 +108,6 @@ pantheon --network=rinkeby --data-path=/ ``` Where `` and `` are the path and directory where the Rinkeby chain data is to be saved. -!!!note - `--network` option is new from 0.9 - ## Run a Node on Goerli Testnet To run a node on [Goerli](https://github.com/goerli/testnet) specifying a data directory: @@ -127,9 +118,6 @@ pantheon --network=goerli --data-path=/ Where `` and `` are the path and directory where the Goerli chain data is to be saved. -!!!note - `--network` option is new from 0.9 - ## Run a Node on Ethereum Mainnet To run a node on the Ethereum mainnet: diff --git a/docs/Reference/Pantheon-CLI-Syntax.md b/docs/Reference/Pantheon-CLI-Syntax.md index 88b85cb24f..2a7dc8e6d8 100644 --- a/docs/Reference/Pantheon-CLI-Syntax.md +++ b/docs/Reference/Pantheon-CLI-Syntax.md @@ -4,9 +4,10 @@ description: Pantheon commande line interface reference # Pantheon Command Line !!! important "Breaking Changes in v0.9" - In v0.9, changes will be made to the command line options to improve usability. These will be breaking changes; that is, - in many cases the v0.8 command line options will no longer work. This reference and the rest of the documentation will be - updated to reflect these changes. Any further information required about the changes will be included in the v0.9 release notes. + In v0.9 the command line changed to improve usability. These are breaking changes; that is, + in many cases the v0.8 command line options will no longer work. This reference and the rest of + the documentation will be updated to reflect these changes. Any further information required + about the changes are included in the v0.9 release notes. This reference describes the syntax of the Pantheon Command Line Interface (CLI) options and subcommands. @@ -125,16 +126,33 @@ The path to the Pantheon data directory. The default is the `/build/distribution !!!note This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#persisting-data). +### genesis-file -### dev-mode +Genesis file is used to create a custom network. -!!!important - This option was removed in favor of the new [`--network`](#network) option. +!!!tip + To use a public Ethereum network such as Rinkeby, use the [`--network`](#network) option. + The network option defines the genesis file for public networks. + +```bash tab="Syntax" +--genesis-file= +``` + +```bash tab="Example Command Line" +--genesis-file=/home/me/me_node/customGenesisFile.json +``` + +```bash tab="Example Configuration File" +genesis-file="/home/me/me_node/customGenesisFile.json" +``` -### goerli +The path to the genesis file. !!!important - This option was removed in favor of the new [`--network`](#network) option. + The [`--genesis-file`](#genesis-file) and [`--network`](#network) option can't be used at the same time. + +!!!note + This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#custom-genesis-file). ### host-whitelist @@ -325,7 +343,7 @@ The default is 1000. network="rinkeby" ``` -Known network predefined configuration. +Predefined network configuration. The default is `mainnet`. Possible values are : @@ -337,16 +355,19 @@ Possible values are : : PoW test network similar to current main Ethereum network. `rinkeby` -: PoA test network using Clique _(only compatible with some clients)_. +: PoA test network using Clique. `goerli` -: PoA test network using Clique _(compatible with most clients)_. +: PoA test network using Clique. `dev` : PoW development network with a very low difficulty to enable local CPU mining. !!!note Values are case insensitive, so either `mainnet` or `MAINNET` works. + +!!!important + The [`--network`](#network) and [`--genesis-file`](#genesis-file) option can't be used at the same time. ### network-id @@ -364,8 +385,8 @@ network-id="8675309" P2P network identifier. -This option can be used to override your current network id. -The default value is the current network chain id which is defined in the genesis file. +This option can be used to override your current network ID. +The default value is the current network chain ID which is defined in the genesis file. ### no-discovery @@ -430,11 +451,6 @@ Not intended for use with mainnet or public testnets. !!!note Permissioning is under development and will be available in v1.0. -### ottoman - -!!!important - This version is not supporting IBFT Ottoman test network anymore. - ### p2p-host ```bash tab="Syntax" @@ -477,49 +493,6 @@ The default is 30303. !!!note This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#exposing-ports). -### genesis-file - -Genesis file is used to create a custom network. - -!!!tip - If you need to use one of the well-known networks like Ethereum MainNet, you should use - the [`--network`](#network) option instead as all nodes of a same network have to define the - exact same genesis parameters. - -```bash tab="Syntax" ---genesis-file= -``` - -```bash tab="Example Command Line" ---genesis-file=/home/me/me_node/customGenesisFile.json -``` - -```bash tab="Example Configuration File" -genesis-file="/home/me/me_node/customGenesisFile.json" -``` - -The path to the genesis file. There's no default for this option. - -!!!important - The [`--genesis-file`](#genesis-file) option overrides the genesis file - defined in the preset configuration of [`--network`](#network) option. - If both are specified, the [`--genesis-file`](#genesis-file) option file is - taken in account and the known network one is ignored. - -!!!note - This option is not used when running Pantheon from the [Docker image](../Getting-Started/Run-Docker-Image.md#custom-genesis-file). - - -### rinkeby - -!!!important - This option was removed in favor of the new [`--network`](#network) option. - -### ropsten - -!!!important - This option was removed in favor of the new [`--network`](#network) option. - ### rpc-http-enabled ```bash tab="Syntax" 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 503bb47e18..99fc395486 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -232,9 +232,9 @@ public static class RpcApisConversionException extends Exception { paramLabel = MANDATORY_NETWORK_FORMAT_HELP, description = "Synchronize against the indicated network, possible values are ${COMPLETION-CANDIDATES}." - + " (default: ${DEFAULT-VALUE})" + + " (default: MAINNET)" ) - private final NetworkName network = MAINNET; + private final NetworkName network = null; @Option( names = {"--p2p-host"}, @@ -257,7 +257,7 @@ public static class RpcApisConversionException extends Exception { names = {"--network-id"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, description = - "P2P network identifier. (default: the selected network chain id or custom genesis chain id)", + "P2P network identifier. (default: the selected network chain ID or custom genesis chain ID)", arity = "1" ) private final Integer networkId = null; @@ -568,7 +568,7 @@ public void run() { + "or specify the beneficiary of mining (via --miner-coinbase
)"); } - final EthNetworkConfig ethNetworkConfig = updateNetworkConfig(network); + final EthNetworkConfig ethNetworkConfig = updateNetworkConfig(getNetwork()); final PermissioningConfiguration permissioningConfiguration = permissioningConfiguration(); ensureAllBootnodesAreInWhitelist(ethNetworkConfig, permissioningConfiguration); @@ -585,6 +585,11 @@ public void run() { permissioningConfiguration); } + private NetworkName getNetwork() { + //noinspection ConstantConditions network is not always null but injected by PicoCLI if used + return network == null ? MAINNET : network; + } + private void ensureAllBootnodesAreInWhitelist( final EthNetworkConfig ethNetworkConfig, final PermissioningConfiguration permissioningConfiguration) { @@ -613,11 +618,11 @@ PantheonController buildController() { return controllerBuilder .synchronizerConfiguration(buildSyncConfig()) .homePath(dataDir()) - .ethNetworkConfig(updateNetworkConfig(network)) + .ethNetworkConfig(updateNetworkConfig(getNetwork())) .syncWithOttoman(false) // ottoman feature is still there but it's now removed from CLI .miningParameters( new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled)) - .devMode(NetworkName.DEV.equals(network)) + .devMode(NetworkName.DEV.equals(getNetwork())) .nodePrivateKeyFile(getNodePrivateKeyFile()) .metricsSystem(metricsSystem) .privacyParameters(orionConfiguration()) @@ -764,6 +769,19 @@ private EthNetworkConfig updateNetworkConfig(final NetworkName network) { // but also for the network id and the bootnodes list. File genesisFile = genesisFile(); if (genesisFile != null) { + + //noinspection ConstantConditions network is not always null but injected by PicoCLI if used + if (this.network != null) { + // We check if network option was really provided by user and not only looking at the + // default value. + // if user provided it and provided the genesis file option at the same time, it raises a + // conflict error + throw new ParameterException( + new CommandLine(this), + "--network option and --genesis-file option can't be used at the same time." + + "Please refer to CLI reference for more details about this constraint."); + } + builder.setGenesisConfig(genesisConfig()); if (networkId == null) { 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 6376528b75..6314c305e9 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -481,6 +481,23 @@ public void genesisPathOptionMustBeUsed() throws Exception { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void genesisAndNetworkMustNotBeUsedTogether() throws Exception { + assumeTrue(isFullInstantiation()); + + final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); + + parseCommand("--genesis-file", genesisFile.toString(), "--network", "rinkeby"); + + verifyZeroInteractions(mockRunnerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .startsWith("--network option and --genesis-file option can't be used at the same time."); + } + @Test public void defaultNetworkIdAndBootnodesForCustomNetworkOptions() throws Exception { assumeTrue(isFullInstantiation()); @@ -1577,16 +1594,13 @@ public void devValuesCanBeOverridden() throws Exception { } private void networkValuesCanBeOverridden(final String network) throws Exception { - final Path genesisFile = createFakeGenesisFile(GENESIS_VALID_JSON); parseCommand( "--network", network, "--network-id", "1234567", "--bootnodes", - String.join(",", validENodeStrings), - "--genesis-file", - genesisFile.toString()); + String.join(",", validENodeStrings)); final ArgumentCaptor networkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -1594,13 +1608,12 @@ private void networkValuesCanBeOverridden(final String network) throws Exception verify(mockControllerBuilder).ethNetworkConfig(networkArg.capture()); verify(mockControllerBuilder).build(); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(networkArg.getValue().getGenesisConfig()) - .isEqualTo(encodeJsonGenesis(GENESIS_VALID_JSON)); assertThat(networkArg.getValue().getBootNodes()) .isEqualTo(Stream.of(validENodeStrings).map(URI::create).collect(Collectors.toList())); assertThat(networkArg.getValue().getNetworkId()).isEqualTo(1234567); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); } @Test