From c53b8498b0eb88398b673f660e44315751f4ac77 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Fri, 26 Oct 2018 13:18:15 +1000 Subject: [PATCH] Revert "[NC-1805] net_version should return the network ID not the chain ID (#162)" (#166) MetaMask depends on net_version returning the chain ID, not the network ID. --- .../dsl/node/ThreadPantheonNodeRunner.java | 1 - .../jsonrpc/JsonRpcMethodsFactory.java | 8 ++--- .../jsonrpc/internal/methods/NetVersion.java | 14 +++++--- .../tech/pegasys/pantheon/RunnerBuilder.java | 9 +++-- .../pegasys/pantheon/cli/PantheonCommand.java | 7 ++-- .../tech/pegasys/pantheon/RunnerTest.java | 2 -- .../pantheon/cli/PantheonCommandTest.java | 34 +++---------------- 7 files changed, 25 insertions(+), 50 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 cad28cedf7..f1b79285f7 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 @@ -71,7 +71,6 @@ public class ThreadPantheonNodeRunner implements PantheonNodeRunner { pantheonController, true, node.bootnodes(), - NETWORK_ID, node.getHost(), node.p2pPort(), 25, diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java index d0ba2c26a2..c74a27072c 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java @@ -87,7 +87,7 @@ public class JsonRpcMethodsFactory { public Map methods( final String clientVersion, - final String networkId, + final String chainId, final P2PNetwork peerNetworkingService, final Blockchain blockchain, final WorldStateArchive worldStateArchive, @@ -102,7 +102,7 @@ public class JsonRpcMethodsFactory { new BlockchainQueries(blockchain, worldStateArchive); return methods( clientVersion, - networkId, + chainId, peerNetworkingService, blockchainQueries, synchronizer, @@ -116,7 +116,7 @@ public class JsonRpcMethodsFactory { public Map methods( final String clientVersion, - final String networkId, + final String chainId, final P2PNetwork p2pNetwork, final BlockchainQueries blockchainQueries, final Synchronizer synchronizer, @@ -195,7 +195,7 @@ public class JsonRpcMethodsFactory { if (rpcApis.contains(RpcApis.NET)) { addMethods( enabledMethods, - new NetVersion(networkId), + new NetVersion(chainId), new NetListening(p2pNetwork), new NetPeerCount(p2pNetwork), new AdminPeers(p2pNetwork)); diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetVersion.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetVersion.java index 073c8b46b9..7646effe78 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetVersion.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetVersion.java @@ -16,11 +16,17 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; +/** + * In Consensys' client, net_version maps to the network id, as specified in * + * https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version + * + *

This method can be deprecated in the future, @see https://github.com/ethereum/EIPs/issues/611 + */ public class NetVersion implements JsonRpcMethod { - private final String networkId; + private final String chainId; - public NetVersion(final String networkId) { - this.networkId = networkId; + public NetVersion(final String chainId) { + this.chainId = chainId; } @Override @@ -30,6 +36,6 @@ public class NetVersion implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequest req) { - return new JsonRpcSuccessResponse(req.getId(), networkId); + return new JsonRpcSuccessResponse(req.getId(), chainId); } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 84fab1ab1b..4fb2bfc222 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -73,7 +73,6 @@ public class RunnerBuilder { final PantheonController pantheonController, final boolean discovery, final Collection bootstrapPeers, - final int networkId, final String discoveryHost, final int listenPort, final int maxPeers, @@ -151,7 +150,7 @@ public class RunnerBuilder { jsonRpcMethods( context, protocolSchedule, - networkId, + pantheonController, networkRunner, synchronizer, transactionPool, @@ -169,7 +168,7 @@ public class RunnerBuilder { jsonRpcMethods( context, protocolSchedule, - networkId, + pantheonController, networkRunner, synchronizer, transactionPool, @@ -214,7 +213,7 @@ public class RunnerBuilder { private Map jsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final int networkId, + final PantheonController pantheonController, final NetworkRunner networkRunner, final Synchronizer synchronizer, final TransactionPool transactionPool, @@ -226,7 +225,7 @@ public class RunnerBuilder { new JsonRpcMethodsFactory() .methods( PantheonInfo.version(), - String.valueOf(networkId), + String.valueOf(pantheonController.getGenesisConfig().getChainId()), networkRunner.getNetwork(), context.getBlockchain(), context.getWorldStateArchive(), 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 f52d87827f..e76bfa8d2a 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -414,7 +414,7 @@ public class PantheonCommand implements Runnable { synchronize( buildController(), noPeerDiscovery, - ethNetworkConfig, + ethNetworkConfig.getBootNodes(), maxPeers, p2pHostAndPort, jsonRpcConfiguration(), @@ -467,7 +467,7 @@ public class PantheonCommand implements Runnable { private void synchronize( final PantheonController controller, final boolean noPeerDiscovery, - final EthNetworkConfig ethNetworkConfig, + final Collection bootstrapNodes, final int maxPeers, final HostAndPort discoveryHostAndPort, final JsonRpcConfiguration jsonRpcConfiguration, @@ -481,8 +481,7 @@ public class PantheonCommand implements Runnable { Vertx.vertx(), controller, !noPeerDiscovery, - ethNetworkConfig.getBootNodes(), - ethNetworkConfig.getNetworkId(), + bootstrapNodes, discoveryHostAndPort.getHost(), discoveryHostAndPort.getPort(), maxPeers, diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index 484fd248af..f1e70dde51 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -120,7 +120,6 @@ public final class RunnerTest { controllerAhead, true, Collections.emptyList(), - NETWORK_ID, listenHost, 0, 3, @@ -154,7 +153,6 @@ public final class RunnerTest { listenHost, runnerAhead.getP2pUdpPort(), runnerAhead.getP2pTcpPort())), - NETWORK_ID, listenHost, 0, 3, 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 30b6797ce2..8acf33d587 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -88,7 +88,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -131,7 +130,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), eq(true), eq(MAINNET_BOOTSTRAP_NODES), - eq(1), eq("127.0.0.1"), eq(30303), eq(25), @@ -259,7 +257,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), eq(false), stringListArgumentCaptor.capture(), - eq(1), eq("1.2.3.4"), eq(1234), eq(42), @@ -313,7 +310,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), eq(true), eq(MAINNET_BOOTSTRAP_NODES), - eq(1), eq("127.0.0.1"), eq(30303), eq(25), @@ -372,17 +368,7 @@ public class PantheonCommandTest extends CommandTestAbstract { verify(mockRunnerBuilder) .build( - any(), - any(), - eq(false), - any(), - anyInt(), - anyString(), - anyInt(), - anyInt(), - any(), - any(), - any()); + any(), any(), eq(false), any(), anyString(), anyInt(), anyInt(), any(), any(), any()); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -408,7 +394,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), stringListArgumentCaptor.capture(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -435,7 +420,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), stringArgumentCaptor.capture(), intArgumentCaptor.capture(), anyInt(), @@ -462,7 +446,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), intArgumentCaptor.capture(), @@ -509,7 +492,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -533,7 +515,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -557,7 +538,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -585,7 +565,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -611,7 +590,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -637,7 +615,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -663,7 +640,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -689,7 +665,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -761,7 +736,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -785,7 +759,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -809,7 +782,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -836,7 +808,6 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), - anyInt(), anyString(), anyInt(), anyInt(), @@ -855,6 +826,9 @@ public class PantheonCommandTest extends CommandTestAbstract { public void pantheonDoesNotStartInMiningModeIfCoinbaseNotSet() throws Exception { parseCommand("--miner-enabled"); + final ArgumentCaptor miningArg = + ArgumentCaptor.forClass(MiningParameters.class); + verifyZeroInteractions(mockControllerBuilder); }