From b9e5d74debebbf371da092129d84f11f41d5307e Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Sun, 28 Oct 2018 11:28:57 +0200 Subject: [PATCH] Add --ropsten command line argument (#197) --- .../p2p/config/DiscoveryConfiguration.java | 7 +++++++ .../pantheon/cli/EthNetworkConfig.java | 12 +++++++++-- .../pegasys/pantheon/cli/PantheonCommand.java | 21 +++++++++++++++++-- .../controller/CliquePantheonController.java | 1 - .../controller/MainnetPantheonController.java | 1 - 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java index 44c5060996..9712b24c45 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java @@ -44,6 +44,13 @@ public class DiscoveryConfiguration { "enode://b6b28890b006743680c52e64e0d16db57f28124885595fa03a562be1d2bf0f3a1da297d56b13da25fb992888fd556d4c1a27b1f39d531bde7de1921c90061cc6@159.89.28.211:30303") .map(DefaultPeer::fromURI) .collect(toList())); + public static List ROPSTEN_BOOTSTRAP_NODES = + Collections.unmodifiableList( + Stream.of( + "enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303", + "enode://94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09@192.81.208.223:30303") + .map(DefaultPeer::fromURI) + .collect(toList())); private boolean active = true; private String bindHost = "0.0.0.0"; 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 4a57341c80..cbe72ca993 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java @@ -12,10 +12,9 @@ */ package tech.pegasys.pantheon.cli; -import static tech.pegasys.pantheon.controller.CliquePantheonController.RINKEBY_NETWORK_ID; -import static tech.pegasys.pantheon.controller.MainnetPantheonController.MAINNET_NETWORK_ID; import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.MAINNET_BOOTSTRAP_NODES; import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES; +import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.ROPSTEN_BOOTSTRAP_NODES; import java.net.URI; import java.net.URISyntaxException; @@ -26,8 +25,12 @@ import com.google.common.base.Preconditions; import com.google.common.io.Resources; public class EthNetworkConfig { + private static final int MAINNET_NETWORK_ID = 1; + private static final int RINKEBY_NETWORK_ID = 4; + private static final int ROPSTEN_NETWORK_ID = 3; 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 final URI genesisConfig; private final int networkId; private final Collection bootNodes; @@ -94,6 +97,11 @@ public class EthNetworkConfig { return new EthNetworkConfig(genesisConfig, RINKEBY_NETWORK_ID, RINKEBY_BOOTSTRAP_NODES); } + public static EthNetworkConfig ropsten() { + final URI genesisConfig = jsonConfigURI(ROPSTEN_GENESIS); + return new EthNetworkConfig(genesisConfig, ROPSTEN_NETWORK_ID, ROPSTEN_BOOTSTRAP_NODES); + } + private static URI jsonConfigURI(final String resourceName) { try { return Resources.getResource(resourceName).toURI(); 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 1a1b8d75aa..1e60058df6 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -230,6 +230,12 @@ public class PantheonCommand implements Runnable { ) private final Boolean rinkeby = false; + @Option( + names = {"--ropsten"}, + description = "Use the Ropsten test network (default: ${DEFAULT-VALUE})" + ) + private final Boolean ropsten = false; + @Option( names = {"--p2p-listen"}, paramLabel = MANDATORY_HOST_AND_PORT_FORMAT_HELP, @@ -410,6 +416,11 @@ public class PantheonCommand implements Runnable { + "or specify the beneficiary of mining (via --miner-coinbase
)"); return; } + if (ropsten && rinkeby) { + System.out.println( + "Unable to connect to multiple networks simultaneously. Remove one of --ropsten or --rinkeby"); + return; + } final EthNetworkConfig ethNetworkConfig = ethNetworkConfig(); synchronize( buildController(), @@ -562,8 +573,14 @@ public class PantheonCommand implements Runnable { } private EthNetworkConfig ethNetworkConfig() { - final EthNetworkConfig predefinedNetworkConfig = - rinkeby ? EthNetworkConfig.rinkeby() : EthNetworkConfig.mainnet(); + final EthNetworkConfig predefinedNetworkConfig; + if (rinkeby) { + predefinedNetworkConfig = EthNetworkConfig.rinkeby(); + } else if (ropsten) { + predefinedNetworkConfig = EthNetworkConfig.ropsten(); + } else { + predefinedNetworkConfig = EthNetworkConfig.mainnet(); + } return updateNetworkConfig(predefinedNetworkConfig); } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java index baccca9fe6..f300bf21eb 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java @@ -61,7 +61,6 @@ import io.vertx.core.json.JsonObject; import org.apache.logging.log4j.Logger; public class CliquePantheonController implements PantheonController { - public static int RINKEBY_NETWORK_ID = 4; private static final Logger LOG = getLogger(); private final GenesisConfig genesisConfig; private final ProtocolContext context; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java index fbfd18bb66..da3940056f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java @@ -58,7 +58,6 @@ import org.apache.logging.log4j.Logger; public class MainnetPantheonController implements PantheonController { private static final Logger LOG = LogManager.getLogger(); - public static final int MAINNET_NETWORK_ID = 1; private final GenesisConfig genesisConfig; private final ProtocolContext protocolContext;