From 8a53c32ebf66d219d123c95bc9beb01bab2c528b Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Fri, 26 Oct 2018 11:31:24 +1000 Subject: [PATCH] [NC-1805] net_version should return the network ID not the chain ID (#162) --- .../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, 50 insertions(+), 25 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 f1b79285f7..cad28cedf7 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,6 +71,7 @@ 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 c74a27072c..d0ba2c26a2 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 chainId, + final String networkId, final P2PNetwork peerNetworkingService, final Blockchain blockchain, final WorldStateArchive worldStateArchive, @@ -102,7 +102,7 @@ public class JsonRpcMethodsFactory { new BlockchainQueries(blockchain, worldStateArchive); return methods( clientVersion, - chainId, + networkId, peerNetworkingService, blockchainQueries, synchronizer, @@ -116,7 +116,7 @@ public class JsonRpcMethodsFactory { public Map methods( final String clientVersion, - final String chainId, + final String networkId, 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(chainId), + new NetVersion(networkId), 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 7646effe78..073c8b46b9 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,17 +16,11 @@ 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 chainId; + private final String networkId; - public NetVersion(final String chainId) { - this.chainId = chainId; + public NetVersion(final String networkId) { + this.networkId = networkId; } @Override @@ -36,6 +30,6 @@ public class NetVersion implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequest req) { - return new JsonRpcSuccessResponse(req.getId(), chainId); + return new JsonRpcSuccessResponse(req.getId(), networkId); } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 4fb2bfc222..84fab1ab1b 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -73,6 +73,7 @@ public class RunnerBuilder { final PantheonController pantheonController, final boolean discovery, final Collection bootstrapPeers, + final int networkId, final String discoveryHost, final int listenPort, final int maxPeers, @@ -150,7 +151,7 @@ public class RunnerBuilder { jsonRpcMethods( context, protocolSchedule, - pantheonController, + networkId, networkRunner, synchronizer, transactionPool, @@ -168,7 +169,7 @@ public class RunnerBuilder { jsonRpcMethods( context, protocolSchedule, - pantheonController, + networkId, networkRunner, synchronizer, transactionPool, @@ -213,7 +214,7 @@ public class RunnerBuilder { private Map jsonRpcMethods( final ProtocolContext context, final ProtocolSchedule protocolSchedule, - final PantheonController pantheonController, + final int networkId, final NetworkRunner networkRunner, final Synchronizer synchronizer, final TransactionPool transactionPool, @@ -225,7 +226,7 @@ public class RunnerBuilder { new JsonRpcMethodsFactory() .methods( PantheonInfo.version(), - String.valueOf(pantheonController.getGenesisConfig().getChainId()), + String.valueOf(networkId), 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 e76bfa8d2a..f52d87827f 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.getBootNodes(), + ethNetworkConfig, maxPeers, p2pHostAndPort, jsonRpcConfiguration(), @@ -467,7 +467,7 @@ public class PantheonCommand implements Runnable { private void synchronize( final PantheonController controller, final boolean noPeerDiscovery, - final Collection bootstrapNodes, + final EthNetworkConfig ethNetworkConfig, final int maxPeers, final HostAndPort discoveryHostAndPort, final JsonRpcConfiguration jsonRpcConfiguration, @@ -481,7 +481,8 @@ public class PantheonCommand implements Runnable { Vertx.vertx(), controller, !noPeerDiscovery, - bootstrapNodes, + ethNetworkConfig.getBootNodes(), + ethNetworkConfig.getNetworkId(), 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 f1e70dde51..484fd248af 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -120,6 +120,7 @@ public final class RunnerTest { controllerAhead, true, Collections.emptyList(), + NETWORK_ID, listenHost, 0, 3, @@ -153,6 +154,7 @@ 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 8acf33d587..30b6797ce2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -88,6 +88,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -130,6 +131,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), eq(true), eq(MAINNET_BOOTSTRAP_NODES), + eq(1), eq("127.0.0.1"), eq(30303), eq(25), @@ -257,6 +259,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), eq(false), stringListArgumentCaptor.capture(), + eq(1), eq("1.2.3.4"), eq(1234), eq(42), @@ -310,6 +313,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), eq(true), eq(MAINNET_BOOTSTRAP_NODES), + eq(1), eq("127.0.0.1"), eq(30303), eq(25), @@ -368,7 +372,17 @@ public class PantheonCommandTest extends CommandTestAbstract { verify(mockRunnerBuilder) .build( - any(), any(), eq(false), any(), anyString(), anyInt(), anyInt(), any(), any(), any()); + any(), + any(), + eq(false), + any(), + anyInt(), + anyString(), + anyInt(), + anyInt(), + any(), + any(), + any()); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -394,6 +408,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), stringListArgumentCaptor.capture(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -420,6 +435,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), stringArgumentCaptor.capture(), intArgumentCaptor.capture(), anyInt(), @@ -446,6 +462,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), intArgumentCaptor.capture(), @@ -492,6 +509,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -515,6 +533,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -538,6 +557,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -565,6 +585,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -590,6 +611,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -615,6 +637,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -640,6 +663,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -665,6 +689,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -736,6 +761,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -759,6 +785,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -782,6 +809,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -808,6 +836,7 @@ public class PantheonCommandTest extends CommandTestAbstract { any(), anyBoolean(), any(), + anyInt(), anyString(), anyInt(), anyInt(), @@ -826,9 +855,6 @@ public class PantheonCommandTest extends CommandTestAbstract { public void pantheonDoesNotStartInMiningModeIfCoinbaseNotSet() throws Exception { parseCommand("--miner-enabled"); - final ArgumentCaptor miningArg = - ArgumentCaptor.forClass(MiningParameters.class); - verifyZeroInteractions(mockControllerBuilder); }