Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
[PAN-2373] admin_nodeInfo rpc-api (#1012)
Browse files Browse the repository at this point in the history
Implement admin_nodeInfo RPC call.  This involved bringing data from the
ethNetworkConfig and genesis json into the rpc call, so it had a lot of
testing side effects.
  • Loading branch information
shemnon authored Mar 1, 2019
1 parent 07446b1 commit 8ee3328
Show file tree
Hide file tree
Showing 28 changed files with 536 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public void startNode(final PantheonNode node) {
runnerBuilder
.vertx(Vertx.vertx())
.pantheonController(pantheonController)
.ethNetworkConfig(ethNetworkConfig)
.discovery(node.isDiscoveryEnabled())
.bootstrapPeers(node.bootnodes())
.discoveryHost(node.hostName())
.discoveryPort(node.p2pPort())
.maxPeers(25)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
package tech.pegasys.pantheon.config;

import java.util.Map;

import com.google.common.collect.ImmutableMap;
import io.vertx.core.json.JsonObject;

public class CliqueConfigOptions {
Expand All @@ -34,4 +37,9 @@ public long getEpochLength() {
public int getBlockPeriodSeconds() {
return cliqueConfigRoot.getInteger("blockperiodseconds", DEFAULT_BLOCK_PERIOD_SECONDS);
}

Map<String, Object> asMap() {
return ImmutableMap.of(
"epochLength", getEpochLength(), "blockPeriodSeconds", getBlockPeriodSeconds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
*/
package tech.pegasys.pantheon.config;

import java.util.Map;
import java.util.OptionalLong;

import com.google.common.collect.ImmutableMap;
import io.vertx.core.json.JsonObject;

public class EthashConfigOptions {
Expand All @@ -28,4 +30,10 @@ public class EthashConfigOptions {
public OptionalLong getFixedDifficulty() {
return ConfigUtil.getOptionalLong(ethashConfigRoot, "fixeddifficulty");
}

Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
getFixedDifficulty().ifPresent(l -> builder.put("fixeddifficulty", l));
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package tech.pegasys.pantheon.config;

import java.util.Map;
import java.util.OptionalInt;
import java.util.OptionalLong;

Expand Down Expand Up @@ -48,4 +49,6 @@ public interface GenesisConfigOptions {
OptionalLong getConstantinopleFixBlockNumber();

OptionalInt getChainId();

Map<String, Object> asMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
package tech.pegasys.pantheon.config;

import java.util.Map;

import com.google.common.collect.ImmutableMap;
import io.vertx.core.json.JsonObject;

public class IbftConfigOptions {
Expand Down Expand Up @@ -67,4 +70,33 @@ public int getFutureMessagesMaxDistance() {
return ibftConfigRoot.getInteger(
"futuremessagesmaxdistance", DEFAULT_FUTURE_MESSAGES_MAX_DISTANCE);
}

Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
if (ibftConfigRoot.containsKey("epochlength")) {
builder.put("epochLength", getEpochLength());
}
if (ibftConfigRoot.containsKey("blockperiodseconds")) {
builder.put("blockPeriodSeconds", getBlockPeriodSeconds());
}
if (ibftConfigRoot.containsKey("requesttimeoutseconds")) {
builder.put("requestTimeoutSeconds", getRequestTimeoutSeconds());
}
if (ibftConfigRoot.containsKey("gossipedhistorylimit")) {
builder.put("gossipedHistoryLimit", getGossipedHistoryLimit());
}
if (ibftConfigRoot.containsKey("messagequeuelimit")) {
builder.put("messageQueueLimit", getMessageQueueLimit());
}
if (ibftConfigRoot.containsKey("duplicatemessagelimit")) {
builder.put("duplicateMessageLimit", getDuplicateMessageLimit());
}
if (ibftConfigRoot.containsKey("futuremessageslimit")) {
builder.put("futureMessagesLimit", getFutureMessagesLimit());
}
if (ibftConfigRoot.containsKey("futuremessagesmaxdistance")) {
builder.put("futureMessagesMaxDistance", getFutureMessagesMaxDistance());
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
*/
package tech.pegasys.pantheon.config;

import java.util.Map;
import java.util.OptionalInt;
import java.util.OptionalLong;

import com.google.common.collect.ImmutableMap;
import io.vertx.core.json.JsonObject;

public class JsonGenesisConfigOptions implements GenesisConfigOptions {
Expand Down Expand Up @@ -119,6 +121,49 @@ public OptionalInt getChainId() {
: OptionalInt.empty();
}

@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
builder.put("chainId", getChainId().getAsInt());
getHomesteadBlockNumber().ifPresent(l -> builder.put("homesteadBlock", l));
getDaoForkBlock()
.ifPresent(
l -> {
builder.put("daoForkBlock", l);
builder.put("daoForkSupport", Boolean.TRUE);
});
getTangerineWhistleBlockNumber()
.ifPresent(
l -> {
builder.put("eip150Block", l);
if (configRoot.containsKey("eip150hash")) {
builder.put("eip150Hash", configRoot.getString("eip150hash"));
}
});
getSpuriousDragonBlockNumber()
.ifPresent(
l -> {
builder.put("eip155Block", l);
builder.put("eip158Block", l);
});
getByzantiumBlockNumber().ifPresent(l -> builder.put("byzantiumBlock", l));
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getConstantinopleFixBlockNumber().ifPresent(l -> builder.put("constantinopleFixBlock", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}
if (isEthHash()) {
builder.put("ethash", getEthashConfigOptions().asMap());
}
if (isIbftLegacy()) {
builder.put("ibft", getIbftLegacyConfigOptions().asMap());
}
if (isIbft2()) {
builder.put("ibft2", getIbft2ConfigOptions().asMap());
}
return builder.build();
}

private OptionalLong getOptionalLong(final String key) {
return ConfigUtil.getOptionalLong(configRoot, key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
*/
package tech.pegasys.pantheon.config;

import java.util.Map;
import java.util.OptionalInt;
import java.util.OptionalLong;

import com.google.common.collect.ImmutableMap;

public class StubGenesisConfigOptions implements GenesisConfigOptions {

private OptionalLong homesteadBlockNumber = OptionalLong.empty();
Expand Down Expand Up @@ -106,6 +109,42 @@ public OptionalInt getChainId() {
return chainId;
}

@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
builder.put("chainId", getChainId().getAsInt());
getHomesteadBlockNumber().ifPresent(l -> builder.put("homesteadBlock", l));
getDaoForkBlock()
.ifPresent(
l -> {
builder.put("daoForkBlock", l);
builder.put("daoForkSupport", Boolean.TRUE);
});
getTangerineWhistleBlockNumber().ifPresent(l -> builder.put("eip150Block", l));
getSpuriousDragonBlockNumber()
.ifPresent(
l -> {
builder.put("eip155Block", l);
builder.put("eip158Block", l);
});
getByzantiumBlockNumber().ifPresent(l -> builder.put("byzantiumBlock", l));
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getConstantinopleFixBlockNumber().ifPresent(l -> builder.put("constantinopleFixBlock", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}
if (isEthHash()) {
builder.put("ethash", getEthashConfigOptions().asMap());
}
if (isIbftLegacy()) {
builder.put("ibft", getIbftLegacyConfigOptions().asMap());
}
if (isIbft2()) {
builder.put("ibft2", getIbft2ConfigOptions().asMap());
}
return builder.build();
}

public StubGenesisConfigOptions homesteadBlock(final long blockNumber) {
homesteadBlockNumber = OptionalLong.of(blockNumber);
return this;
Expand Down
1 change: 1 addition & 0 deletions ethereum/jsonrpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jar {
}

dependencies {
implementation project(':config')
implementation project(':crypto')
implementation project(':enclave')
implementation project(':ethereum:blockcreation')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryBlockchain;
import static tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider.createInMemoryWorldStateArchive;

import tech.pegasys.pantheon.config.StubGenesisConfigOptions;
import tech.pegasys.pantheon.ethereum.ProtocolContext;
import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain;
Expand Down Expand Up @@ -47,6 +48,7 @@
public class JsonRpcTestMethodsFactory {

private static final String CLIENT_VERSION = "TestClientVersion/0.1.0";
private static final int NETWORK_ID = 123;

private final BlockchainImporter importer;

Expand Down Expand Up @@ -87,6 +89,8 @@ public Map<String, JsonRpcMethod> methods() {
return new JsonRpcMethodsFactory()
.methods(
CLIENT_VERSION,
NETWORK_ID,
new StubGenesisConfigOptions(),
peerDiscovery,
blockchainQueries,
synchronizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package tech.pegasys.pantheon.ethereum.jsonrpc;

import tech.pegasys.pantheon.config.GenesisConfigOptions;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
Expand All @@ -20,6 +21,7 @@
import tech.pegasys.pantheon.ethereum.core.TransactionPool;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.AdminAddPeer;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.AdminNodeInfo;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.AdminPeers;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.DebugMetrics;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.DebugStorageRangeAt;
Expand Down Expand Up @@ -106,6 +108,8 @@ public class JsonRpcMethodsFactory {

public Map<String, JsonRpcMethod> methods(
final String clientVersion,
final int networkId,
final GenesisConfigOptions genesisConfigOptions,
final P2PNetwork peerNetworkingService,
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
Expand All @@ -123,6 +127,8 @@ public Map<String, JsonRpcMethod> methods(
new BlockchainQueries(blockchain, worldStateArchive);
return methods(
clientVersion,
networkId,
genesisConfigOptions,
peerNetworkingService,
blockchainQueries,
synchronizer,
Expand All @@ -139,6 +145,8 @@ public Map<String, JsonRpcMethod> methods(

public Map<String, JsonRpcMethod> methods(
final String clientVersion,
final int networkId,
final GenesisConfigOptions genesisConfigOptions,
final P2PNetwork p2pNetwork,
final BlockchainQueries blockchainQueries,
final Synchronizer synchronizer,
Expand Down Expand Up @@ -252,8 +260,12 @@ blockchainQueries, new TransactionTracer(blockReplay), parameter),
accountsWhitelistController, p2pNetwork.getNodeWhitelistController()));
}
if (rpcApis.contains(RpcApis.ADMIN)) {
addMethods(enabledMethods, new AdminPeers(p2pNetwork));
addMethods(enabledMethods, new AdminAddPeer(p2pNetwork, parameter));
addMethods(
enabledMethods,
new AdminAddPeer(p2pNetwork, parameter),
new AdminNodeInfo(
clientVersion, networkId, genesisConfigOptions, p2pNetwork, blockchainQueries),
new AdminPeers(p2pNetwork));
}
if (rpcApis.contains(RpcApis.EEA)) {
addMethods(
Expand Down
Loading

0 comments on commit 8ee3328

Please sign in to comment.