From 4fa95f9f0d52db09e8f0eb76b669cc3dcbc8fb54 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Thu, 20 Jun 2019 15:28:05 -0400 Subject: [PATCH 01/15] Check connections more frequently during acceptance tests --- .../acceptance/dsl/node/PantheonNode.java | 8 ++++ .../dsl/node/ProcessPantheonNodeRunner.java | 5 +++ .../dsl/node/ThreadPantheonNodeRunner.java | 1 + .../PantheonFactoryConfiguration.java | 8 ++++ .../PantheonFactoryConfigurationBuilder.java | 9 ++++ .../configuration/PantheonNodeFactory.java | 1 + .../PrivacyPantheonFactoryConfiguration.java | 3 ++ ...cyPantheonFactoryConfigurationBuilder.java | 1 + .../privacy/PrivacyPantheonNodeFactory.java | 1 + .../acceptance/dsl/privacy/PrivacyNode.java | 3 ++ ethereum/p2p/build.gradle | 1 + .../p2p/config/NetworkingConfiguration.java | 44 +++++++++++++++++++ .../p2p/network/DefaultP2PNetwork.java | 8 +++- .../java/tech/pegasys/pantheon/Pantheon.java | 2 + .../tech/pegasys/pantheon/RunnerBuilder.java | 20 ++++++--- .../pegasys/pantheon/cli/PantheonCommand.java | 7 +++ .../pantheon/cli/CommandTestAbstract.java | 5 +++ 17 files changed, 118 insertions(+), 9 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index 21b17968e4..894bbfc0cc 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -24,6 +24,7 @@ import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; @@ -78,6 +79,7 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea private final KeyPair keyPair; private final Properties portsProperties = new Properties(); private final Boolean p2pEnabled; + private final NetworkingConfiguration networkingConfiguration; private final String name; private final MiningParameters miningParameters; @@ -112,6 +114,7 @@ public PantheonNode( final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, + final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -139,6 +142,7 @@ public PantheonNode( this.genesisConfigProvider = genesisConfigProvider; this.devMode = devMode; this.p2pEnabled = p2pEnabled; + this.networkingConfiguration = networkingConfiguration; this.discoveryEnabled = discoveryEnabled; plugins.forEach( pluginName -> { @@ -472,6 +476,10 @@ public boolean isP2pEnabled() { return p2pEnabled; } + public NetworkingConfiguration getNetworkingConfiguration() { + return networkingConfiguration; + } + @Override public boolean isBootnodeEligible() { return bootnodeEligible; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index 081bc8cfc4..a12989ff7f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -143,6 +143,11 @@ public void startNode(final PantheonNode node) { if (!node.isP2pEnabled()) { params.add("--p2p-enabled"); params.add("false"); + } else { + final int initiateConnectionsFreq = + node.getNetworkingConfiguration().getInitiateConnectionsFrequencySec(); + params.add("--Xp2p-initiate-connections-frequency"); + params.add(Integer.toString(initiateConnectionsFreq, 10)); } node.getPermissioningConfiguration() 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 1597ad1c87..be413db12d 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 @@ -146,6 +146,7 @@ public void startNode(final PantheonNode node) { .p2pAdvertisedHost(node.getHostName()) .p2pListenPort(0) .maxPeers(25) + .networkingConfiguration(node.getNetworkingConfiguration()) .jsonRpcConfiguration(node.jsonRpcConfiguration()) .webSocketConfiguration(node.webSocketConfiguration()) .dataDir(node.homeDirectory()) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java index 1e486075fc..d3aea06527 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java @@ -16,6 +16,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider; @@ -36,6 +37,7 @@ public class PantheonFactoryConfiguration { private final boolean devMode; private final GenesisConfigurationProvider genesisConfigProvider; private final boolean p2pEnabled; + private final NetworkingConfiguration networkingConfiguration; private final boolean discoveryEnabled; private final boolean bootnodeEligible; private final List plugins; @@ -53,6 +55,7 @@ public PantheonFactoryConfiguration( final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, + final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -68,6 +71,7 @@ public PantheonFactoryConfiguration( this.devMode = devMode; this.genesisConfigProvider = genesisConfigProvider; this.p2pEnabled = p2pEnabled; + this.networkingConfiguration = networkingConfiguration; this.discoveryEnabled = discoveryEnabled; this.bootnodeEligible = bootnodeEligible; this.plugins = plugins; @@ -122,6 +126,10 @@ public boolean isP2pEnabled() { return p2pEnabled; } + public NetworkingConfiguration getNetworkingConfiguration() { + return networkingConfiguration; + } + public boolean isBootnodeEligible() { return bootnodeEligible; } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java index a673c26b30..c0bec820f1 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider; @@ -45,11 +46,18 @@ public class PantheonFactoryConfigurationBuilder { private boolean devMode = true; private GenesisConfigurationProvider genesisConfigProvider = ignore -> Optional.empty(); private Boolean p2pEnabled = true; + private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create(); private boolean discoveryEnabled = true; private boolean bootnodeEligible = true; private List plugins = new ArrayList<>(); private List extraCLIOptions = new ArrayList<>(); + public PantheonFactoryConfigurationBuilder() { + // Check connections more frequently during acceptance tests to cut down on + // intermittent failures due to the fact that we're running over a real network + networkingConfiguration.setInitiateConnectionsFrequency(5); + } + public PantheonFactoryConfigurationBuilder name(final String name) { this.name = name; return this; @@ -192,6 +200,7 @@ public PantheonFactoryConfiguration build() { devMode, genesisConfigProvider, p2pEnabled, + networkingConfiguration, discoveryEnabled, bootnodeEligible, plugins, diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java index aded2d7499..9606263d87 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java @@ -44,6 +44,7 @@ public PantheonNode create(final PantheonFactoryConfiguration config) throws IOE config.isDevMode(), config.getGenesisConfigProvider(), config.isP2pEnabled(), + config.getNetworkingConfiguration(), config.isDiscoveryEnabled(), config.isBootnodeEligible(), config.getPlugins(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java index c379e963e9..f9fd3aac1b 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java @@ -17,6 +17,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonFactoryConfiguration; @@ -41,6 +42,7 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, + final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -58,6 +60,7 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur devMode, genesisConfigProvider, p2pEnabled, + networkingConfiguration, discoveryEnabled, bootnodeEligible, plugins, diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java index 927062c3e6..34aeef9639 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java @@ -44,6 +44,7 @@ public PrivacyPantheonFactoryConfiguration build() { config.isDevMode(), config.getGenesisConfigProvider(), config.isP2pEnabled(), + config.getNetworkingConfiguration(), config.isDiscoveryEnabled(), config.isBootnodeEligible(), config.getPlugins(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java index b7f43f4479..9971d92f2f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java @@ -40,6 +40,7 @@ private static PrivacyNode create(final PrivacyPantheonFactoryConfiguration conf config.isDevMode(), config.getGenesisConfigProvider(), config.isP2pEnabled(), + config.getNetworkingConfiguration(), config.isDiscoveryEnabled(), config.isBootnodeEligible(), config.getPlugins(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java index 10de64e65d..867fe2371c 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java @@ -22,6 +22,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; @@ -55,6 +56,7 @@ public PrivacyNode( final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, + final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -73,6 +75,7 @@ public PrivacyNode( devMode, genesisConfigProvider, p2pEnabled, + networkingConfiguration, discoveryEnabled, bootnodeEligible, plugins, diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 97052ea8e5..604c88df0d 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -30,6 +30,7 @@ dependencies { implementation project(':ethereum:core') implementation project(':ethereum:rlp') implementation project(':metrics:core') + implementation 'info.picocli:picocli' implementation 'com.google.guava:guava' implementation 'io.prometheus:simpleclient' diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java index c94c9c8b0b..83e6ed822a 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java @@ -12,12 +12,34 @@ */ package tech.pegasys.pantheon.ethereum.p2p.config; +import static com.google.common.base.Preconditions.checkArgument; + import java.util.Objects; +import picocli.CommandLine; + public class NetworkingConfiguration { private DiscoveryConfiguration discovery = new DiscoveryConfiguration(); private RlpxConfiguration rlpx = new RlpxConfiguration(); + @CommandLine.Option( + names = "--Xp2p-initiate-connections-frequency", + hidden = true, + defaultValue = "30", + paramLabel = "", + description = + "The frequency (in seconds) at which to initiate new outgoing connections (default: ${DEFAULT-VALUE})") + private int initiateConnectionsFrequencySec = 30; + + @CommandLine.Option( + names = "--Xp2p-check-maintained-connections-frequency", + hidden = true, + defaultValue = "60", + paramLabel = "", + description = + "The frequency (in seconds) at which to check maintained connections (default: ${DEFAULT-VALUE})") + private int checkMaintainedConnectionsFrequencySec = 60; + public static NetworkingConfiguration create() { return new NetworkingConfiguration(); } @@ -40,6 +62,28 @@ public NetworkingConfiguration setRlpx(final RlpxConfiguration rlpx) { return this; } + public int getInitiateConnectionsFrequencySec() { + return initiateConnectionsFrequencySec; + } + + public NetworkingConfiguration setInitiateConnectionsFrequency( + final int initiateConnectionsFrequency) { + checkArgument(initiateConnectionsFrequency > 0); + this.initiateConnectionsFrequencySec = initiateConnectionsFrequency; + return this; + } + + public int getCheckMaintainedConnectionsFrequencySec() { + return checkMaintainedConnectionsFrequencySec; + } + + public NetworkingConfiguration setCheckMaintainedConnectionsFrequency( + final int checkMaintainedConnectionsFrequency) { + checkArgument(checkMaintainedConnectionsFrequency > 0); + this.checkMaintainedConnectionsFrequencySec = checkMaintainedConnectionsFrequency; + return this; + } + @Override public boolean equals(final Object o) { if (o == this) { diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java index de69148d98..b8b2713ca9 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java @@ -181,10 +181,14 @@ public void start() { peerBondedObserverId = OptionalLong.of(peerDiscoveryAgent.observePeerBondedEvents(this::handlePeerBondedEvent)); + // Periodically check maintained connections + final int checkMaintainedConnectionsSec = config.getCheckMaintainedConnectionsFrequencySec(); peerConnectionScheduler.scheduleWithFixedDelay( - this::checkMaintainedConnectionPeers, 2, 60, TimeUnit.SECONDS); + this::checkMaintainedConnectionPeers, 2, checkMaintainedConnectionsSec, TimeUnit.SECONDS); + // Periodically initiate outgoing connections to discovered peers + final int checkConnectionsSec = config.getInitiateConnectionsFrequencySec(); peerConnectionScheduler.scheduleWithFixedDelay( - this::attemptPeerConnections, 30, 30, TimeUnit.SECONDS); + this::attemptPeerConnections, checkConnectionsSec, checkConnectionsSec, TimeUnit.SECONDS); } @Override diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index 2ab80980f7..42049cd44e 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -18,6 +18,7 @@ import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; @@ -42,6 +43,7 @@ public static void main(final String... args) { new PantheonController.Builder(), new SynchronizerConfiguration.Builder(), EthereumWireProtocolConfiguration.builder(), + NetworkingConfiguration.create(), new RocksDbConfiguration.Builder(), new PantheonPluginContextImpl()); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index bc6bf6ce23..e90fb5a333 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -104,17 +104,20 @@ public class RunnerBuilder { private Vertx vertx; private PantheonController pantheonController; + + private NetworkingConfiguration networkingConfiguration; + private Collection bannedNodeIds = new ArrayList<>(); private boolean p2pEnabled = true; private boolean discovery; - private EthNetworkConfig ethNetworkConfig; private String p2pAdvertisedHost; private int p2pListenPort; private int maxPeers; + private EthNetworkConfig ethNetworkConfig; + private JsonRpcConfiguration jsonRpcConfiguration; private GraphQLConfiguration graphQLConfiguration; private WebSocketConfiguration webSocketConfiguration; private Path dataDir; - private Collection bannedNodeIds = new ArrayList<>(); private MetricsConfiguration metricsConfiguration; private MetricsSystem metricsSystem; private Optional permissioningConfiguration = Optional.empty(); @@ -145,6 +148,12 @@ public RunnerBuilder ethNetworkConfig(final EthNetworkConfig ethNetworkConfig) { return this; } + public RunnerBuilder networkingConfiguration( + final NetworkingConfiguration networkingConfiguration) { + this.networkingConfiguration = networkingConfiguration; + return this; + } + public RunnerBuilder p2pAdvertisedHost(final String p2pAdvertisedHost) { this.p2pAdvertisedHost = p2pAdvertisedHost; return this; @@ -248,10 +257,7 @@ public Runner build() { .setMaxPeers(maxPeers) .setSupportedProtocols(subProtocols) .setClientId(PantheonInfo.version()); - final NetworkingConfiguration networkConfig = - new NetworkingConfiguration() - .setRlpx(rlpxConfiguration) - .setDiscovery(discoveryConfiguration); + networkingConfiguration.setRlpx(rlpxConfiguration).setDiscovery(discoveryConfiguration); final PeerPermissionsBlacklist bannedNodes = PeerPermissionsBlacklist.create(); bannedNodeIds.forEach(bannedNodes::add); @@ -281,7 +287,7 @@ public Runner build() { DefaultP2PNetwork.builder() .vertx(vertx) .keyPair(keyPair) - .config(networkConfig) + .config(networkingConfiguration) .peerPermissions(peerPermissions) .metricsSystem(metricsSystem) .supportedCapabilities(caps) 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 8e53314aee..9bea1fafa1 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -56,6 +56,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.StaticNodesParser; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; @@ -138,6 +139,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final BlockImporter blockImporter; + private final NetworkingConfiguration networkingConfiguration; private final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder; private final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder; private final RocksDbConfiguration.Builder rocksDbConfigurationBuilder; @@ -605,12 +607,14 @@ public PantheonCommand( final PantheonController.Builder controllerBuilderFactory, final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder, final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder, + final NetworkingConfiguration networkingConfiguration, final RocksDbConfiguration.Builder rocksDbConfigurationBuilder, final PantheonPluginContextImpl pantheonPluginContext) { this.logger = logger; this.blockImporter = blockImporter; this.runnerBuilder = runnerBuilder; this.controllerBuilderFactory = controllerBuilderFactory; + this.networkingConfiguration = networkingConfiguration; this.synchronizerConfigurationBuilder = synchronizerConfigurationBuilder; this.ethereumWireConfigurationBuilder = ethereumWireConfigurationBuilder; this.rocksDbConfigurationBuilder = rocksDbConfigurationBuilder; @@ -664,6 +668,8 @@ public void parse( UnstableOptionsSubCommand.createUnstableOptions( commandLine, ImmutableMap.of( + "P2P Network", + networkingConfiguration, "Synchronizer", synchronizerConfigurationBuilder, "RocksDB", @@ -1107,6 +1113,7 @@ private void synchronize( .p2pAdvertisedHost(p2pAdvertisedHost) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) + .networkingConfiguration(networkingConfiguration) .graphQLConfiguration(graphQLConfiguration) .jsonRpcConfiguration(jsonRpcConfiguration) .webSocketConfiguration(webSocketConfiguration) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index f3c162d378..aef4468197 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -35,6 +35,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; @@ -88,6 +89,7 @@ public abstract class CommandTestAbstract { @Mock BlockBroadcaster mockBlockBroadcaster; @Mock SynchronizerConfiguration.Builder mockSyncConfBuilder; @Mock EthereumWireProtocolConfiguration.Builder mockEthereumWireProtocolConfigurationBuilder; + @Mock NetworkingConfiguration mockNetworkingConfiguration; @Mock SynchronizerConfiguration mockSyncConf; @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; @Mock RocksDbConfiguration mockRocksDbConf; @@ -213,6 +215,7 @@ private CommandLine.Model.CommandSpec parseCommand( mockControllerBuilderFactory, mockSyncConfBuilder, mockEthereumWireProtocolConfigurationBuilder, + mockNetworkingConfiguration, mockRocksDbConfBuilder, keyLoader, mockPantheonPluginContext); @@ -243,6 +246,7 @@ protected KeyLoader getKeyLoader() { final PantheonController.Builder controllerBuilderFactory, final SynchronizerConfiguration.Builder mockSyncConfBuilder, final EthereumWireProtocolConfiguration.Builder mockEthereumConfigurationMockBuilder, + final NetworkingConfiguration mockNetworkingConfiguration, final RocksDbConfiguration.Builder mockRocksDbConfBuilder, final KeyLoader keyLoader, final PantheonPluginContextImpl pantheonPluginContext) { @@ -253,6 +257,7 @@ protected KeyLoader getKeyLoader() { controllerBuilderFactory, mockSyncConfBuilder, mockEthereumConfigurationMockBuilder, + mockNetworkingConfiguration, mockRocksDbConfBuilder, pantheonPluginContext); this.keyLoader = keyLoader; From f9c716cebdf2306a02e8ebfb2928592076c63d74 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Thu, 20 Jun 2019 15:52:30 -0400 Subject: [PATCH 02/15] Get CLI params from NetworkingConfiguration --- .../dsl/node/ProcessPantheonNodeRunner.java | 5 +---- .../p2p/config/NetworkingConfiguration.java | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index a12989ff7f..bd83d6a18d 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -144,10 +144,7 @@ public void startNode(final PantheonNode node) { params.add("--p2p-enabled"); params.add("false"); } else { - final int initiateConnectionsFreq = - node.getNetworkingConfiguration().getInitiateConnectionsFrequencySec(); - params.add("--Xp2p-initiate-connections-frequency"); - params.add(Integer.toString(initiateConnectionsFreq, 10)); + params.addAll(node.getNetworkingConfiguration().toCLIParams()); } node.getPermissioningConfiguration() diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java index 83e6ed822a..2f4bb92a91 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java @@ -14,16 +14,23 @@ import static com.google.common.base.Preconditions.checkArgument; +import java.util.Arrays; +import java.util.List; import java.util.Objects; import picocli.CommandLine; public class NetworkingConfiguration { + private final String INITIATE_CONNECTIONS_FREQUENCY_FLAG = + "--Xp2p-initiate-connections-frequency"; + private final String CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG = + "--Xp2p-check-maintained-connections-frequency"; + private DiscoveryConfiguration discovery = new DiscoveryConfiguration(); private RlpxConfiguration rlpx = new RlpxConfiguration(); @CommandLine.Option( - names = "--Xp2p-initiate-connections-frequency", + names = INITIATE_CONNECTIONS_FREQUENCY_FLAG, hidden = true, defaultValue = "30", paramLabel = "", @@ -32,7 +39,7 @@ public class NetworkingConfiguration { private int initiateConnectionsFrequencySec = 30; @CommandLine.Option( - names = "--Xp2p-check-maintained-connections-frequency", + names = CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, hidden = true, defaultValue = "60", paramLabel = "", @@ -44,6 +51,14 @@ public static NetworkingConfiguration create() { return new NetworkingConfiguration(); } + public List toCLIParams() { + return Arrays.asList( + CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, + Integer.toString(getCheckMaintainedConnectionsFrequencySec(), 10), + INITIATE_CONNECTIONS_FREQUENCY_FLAG, + Integer.toString(getInitiateConnectionsFrequencySec(), 10)); + } + public DiscoveryConfiguration getDiscovery() { return discovery; } From 097ea41e89c2107abcae77bcf6bc6f065f3522d7 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Thu, 20 Jun 2019 15:54:28 -0400 Subject: [PATCH 03/15] Set a default NetworkingConfiguration --- pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index e90fb5a333..d0bddac3c8 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -105,7 +105,7 @@ public class RunnerBuilder { private Vertx vertx; private PantheonController pantheonController; - private NetworkingConfiguration networkingConfiguration; + private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create(); private Collection bannedNodeIds = new ArrayList<>(); private boolean p2pEnabled = true; private boolean discovery; From 75fa3fefe8a128f54555029779a4e437e9222c8d Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 21 Jun 2019 16:50:39 -0400 Subject: [PATCH 04/15] Add missing mocked method --- .../tech/pegasys/pantheon/cli/CommandTestAbstract.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index aef4468197..4cb89ee054 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -89,7 +89,7 @@ public abstract class CommandTestAbstract { @Mock BlockBroadcaster mockBlockBroadcaster; @Mock SynchronizerConfiguration.Builder mockSyncConfBuilder; @Mock EthereumWireProtocolConfiguration.Builder mockEthereumWireProtocolConfigurationBuilder; - @Mock NetworkingConfiguration mockNetworkingConfiguration; + NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create(); @Mock SynchronizerConfiguration mockSyncConf; @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; @Mock RocksDbConfiguration mockRocksDbConf; @@ -161,6 +161,7 @@ public void initMocks() throws Exception { when(mockRunnerBuilder.pantheonController(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.discovery(anyBoolean())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.ethNetworkConfig(any())).thenReturn(mockRunnerBuilder); + when(mockRunnerBuilder.networkingConfiguration(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.p2pAdvertisedHost(anyString())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.p2pListenPort(anyInt())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.maxPeers(anyInt())).thenReturn(mockRunnerBuilder); @@ -215,7 +216,7 @@ private CommandLine.Model.CommandSpec parseCommand( mockControllerBuilderFactory, mockSyncConfBuilder, mockEthereumWireProtocolConfigurationBuilder, - mockNetworkingConfiguration, + networkingConfiguration, mockRocksDbConfBuilder, keyLoader, mockPantheonPluginContext); @@ -246,7 +247,7 @@ protected KeyLoader getKeyLoader() { final PantheonController.Builder controllerBuilderFactory, final SynchronizerConfiguration.Builder mockSyncConfBuilder, final EthereumWireProtocolConfiguration.Builder mockEthereumConfigurationMockBuilder, - final NetworkingConfiguration mockNetworkingConfiguration, + final NetworkingConfiguration networkingConfiguration, final RocksDbConfiguration.Builder mockRocksDbConfBuilder, final KeyLoader keyLoader, final PantheonPluginContextImpl pantheonPluginContext) { @@ -257,7 +258,7 @@ protected KeyLoader getKeyLoader() { controllerBuilderFactory, mockSyncConfBuilder, mockEthereumConfigurationMockBuilder, - mockNetworkingConfiguration, + networkingConfiguration, mockRocksDbConfBuilder, pantheonPluginContext); this.keyLoader = keyLoader; From 71838500a0527f843b225093df26da44555a596a Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 21 Jun 2019 17:57:33 -0400 Subject: [PATCH 05/15] Rework CLI flag handling --- .../dsl/node/ProcessPantheonNodeRunner.java | 5 +- ethereum/p2p/build.gradle | 1 - .../p2p/config/NetworkingConfiguration.java | 33 --------- .../java/tech/pegasys/pantheon/Pantheon.java | 2 - .../pegasys/pantheon/cli/PantheonCommand.java | 11 +-- .../pantheon/cli/adapter/CLIAdapter.java | 22 ++++++ .../NetworkingConfigurationCLIAdapter.java | 72 +++++++++++++++++++ .../pantheon/cli/CommandTestAbstract.java | 5 +- .../pantheon/cli/PantheonCommandTest.java | 53 ++++++++++++++ 9 files changed, 158 insertions(+), 46 deletions(-) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index bd83d6a18d..1a95fdfc84 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -14,6 +14,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; +import tech.pegasys.pantheon.cli.adapter.NetworkingConfigurationCLIAdapter; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; @@ -144,7 +145,9 @@ public void startNode(final PantheonNode node) { params.add("--p2p-enabled"); params.add("false"); } else { - params.addAll(node.getNetworkingConfiguration().toCLIParams()); + final List networkConfigParams = + NetworkingConfigurationCLIAdapter.toCLI(node.getNetworkingConfiguration()); + params.addAll(networkConfigParams); } node.getPermissioningConfiguration() diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 604c88df0d..97052ea8e5 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -30,7 +30,6 @@ dependencies { implementation project(':ethereum:core') implementation project(':ethereum:rlp') implementation project(':metrics:core') - implementation 'info.picocli:picocli' implementation 'com.google.guava:guava' implementation 'io.prometheus:simpleclient' diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java index 2f4bb92a91..7c2f31159b 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java @@ -14,51 +14,18 @@ import static com.google.common.base.Preconditions.checkArgument; -import java.util.Arrays; -import java.util.List; import java.util.Objects; -import picocli.CommandLine; - public class NetworkingConfiguration { - private final String INITIATE_CONNECTIONS_FREQUENCY_FLAG = - "--Xp2p-initiate-connections-frequency"; - private final String CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG = - "--Xp2p-check-maintained-connections-frequency"; - private DiscoveryConfiguration discovery = new DiscoveryConfiguration(); private RlpxConfiguration rlpx = new RlpxConfiguration(); - - @CommandLine.Option( - names = INITIATE_CONNECTIONS_FREQUENCY_FLAG, - hidden = true, - defaultValue = "30", - paramLabel = "", - description = - "The frequency (in seconds) at which to initiate new outgoing connections (default: ${DEFAULT-VALUE})") private int initiateConnectionsFrequencySec = 30; - - @CommandLine.Option( - names = CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, - hidden = true, - defaultValue = "60", - paramLabel = "", - description = - "The frequency (in seconds) at which to check maintained connections (default: ${DEFAULT-VALUE})") private int checkMaintainedConnectionsFrequencySec = 60; public static NetworkingConfiguration create() { return new NetworkingConfiguration(); } - public List toCLIParams() { - return Arrays.asList( - CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, - Integer.toString(getCheckMaintainedConnectionsFrequencySec(), 10), - INITIATE_CONNECTIONS_FREQUENCY_FLAG, - Integer.toString(getInitiateConnectionsFrequencySec(), 10)); - } - public DiscoveryConfiguration getDiscovery() { return discovery; } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index 42049cd44e..2ab80980f7 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -18,7 +18,6 @@ import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; @@ -43,7 +42,6 @@ public static void main(final String... args) { new PantheonController.Builder(), new SynchronizerConfiguration.Builder(), EthereumWireProtocolConfiguration.builder(), - NetworkingConfiguration.create(), new RocksDbConfiguration.Builder(), new PantheonPluginContextImpl()); 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 9bea1fafa1..984d0998c2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -31,6 +31,8 @@ import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; +import tech.pegasys.pantheon.cli.adapter.CLIAdapter; +import tech.pegasys.pantheon.cli.adapter.NetworkingConfigurationCLIAdapter; import tech.pegasys.pantheon.cli.converter.MetricCategoryConverter; import tech.pegasys.pantheon.cli.converter.RpcApisConverter; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; @@ -139,7 +141,8 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final BlockImporter blockImporter; - private final NetworkingConfiguration networkingConfiguration; + private final CLIAdapter networkingConfigAdapter = + NetworkingConfigurationCLIAdapter.create(); private final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder; private final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder; private final RocksDbConfiguration.Builder rocksDbConfigurationBuilder; @@ -607,14 +610,12 @@ public PantheonCommand( final PantheonController.Builder controllerBuilderFactory, final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder, final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder, - final NetworkingConfiguration networkingConfiguration, final RocksDbConfiguration.Builder rocksDbConfigurationBuilder, final PantheonPluginContextImpl pantheonPluginContext) { this.logger = logger; this.blockImporter = blockImporter; this.runnerBuilder = runnerBuilder; this.controllerBuilderFactory = controllerBuilderFactory; - this.networkingConfiguration = networkingConfiguration; this.synchronizerConfigurationBuilder = synchronizerConfigurationBuilder; this.ethereumWireConfigurationBuilder = ethereumWireConfigurationBuilder; this.rocksDbConfigurationBuilder = rocksDbConfigurationBuilder; @@ -669,7 +670,7 @@ public void parse( commandLine, ImmutableMap.of( "P2P Network", - networkingConfiguration, + networkingConfigAdapter, "Synchronizer", synchronizerConfigurationBuilder, "RocksDB", @@ -1113,7 +1114,7 @@ private void synchronize( .p2pAdvertisedHost(p2pAdvertisedHost) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) - .networkingConfiguration(networkingConfiguration) + .networkingConfiguration(networkingConfigAdapter.fromCLI()) .graphQLConfiguration(graphQLConfiguration) .jsonRpcConfiguration(jsonRpcConfiguration) .webSocketConfiguration(webSocketConfiguration) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java new file mode 100644 index 0000000000..9ab7fe8412 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java @@ -0,0 +1,22 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.adapter; + +import java.util.List; + +public interface CLIAdapter { + + T fromCLI(); + + List toCLIParams(T config); +} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java new file mode 100644 index 0000000000..11d958d94f --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java @@ -0,0 +1,72 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.adapter; + +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; + +import java.util.Arrays; +import java.util.List; + +import picocli.CommandLine; + +public class NetworkingConfigurationCLIAdapter implements CLIAdapter { + private final String INITIATE_CONNECTIONS_FREQUENCY_FLAG = + "--Xp2p-initiate-connections-frequency"; + private final String CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG = + "--Xp2p-check-maintained-connections-frequency"; + + @CommandLine.Option( + names = INITIATE_CONNECTIONS_FREQUENCY_FLAG, + hidden = true, + defaultValue = "30", + paramLabel = "", + description = + "The frequency (in seconds) at which to initiate new outgoing connections (default: ${DEFAULT-VALUE})") + private int initiateConnectionsFrequencySec = 30; + + @CommandLine.Option( + names = CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, + hidden = true, + defaultValue = "60", + paramLabel = "", + description = + "The frequency (in seconds) at which to check maintained connections (default: ${DEFAULT-VALUE})") + private int checkMaintainedConnectionsFrequencySec = 60; + + private static final NetworkingConfigurationCLIAdapter internalInstance = create(); + + public static NetworkingConfigurationCLIAdapter create() { + return new NetworkingConfigurationCLIAdapter(); + } + + public static List toCLI(final NetworkingConfiguration config) { + return internalInstance.toCLIParams(config); + } + + @Override + public NetworkingConfiguration fromCLI() { + NetworkingConfiguration config = NetworkingConfiguration.create(); + config.setCheckMaintainedConnectionsFrequency(checkMaintainedConnectionsFrequencySec); + config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec); + return config; + } + + @Override + public List toCLIParams(final NetworkingConfiguration config) { + return Arrays.asList( + CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, + Integer.toString(config.getCheckMaintainedConnectionsFrequencySec(), 10), + INITIATE_CONNECTIONS_FREQUENCY_FLAG, + Integer.toString(config.getInitiateConnectionsFrequencySec(), 10)); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index 4cb89ee054..dd9cfbb045 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -89,7 +89,6 @@ public abstract class CommandTestAbstract { @Mock BlockBroadcaster mockBlockBroadcaster; @Mock SynchronizerConfiguration.Builder mockSyncConfBuilder; @Mock EthereumWireProtocolConfiguration.Builder mockEthereumWireProtocolConfigurationBuilder; - NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create(); @Mock SynchronizerConfiguration mockSyncConf; @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; @Mock RocksDbConfiguration mockRocksDbConf; @@ -105,6 +104,7 @@ public abstract class CommandTestAbstract { @Captor ArgumentCaptor stringArgumentCaptor; @Captor ArgumentCaptor intArgumentCaptor; @Captor ArgumentCaptor ethNetworkConfigArgumentCaptor; + @Captor ArgumentCaptor networkingConfigurationArgumentCaptor; @Captor ArgumentCaptor jsonRpcConfigArgumentCaptor; @Captor ArgumentCaptor graphQLConfigArgumentCaptor; @Captor ArgumentCaptor wsRpcConfigArgumentCaptor; @@ -216,7 +216,6 @@ private CommandLine.Model.CommandSpec parseCommand( mockControllerBuilderFactory, mockSyncConfBuilder, mockEthereumWireProtocolConfigurationBuilder, - networkingConfiguration, mockRocksDbConfBuilder, keyLoader, mockPantheonPluginContext); @@ -247,7 +246,6 @@ protected KeyLoader getKeyLoader() { final PantheonController.Builder controllerBuilderFactory, final SynchronizerConfiguration.Builder mockSyncConfBuilder, final EthereumWireProtocolConfiguration.Builder mockEthereumConfigurationMockBuilder, - final NetworkingConfiguration networkingConfiguration, final RocksDbConfiguration.Builder mockRocksDbConfBuilder, final KeyLoader keyLoader, final PantheonPluginContextImpl pantheonPluginContext) { @@ -258,7 +256,6 @@ protected KeyLoader getKeyLoader() { controllerBuilderFactory, mockSyncConfBuilder, mockEthereumConfigurationMockBuilder, - networkingConfiguration, mockRocksDbConfBuilder, pantheonPluginContext); this.keyLoader = keyLoader; 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 7873d67da6..194b2b8a8d 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -45,6 +45,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; @@ -336,6 +337,58 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void checkMaintainedConnectionsFrequencyFlag_isSet() { + parseCommand("--Xp2p-check-maintained-connections-frequency", "2"); + verify(mockRunnerBuilder) + .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); + final NetworkingConfiguration networkingConfig = + networkingConfigurationArgumentCaptor.getValue(); + assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(2); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void checkMaintainedFrequencyConnectionsFlag_isNotSet() { + parseCommand(); + verify(mockRunnerBuilder) + .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); + final NetworkingConfiguration networkingConfig = + networkingConfigurationArgumentCaptor.getValue(); + assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(60); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void initiateConnectionsFrequencyFlag_isSet() { + parseCommand("--Xp2p-initiate-connections-frequency", "2"); + verify(mockRunnerBuilder) + .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); + final NetworkingConfiguration networkingConfig = + networkingConfigurationArgumentCaptor.getValue(); + assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(2); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void initiateConnectionsFrequencyFlag_isNotSet() { + parseCommand(); + verify(mockRunnerBuilder) + .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); + final NetworkingConfiguration networkingConfig = + networkingConfigurationArgumentCaptor.getValue(); + assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(30); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + @Test public void nodePermissionsSmartContractWithoutOptionMustError() { parseCommand("--permissions-nodes-contract-address"); From f60e2e266ddc49bcb38cd71d5cf4fa9e88c87af7 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 25 Jun 2019 14:59:28 -0400 Subject: [PATCH 06/15] Rework Options interface --- .../dsl/node/ProcessPantheonNodeRunner.java | 4 +-- .../pegasys/pantheon/cli/PantheonCommand.java | 11 ++++---- .../CLIOptions.java} | 19 ++++++++++--- .../NetworkingOptions.java} | 28 +++++++++++-------- 4 files changed, 39 insertions(+), 23 deletions(-) rename pantheon/src/main/java/tech/pegasys/pantheon/cli/{adapter/CLIAdapter.java => options/CLIOptions.java} (55%) rename pantheon/src/main/java/tech/pegasys/pantheon/cli/{adapter/NetworkingConfigurationCLIAdapter.java => options/NetworkingOptions.java} (69%) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index 1a95fdfc84..10da4b6972 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -14,7 +14,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; -import tech.pegasys.pantheon.cli.adapter.NetworkingConfigurationCLIAdapter; +import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; @@ -146,7 +146,7 @@ public void startNode(final PantheonNode node) { params.add("false"); } else { final List networkConfigParams = - NetworkingConfigurationCLIAdapter.toCLI(node.getNetworkingConfiguration()); + NetworkingOptions.fromConfig(node.getNetworkingConfiguration()).getCLIOptions(); params.addAll(networkConfigParams); } 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 4990a786de..421f0a6db2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -32,14 +32,14 @@ import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; -import tech.pegasys.pantheon.cli.adapter.CLIAdapter; -import tech.pegasys.pantheon.cli.adapter.NetworkingConfigurationCLIAdapter; import tech.pegasys.pantheon.cli.converter.MetricCategoryConverter; import tech.pegasys.pantheon.cli.converter.RpcApisConverter; import tech.pegasys.pantheon.cli.custom.CorsAllowedOriginsProperty; import tech.pegasys.pantheon.cli.custom.JsonRPCWhitelistHostsProperty; import tech.pegasys.pantheon.cli.custom.RpcAuthFileValidator; import tech.pegasys.pantheon.cli.operator.OperatorSubCommand; +import tech.pegasys.pantheon.cli.options.CLIOptions; +import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.cli.rlp.RLPSubCommand; import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.controller.KeyPairUtil; @@ -143,8 +143,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final BlockImporter blockImporter; - private final CLIAdapter networkingConfigAdapter = - NetworkingConfigurationCLIAdapter.create(); + private final CLIOptions networkingOptions = NetworkingOptions.create(); private final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder; private final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder; private final RocksDbConfiguration.Builder rocksDbConfigurationBuilder; @@ -675,7 +674,7 @@ public void parse( commandLine, ImmutableMap.of( "P2P Network", - networkingConfigAdapter, + networkingOptions, "Synchronizer", synchronizerConfigurationBuilder, "RocksDB", @@ -1121,7 +1120,7 @@ private void synchronize( .p2pAdvertisedHost(p2pAdvertisedHost) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) - .networkingConfiguration(networkingConfigAdapter.fromCLI()) + .networkingConfiguration(networkingOptions.toDomainObject()) .graphQLConfiguration(graphQLConfiguration) .jsonRpcConfiguration(jsonRpcConfiguration) .webSocketConfiguration(webSocketConfiguration) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/CLIOptions.java similarity index 55% rename from pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java rename to pantheon/src/main/java/tech/pegasys/pantheon/cli/options/CLIOptions.java index 9ab7fe8412..76ceeb9280 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/CLIAdapter.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/CLIOptions.java @@ -10,13 +10,24 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.cli.adapter; +package tech.pegasys.pantheon.cli.options; import java.util.List; -public interface CLIAdapter { +/** + * This interface represents logic that translates between CLI options and a domain object. + * + * @param A class to be constructed from CLI arguments. + */ +public interface CLIOptions { - T fromCLI(); + /** + * Transform CLI options into a domain object. + * + * @return A domain object representing these CLI options. + */ + T toDomainObject(); - List toCLIParams(T config); + /** @return The list of CLI options corresponding to this class. */ + List getCLIOptions(); } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java similarity index 69% rename from pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java rename to pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java index 11d958d94f..2b8e9cf095 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/adapter/NetworkingConfigurationCLIAdapter.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java @@ -10,7 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.cli.adapter; +package tech.pegasys.pantheon.cli.options; import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; @@ -19,7 +19,7 @@ import picocli.CommandLine; -public class NetworkingConfigurationCLIAdapter implements CLIAdapter { +public class NetworkingOptions implements CLIOptions { private final String INITIATE_CONNECTIONS_FREQUENCY_FLAG = "--Xp2p-initiate-connections-frequency"; private final String CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG = @@ -43,18 +43,24 @@ public class NetworkingConfigurationCLIAdapter implements CLIAdapter toCLI(final NetworkingConfiguration config) { - return internalInstance.toCLIParams(config); + public static CLIOptions fromConfig( + final NetworkingConfiguration networkingConfig) { + final NetworkingOptions cliOptions = new NetworkingOptions(); + cliOptions.checkMaintainedConnectionsFrequencySec = + networkingConfig.getCheckMaintainedConnectionsFrequencySec(); + cliOptions.initiateConnectionsFrequencySec = + networkingConfig.getInitiateConnectionsFrequencySec(); + return cliOptions; } @Override - public NetworkingConfiguration fromCLI() { + public NetworkingConfiguration toDomainObject() { NetworkingConfiguration config = NetworkingConfiguration.create(); config.setCheckMaintainedConnectionsFrequency(checkMaintainedConnectionsFrequencySec); config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec); @@ -62,11 +68,11 @@ public NetworkingConfiguration fromCLI() { } @Override - public List toCLIParams(final NetworkingConfiguration config) { + public List getCLIOptions() { return Arrays.asList( CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, - Integer.toString(config.getCheckMaintainedConnectionsFrequencySec(), 10), + Integer.toString(checkMaintainedConnectionsFrequencySec, 10), INITIATE_CONNECTIONS_FREQUENCY_FLAG, - Integer.toString(config.getInitiateConnectionsFrequencySec(), 10)); + Integer.toString(initiateConnectionsFrequencySec, 10)); } } From f6c1343031aff39d3c5d86326fd31bcaf8f638ef Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 28 Jun 2019 10:41:09 -0400 Subject: [PATCH 07/15] Move sync CLI config to new model, update getters --- .../WorldStateDownloaderBenchmark.java | 6 +- .../eth/sync/BlockPropagationManager.java | 4 +- .../eth/sync/CheckpointHeaderFetcher.java | 6 +- .../ethereum/eth/sync/SyncTargetManager.java | 2 +- .../eth/sync/SynchronizerConfiguration.java | 211 ++++--------- .../sync/fastsync/FastDownloaderFactory.java | 2 +- .../eth/sync/fastsync/FastSyncActions.java | 2 +- .../FastSyncDownloadPipelineFactory.java | 15 +- .../fullsync/BetterSyncTargetEvaluator.java | 4 +- .../FullSyncDownloadPipelineFactory.java | 6 +- .../sync/fastsync/FastSyncActionsTest.java | 5 +- .../fastsync/FastSyncChainDownloaderTest.java | 2 +- .../java/tech/pegasys/pantheon/Pantheon.java | 2 - .../pegasys/pantheon/cli/PantheonCommand.java | 12 +- .../cli/options/NetworkingOptions.java | 7 +- .../pantheon/cli/options/OptionParser.java | 56 ++++ .../cli/options/SynchronizerOptions.java | 282 ++++++++++++++++++ .../IbftLegacyPantheonControllerBuilder.java | 6 +- .../controller/PantheonControllerBuilder.java | 8 +- .../pantheon/cli/CommandTestAbstract.java | 77 +++-- .../pantheon/cli/PantheonCommandTest.java | 44 ++- .../cli/options/NetworkingOptionsTest.java | 64 ++++ .../cli/options/OptionParserTest.java | 103 +++++++ .../cli/options/SynchronizerOptionsTest.java | 62 ++++ 24 files changed, 726 insertions(+), 262 deletions(-) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/options/OptionParser.java create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/options/SynchronizerOptions.java create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/OptionParserTest.java create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java diff --git a/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java b/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java index 1e63b6d858..80a395b80c 100644 --- a/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java +++ b/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java @@ -81,9 +81,9 @@ public void setUpUnchangedState() throws Exception { ethProtocolManager = EthProtocolManagerTestUtil.create( new EthScheduler( - syncConfig.downloaderParallelism(), - syncConfig.transactionsParallelism(), - syncConfig.computationParallelism(), + syncConfig.getDownloaderParallelism(), + syncConfig.getTransactionsParallelism(), + syncConfig.getComputationParallelism(), metricsSystem)); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber()); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/BlockPropagationManager.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/BlockPropagationManager.java index 8c95d24bbf..2dd04483ea 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/BlockPropagationManager.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/BlockPropagationManager.java @@ -143,7 +143,7 @@ private void onBlockAdded(final BlockAddedEvent blockAddedEvent, final Blockchai if (blockAddedEvent.getEventType().equals(EventType.HEAD_ADVANCED)) { final long head = blockchain.getChainHeadBlockNumber(); - final long cutoff = head + config.blockPropagationRange().lowerEndpoint(); + final long cutoff = head + config.getBlockPropagationRange().lowerEndpoint(); pendingBlocks.purgeBlocksOlderThan(cutoff); } } @@ -350,7 +350,7 @@ private boolean shouldImportBlockAtHeight( final long blockNumber, final long localHeight, final long bestChainHeight) { final long distanceFromLocalHead = blockNumber - localHeight; final long distanceFromBestPeer = blockNumber - bestChainHeight; - final Range importRange = config.blockPropagationRange(); + final Range importRange = config.getBlockPropagationRange(); return importRange.contains(distanceFromLocalHead) && importRange.contains(distanceFromBestPeer); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/CheckpointHeaderFetcher.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/CheckpointHeaderFetcher.java index 8542f6455b..62edb7518e 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/CheckpointHeaderFetcher.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/CheckpointHeaderFetcher.java @@ -56,8 +56,8 @@ public CheckpointHeaderFetcher( public CompletableFuture> getNextCheckpointHeaders( final EthPeer peer, final BlockHeader previousCheckpointHeader) { - final int skip = syncConfig.downloaderChainSegmentSize() - 1; - final int maximumHeaderRequestSize = syncConfig.downloaderHeaderRequestSize(); + final int skip = syncConfig.getDownloaderChainSegmentSize() - 1; + final int maximumHeaderRequestSize = syncConfig.getDownloaderHeaderRequestSize(); final long previousCheckpointNumber = previousCheckpointHeader.getNumber(); final int additionalHeaderCount; @@ -117,7 +117,7 @@ public boolean nextCheckpointEndsAtChainHead( if (finalCheckpointHeader.isPresent()) { return false; } - final int skip = syncConfig.downloaderChainSegmentSize() - 1; + final int skip = syncConfig.getDownloaderChainSegmentSize() - 1; final long peerEstimatedHeight = peer.chainState().getEstimatedHeight(); final long previousCheckpointNumber = previousCheckpointHeader.getNumber(); return previousCheckpointNumber + skip >= peerEstimatedHeight; diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SyncTargetManager.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SyncTargetManager.java index 1c56906f86..d9430c6a0c 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SyncTargetManager.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SyncTargetManager.java @@ -71,7 +71,7 @@ private CompletableFuture selectNewSyncTarget() { protocolContext, ethContext, bestPeer, - config.downloaderHeaderRequestSize(), + config.getDownloaderHeaderRequestSize(), metricsSystem) .run() .handle( diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SynchronizerConfiguration.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SynchronizerConfiguration.java index 539c673a87..99e7bc309d 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SynchronizerConfiguration.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SynchronizerConfiguration.java @@ -13,27 +13,34 @@ package tech.pegasys.pantheon.ethereum.eth.sync; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import tech.pegasys.pantheon.util.uint.UInt256; -import java.util.Iterator; import java.util.concurrent.TimeUnit; -import com.google.common.base.Splitter; import com.google.common.collect.Range; -import picocli.CommandLine; public class SynchronizerConfiguration { - // TODO: Determine reasonable defaults here - private static final int DEFAULT_PIVOT_DISTANCE_FROM_HEAD = 50; - private static final float DEFAULT_FULL_VALIDATION_RATE = .1f; - private static final int DEFAULT_FAST_SYNC_MINIMUM_PEERS = 5; - private static final int DEFAULT_WORLD_STATE_HASH_COUNT_PER_REQUEST = 384; - private static final int DEFAULT_WORLD_STATE_REQUEST_PARALLELISM = 10; - private static final int DEFAULT_WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS = 1000; - private static final long DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING = + public static final int DEFAULT_PIVOT_DISTANCE_FROM_HEAD = 50; + public static final float DEFAULT_FULL_VALIDATION_RATE = .1f; + public static final int DEFAULT_FAST_SYNC_MINIMUM_PEERS = 5; + public static final int DEFAULT_WORLD_STATE_HASH_COUNT_PER_REQUEST = 384; + public static final int DEFAULT_WORLD_STATE_REQUEST_PARALLELISM = 10; + public static final int DEFAULT_WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS = 1000; + public static final long DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING = TimeUnit.MINUTES.toMillis(5); + public static final Range DEFAULT_BLOCK_PROPAGATION_RANGE = Range.closed(-10L, 30L); + public static final long DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT = 200L; + public static final UInt256 DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD = + UInt256.of(1_000_000_000_000_000_000L); + public static final int DEFAULT_DOWNLOADER_HEADER_REQUEST_SIZE = 200; + public static final int DEFAULT_DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED = 5; + public static final int DEFAULT_DOWNLOADER_CHAIN_SEGMENT_SIZE = 200; + public static final int DEFAULT_DOWNLOADER_PARALLELISM = 4; + public static final int DEFAULT_TRANSACTIONS_PARALLELISM = 2; + public static final int DEFAULT_COMPUTATION_PARALLELISM = 2; // Fast sync config private final int fastSyncPivotDistance; @@ -109,7 +116,7 @@ public static Builder builder() { * * @return the sync mode */ - public SyncMode syncMode() { + public SyncMode getSyncMode() { return syncMode; } @@ -120,7 +127,7 @@ public SyncMode syncMode() { * @return the range of blocks considered valid to import from the network, relative to the the * current chain head. */ - public Range blockPropagationRange() { + public Range getBlockPropagationRange() { return blockPropagationRange; } @@ -129,39 +136,39 @@ public Range blockPropagationRange() { * * @return distance from the chain head at which we should switch from fast sync to full sync. */ - public int fastSyncPivotDistance() { + public int getFastSyncPivotDistance() { return fastSyncPivotDistance; } - public long downloaderChangeTargetThresholdByHeight() { + public long getDownloaderChangeTargetThresholdByHeight() { return downloaderChangeTargetThresholdByHeight; } - public UInt256 downloaderChangeTargetThresholdByTd() { + public UInt256 getDownloaderChangeTargetThresholdByTd() { return downloaderChangeTargetThresholdByTd; } - public int downloaderHeaderRequestSize() { + public int getDownloaderHeaderRequestSize() { return downloaderHeaderRequestSize; } - public int downloaderCheckpointTimeoutsPermitted() { + public int getDownloaderCheckpointTimeoutsPermitted() { return downloaderCheckpointTimeoutsPermitted; } - public int downloaderChainSegmentSize() { + public int getDownloaderChainSegmentSize() { return downloaderChainSegmentSize; } - public int downloaderParallelism() { + public int getDownloaderParallelism() { return downloaderParallelism; } - public int transactionsParallelism() { + public int getTransactionsParallelism() { return transactionsParallelism; } - public int computationParallelism() { + public int getComputationParallelism() { return computationParallelism; } @@ -172,7 +179,7 @@ public int computationParallelism() { * * @return rate at which blocks should be fully validated during fast sync. */ - public float fastSyncFullValidationRate() { + public float getFastSyncFullValidationRate() { return fastSyncFullValidationRate; } @@ -204,148 +211,24 @@ public static class Builder { private SyncMode syncMode = SyncMode.FULL; private int fastSyncMinimumPeerCount = DEFAULT_FAST_SYNC_MINIMUM_PEERS; private int maxTrailingPeers = Integer.MAX_VALUE; - - @CommandLine.Option( - names = "--Xsynchronizer-block-propagation-range", - hidden = true, - defaultValue = "-10..30", - paramLabel = "..", - description = - "Range around chain head where inbound blocks are propagated (default: ${DEFAULT-VALUE})") - public void parseBlockPropagationRange(final String arg) { - // Use a method instead of a registered converter because of generics. - checkArgument( - arg.matches("-?\\d+\\.\\.-?\\d+"), - "--Xsynchronizer-block-propagation-range should be of the form '..'"); - final Iterator ends = Splitter.on("..").split(arg).iterator(); - blockPropagationRange = - Range.closed(Long.parseLong(ends.next()), Long.parseLong(ends.next())); - } - - private Range blockPropagationRange = Range.closed(-10L, 30L); - - @CommandLine.Option( - names = "--Xsynchronizer-downloader-change-target-threshold-by-height", - hidden = true, - defaultValue = "200", - paramLabel = "", - description = - "Minimum height difference before switching fast sync download peers (default: ${DEFAULT-VALUE})") - private long downloaderChangeTargetThresholdByHeight = 200L; - - @CommandLine.Option( - names = "--Xsynchronizer-downloader-change-target-threshold-by-td", - hidden = true, - defaultValue = "1000000000000000000", - paramLabel = "", - description = - "Minimum total difficulty difference before switching fast sync download peers (default: ${DEFAULT-VALUE})") - private UInt256 downloaderChangeTargetThresholdByTd = UInt256.of(1_000_000_000_000_000_000L); - - @CommandLine.Option( - names = "--Xsynchronizer-downloader-header-request-size", - hidden = true, - defaultValue = "200", - paramLabel = "", - description = "Number of headers to request per packet (default: ${DEFAULT-VALUE})") - private int downloaderHeaderRequestSize = 200; - - @CommandLine.Option( - names = "--Xsynchronizer-downloader-checkpoint-timeouts-permitted", - hidden = true, - defaultValue = "5", - paramLabel = "", - description = - "Number of tries to attempt to download checkpoints before stopping (default: ${DEFAULT-VALUE})") - private int downloaderCheckpointTimeoutsPermitted = 5; - - @CommandLine.Option( - names = "--Xsynchronizer-downloader-chain-segment-size", - hidden = true, - defaultValue = "200", - paramLabel = "", - description = "Distance between checkpoint headers (default: ${DEFAULT-VALUE})") - private int downloaderChainSegmentSize = 200; - - @CommandLine.Option( - names = "--Xsynchronizer-downloader-parallelism", - hidden = true, - defaultValue = "4", - paramLabel = "", - description = - "Number of threads to provide to chain downloader (default: ${DEFAULT-VALUE})") - private int downloaderParallelism = 4; - - @CommandLine.Option( - names = "--Xsynchronizer-transactions-parallelism", - hidden = true, - defaultValue = "2", - paramLabel = "", - description = - "Number of threads to commit to transaction processing (default: ${DEFAULT-VALUE})") - private int transactionsParallelism = 2; - - @CommandLine.Option( - names = "--Xsynchronizer-computation-parallelism", - hidden = true, - paramLabel = "", - description = - "Number of threads to make available for bulk hash computations durring downloads (default: # of processors)") - private int computationParallelism = Runtime.getRuntime().availableProcessors(); - - @CommandLine.Option( - names = "--Xsynchronizer-fast-sync-pivot-distance", - hidden = true, - defaultValue = "50", - paramLabel = "", - description = - "Distance from initial chain head to fast sync target (default: ${DEFAULT-VALUE})") + private Range blockPropagationRange = DEFAULT_BLOCK_PROPAGATION_RANGE; + private long downloaderChangeTargetThresholdByHeight = + DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT; + private UInt256 downloaderChangeTargetThresholdByTd = + DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD; + private int downloaderHeaderRequestSize = DEFAULT_DOWNLOADER_HEADER_REQUEST_SIZE; + private int downloaderCheckpointTimeoutsPermitted = + DEFAULT_DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED; + private int downloaderChainSegmentSize = DEFAULT_DOWNLOADER_CHAIN_SEGMENT_SIZE; + private int downloaderParallelism = DEFAULT_DOWNLOADER_PARALLELISM; + private int transactionsParallelism = DEFAULT_TRANSACTIONS_PARALLELISM; + private int computationParallelism = DEFAULT_COMPUTATION_PARALLELISM; private int fastSyncPivotDistance = DEFAULT_PIVOT_DISTANCE_FROM_HEAD; - - @CommandLine.Option( - names = "--Xsynchronizer-fast-sync-full-validation-rate", - hidden = true, - defaultValue = "0.1", - paramLabel = "", - description = - "Fraction of headers fast sync will fully validate (default: ${DEFAULT-VALUE})") private float fastSyncFullValidationRate = DEFAULT_FULL_VALIDATION_RATE; - - @CommandLine.Option( - names = "--Xsynchronizer-world-state-hash-count-per-request", - hidden = true, - defaultValue = "348", - paramLabel = "", - description = - "Fast sync world state hashes queried per request (default: ${DEFAULT-VALUE})") private int worldStateHashCountPerRequest = DEFAULT_WORLD_STATE_HASH_COUNT_PER_REQUEST; - - @CommandLine.Option( - names = "--Xsynchronizer-world-state-request-parallelism", - hidden = true, - defaultValue = "10", - paramLabel = "", - description = - "Number of concurrent requests to use when downloading fast sync world state (default: ${DEFAULT-VALUE})") private int worldStateRequestParallelism = DEFAULT_WORLD_STATE_REQUEST_PARALLELISM; - - @CommandLine.Option( - names = "--Xsynchronizer-world-state-max-requests-without-progress", - hidden = true, - defaultValue = "1000", - paramLabel = "", - description = - "Number of world state requests accepted without progress before considering the download stalled (default: ${DEFAULT-VALUE})") private int worldStateMaxRequestsWithoutProgress = DEFAULT_WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS; - - @CommandLine.Option( - names = "--Xsynchronizer-world-state-min-millis-before-stalling", - hidden = true, - defaultValue = "300000", - paramLabel = "", - description = - "Minimum time in ms without progress before considering a world state download as stalled (default: ${DEFAULT-VALUE})") private long worldStateMinMillisBeforeStalling = DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING; public Builder fastSyncPivotDistance(final int distance) { @@ -353,7 +236,7 @@ public Builder fastSyncPivotDistance(final int distance) { return this; } - public Builder fastSyncFastSyncFullValidationRate(final float rate) { + public Builder fastSyncFullValidationRate(final float rate) { this.fastSyncFullValidationRate = rate; return this; } @@ -363,6 +246,12 @@ public Builder syncMode(final SyncMode mode) { return this; } + public Builder blockPropagationRange(final Range blockPropagationRange) { + checkNotNull(blockPropagationRange); + this.blockPropagationRange = blockPropagationRange; + return this; + } + public Builder downloaderChangeTargetThresholdByHeight( final long downloaderChangeTargetThresholdByHeight) { this.downloaderChangeTargetThresholdByHeight = downloaderChangeTargetThresholdByHeight; @@ -397,7 +286,7 @@ public Builder blockPropagationRange(final long min, final long max) { return this; } - public Builder downloaderParallelisim(final int downloaderParallelism) { + public Builder downloaderParallelism(final int downloaderParallelism) { this.downloaderParallelism = downloaderParallelism; return this; } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java index c4a32901f7..1580bea82f 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastDownloaderFactory.java @@ -49,7 +49,7 @@ public static Optional> create( final WorldStateStorage worldStateStorage, final SyncState syncState, final Clock clock) { - if (syncConfig.syncMode() != SyncMode.FAST) { + if (syncConfig.getSyncMode() != SyncMode.FAST) { return Optional.empty(); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java index 1efd7550d6..15e7b3bf24 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -119,7 +119,7 @@ private CompletableFuture selectPivotBlockFromPeers() { .map( peer -> { final long pivotBlockNumber = - peer.chainState().getEstimatedHeight() - syncConfig.fastSyncPivotDistance(); + peer.chainState().getEstimatedHeight() - syncConfig.getFastSyncPivotDistance(); if (pivotBlockNumber <= BlockHeader.GENESIS_BLOCK_NUMBER) { throw new FastSyncException(CHAIN_TOO_SHORT); } else { diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index 3f119eb571..37c243a236 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -73,16 +73,19 @@ public FastSyncDownloadPipelineFactory( "validationMode"); attachedValidationPolicy = new FastSyncValidationPolicy( - this.syncConfig.fastSyncFullValidationRate(), + this.syncConfig.getFastSyncFullValidationRate(), LIGHT_SKIP_DETACHED, SKIP_DETACHED, fastSyncValidationCounter); ommerValidationPolicy = new FastSyncValidationPolicy( - this.syncConfig.fastSyncFullValidationRate(), LIGHT, FULL, fastSyncValidationCounter); + this.syncConfig.getFastSyncFullValidationRate(), + LIGHT, + FULL, + fastSyncValidationCounter); detachedValidationPolicy = new FastSyncValidationPolicy( - this.syncConfig.fastSyncFullValidationRate(), + this.syncConfig.getFastSyncFullValidationRate(), LIGHT_DETACHED_ONLY, DETACHED_ONLY, fastSyncValidationCounter); @@ -90,8 +93,8 @@ public FastSyncDownloadPipelineFactory( @Override public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) { - final int downloaderParallelism = syncConfig.downloaderParallelism(); - final int headerRequestSize = syncConfig.downloaderHeaderRequestSize(); + final int downloaderParallelism = syncConfig.getDownloaderParallelism(); + final int headerRequestSize = syncConfig.getDownloaderHeaderRequestSize(); final int singleHeaderBufferSize = headerRequestSize * downloaderParallelism; final CheckpointRangeSource checkpointRangeSource = new CheckpointRangeSource( @@ -105,7 +108,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) ethContext.getScheduler(), target.peer(), target.commonAncestor(), - syncConfig.downloaderCheckpointTimeoutsPermitted()); + syncConfig.getDownloaderCheckpointTimeoutsPermitted()); final DownloadHeadersStep downloadHeadersStep = new DownloadHeadersStep<>( protocolSchedule, diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java index 83dc05ccf7..c456d48ce6 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/BetterSyncTargetEvaluator.java @@ -50,13 +50,13 @@ public boolean shouldSwitchSyncTarget(final EthPeer currentSyncTarget) { .getBestBlock() .getTotalDifficulty() .minus(currentPeerChainState.getBestBlock().getTotalDifficulty()); - if (tdDifference.compareTo(config.downloaderChangeTargetThresholdByTd()) > 0) { + if (tdDifference.compareTo(config.getDownloaderChangeTargetThresholdByTd()) > 0) { return true; } final long heightDifference = bestPeerChainState.getEstimatedHeight() - currentPeerChainState.getEstimatedHeight(); - return heightDifference > config.downloaderChangeTargetThresholdByHeight(); + return heightDifference > config.getDownloaderChangeTargetThresholdByHeight(); }) .orElse(false); } diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java index fd93395e59..b15e99a5b7 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/fullsync/FullSyncDownloadPipelineFactory.java @@ -61,8 +61,8 @@ public FullSyncDownloadPipelineFactory( @Override public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) { - final int downloaderParallelism = syncConfig.downloaderParallelism(); - final int headerRequestSize = syncConfig.downloaderHeaderRequestSize(); + final int downloaderParallelism = syncConfig.getDownloaderParallelism(); + final int headerRequestSize = syncConfig.getDownloaderHeaderRequestSize(); final int singleHeaderBufferSize = headerRequestSize * downloaderParallelism; final CheckpointRangeSource checkpointRangeSource = new CheckpointRangeSource( @@ -72,7 +72,7 @@ public Pipeline createDownloadPipelineForSyncTarget(final SyncTarget target) ethContext.getScheduler(), target.peer(), target.commonAncestor(), - syncConfig.downloaderCheckpointTimeoutsPermitted()); + syncConfig.getDownloaderCheckpointTimeoutsPermitted()); final DownloadHeadersStep downloadHeadersStep = new DownloadHeadersStep<>( protocolSchedule, diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java index 601dbc11b1..9d01c61663 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncActionsTest.java @@ -152,7 +152,7 @@ public void selectPivotBlockShouldWaitAndRetryIfNoPeersAreAvailable() { @Test public void selectPivotBlockShouldFailIfBestPeerChainIsShorterThanPivotDistance() { EthProtocolManagerTestUtil.createPeer( - ethProtocolManager, syncConfig.fastSyncPivotDistance() - 1); + ethProtocolManager, syncConfig.getFastSyncPivotDistance() - 1); assertThrowsFastSyncException( CHAIN_TOO_SHORT, () -> fastSyncActions.selectPivotBlock(EMPTY_SYNC_STATE)); @@ -160,7 +160,8 @@ public void selectPivotBlockShouldFailIfBestPeerChainIsShorterThanPivotDistance( @Test public void selectPivotBlockShouldFailIfBestPeerChainIsEqualToPivotDistance() { - EthProtocolManagerTestUtil.createPeer(ethProtocolManager, syncConfig.fastSyncPivotDistance()); + EthProtocolManagerTestUtil.createPeer( + ethProtocolManager, syncConfig.getFastSyncPivotDistance()); assertThrowsFastSyncException( CHAIN_TOO_SHORT, () -> fastSyncActions.selectPivotBlock(EMPTY_SYNC_STATE)); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java index 7600f1e437..3f043e9536 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java @@ -171,7 +171,7 @@ public void recoversFromSyncTargetDisconnect() { SynchronizerConfiguration.builder() .downloaderChainSegmentSize(5) .downloaderHeadersRequestSize(3) - .downloaderParallelisim(1) + .downloaderParallelism(1) .build(); final long pivotBlockNumber = 25; final ChainDownloader downloader = downloader(syncConfig, pivotBlockNumber); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index edca09d11b..6882f871b2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -17,7 +17,6 @@ import tech.pegasys.pantheon.cli.PantheonCommand; import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; -import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; @@ -40,7 +39,6 @@ public static void main(final String... args) { new BlockImporter(), new RunnerBuilder(), new PantheonController.Builder(), - new SynchronizerConfiguration.Builder(), EthereumWireProtocolConfiguration.builder(), new RocksDbConfiguration.Builder(), new PantheonPluginContextImpl(), 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 421f0a6db2..fe8f28b37e 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -40,6 +40,7 @@ import tech.pegasys.pantheon.cli.operator.OperatorSubCommand; import tech.pegasys.pantheon.cli.options.CLIOptions; import tech.pegasys.pantheon.cli.options.NetworkingOptions; +import tech.pegasys.pantheon.cli.options.SynchronizerOptions; import tech.pegasys.pantheon.cli.rlp.RLPSubCommand; import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.controller.KeyPairUtil; @@ -51,7 +52,6 @@ import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; -import tech.pegasys.pantheon.ethereum.eth.sync.TrailingPeerRequirements; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.graphql.GraphQLConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; @@ -144,7 +144,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final BlockImporter blockImporter; private final CLIOptions networkingOptions = NetworkingOptions.create(); - private final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder; + private final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); private final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder; private final RocksDbConfiguration.Builder rocksDbConfigurationBuilder; private final RunnerBuilder runnerBuilder; @@ -610,7 +610,6 @@ public PantheonCommand( final BlockImporter blockImporter, final RunnerBuilder runnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final SynchronizerConfiguration.Builder synchronizerConfigurationBuilder, final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder, final RocksDbConfiguration.Builder rocksDbConfigurationBuilder, final PantheonPluginContextImpl pantheonPluginContext, @@ -619,7 +618,6 @@ public PantheonCommand( this.blockImporter = blockImporter; this.runnerBuilder = runnerBuilder; this.controllerBuilderFactory = controllerBuilderFactory; - this.synchronizerConfigurationBuilder = synchronizerConfigurationBuilder; this.ethereumWireConfigurationBuilder = ethereumWireConfigurationBuilder; this.rocksDbConfigurationBuilder = rocksDbConfigurationBuilder; this.pantheonPluginContext = pantheonPluginContext; @@ -676,7 +674,7 @@ public void parse( "P2P Network", networkingOptions, "Synchronizer", - synchronizerConfigurationBuilder, + synchronizerOptions, "RocksDB", rocksDbConfigurationBuilder, "Ethereum Wire Protocol", @@ -1078,10 +1076,10 @@ private PrivacyParameters privacyParameters() throws IOException { } private SynchronizerConfiguration buildSyncConfig() { - return synchronizerConfigurationBuilder + return synchronizerOptions + .toDomainObject() .syncMode(syncMode) .fastSyncMinimumPeerCount(fastSyncMinPeerCount) - .maxTrailingPeers(TrailingPeerRequirements.calculateMaxTrailingPeers(maxPeers)) .build(); } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java index 2b8e9cf095..dd0602ec0b 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java @@ -49,8 +49,7 @@ public static NetworkingOptions create() { return new NetworkingOptions(); } - public static CLIOptions fromConfig( - final NetworkingConfiguration networkingConfig) { + public static NetworkingOptions fromConfig(final NetworkingConfiguration networkingConfig) { final NetworkingOptions cliOptions = new NetworkingOptions(); cliOptions.checkMaintainedConnectionsFrequencySec = networkingConfig.getCheckMaintainedConnectionsFrequencySec(); @@ -71,8 +70,8 @@ public NetworkingConfiguration toDomainObject() { public List getCLIOptions() { return Arrays.asList( CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, - Integer.toString(checkMaintainedConnectionsFrequencySec, 10), + OptionParser.format(checkMaintainedConnectionsFrequencySec), INITIATE_CONNECTIONS_FREQUENCY_FLAG, - Integer.toString(initiateConnectionsFrequencySec, 10)); + OptionParser.format(initiateConnectionsFrequencySec)); } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/OptionParser.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/OptionParser.java new file mode 100644 index 0000000000..197ee7aabe --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/OptionParser.java @@ -0,0 +1,56 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static com.google.common.base.Preconditions.checkArgument; + +import tech.pegasys.pantheon.util.uint.UInt256; + +import java.math.BigInteger; +import java.util.Iterator; + +import com.google.common.base.Splitter; +import com.google.common.collect.Range; + +public class OptionParser { + + public static Range parseLongRange(final String arg) { + checkArgument(arg.matches("-?\\d+\\.\\.-?\\d+")); + final Iterator ends = Splitter.on("..").split(arg).iterator(); + return Range.closed(parseLong(ends.next()), parseLong(ends.next())); + } + + public static long parseLong(final String arg) { + return Long.parseLong(arg, 10); + } + + public static String format(final Range range) { + return format(range.lowerEndpoint()) + ".." + format(range.upperEndpoint()); + } + + public static String format(final int value) { + return Integer.toString(value, 10); + } + + public static String format(final long value) { + return Long.toString(value, 10); + } + + public static String format(final float value) { + return Float.toString(value); + } + + public static String format(final UInt256 value) { + return new BigInteger(value.toUnprefixedHexString(), 16).toString(10); + } +} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/SynchronizerOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/SynchronizerOptions.java new file mode 100644 index 0000000000..396e0827a4 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/SynchronizerOptions.java @@ -0,0 +1,282 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; +import tech.pegasys.pantheon.util.uint.UInt256; + +import java.util.Arrays; +import java.util.List; + +import com.google.common.collect.Range; +import picocli.CommandLine; + +public class SynchronizerOptions implements CLIOptions { + private static final String BLOCK_PROPAGATION_RANGE_FLAG = + "--Xsynchronizer-block-propagation-range"; + private static final String DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT_FLAG = + "--Xsynchronizer-downloader-change-target-threshold-by-height"; + private static final String DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD_FLAG = + "--Xsynchronizer-downloader-change-target-threshold-by-td"; + private static final String DOWNLOADER_HEADER_REQUEST_SIZE_FLAG = + "--Xsynchronizer-downloader-header-request-size"; + private static final String DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED_FLAG = + "--Xsynchronizer-downloader-checkpoint-timeouts-permitted"; + private static final String DOWNLOADER_CHAIN_SEGMENT_SIZE_FLAG = + "--Xsynchronizer-downloader-chain-segment-size"; + private static final String DOWNLOADER_PARALLELISM_FLAG = + "--Xsynchronizer-downloader-parallelism"; + private static final String TRANSACTIONS_PARALLELISM_FLAG = + "--Xsynchronizer-transactions-parallelism"; + private static final String COMPUTATION_PARALLELISM_FLAG = + "--Xsynchronizer-computation-parallelism"; + private static final String PIVOT_DISTANCE_FROM_HEAD_FLAG = + "--Xsynchronizer-fast-sync-pivot-distance"; + private static final String FULL_VALIDATION_RATE_FLAG = + "--Xsynchronizer-fast-sync-full-validation-rate"; + private static final String WORLD_STATE_HASH_COUNT_PER_REQUEST_FLAG = + "--Xsynchronizer-world-state-hash-count-per-request"; + private static final String WORLD_STATE_REQUEST_PARALLELISM_FLAG = + "--Xsynchronizer-world-state-request-parallelism"; + private static final String WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS_FLAG = + "--Xsynchronizer-world-state-max-requests-without-progress"; + private static final String WORLD_STATE_MIN_MILLIS_BEFORE_STALLING_FLAG = + "--Xsynchronizer-world-state-min-millis-before-stalling"; + + @CommandLine.Option( + names = BLOCK_PROPAGATION_RANGE_FLAG, + hidden = true, + defaultValue = "-10..30", + paramLabel = "..", + description = + "Range around chain head where inbound blocks are propagated (default: ${DEFAULT-VALUE})") + public void parseBlockPropagationRange(final String arg) { + blockPropagationRange = OptionParser.parseLongRange(arg); + } + + private Range blockPropagationRange = + SynchronizerConfiguration.DEFAULT_BLOCK_PROPAGATION_RANGE; + + @CommandLine.Option( + names = DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT_FLAG, + hidden = true, + defaultValue = "200", + paramLabel = "", + description = + "Minimum height difference before switching fast sync download peers (default: ${DEFAULT-VALUE})") + private long downloaderChangeTargetThresholdByHeight = + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT; + + @CommandLine.Option( + names = DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD_FLAG, + hidden = true, + defaultValue = "1000000000000000000", + paramLabel = "", + description = + "Minimum total difficulty difference before switching fast sync download peers (default: ${DEFAULT-VALUE})") + private UInt256 downloaderChangeTargetThresholdByTd = + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD; + + @CommandLine.Option( + names = DOWNLOADER_HEADER_REQUEST_SIZE_FLAG, + hidden = true, + defaultValue = "200", + paramLabel = "", + description = "Number of headers to request per packet (default: ${DEFAULT-VALUE})") + private int downloaderHeaderRequestSize = + SynchronizerConfiguration.DEFAULT_DOWNLOADER_HEADER_REQUEST_SIZE; + + @CommandLine.Option( + names = DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED_FLAG, + hidden = true, + defaultValue = "5", + paramLabel = "", + description = + "Number of tries to attempt to download checkpoints before stopping (default: ${DEFAULT-VALUE})") + private int downloaderCheckpointTimeoutsPermitted = + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED; + + @CommandLine.Option( + names = DOWNLOADER_CHAIN_SEGMENT_SIZE_FLAG, + hidden = true, + defaultValue = "200", + paramLabel = "", + description = "Distance between checkpoint headers (default: ${DEFAULT-VALUE})") + private int downloaderChainSegmentSize = + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHAIN_SEGMENT_SIZE; + + @CommandLine.Option( + names = DOWNLOADER_PARALLELISM_FLAG, + hidden = true, + defaultValue = "4", + paramLabel = "", + description = "Number of threads to provide to chain downloader (default: ${DEFAULT-VALUE})") + private int downloaderParallelism = SynchronizerConfiguration.DEFAULT_DOWNLOADER_PARALLELISM; + + @CommandLine.Option( + names = TRANSACTIONS_PARALLELISM_FLAG, + hidden = true, + defaultValue = "2", + paramLabel = "", + description = + "Number of threads to commit to transaction processing (default: ${DEFAULT-VALUE})") + private int transactionsParallelism = SynchronizerConfiguration.DEFAULT_TRANSACTIONS_PARALLELISM; + + @CommandLine.Option( + names = COMPUTATION_PARALLELISM_FLAG, + hidden = true, + paramLabel = "", + description = + "Number of threads to make available for bulk hash computations during downloads (default: # of processors)") + private int computationParallelism = Runtime.getRuntime().availableProcessors(); + + @CommandLine.Option( + names = PIVOT_DISTANCE_FROM_HEAD_FLAG, + hidden = true, + defaultValue = "50", + paramLabel = "", + description = + "Distance from initial chain head to fast sync target (default: ${DEFAULT-VALUE})") + private int fastSyncPivotDistance = SynchronizerConfiguration.DEFAULT_PIVOT_DISTANCE_FROM_HEAD; + + @CommandLine.Option( + names = FULL_VALIDATION_RATE_FLAG, + hidden = true, + defaultValue = "0.1", + paramLabel = "", + description = "Fraction of headers fast sync will fully validate (default: ${DEFAULT-VALUE})") + private float fastSyncFullValidationRate = SynchronizerConfiguration.DEFAULT_FULL_VALIDATION_RATE; + + @CommandLine.Option( + names = WORLD_STATE_HASH_COUNT_PER_REQUEST_FLAG, + hidden = true, + defaultValue = "384", + paramLabel = "", + description = "Fast sync world state hashes queried per request (default: ${DEFAULT-VALUE})") + private int worldStateHashCountPerRequest = + SynchronizerConfiguration.DEFAULT_WORLD_STATE_HASH_COUNT_PER_REQUEST; + + @CommandLine.Option( + names = WORLD_STATE_REQUEST_PARALLELISM_FLAG, + hidden = true, + defaultValue = "10", + paramLabel = "", + description = + "Number of concurrent requests to use when downloading fast sync world state (default: ${DEFAULT-VALUE})") + private int worldStateRequestParallelism = + SynchronizerConfiguration.DEFAULT_WORLD_STATE_REQUEST_PARALLELISM; + + @CommandLine.Option( + names = WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS_FLAG, + hidden = true, + defaultValue = "1000", + paramLabel = "", + description = + "Number of world state requests accepted without progress before considering the download stalled (default: ${DEFAULT-VALUE})") + private int worldStateMaxRequestsWithoutProgress = + SynchronizerConfiguration.DEFAULT_WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS; + + @CommandLine.Option( + names = WORLD_STATE_MIN_MILLIS_BEFORE_STALLING_FLAG, + hidden = true, + defaultValue = "300000", + paramLabel = "", + description = + "Minimum time in ms without progress before considering a world state download as stalled (default: ${DEFAULT-VALUE})") + private long worldStateMinMillisBeforeStalling = + SynchronizerConfiguration.DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING; + + private SynchronizerOptions() {} + + public static SynchronizerOptions create() { + return new SynchronizerOptions(); + } + + public static SynchronizerOptions fromConfig(final SynchronizerConfiguration config) { + final SynchronizerOptions options = new SynchronizerOptions(); + options.blockPropagationRange = config.getBlockPropagationRange(); + options.downloaderChangeTargetThresholdByHeight = + config.getDownloaderChangeTargetThresholdByHeight(); + options.downloaderChangeTargetThresholdByTd = config.getDownloaderChangeTargetThresholdByTd(); + options.downloaderHeaderRequestSize = config.getDownloaderHeaderRequestSize(); + options.downloaderCheckpointTimeoutsPermitted = + config.getDownloaderCheckpointTimeoutsPermitted(); + options.downloaderChainSegmentSize = config.getDownloaderChainSegmentSize(); + options.downloaderParallelism = config.getDownloaderParallelism(); + options.transactionsParallelism = config.getTransactionsParallelism(); + options.computationParallelism = config.getComputationParallelism(); + options.fastSyncPivotDistance = config.getFastSyncPivotDistance(); + options.fastSyncFullValidationRate = config.getFastSyncFullValidationRate(); + options.worldStateHashCountPerRequest = config.getWorldStateHashCountPerRequest(); + options.worldStateRequestParallelism = config.getWorldStateRequestParallelism(); + options.worldStateMaxRequestsWithoutProgress = config.getWorldStateMaxRequestsWithoutProgress(); + options.worldStateMinMillisBeforeStalling = config.getWorldStateMinMillisBeforeStalling(); + return options; + } + + @Override + public SynchronizerConfiguration.Builder toDomainObject() { + final SynchronizerConfiguration.Builder builder = SynchronizerConfiguration.builder(); + builder.blockPropagationRange(blockPropagationRange); + builder.downloaderChangeTargetThresholdByHeight(downloaderChangeTargetThresholdByHeight); + builder.downloaderChangeTargetThresholdByTd(downloaderChangeTargetThresholdByTd); + builder.downloaderHeadersRequestSize(downloaderHeaderRequestSize); + builder.downloaderCheckpointTimeoutsPermitted(downloaderCheckpointTimeoutsPermitted); + builder.downloaderChainSegmentSize(downloaderChainSegmentSize); + builder.downloaderParallelism(downloaderParallelism); + builder.transactionsParallelism(transactionsParallelism); + builder.computationParallelism(computationParallelism); + builder.fastSyncPivotDistance(fastSyncPivotDistance); + builder.fastSyncFullValidationRate(fastSyncFullValidationRate); + builder.worldStateHashCountPerRequest(worldStateHashCountPerRequest); + builder.worldStateRequestParallelism(worldStateRequestParallelism); + builder.worldStateMaxRequestsWithoutProgress(worldStateMaxRequestsWithoutProgress); + builder.worldStateMinMillisBeforeStalling(worldStateMinMillisBeforeStalling); + return builder; + } + + @Override + public List getCLIOptions() { + return Arrays.asList( + BLOCK_PROPAGATION_RANGE_FLAG, + OptionParser.format(blockPropagationRange), + DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT_FLAG, + OptionParser.format(downloaderChangeTargetThresholdByHeight), + DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD_FLAG, + OptionParser.format(downloaderChangeTargetThresholdByTd), + DOWNLOADER_HEADER_REQUEST_SIZE_FLAG, + OptionParser.format(downloaderHeaderRequestSize), + DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED_FLAG, + OptionParser.format(downloaderCheckpointTimeoutsPermitted), + DOWNLOADER_CHAIN_SEGMENT_SIZE_FLAG, + OptionParser.format(downloaderChainSegmentSize), + DOWNLOADER_PARALLELISM_FLAG, + OptionParser.format(downloaderParallelism), + TRANSACTIONS_PARALLELISM_FLAG, + OptionParser.format(transactionsParallelism), + COMPUTATION_PARALLELISM_FLAG, + OptionParser.format(computationParallelism), + PIVOT_DISTANCE_FROM_HEAD_FLAG, + OptionParser.format(fastSyncPivotDistance), + FULL_VALIDATION_RATE_FLAG, + OptionParser.format(fastSyncFullValidationRate), + WORLD_STATE_HASH_COUNT_PER_REQUEST_FLAG, + OptionParser.format(worldStateHashCountPerRequest), + WORLD_STATE_REQUEST_PARALLELISM_FLAG, + OptionParser.format(worldStateRequestParallelism), + WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS_FLAG, + OptionParser.format(worldStateMaxRequestsWithoutProgress), + WORLD_STATE_MIN_MILLIS_BEFORE_STALLING_FLAG, + OptionParser.format(worldStateMinMillisBeforeStalling)); + } +} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java index 19aad47024..c8efc8e420 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftLegacyPantheonControllerBuilder.java @@ -101,9 +101,9 @@ protected EthProtocolManager createEthProtocolManager( protocolContext.getWorldStateArchive(), networkId, fastSyncEnabled, - syncConfig.downloaderParallelism(), - syncConfig.transactionsParallelism(), - syncConfig.computationParallelism(), + syncConfig.getDownloaderParallelism(), + syncConfig.getTransactionsParallelism(), + syncConfig.getComputationParallelism(), clock, metricsSystem, ethereumWireProtocolConfiguration); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java index b39bc88962..8f1eba7505 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java @@ -198,7 +198,7 @@ public PantheonController build() throws IOException { final MutableBlockchain blockchain = protocolContext.getBlockchain(); - final boolean fastSyncEnabled = syncConfig.syncMode().equals(SyncMode.FAST); + final boolean fastSyncEnabled = syncConfig.getSyncMode().equals(SyncMode.FAST); ethProtocolManager = createEthProtocolManager(protocolContext, fastSyncEnabled); final SyncState syncState = new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers()); @@ -314,9 +314,9 @@ protected EthProtocolManager createEthProtocolManager( protocolContext.getWorldStateArchive(), networkId, fastSyncEnabled, - syncConfig.downloaderParallelism(), - syncConfig.transactionsParallelism(), - syncConfig.computationParallelism(), + syncConfig.getDownloaderParallelism(), + syncConfig.getTransactionsParallelism(), + syncConfig.getComputationParallelism(), clock, metricsSystem, ethereumWireProtocolConfiguration); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index 64a3ceb615..fcc41e5e1d 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -80,39 +80,41 @@ public abstract class CommandTestAbstract { private final PrintStream errPrintStream = new PrintStream(commandErrorOutput); private final HashMap environment = new HashMap<>(); - @Mock RunnerBuilder mockRunnerBuilder; - @Mock Runner mockRunner; - - @Mock PantheonController.Builder mockControllerBuilderFactory; - - @Mock PantheonControllerBuilder mockControllerBuilder; - @Mock EthProtocolManager mockEthProtocolManager; - @Mock ProtocolSchedule mockProtocolSchedule; - @Mock ProtocolContext mockProtocolContext; - @Mock BlockBroadcaster mockBlockBroadcaster; - @Mock SynchronizerConfiguration.Builder mockSyncConfBuilder; - @Mock EthereumWireProtocolConfiguration.Builder mockEthereumWireProtocolConfigurationBuilder; - @Mock SynchronizerConfiguration mockSyncConf; - @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; - @Mock RocksDbConfiguration mockRocksDbConf; - @Mock PantheonController mockController; - @Mock BlockImporter mockBlockImporter; - @Mock Logger mockLogger; - @Mock PantheonPluginContextImpl mockPantheonPluginContext; - - @Captor ArgumentCaptor> bytesValueCollectionCollector; - @Captor ArgumentCaptor> stringListArgumentCaptor; - @Captor ArgumentCaptor pathArgumentCaptor; - @Captor ArgumentCaptor fileArgumentCaptor; - @Captor ArgumentCaptor stringArgumentCaptor; - @Captor ArgumentCaptor intArgumentCaptor; - @Captor ArgumentCaptor ethNetworkConfigArgumentCaptor; - @Captor ArgumentCaptor networkingConfigurationArgumentCaptor; - @Captor ArgumentCaptor jsonRpcConfigArgumentCaptor; - @Captor ArgumentCaptor graphQLConfigArgumentCaptor; - @Captor ArgumentCaptor wsRpcConfigArgumentCaptor; - @Captor ArgumentCaptor metricsConfigArgumentCaptor; - @Captor ArgumentCaptor permissioningConfigurationArgumentCaptor; + protected @Mock RunnerBuilder mockRunnerBuilder; + protected @Mock Runner mockRunner; + + protected @Mock PantheonController.Builder mockControllerBuilderFactory; + + protected @Mock PantheonControllerBuilder mockControllerBuilder; + protected @Mock EthProtocolManager mockEthProtocolManager; + protected @Mock ProtocolSchedule mockProtocolSchedule; + protected @Mock ProtocolContext mockProtocolContext; + protected @Mock BlockBroadcaster mockBlockBroadcaster; + protected @Mock EthereumWireProtocolConfiguration.Builder + mockEthereumWireProtocolConfigurationBuilder; + protected @Mock SynchronizerConfiguration mockSyncConf; + protected @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; + protected @Mock RocksDbConfiguration mockRocksDbConf; + protected @Mock PantheonController mockController; + protected @Mock BlockImporter mockBlockImporter; + protected @Mock Logger mockLogger; + protected @Mock PantheonPluginContextImpl mockPantheonPluginContext; + + protected @Captor ArgumentCaptor> bytesValueCollectionCollector; + protected @Captor ArgumentCaptor> stringListArgumentCaptor; + protected @Captor ArgumentCaptor pathArgumentCaptor; + protected @Captor ArgumentCaptor fileArgumentCaptor; + protected @Captor ArgumentCaptor stringArgumentCaptor; + protected @Captor ArgumentCaptor intArgumentCaptor; + protected @Captor ArgumentCaptor ethNetworkConfigArgumentCaptor; + protected @Captor ArgumentCaptor networkingConfigurationArgumentCaptor; + protected @Captor ArgumentCaptor syncConfigurationCaptor; + protected @Captor ArgumentCaptor jsonRpcConfigArgumentCaptor; + protected @Captor ArgumentCaptor graphQLConfigArgumentCaptor; + protected @Captor ArgumentCaptor wsRpcConfigArgumentCaptor; + protected @Captor ArgumentCaptor metricsConfigArgumentCaptor; + protected @Captor ArgumentCaptor + permissioningConfigurationArgumentCaptor; @Rule public final TemporaryFolder temp = new TemporaryFolder(); @@ -148,12 +150,6 @@ public void initMocks() throws Exception { lenient().when(mockController.getProtocolContext()).thenReturn(mockProtocolContext); when(mockEthProtocolManager.getBlockBroadcaster()).thenReturn(mockBlockBroadcaster); - - when(mockSyncConfBuilder.syncMode(any())).thenReturn(mockSyncConfBuilder); - when(mockSyncConfBuilder.maxTrailingPeers(anyInt())).thenReturn(mockSyncConfBuilder); - when(mockSyncConfBuilder.fastSyncMinimumPeerCount(anyInt())).thenReturn(mockSyncConfBuilder); - when(mockSyncConfBuilder.build()).thenReturn(mockSyncConf); - when(mockEthereumWireProtocolConfigurationBuilder.build()) .thenReturn(EthereumWireProtocolConfiguration.defaultConfig()); @@ -221,7 +217,6 @@ private CommandLine.Model.CommandSpec parseCommand( mockBlockImporter, mockRunnerBuilder, mockControllerBuilderFactory, - mockSyncConfBuilder, mockEthereumWireProtocolConfigurationBuilder, mockRocksDbConfBuilder, keyLoader, @@ -252,7 +247,6 @@ protected KeyLoader getKeyLoader() { final BlockImporter mockBlockImporter, final RunnerBuilder mockRunnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final SynchronizerConfiguration.Builder mockSyncConfBuilder, final EthereumWireProtocolConfiguration.Builder mockEthereumConfigurationMockBuilder, final RocksDbConfiguration.Builder mockRocksDbConfBuilder, final KeyLoader keyLoader, @@ -263,7 +257,6 @@ protected KeyLoader getKeyLoader() { mockBlockImporter, mockRunnerBuilder, controllerBuilderFactory, - mockSyncConfBuilder, mockEthereumConfigurationMockBuilder, mockRocksDbConfBuilder, pantheonPluginContext, 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 327f34375f..60d513e38a 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -40,6 +40,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; +import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.graphql.GraphQLConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; @@ -165,14 +166,13 @@ public void callingPantheonCommandWithoutOptionsMustSyncWithDefaultValues() thro verify(mockControllerBuilderFactory).fromEthNetworkConfig(ethNetworkArg.capture()); final ArgumentCaptor miningArg = ArgumentCaptor.forClass(MiningParameters.class); - verify(mockControllerBuilder).synchronizerConfiguration(isNotNull()); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); verify(mockControllerBuilder).dataDirectory(isNotNull()); verify(mockControllerBuilder).miningParameters(miningArg.capture()); verify(mockControllerBuilder).nodePrivateKeyFile(isNotNull()); verify(mockControllerBuilder).build(); - verify(mockSyncConfBuilder).syncMode(eq(SyncMode.FULL)); - + assertThat(syncConfigurationCaptor.getValue().getSyncMode()).isEqualTo(SyncMode.FULL); assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.empty()); assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(1000)); @@ -329,9 +329,10 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException .build(); verify(mockControllerBuilder).dataDirectory(eq(Paths.get("/opt/pantheon").toAbsolutePath())); verify(mockControllerBuilderFactory).fromEthNetworkConfig(eq(networkConfig)); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); - verify(mockSyncConfBuilder).syncMode(eq(SyncMode.FAST)); - verify(mockSyncConfBuilder).fastSyncMinimumPeerCount(eq(13)); + assertThat(syncConfigurationCaptor.getValue().getSyncMode()).isEqualTo(SyncMode.FAST); + assertThat(syncConfigurationCaptor.getValue().getFastSyncMinimumPeerCount()).isEqualTo(13); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -775,9 +776,11 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce verify(mockControllerBuilder) .pendingTransactionRetentionPeriod(eq(PendingTransactions.DEFAULT_TX_RETENTION_HOURS)); verify(mockControllerBuilder).build(); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); - verify(mockSyncConfBuilder).syncMode(eq(SyncMode.FULL)); - verify(mockSyncConfBuilder).fastSyncMinimumPeerCount(eq(5)); + final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); + assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FULL); + assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(5); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -1278,13 +1281,24 @@ public void maxpeersOptionMustBeUsed() { } @Test - public void syncModeOptionMustBeUsed() { - + public void syncMode_fast() { parseCommand("--sync-mode", "FAST"); - verify(mockSyncConfBuilder).syncMode(eq(SyncMode.FAST)); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); + + final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); + assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void syncMode_full() { parseCommand("--sync-mode", "FULL"); - verify(mockSyncConfBuilder).syncMode(eq(SyncMode.FULL)); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); + + final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); + assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FULL); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -1302,10 +1316,12 @@ public void helpShouldDisplayFastSyncOptions() { @Test public void parsesValidFastSyncMinPeersOption() { - parseCommand("--sync-mode", "FAST", "--fast-sync-min-peers", "11"); - verify(mockSyncConfBuilder).syncMode(eq(SyncMode.FAST)); - verify(mockSyncConfBuilder).fastSyncMinimumPeerCount(eq(11)); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); + + final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); + assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST); + assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(11); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java new file mode 100644 index 0000000000..355beccd8d --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import tech.pegasys.pantheon.cli.CommandTestAbstract; +import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; + +import org.junit.Test; + +public class NetworkingOptionsTest extends CommandTestAbstract { + + @Test + public void fromConfig() { + final NetworkingConfiguration config = NetworkingConfiguration.create(); + NetworkingOptions options = NetworkingOptions.fromConfig(config); + + final NetworkingConfiguration configFromOptions = options.toDomainObject(); + assertThat(configFromOptions).isEqualToComparingFieldByField(config); + } + + @Test + public void getCLIOptions() { + NetworkingOptions options = NetworkingOptions.create(); + final String[] cliOptions = options.getCLIOptions().toArray(new String[0]); + final NetworkingConfiguration actualConfig = options.toDomainObject(); + + parseCommand(cliOptions); + verify(mockRunnerBuilder) + .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); + final NetworkingConfiguration networkingConfiguration = + networkingConfigurationArgumentCaptor.getValue(); + assertThat(actualConfig).isEqualToComparingFieldByField(networkingConfiguration); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void defaultValues() { + parseCommand(); + + // Check default values supplied by CLI match default config + final NetworkingConfiguration defaultConfig = NetworkingConfiguration.create(); + verify(mockRunnerBuilder) + .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); + final NetworkingConfiguration networkingConfiguration = + networkingConfigurationArgumentCaptor.getValue(); + + assertThat(networkingConfiguration).isEqualToComparingFieldByField(defaultConfig); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/OptionParserTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/OptionParserTest.java new file mode 100644 index 0000000000..210368c532 --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/OptionParserTest.java @@ -0,0 +1,103 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import tech.pegasys.pantheon.util.uint.UInt256; + +import java.math.BigInteger; + +import com.google.common.collect.Range; +import org.junit.Test; + +public class OptionParserTest { + + @Test + public void parseLongRange_negative() { + final String input = "-11..-5"; + final Range expected = Range.closed(-11L, -5L); + assertThat(OptionParser.parseLongRange(input)).isEqualTo(expected); + } + + @Test + public void parseLongRange_positive() { + final String input = "11..22"; + final Range expected = Range.closed(11L, 22L); + assertThat(OptionParser.parseLongRange(input)).isEqualTo(expected); + } + + @Test + public void parseLongRange_spanningZero() { + final String input = "-11..22"; + final Range expected = Range.closed(-11L, 22L); + assertThat(OptionParser.parseLongRange(input)).isEqualTo(expected); + } + + @Test + public void parseLongRange_singleElement() { + final String input = "1..1"; + final Range expected = Range.closed(1L, 1L); + assertThat(OptionParser.parseLongRange(input)).isEqualTo(expected); + } + + @Test + public void parseLongRange_outOfOrderBounds() { + final String input = "2..1"; + assertThatThrownBy(() -> OptionParser.parseLongRange(input)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void format_longRange() { + final Range input = Range.closed(-11L, -5L); + final String expected = "-11..-5"; + assertThat(OptionParser.format(input)).isEqualTo(expected); + } + + @Test + public void format_uint256() { + final UInt256 input = UInt256.of(new BigInteger("123456789", 10)); + final String expected = "123456789"; + assertThat(OptionParser.format(input)).isEqualTo(expected); + } + + @Test + public void format_positiveInt() { + final int input = 1233; + final String expected = "1233"; + assertThat(OptionParser.format(input)).isEqualTo(expected); + } + + @Test + public void format_negativeInt() { + final int input = -1233; + final String expected = "-1233"; + assertThat(OptionParser.format(input)).isEqualTo(expected); + } + + @Test + public void format_positiveLong() { + final long input = 1233L; + final String expected = "1233"; + assertThat(OptionParser.format(input)).isEqualTo(expected); + } + + @Test + public void format_negativeLong() { + final long input = -1233L; + final String expected = "-1233"; + assertThat(OptionParser.format(input)).isEqualTo(expected); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java new file mode 100644 index 0000000000..bcbd646aa8 --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import tech.pegasys.pantheon.cli.CommandTestAbstract; +import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; + +import org.junit.Test; + +public class SynchronizerOptionsTest extends CommandTestAbstract { + + @Test + public void fromConfig() { + final SynchronizerConfiguration config = SynchronizerConfiguration.builder().build(); + SynchronizerOptions options = SynchronizerOptions.fromConfig(config); + final SynchronizerConfiguration.Builder builderFromOptions = options.toDomainObject(); + assertThat(builderFromOptions).isEqualToComparingFieldByField(config); + } + + @Test + public void getCLIOptions() { + SynchronizerOptions options = SynchronizerOptions.create(); + final String[] cliOptions = options.getCLIOptions().toArray(new String[0]); + final SynchronizerConfiguration actualSyncConfig = options.toDomainObject().build(); + + parseCommand(cliOptions); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); + final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); + assertThat(actualSyncConfig).isEqualToComparingFieldByField(syncConfig); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void defaultValues() { + parseCommand(); + + // Check default values supplied by CLI match default SynchronizerConfiguration + final SynchronizerConfiguration defaultConfig = SynchronizerConfiguration.builder().build(); + verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); + final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); + + // Ignore fields that are initialized in a special way + final String[] ignoredDefaults = {"maxTrailingPeers", "computationParallelism"}; + + assertThat(syncConfig).isEqualToIgnoringGivenFields(defaultConfig, ignoredDefaults); + } +} From a5b0458173a4fe038f1773d1f83c7a3abed8d049 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 28 Jun 2019 16:36:07 -0400 Subject: [PATCH 08/15] Rework CLIOptions tests --- .../p2p/config/NetworkingConfiguration.java | 8 +- .../cli/options/NetworkingOptions.java | 6 +- .../cli/options/AbstractCLIOptionsTest.java | 87 +++++++++++++++++++ .../cli/options/NetworkingOptionsTest.java | 57 +++++------- .../cli/options/SynchronizerOptionsTest.java | 87 ++++++++++++------- 5 files changed, 175 insertions(+), 70 deletions(-) create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java index 7c2f31159b..44d503d6c1 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java @@ -17,10 +17,14 @@ import java.util.Objects; public class NetworkingConfiguration { + public static final int DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC = 30; + public static final int DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC = 60; + private DiscoveryConfiguration discovery = new DiscoveryConfiguration(); private RlpxConfiguration rlpx = new RlpxConfiguration(); - private int initiateConnectionsFrequencySec = 30; - private int checkMaintainedConnectionsFrequencySec = 60; + private int initiateConnectionsFrequencySec = DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC; + private int checkMaintainedConnectionsFrequencySec = + DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC; public static NetworkingConfiguration create() { return new NetworkingConfiguration(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java index dd0602ec0b..888133aab6 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java @@ -32,7 +32,8 @@ public class NetworkingOptions implements CLIOptions { paramLabel = "", description = "The frequency (in seconds) at which to initiate new outgoing connections (default: ${DEFAULT-VALUE})") - private int initiateConnectionsFrequencySec = 30; + private int initiateConnectionsFrequencySec = + NetworkingConfiguration.DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC; @CommandLine.Option( names = CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, @@ -41,7 +42,8 @@ public class NetworkingOptions implements CLIOptions { paramLabel = "", description = "The frequency (in seconds) at which to check maintained connections (default: ${DEFAULT-VALUE})") - private int checkMaintainedConnectionsFrequencySec = 60; + private int checkMaintainedConnectionsFrequencySec = + NetworkingConfiguration.DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC; private NetworkingOptions() {} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java new file mode 100644 index 0000000000..004cdfcf2d --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.cli.CommandTestAbstract; + +import org.junit.Test; + +public abstract class AbstractCLIOptionsTest> + extends CommandTestAbstract { + @Test + public void fromDomainObject_default() { + fromDomainObject(createDefaultDomainObject()); + } + + @Test + public void fromDomainObject_customize() { + fromDomainObject(createCustomizedDomainObject()); + } + + private void fromDomainObject(final D domainObject) { + final T options = optionsFromDomainObject(domainObject); + final D domainObjectFromOptions = optionsToDomainObject(options); + assertThat(domainObjectFromOptions).isEqualToComparingFieldByField(domainObject); + } + + @Test + public void getCLIOptions_default() { + getCLIOptions(createDefaultDomainObject()); + } + + @Test + public void getCLIOptions_custom() { + getCLIOptions(createCustomizedDomainObject()); + } + + private void getCLIOptions(final D domainObject) { + T options = optionsFromDomainObject(domainObject); + final String[] cliOptions = options.getCLIOptions().toArray(new String[0]); + + parseCommand(cliOptions); + final D actualDomainObject = getDomainObjectFromPantheonCommand(); + assertThat(actualDomainObject).isEqualToComparingFieldByField(domainObject); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void defaultValues() { + parseCommand(); + + final D defaultDomainObject = createDefaultDomainObject(); + final D actualDomainObject = getDomainObjectFromPantheonCommand(); + + // Check default values supplied by CLI match expected default values + final String[] ignoredDefaults = getFieldsWithComputedDefaults(); + assertThat(actualDomainObject) + .isEqualToIgnoringGivenFields(defaultDomainObject, ignoredDefaults); + } + + abstract D createDefaultDomainObject(); + + abstract D createCustomizedDomainObject(); + + protected String[] getFieldsWithComputedDefaults() { + return new String[] {}; + } + + abstract T optionsFromDomainObject(D domainObject); + + abstract D optionsToDomainObject(T options); + + abstract D getDomainObjectFromPantheonCommand(); +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java index 355beccd8d..4d59e4cb41 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java @@ -12,53 +12,42 @@ */ package tech.pegasys.pantheon.cli.options; -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; -import tech.pegasys.pantheon.cli.CommandTestAbstract; import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; -import org.junit.Test; +public class NetworkingOptionsTest + extends AbstractCLIOptionsTest { -public class NetworkingOptionsTest extends CommandTestAbstract { + @Override + NetworkingConfiguration createDefaultDomainObject() { + return NetworkingConfiguration.create(); + } - @Test - public void fromConfig() { + @Override + NetworkingConfiguration createCustomizedDomainObject() { final NetworkingConfiguration config = NetworkingConfiguration.create(); - NetworkingOptions options = NetworkingOptions.fromConfig(config); - - final NetworkingConfiguration configFromOptions = options.toDomainObject(); - assertThat(configFromOptions).isEqualToComparingFieldByField(config); + config.setInitiateConnectionsFrequency( + NetworkingConfiguration.DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC + 10); + config.setCheckMaintainedConnectionsFrequency( + NetworkingConfiguration.DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC + 10); + return config; } - @Test - public void getCLIOptions() { - NetworkingOptions options = NetworkingOptions.create(); - final String[] cliOptions = options.getCLIOptions().toArray(new String[0]); - final NetworkingConfiguration actualConfig = options.toDomainObject(); - - parseCommand(cliOptions); - verify(mockRunnerBuilder) - .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - final NetworkingConfiguration networkingConfiguration = - networkingConfigurationArgumentCaptor.getValue(); - assertThat(actualConfig).isEqualToComparingFieldByField(networkingConfiguration); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); + @Override + NetworkingOptions optionsFromDomainObject(final NetworkingConfiguration domainObject) { + return NetworkingOptions.fromConfig(domainObject); } - @Test - public void defaultValues() { - parseCommand(); + @Override + NetworkingConfiguration optionsToDomainObject(final NetworkingOptions options) { + return options.toDomainObject(); + } - // Check default values supplied by CLI match default config - final NetworkingConfiguration defaultConfig = NetworkingConfiguration.create(); + @Override + NetworkingConfiguration getDomainObjectFromPantheonCommand() { verify(mockRunnerBuilder) .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - final NetworkingConfiguration networkingConfiguration = - networkingConfigurationArgumentCaptor.getValue(); - - assertThat(networkingConfiguration).isEqualToComparingFieldByField(defaultConfig); + return networkingConfigurationArgumentCaptor.getValue(); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java index bcbd646aa8..53141505c4 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java @@ -12,51 +12,74 @@ */ package tech.pegasys.pantheon.cli.options; -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; -import tech.pegasys.pantheon.cli.CommandTestAbstract; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; -import org.junit.Test; +import com.google.common.collect.Range; -public class SynchronizerOptionsTest extends CommandTestAbstract { +public class SynchronizerOptionsTest + extends AbstractCLIOptionsTest { - @Test - public void fromConfig() { - final SynchronizerConfiguration config = SynchronizerConfiguration.builder().build(); - SynchronizerOptions options = SynchronizerOptions.fromConfig(config); - final SynchronizerConfiguration.Builder builderFromOptions = options.toDomainObject(); - assertThat(builderFromOptions).isEqualToComparingFieldByField(config); + @Override + SynchronizerConfiguration createDefaultDomainObject() { + return SynchronizerConfiguration.builder().build(); } - @Test - public void getCLIOptions() { - SynchronizerOptions options = SynchronizerOptions.create(); - final String[] cliOptions = options.getCLIOptions().toArray(new String[0]); - final SynchronizerConfiguration actualSyncConfig = options.toDomainObject().build(); + @Override + SynchronizerConfiguration createCustomizedDomainObject() { + return SynchronizerConfiguration.builder() + .fastSyncPivotDistance(SynchronizerConfiguration.DEFAULT_PIVOT_DISTANCE_FROM_HEAD + 10) + .fastSyncFullValidationRate(SynchronizerConfiguration.DEFAULT_FULL_VALIDATION_RATE / 2) + // Min peers are currently handled outside of SynchronizerOptions + // .fastSyncMinimumPeerCount(SynchronizerConfiguration.DEFAULT_FAST_SYNC_MINIMUM_PEERS + // + 2) + .worldStateHashCountPerRequest( + SynchronizerConfiguration.DEFAULT_WORLD_STATE_HASH_COUNT_PER_REQUEST + 2) + .worldStateRequestParallelism( + SynchronizerConfiguration.DEFAULT_WORLD_STATE_REQUEST_PARALLELISM * 2) + .worldStateMaxRequestsWithoutProgress( + SynchronizerConfiguration.DEFAULT_WORLD_STATE_MAX_REQUESTS_WITHOUT_PROGRESS * 2) + .worldStateMinMillisBeforeStalling( + SynchronizerConfiguration.DEFAULT_WORLD_STATE_MIN_MILLIS_BEFORE_STALLING * 2) + .blockPropagationRange( + Range.closed( + SynchronizerConfiguration.DEFAULT_BLOCK_PROPAGATION_RANGE.lowerEndpoint() - 2, + SynchronizerConfiguration.DEFAULT_BLOCK_PROPAGATION_RANGE.upperEndpoint() + 2)) + .downloaderChangeTargetThresholdByHeight( + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_HEIGHT + 2) + .downloaderChangeTargetThresholdByTd( + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHANGE_TARGET_THRESHOLD_BY_TD.plus(2L)) + .downloaderHeadersRequestSize( + SynchronizerConfiguration.DEFAULT_DOWNLOADER_HEADER_REQUEST_SIZE + 2) + .downloaderCheckpointTimeoutsPermitted( + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHECKPOINT_TIMEOUTS_PERMITTED + 2) + .downloaderChainSegmentSize( + SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHAIN_SEGMENT_SIZE + 2) + .downloaderParallelism(SynchronizerConfiguration.DEFAULT_DOWNLOADER_PARALLELISM + 2) + .transactionsParallelism(SynchronizerConfiguration.DEFAULT_TRANSACTIONS_PARALLELISM + 2) + .computationParallelism(SynchronizerConfiguration.DEFAULT_COMPUTATION_PARALLELISM + 2) + .build(); + } - parseCommand(cliOptions); - verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); - final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); - assertThat(actualSyncConfig).isEqualToComparingFieldByField(syncConfig); + @Override + protected String[] getFieldsWithComputedDefaults() { + return new String[] {"maxTrailingPeers", "computationParallelism"}; + } - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); + @Override + SynchronizerOptions optionsFromDomainObject(final SynchronizerConfiguration domainObject) { + return SynchronizerOptions.fromConfig(domainObject); } - @Test - public void defaultValues() { - parseCommand(); + @Override + SynchronizerConfiguration optionsToDomainObject(final SynchronizerOptions options) { + return options.toDomainObject().build(); + } - // Check default values supplied by CLI match default SynchronizerConfiguration - final SynchronizerConfiguration defaultConfig = SynchronizerConfiguration.builder().build(); + @Override + SynchronizerConfiguration getDomainObjectFromPantheonCommand() { verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); - final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); - - // Ignore fields that are initialized in a special way - final String[] ignoredDefaults = {"maxTrailingPeers", "computationParallelism"}; - - assertThat(syncConfig).isEqualToIgnoringGivenFields(defaultConfig, ignoredDefaults); + return syncConfigurationCaptor.getValue(); } } From 4f543a636c093188b9b4aa10872eaa5d79ab4e09 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 28 Jun 2019 17:11:35 -0400 Subject: [PATCH 09/15] Create EthProtocolOptions --- .../dsl/node/ThreadPantheonNodeRunner.java | 4 +- .../protocol/Istanbul64ProtocolManager.java | 4 +- ethereum/eth/build.gradle | 1 - ...ion.java => EthProtocolConfiguration.java} | 53 ++---- .../eth/manager/EthProtocolManager.java | 8 +- .../ethereum/eth/manager/EthServer.java | 6 +- .../eth/manager/EthProtocolManagerTest.java | 46 ++--- .../manager/EthProtocolManagerTestUtil.java | 4 +- .../ethereum/eth/manager/EthServerTest.java | 7 +- .../ethereum/eth/transactions/TestNode.java | 4 +- .../java/tech/pegasys/pantheon/Pantheon.java | 2 - .../pegasys/pantheon/cli/PantheonCommand.java | 10 +- .../cli/options/EthProtocolOptions.java | 102 ++++++++++++ .../controller/PantheonControllerBuilder.java | 10 +- .../tech/pegasys/pantheon/PrivacyTest.java | 4 +- .../tech/pegasys/pantheon/RunnerTest.java | 8 +- .../pantheon/cli/CommandTestAbstract.java | 14 +- .../pantheon/cli/PantheonCommandTest.java | 83 --------- .../cli/options/EthProtocolOptionsTest.java | 157 ++++++++++++++++++ .../pantheon/util/BlockImporterTest.java | 6 +- 20 files changed, 334 insertions(+), 199 deletions(-) rename ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/{EthereumWireProtocolConfiguration.java => EthProtocolConfiguration.java} (67%) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/options/EthProtocolOptions.java create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java 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 be413db12d..00e16a285e 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 @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.controller.KeyPairUtil; import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.controller.PantheonControllerBuilder; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.graphql.GraphQLConfiguration; @@ -117,7 +117,7 @@ public void startNode(final PantheonNode node) { .maxPendingTransactions(PendingTransactions.MAX_PENDING_TRANSACTIONS) .pendingTransactionRetentionPeriod(PendingTransactions.DEFAULT_TX_RETENTION_HOURS) .rocksDbConfiguration(new RocksDbConfiguration.Builder().databaseDir(tempDir).build()) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .clock(Clock.systemUTC()) .build(); } catch (final IOException e) { diff --git a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64ProtocolManager.java b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64ProtocolManager.java index be1488fdee..80c705d451 100644 --- a/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64ProtocolManager.java +++ b/consensus/ibftlegacy/src/main/java/tech/pegasys/pantheon/consensus/ibftlegacy/protocol/Istanbul64ProtocolManager.java @@ -15,7 +15,7 @@ import static java.util.Collections.singletonList; import tech.pegasys.pantheon.ethereum.chain.Blockchain; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.p2p.rlpx.wire.Capability; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; @@ -37,7 +37,7 @@ public Istanbul64ProtocolManager( final int computationWorkers, final Clock clock, final MetricsSystem metricsSystem, - final EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration) { + final EthProtocolConfiguration ethereumWireProtocolConfiguration) { super( blockchain, worldStateArchive, diff --git a/ethereum/eth/build.gradle b/ethereum/eth/build.gradle index ca0881d113..94000afb88 100644 --- a/ethereum/eth/build.gradle +++ b/ethereum/eth/build.gradle @@ -36,7 +36,6 @@ dependencies { implementation project(':services:pipeline') implementation project(':services:tasks') - implementation 'info.picocli:picocli' implementation 'io.vertx:vertx-core' implementation 'com.google.guava:guava' diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthereumWireProtocolConfiguration.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocolConfiguration.java similarity index 67% rename from ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthereumWireProtocolConfiguration.java rename to ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocolConfiguration.java index dd6aa1ef5f..a75b12d204 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthereumWireProtocolConfiguration.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/EthProtocolConfiguration.java @@ -17,9 +17,8 @@ import java.util.Objects; import com.google.common.base.MoreObjects; -import picocli.CommandLine; -public class EthereumWireProtocolConfiguration { +public class EthProtocolConfiguration { public static final int DEFAULT_MAX_GET_BLOCK_HEADERS = 192; public static final int DEFAULT_MAX_GET_BLOCK_BODIES = 128; @@ -31,7 +30,7 @@ public class EthereumWireProtocolConfiguration { private final int maxGetReceipts; private final int maxGetNodeData; - public EthereumWireProtocolConfiguration( + public EthProtocolConfiguration( final int maxGetBlockHeaders, final int maxGetBlockBodies, final int maxGetReceipts, @@ -42,8 +41,8 @@ public EthereumWireProtocolConfiguration( this.maxGetNodeData = maxGetNodeData; } - public static EthereumWireProtocolConfiguration defaultConfig() { - return new EthereumWireProtocolConfiguration( + public static EthProtocolConfiguration defaultConfig() { + return new EthProtocolConfiguration( DEFAULT_MAX_GET_BLOCK_HEADERS, DEFAULT_MAX_GET_BLOCK_BODIES, DEFAULT_MAX_GET_RECEIPTS, @@ -78,7 +77,7 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - final EthereumWireProtocolConfiguration that = (EthereumWireProtocolConfiguration) o; + final EthProtocolConfiguration that = (EthProtocolConfiguration) o; return maxGetBlockHeaders == that.maxGetBlockHeaders && maxGetBlockBodies == that.maxGetBlockBodies && maxGetReceipts == that.maxGetReceipts @@ -101,41 +100,17 @@ public String toString() { } public static class Builder { - @CommandLine.Option( - hidden = true, - names = {"--Xewp-max-get-headers"}, - paramLabel = "", - description = - "Maximum request limit for Ethereum Wire Protocol GET_BLOCK_HEADERS. (default: ${DEFAULT-VALUE})") private PositiveNumber maxGetBlockHeaders = - PositiveNumber.fromInt(EthereumWireProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_HEADERS); - - @CommandLine.Option( - hidden = true, - names = {"--Xewp-max-get-bodies"}, - paramLabel = "", - description = - "Maximum request limit for Ethereum Wire Protocol GET_BLOCK_BODIES. (default: ${DEFAULT-VALUE})") + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_HEADERS); + private PositiveNumber maxGetBlockBodies = - PositiveNumber.fromInt(EthereumWireProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_BODIES); - - @CommandLine.Option( - hidden = true, - names = {"--Xewp-max-get-receipts"}, - paramLabel = "", - description = - "Maximum request limit for Ethereum Wire Protocol GET_RECEIPTS. (default: ${DEFAULT-VALUE})") + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_BODIES); + private PositiveNumber maxGetReceipts = - PositiveNumber.fromInt(EthereumWireProtocolConfiguration.DEFAULT_MAX_GET_RECEIPTS); - - @CommandLine.Option( - hidden = true, - names = {"--Xewp-max-get-node-data"}, - paramLabel = "", - description = - "Maximum request limit for Ethereum Wire Protocol GET_NODE_DATA. (default: ${DEFAULT-VALUE})") + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_RECEIPTS); + private PositiveNumber maxGetNodeData = - PositiveNumber.fromInt(EthereumWireProtocolConfiguration.DEFAULT_MAX_GET_NODE_DATA); + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_NODE_DATA); public Builder maxGetBlockHeaders(final PositiveNumber maxGetBlockHeaders) { this.maxGetBlockHeaders = maxGetBlockHeaders; @@ -157,8 +132,8 @@ public Builder maxGetNodeData(final PositiveNumber maxGetNodeData) { return this; } - public EthereumWireProtocolConfiguration build() { - return new EthereumWireProtocolConfiguration( + public EthProtocolConfiguration build() { + return new EthProtocolConfiguration( maxGetBlockHeaders.getValue(), maxGetBlockBodies.getValue(), maxGetReceipts.getValue(), diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java index 4f70c03545..a9d2085b3a 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManager.java @@ -19,7 +19,7 @@ import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62; import tech.pegasys.pantheon.ethereum.eth.messages.StatusMessage; import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster; @@ -72,7 +72,7 @@ public EthProtocolManager( final int networkId, final boolean fastSyncEnabled, final EthScheduler scheduler, - final EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration, + final EthProtocolConfiguration ethereumWireProtocolConfiguration, final Clock clock, final MetricsSystem metricsSystem) { this.networkId = networkId; @@ -109,7 +109,7 @@ public EthProtocolManager( networkId, fastSyncEnabled, new EthScheduler(syncWorkers, txWorkers, computationWorkers, metricsSystem), - EthereumWireProtocolConfiguration.defaultConfig(), + EthProtocolConfiguration.defaultConfig(), clock, metricsSystem); } @@ -124,7 +124,7 @@ public EthProtocolManager( final int computationWorkers, final Clock clock, final MetricsSystem metricsSystem, - final EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration) { + final EthProtocolConfiguration ethereumWireProtocolConfiguration) { this( blockchain, worldStateArchive, diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServer.java index fad00a59e4..4ab4382108 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServer.java @@ -17,7 +17,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeader; import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.TransactionReceipt; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.messages.BlockBodiesMessage; import tech.pegasys.pantheon.ethereum.eth.messages.BlockHeadersMessage; import tech.pegasys.pantheon.ethereum.eth.messages.EthPV62; @@ -51,13 +51,13 @@ class EthServer { private final Blockchain blockchain; private final WorldStateArchive worldStateArchive; private final EthMessages ethMessages; - private final EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration; + private final EthProtocolConfiguration ethereumWireProtocolConfiguration; EthServer( final Blockchain blockchain, final WorldStateArchive worldStateArchive, final EthMessages ethMessages, - final EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration) { + final EthProtocolConfiguration ethereumWireProtocolConfiguration) { this.blockchain = blockchain; this.worldStateArchive = worldStateArchive; this.ethMessages = ethMessages; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java index 6d61ea8f04..b42538e81e 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTest.java @@ -34,7 +34,7 @@ import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; import tech.pegasys.pantheon.ethereum.eth.EthProtocol.EthVersion; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.MockPeerConnection.PeerSendHandler; import tech.pegasys.pantheon.ethereum.eth.manager.ethtaskutils.BlockchainSetupUtil; import tech.pegasys.pantheon.ethereum.eth.messages.BlockBodiesMessage; @@ -121,7 +121,7 @@ public void disconnectOnUnsolicitedMessage() { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); @@ -143,7 +143,7 @@ public void disconnectOnFailureToSendStatusMessage() { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = @@ -166,7 +166,7 @@ public void disconnectOnWrongChainId() { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = @@ -200,7 +200,7 @@ public void disconnectOnWrongGenesisHash() { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = @@ -234,7 +234,7 @@ public void doNotDisconnectOnValidMessage() { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final MessageData messageData = GetBlockBodiesMessage.create(Collections.singletonList(gen.hash())); final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); @@ -260,7 +260,7 @@ public void respondToGetHeaders() throws ExecutionException, InterruptedExceptio 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long startBlock = 5L; final int blockCount = 5; final MessageData messageData = @@ -302,7 +302,7 @@ public void respondToGetHeadersWithinLimits() throws ExecutionException, Interru 1, TestClock.fixed(), new NoOpMetricsSystem(), - new EthereumWireProtocolConfiguration(limit, limit, limit, limit))) { + new EthProtocolConfiguration(limit, limit, limit, limit))) { final long startBlock = 5L; final int blockCount = 10; final MessageData messageData = @@ -343,7 +343,7 @@ public void respondToGetHeadersReversed() throws ExecutionException, Interrupted 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long endBlock = 10L; final int blockCount = 5; final MessageData messageData = GetBlockHeadersMessage.create(endBlock, blockCount, 0, true); @@ -383,7 +383,7 @@ public void respondToGetHeadersWithSkip() throws ExecutionException, Interrupted 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long startBlock = 5L; final int blockCount = 5; final int skip = 1; @@ -426,7 +426,7 @@ public void respondToGetHeadersReversedWithSkip() 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long endBlock = 10L; final int blockCount = 5; final int skip = 1; @@ -490,7 +490,7 @@ public void respondToGetHeadersPartial() throws ExecutionException, InterruptedE 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long startBlock = blockchain.getChainHeadBlockNumber() - 1L; final int blockCount = 5; final MessageData messageData = @@ -531,7 +531,7 @@ public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedExc 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long startBlock = blockchain.getChainHeadBlockNumber() + 1; final int blockCount = 5; final MessageData messageData = @@ -569,7 +569,7 @@ public void respondToGetBodies() throws ExecutionException, InterruptedException 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { // Setup blocks query final long startBlock = blockchain.getChainHeadBlockNumber() - 5; final int blockCount = 2; @@ -623,7 +623,7 @@ public void respondToGetBodiesWithinLimits() throws ExecutionException, Interrup 1, TestClock.fixed(), new NoOpMetricsSystem(), - new EthereumWireProtocolConfiguration(limit, limit, limit, limit))) { + new EthProtocolConfiguration(limit, limit, limit, limit))) { // Setup blocks query final int blockCount = 10; final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; @@ -676,7 +676,7 @@ public void respondToGetBodiesPartial() throws ExecutionException, InterruptedEx 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { // Setup blocks query final long expectedBlockNumber = blockchain.getChainHeadBlockNumber() - 1; final BlockHeader header = blockchain.getBlockHeader(expectedBlockNumber).get(); @@ -723,7 +723,7 @@ public void respondToGetReceipts() throws ExecutionException, InterruptedExcepti 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { // Setup blocks query final long startBlock = blockchain.getChainHeadBlockNumber() - 5; final int blockCount = 2; @@ -776,7 +776,7 @@ public void respondToGetReceiptsWithinLimits() throws ExecutionException, Interr 1, TestClock.fixed(), new NoOpMetricsSystem(), - new EthereumWireProtocolConfiguration(limit, limit, limit, limit))) { + new EthProtocolConfiguration(limit, limit, limit, limit))) { // Setup blocks query final int blockCount = 10; final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; @@ -828,7 +828,7 @@ public void respondToGetReceiptsPartial() throws ExecutionException, Interrupted 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { // Setup blocks query final long blockNumber = blockchain.getChainHeadBlockNumber() - 5; final BlockHeader header = blockchain.getBlockHeader(blockNumber).get(); @@ -877,7 +877,7 @@ public void respondToGetNodeData() throws Exception { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { // Setup node data query final List expectedResults = new ArrayList<>(); @@ -929,7 +929,7 @@ public void newBlockMinedSendsNewBlockMessageToAllPeers() { 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig()); + EthProtocolConfiguration.defaultConfig()); // Define handler to validate response final PeerSendHandler onSend = mock(PeerSendHandler.class); @@ -1002,7 +1002,7 @@ public void shouldSuccessfullyRespondToGetHeadersRequestLessThanZero() 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig())) { + EthProtocolConfiguration.defaultConfig())) { final long startBlock = 1L; final int requestedBlockCount = 13; final int receivedBlockCount = 2; @@ -1067,7 +1067,7 @@ public void transactionMessagesGoToTheCorrectExecutor() { 1, true, ethScheduler, - EthereumWireProtocolConfiguration.defaultConfig(), + EthProtocolConfiguration.defaultConfig(), TestClock.fixed(), metricsSystem)) { diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java index 2e09ad1d84..920901734a 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthProtocolManagerTestUtil.java @@ -21,7 +21,7 @@ import tech.pegasys.pantheon.ethereum.chain.ChainHead; import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.DeterministicEthScheduler.TimeoutPolicy; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -52,7 +52,7 @@ public static EthProtocolManager create( networkId, false, ethScheduler, - EthereumWireProtocolConfiguration.defaultConfig(), + EthProtocolConfiguration.defaultConfig(), TestClock.fixed(), new NoOpMetricsSystem()); } diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServerTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServerTest.java index bd75222e6e..1899f70b07 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServerTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/EthServerTest.java @@ -20,7 +20,7 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.messages.GetNodeDataMessage; import tech.pegasys.pantheon.ethereum.eth.messages.NodeDataMessage; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; @@ -47,10 +47,7 @@ public class EthServerTest { @Before public void setUp() { new EthServer( - blockchain, - worldStateArchive, - ethMessages, - new EthereumWireProtocolConfiguration(2, 2, 2, 2)); + blockchain, worldStateArchive, ethMessages, new EthProtocolConfiguration(2, 2, 2, 2)); } @Test diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java index 6069078953..ae4bc97d3b 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java @@ -30,7 +30,7 @@ import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState; @@ -116,7 +116,7 @@ public TestNode( 1, TestClock.fixed(), new NoOpMetricsSystem(), - EthereumWireProtocolConfiguration.defaultConfig()); + EthProtocolConfiguration.defaultConfig()); final NetworkRunner networkRunner = NetworkRunner.builder() diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index 6882f871b2..904d5433ae 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -16,7 +16,6 @@ import tech.pegasys.pantheon.cli.PantheonCommand; import tech.pegasys.pantheon.controller.PantheonController; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; @@ -39,7 +38,6 @@ public static void main(final String... args) { new BlockImporter(), new RunnerBuilder(), new PantheonController.Builder(), - EthereumWireProtocolConfiguration.builder(), new RocksDbConfiguration.Builder(), new PantheonPluginContextImpl(), System.getenv()); 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 fe8f28b37e..9d5cb28797 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -39,6 +39,7 @@ import tech.pegasys.pantheon.cli.custom.RpcAuthFileValidator; import tech.pegasys.pantheon.cli.operator.OperatorSubCommand; import tech.pegasys.pantheon.cli.options.CLIOptions; +import tech.pegasys.pantheon.cli.options.EthProtocolOptions; import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.cli.options.SynchronizerOptions; import tech.pegasys.pantheon.cli.rlp.RLPSubCommand; @@ -49,7 +50,6 @@ import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Wei; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; @@ -145,7 +145,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final CLIOptions networkingOptions = NetworkingOptions.create(); private final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); - private final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder; + private final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create(); private final RocksDbConfiguration.Builder rocksDbConfigurationBuilder; private final RunnerBuilder runnerBuilder; private final PantheonController.Builder controllerBuilderFactory; @@ -610,7 +610,6 @@ public PantheonCommand( final BlockImporter blockImporter, final RunnerBuilder runnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final EthereumWireProtocolConfiguration.Builder ethereumWireConfigurationBuilder, final RocksDbConfiguration.Builder rocksDbConfigurationBuilder, final PantheonPluginContextImpl pantheonPluginContext, final Map environment) { @@ -618,7 +617,6 @@ public PantheonCommand( this.blockImporter = blockImporter; this.runnerBuilder = runnerBuilder; this.controllerBuilderFactory = controllerBuilderFactory; - this.ethereumWireConfigurationBuilder = ethereumWireConfigurationBuilder; this.rocksDbConfigurationBuilder = rocksDbConfigurationBuilder; this.pantheonPluginContext = pantheonPluginContext; this.environment = environment; @@ -678,7 +676,7 @@ public void parse( "RocksDB", rocksDbConfigurationBuilder, "Ethereum Wire Protocol", - ethereumWireConfigurationBuilder)); + ethProtocolOptions)); pantheonPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine)); pantheonPluginContext.registerPlugins(pluginsDir()); @@ -814,7 +812,7 @@ PantheonController buildController() { return controllerBuilderFactory .fromEthNetworkConfig(updateNetworkConfig(getNetwork())) .synchronizerConfiguration(buildSyncConfig()) - .ethereumWireProtocolConfiguration(ethereumWireConfigurationBuilder.build()) + .ethProtocolConfiguration(ethProtocolOptions.toDomainObject()) .rocksDbConfiguration(buildRocksDbConfiguration()) .dataDirectory(dataDir()) .miningParameters( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/EthProtocolOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/EthProtocolOptions.java new file mode 100644 index 0000000000..0e5d3197ca --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/EthProtocolOptions.java @@ -0,0 +1,102 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; +import tech.pegasys.pantheon.util.number.PositiveNumber; + +import java.util.Arrays; +import java.util.List; + +import picocli.CommandLine; + +public class EthProtocolOptions implements CLIOptions { + private static final String MAX_GET_HEADERS_FLAG = "--Xewp-max-get-headers"; + private static final String MAX_GET_BODIES_FLAG = "--Xewp-max-get-bodies"; + private static final String MAX_GET_RECEIPTS_FLAG = "--Xewp-max-get-receipts"; + private static final String MAX_GET_NODE_DATA_FLAG = "--Xewp-max-get-node-data"; + + @CommandLine.Option( + hidden = true, + names = {MAX_GET_HEADERS_FLAG}, + paramLabel = "", + description = + "Maximum request limit for Ethereum Wire Protocol GET_BLOCK_HEADERS. (default: ${DEFAULT-VALUE})") + private PositiveNumber maxGetBlockHeaders = + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_HEADERS); + + @CommandLine.Option( + hidden = true, + names = {MAX_GET_BODIES_FLAG}, + paramLabel = "", + description = + "Maximum request limit for Ethereum Wire Protocol GET_BLOCK_BODIES. (default: ${DEFAULT-VALUE})") + private PositiveNumber maxGetBlockBodies = + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_BODIES); + + @CommandLine.Option( + hidden = true, + names = {MAX_GET_RECEIPTS_FLAG}, + paramLabel = "", + description = + "Maximum request limit for Ethereum Wire Protocol GET_RECEIPTS. (default: ${DEFAULT-VALUE})") + private PositiveNumber maxGetReceipts = + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_RECEIPTS); + + @CommandLine.Option( + hidden = true, + names = {MAX_GET_NODE_DATA_FLAG}, + paramLabel = "", + description = + "Maximum request limit for Ethereum Wire Protocol GET_NODE_DATA. (default: ${DEFAULT-VALUE})") + private PositiveNumber maxGetNodeData = + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_NODE_DATA); + + private EthProtocolOptions() {} + + public static EthProtocolOptions create() { + return new EthProtocolOptions(); + } + + public static EthProtocolOptions fromConfig(final EthProtocolConfiguration config) { + final EthProtocolOptions options = create(); + options.maxGetBlockHeaders = PositiveNumber.fromInt(config.getMaxGetBlockHeaders()); + options.maxGetBlockBodies = PositiveNumber.fromInt(config.getMaxGetBlockBodies()); + options.maxGetReceipts = PositiveNumber.fromInt(config.getMaxGetReceipts()); + options.maxGetNodeData = PositiveNumber.fromInt(config.getMaxGetNodeData()); + return options; + } + + @Override + public EthProtocolConfiguration toDomainObject() { + return EthProtocolConfiguration.builder() + .maxGetBlockHeaders(maxGetBlockHeaders) + .maxGetBlockBodies(maxGetBlockBodies) + .maxGetReceipts(maxGetReceipts) + .maxGetNodeData(maxGetNodeData) + .build(); + } + + @Override + public List getCLIOptions() { + return Arrays.asList( + MAX_GET_HEADERS_FLAG, + OptionParser.format(maxGetBlockHeaders.getValue()), + MAX_GET_BODIES_FLAG, + OptionParser.format(maxGetBlockBodies.getValue()), + MAX_GET_RECEIPTS_FLAG, + OptionParser.format(maxGetReceipts.getValue()), + MAX_GET_NODE_DATA_FLAG, + OptionParser.format(maxGetNodeData.getValue())); + } +} diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java index 8f1eba7505..420a97ffde 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/PantheonControllerBuilder.java @@ -27,7 +27,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.eth.EthProtocol; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.EthContext; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.peervalidation.DaoForkPeerValidator; @@ -65,7 +65,7 @@ public abstract class PantheonControllerBuilder { protected GenesisConfigFile genesisConfig; protected SynchronizerConfiguration syncConfig; protected EthProtocolManager ethProtocolManager; - protected EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration; + protected EthProtocolConfiguration ethereumWireProtocolConfiguration; protected Integer networkId; protected MiningParameters miningParameters; protected MetricsSystem metricsSystem; @@ -101,9 +101,9 @@ public PantheonControllerBuilder synchronizerConfiguration( return this; } - public PantheonControllerBuilder ethereumWireProtocolConfiguration( - final EthereumWireProtocolConfiguration ethereumWireProtocolConfiguration) { - this.ethereumWireProtocolConfiguration = ethereumWireProtocolConfiguration; + public PantheonControllerBuilder ethProtocolConfiguration( + final EthProtocolConfiguration ethProtocolConfiguration) { + this.ethereumWireProtocolConfiguration = ethProtocolConfiguration; return this; } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java index d48ca0bf3b..79d7c51e4d 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/PrivacyTest.java @@ -21,7 +21,7 @@ import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.mainnet.PrecompiledContract; @@ -54,7 +54,7 @@ public void privacyPrecompiled() throws IOException { new PantheonController.Builder() .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryStorageProvider()) .networkId(1) .miningParameters(new MiningParametersTestBuilder().enabled(false).build()) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index 0957b92a80..6a60c2b73a 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -30,7 +30,7 @@ import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; @@ -124,7 +124,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { new MainnetPantheonControllerBuilder() .genesisConfigFile(GenesisConfigFile.mainnet()) .synchronizerConfiguration(syncConfigAhead) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .dataDirectory(dataDirAhead) .networkId(networkId) .miningParameters(new MiningParametersTestBuilder().enabled(false).build()) @@ -144,7 +144,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { new MainnetPantheonControllerBuilder() .genesisConfigFile(GenesisConfigFile.mainnet()) .synchronizerConfiguration(syncConfigAhead) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .dataDirectory(dataDirAhead) .networkId(networkId) .miningParameters(new MiningParametersTestBuilder().enabled(false).build()) @@ -203,7 +203,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { new MainnetPantheonControllerBuilder() .genesisConfigFile(GenesisConfigFile.mainnet()) .synchronizerConfiguration(syncConfigBehind) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .dataDirectory(dataDirBehind) .networkId(networkId) .miningParameters(new MiningParametersTestBuilder().enabled(false).build()) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index fcc41e5e1d..e99344a72f 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -27,7 +27,7 @@ import tech.pegasys.pantheon.controller.PantheonControllerBuilder; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.ProtocolContext; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; @@ -90,9 +90,6 @@ public abstract class CommandTestAbstract { protected @Mock ProtocolSchedule mockProtocolSchedule; protected @Mock ProtocolContext mockProtocolContext; protected @Mock BlockBroadcaster mockBlockBroadcaster; - protected @Mock EthereumWireProtocolConfiguration.Builder - mockEthereumWireProtocolConfigurationBuilder; - protected @Mock SynchronizerConfiguration mockSyncConf; protected @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; protected @Mock RocksDbConfiguration mockRocksDbConf; protected @Mock PantheonController mockController; @@ -108,6 +105,7 @@ public abstract class CommandTestAbstract { protected @Captor ArgumentCaptor intArgumentCaptor; protected @Captor ArgumentCaptor ethNetworkConfigArgumentCaptor; protected @Captor ArgumentCaptor networkingConfigurationArgumentCaptor; + protected @Captor ArgumentCaptor ethProtocolConfigurationCaptor; protected @Captor ArgumentCaptor syncConfigurationCaptor; protected @Captor ArgumentCaptor jsonRpcConfigArgumentCaptor; protected @Captor ArgumentCaptor graphQLConfigArgumentCaptor; @@ -130,8 +128,7 @@ public void initMocks() throws Exception { // doReturn used because of generic PantheonController doReturn(mockControllerBuilder).when(mockControllerBuilderFactory).fromEthNetworkConfig(any()); when(mockControllerBuilder.synchronizerConfiguration(any())).thenReturn(mockControllerBuilder); - when(mockControllerBuilder.ethereumWireProtocolConfiguration(any())) - .thenReturn(mockControllerBuilder); + when(mockControllerBuilder.ethProtocolConfiguration(any())).thenReturn(mockControllerBuilder); when(mockControllerBuilder.rocksDbConfiguration(any())).thenReturn(mockControllerBuilder); when(mockControllerBuilder.dataDirectory(any())).thenReturn(mockControllerBuilder); when(mockControllerBuilder.miningParameters(any())).thenReturn(mockControllerBuilder); @@ -150,8 +147,6 @@ public void initMocks() throws Exception { lenient().when(mockController.getProtocolContext()).thenReturn(mockProtocolContext); when(mockEthProtocolManager.getBlockBroadcaster()).thenReturn(mockBlockBroadcaster); - when(mockEthereumWireProtocolConfigurationBuilder.build()) - .thenReturn(EthereumWireProtocolConfiguration.defaultConfig()); when(mockRocksDbConfBuilder.databaseDir(any())).thenReturn(mockRocksDbConfBuilder); when(mockRocksDbConfBuilder.build()).thenReturn(mockRocksDbConf); @@ -217,7 +212,6 @@ private CommandLine.Model.CommandSpec parseCommand( mockBlockImporter, mockRunnerBuilder, mockControllerBuilderFactory, - mockEthereumWireProtocolConfigurationBuilder, mockRocksDbConfBuilder, keyLoader, mockPantheonPluginContext, @@ -247,7 +241,6 @@ protected KeyLoader getKeyLoader() { final BlockImporter mockBlockImporter, final RunnerBuilder mockRunnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final EthereumWireProtocolConfiguration.Builder mockEthereumConfigurationMockBuilder, final RocksDbConfiguration.Builder mockRocksDbConfBuilder, final KeyLoader keyLoader, final PantheonPluginContextImpl pantheonPluginContext, @@ -257,7 +250,6 @@ protected KeyLoader getKeyLoader() { mockBlockImporter, mockRunnerBuilder, controllerBuilderFactory, - mockEthereumConfigurationMockBuilder, mockRocksDbConfBuilder, pantheonPluginContext, environment); 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 60d513e38a..41e3d50598 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -1336,89 +1336,6 @@ public void parsesInvalidFastSyncMinPeersOptionWrongFormatShouldFail() { .contains("Invalid value for option '--fast-sync-min-peers': 'ten' is not an int"); } - @Test - public void parsesValidEwpMaxGetHeadersOptions() { - - parseCommand("--Xewp-max-get-headers", "13"); - verify(mockEthereumWireProtocolConfigurationBuilder).build(); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void parsesInvalidEwpMaxGetHeadersOptionsShouldFail() { - - parseCommand("--Xewp-max-get-headers", "-13"); - verifyZeroInteractions(mockRunnerBuilder); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains( - "Invalid value for option '--Xewp-max-get-headers': cannot convert '-13' to PositiveNumber"); - } - - @Test - public void parsesValidEwpMaxGetBodiesOptions() { - - parseCommand("--Xewp-max-get-bodies", "14"); - verify(mockEthereumWireProtocolConfigurationBuilder).build(); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void parsesInvalidEwpMaxGetBodiesOptionsShouldFail() { - - parseCommand("--Xewp-max-get-bodies", "-14"); - verifyZeroInteractions(mockRunnerBuilder); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains( - "Invalid value for option '--Xewp-max-get-bodies': cannot convert '-14' to PositiveNumber"); - } - - @Test - public void parsesValidEwpMaxGetReceiptsOptions() { - - parseCommand("--Xewp-max-get-receipts", "15"); - verify(mockEthereumWireProtocolConfigurationBuilder).build(); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void parsesInvalidEwpMaxGetReceiptsOptionsShouldFail() { - - parseCommand("--Xewp-max-get-receipts", "-15"); - verifyZeroInteractions(mockRunnerBuilder); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains( - "Invalid value for option '--Xewp-max-get-receipts': cannot convert '-15' to PositiveNumber"); - } - - @Test - public void parsesValidEwpMaxGetNodeDataOptions() { - - parseCommand("--Xewp-max-get-node-data", "16"); - verify(mockEthereumWireProtocolConfigurationBuilder).build(); - - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - - @Test - public void parsesInvalidEwpMaxGetNodeDataOptionsShouldFail() { - - parseCommand("--Xewp-max-get-node-data", "-16"); - verifyZeroInteractions(mockRunnerBuilder); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()) - .contains( - "Invalid value for option '--Xewp-max-get-node-data': cannot convert '-16' to PositiveNumber"); - } - @Test public void rpcHttpEnabledPropertyDefaultIsFalse() { parseCommand(); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java new file mode 100644 index 0000000000..a9a07e17ff --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java @@ -0,0 +1,157 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; + +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; +import tech.pegasys.pantheon.util.number.PositiveNumber; + +import org.junit.Test; + +public class EthProtocolOptionsTest + extends AbstractCLIOptionsTest { + + @Test + public void parsesValidEwpMaxGetHeadersOptions() { + + parseCommand("--Xewp-max-get-headers", "13"); + verify(mockControllerBuilder) + .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); + final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + assertThat(config.getMaxGetBlockHeaders()).isEqualTo(13); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void parsesInvalidEwpMaxGetHeadersOptionsShouldFail() { + + parseCommand("--Xewp-max-get-headers", "-13"); + verifyZeroInteractions(mockRunnerBuilder); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains( + "Invalid value for option '--Xewp-max-get-headers': cannot convert '-13' to PositiveNumber"); + } + + @Test + public void parsesValidEwpMaxGetBodiesOptions() { + + parseCommand("--Xewp-max-get-bodies", "14"); + verify(mockControllerBuilder) + .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); + final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + assertThat(config.getMaxGetBlockBodies()).isEqualTo(14); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void parsesInvalidEwpMaxGetBodiesOptionsShouldFail() { + + parseCommand("--Xewp-max-get-bodies", "-14"); + verifyZeroInteractions(mockRunnerBuilder); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains( + "Invalid value for option '--Xewp-max-get-bodies': cannot convert '-14' to PositiveNumber"); + } + + @Test + public void parsesValidEwpMaxGetReceiptsOptions() { + + parseCommand("--Xewp-max-get-receipts", "15"); + verify(mockControllerBuilder) + .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); + final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + assertThat(config.getMaxGetReceipts()).isEqualTo(15); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void parsesInvalidEwpMaxGetReceiptsOptionsShouldFail() { + + parseCommand("--Xewp-max-get-receipts", "-15"); + verifyZeroInteractions(mockRunnerBuilder); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains( + "Invalid value for option '--Xewp-max-get-receipts': cannot convert '-15' to PositiveNumber"); + } + + @Test + public void parsesValidEwpMaxGetNodeDataOptions() { + + parseCommand("--Xewp-max-get-node-data", "16"); + verify(mockControllerBuilder) + .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); + final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + assertThat(config.getMaxGetNodeData()).isEqualTo(16); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Test + public void parsesInvalidEwpMaxGetNodeDataOptionsShouldFail() { + + parseCommand("--Xewp-max-get-node-data", "-16"); + verifyZeroInteractions(mockRunnerBuilder); + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()) + .contains( + "Invalid value for option '--Xewp-max-get-node-data': cannot convert '-16' to PositiveNumber"); + } + + @Override + EthProtocolConfiguration createDefaultDomainObject() { + return EthProtocolConfiguration.builder().build(); + } + + @Override + EthProtocolConfiguration createCustomizedDomainObject() { + return EthProtocolConfiguration.builder() + .maxGetBlockHeaders( + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_HEADERS + 2)) + .maxGetBlockBodies( + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_BODIES + 2)) + .maxGetReceipts( + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_RECEIPTS + 2)) + .maxGetNodeData( + PositiveNumber.fromInt(EthProtocolConfiguration.DEFAULT_MAX_GET_NODE_DATA + 2)) + .build(); + } + + @Override + EthProtocolOptions optionsFromDomainObject(final EthProtocolConfiguration domainObject) { + return EthProtocolOptions.fromConfig(domainObject); + } + + @Override + EthProtocolConfiguration optionsToDomainObject(final EthProtocolOptions options) { + return options.toDomainObject(); + } + + @Override + EthProtocolConfiguration getDomainObjectFromPantheonCommand() { + verify(mockControllerBuilder) + .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); + return ethProtocolConfigurationCaptor.getValue(); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java index bbb50ab367..21f8e26922 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/BlockImporterTest.java @@ -21,7 +21,7 @@ import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; -import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; +import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; @@ -55,7 +55,7 @@ public void blockImport() throws IOException { new PantheonController.Builder() .fromGenesisConfig(GenesisConfigFile.mainnet()) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryStorageProvider()) .networkId(1) .miningParameters(new MiningParametersTestBuilder().enabled(false).build()) @@ -95,7 +95,7 @@ public void ibftImport() throws IOException { new PantheonController.Builder() .fromGenesisConfig(GenesisConfigFile.fromConfig(config)) .synchronizerConfiguration(SynchronizerConfiguration.builder().build()) - .ethereumWireProtocolConfiguration(EthereumWireProtocolConfiguration.defaultConfig()) + .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .storageProvider(new InMemoryStorageProvider()) .networkId(10) .miningParameters(new MiningParametersTestBuilder().enabled(false).build()) From bea4084270eab2fe6ed677d59aed39e06df92d65 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 28 Jun 2019 18:05:49 -0400 Subject: [PATCH 10/15] Add RocksDBOptions --- .../dsl/node/ThreadPantheonNodeRunner.java | 2 +- .../operations/OperationBenchmarkHelper.java | 2 +- .../ethereum/core/PrivacyParameters.java | 2 +- .../WorldStateDownloaderBenchmark.java | 2 +- metrics/rocksdb/build.gradle | 1 - .../java/tech/pegasys/pantheon/Pantheon.java | 2 - .../pegasys/pantheon/cli/PantheonCommand.java | 9 +- .../pantheon/cli/options/RocksDBOptions.java | 97 +++++++++++++++++++ .../tech/pegasys/pantheon/RunnerTest.java | 2 +- .../pantheon/cli/CommandTestAbstract.java | 9 -- .../cli/options/AbstractCLIOptionsTest.java | 22 ++++- .../cli/options/RocksDBOptionsTest.java | 64 ++++++++++++ .../cli/options/SynchronizerOptionsTest.java | 7 +- services/kvstore/build.gradle | 1 - .../kvstore/RocksDbConfiguration.java | 78 +++++---------- .../kvstore/RocksDbKeyValueStorage.java | 9 +- .../kvstore/RocksDbKeyValueStorageTest.java | 2 +- 17 files changed, 228 insertions(+), 83 deletions(-) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/options/RocksDBOptions.java create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java 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 00e16a285e..211e99d76d 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 @@ -116,7 +116,7 @@ public void startNode(final PantheonNode node) { .metricsSystem(noOpMetricsSystem) .maxPendingTransactions(PendingTransactions.MAX_PENDING_TRANSACTIONS) .pendingTransactionRetentionPeriod(PendingTransactions.DEFAULT_TX_RETENTION_HOURS) - .rocksDbConfiguration(new RocksDbConfiguration.Builder().databaseDir(tempDir).build()) + .rocksDbConfiguration(RocksDbConfiguration.builder().databaseDir(tempDir).build()) .ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) .clock(Clock.systemUTC()) .build(); diff --git a/ethereum/core/src/jmh/java/tech/pegasys/pantheon/ethereum/vm/operations/OperationBenchmarkHelper.java b/ethereum/core/src/jmh/java/tech/pegasys/pantheon/ethereum/vm/operations/OperationBenchmarkHelper.java index 895f816e6e..8b7147ee62 100644 --- a/ethereum/core/src/jmh/java/tech/pegasys/pantheon/ethereum/vm/operations/OperationBenchmarkHelper.java +++ b/ethereum/core/src/jmh/java/tech/pegasys/pantheon/ethereum/vm/operations/OperationBenchmarkHelper.java @@ -53,7 +53,7 @@ public static OperationBenchmarkHelper create() throws IOException { final Path storageDirectory = Files.createTempDirectory("benchmark"); final KeyValueStorage keyValueStorage = RocksDbKeyValueStorage.create( - new RocksDbConfiguration.Builder().databaseDir(storageDirectory).build(), + RocksDbConfiguration.builder().databaseDir(storageDirectory).build(), new NoOpMetricsSystem()); final ExecutionContextTestFixture executionContext = diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java index 7f50c9cfc9..e412b28e82 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/PrivacyParameters.java @@ -176,7 +176,7 @@ public PrivacyParameters build() throws IOException { Path privateDbPath = dataDir.resolve(PRIVATE_DATABASE_PATH); StorageProvider privateStorageProvider = RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder() + RocksDbConfiguration.builder() .databaseDir(privateDbPath) .label("private_state") .build(), diff --git a/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java b/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java index 80a395b80c..9f28d15007 100644 --- a/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java +++ b/ethereum/eth/src/jmh/java/tech/pegasys/pantheon/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java @@ -91,7 +91,7 @@ public void setUpUnchangedState() throws Exception { final EthContext ethContext = ethProtocolManager.ethContext(); storageProvider = RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder().databaseDir(tempDir.resolve("database")).build(), + RocksDbConfiguration.builder().databaseDir(tempDir.resolve("database")).build(), metricsSystem); worldStateStorage = storageProvider.createWorldStateStorage(); diff --git a/metrics/rocksdb/build.gradle b/metrics/rocksdb/build.gradle index 6994cb7e44..5690b1c3b9 100644 --- a/metrics/rocksdb/build.gradle +++ b/metrics/rocksdb/build.gradle @@ -31,7 +31,6 @@ dependencies { implementation 'com.google.guava:guava' implementation 'io.prometheus:simpleclient' - implementation 'info.picocli:picocli' implementation 'org.apache.logging.log4j:log4j-api' implementation 'org.rocksdb:rocksdbjni' } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index 904d5433ae..131314f02f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -17,7 +17,6 @@ import tech.pegasys.pantheon.cli.PantheonCommand; import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; -import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; import org.apache.logging.log4j.Logger; @@ -38,7 +37,6 @@ public static void main(final String... args) { new BlockImporter(), new RunnerBuilder(), new PantheonController.Builder(), - new RocksDbConfiguration.Builder(), new PantheonPluginContextImpl(), System.getenv()); 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 9d5cb28797..bc3a54be73 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -41,6 +41,7 @@ import tech.pegasys.pantheon.cli.options.CLIOptions; import tech.pegasys.pantheon.cli.options.EthProtocolOptions; import tech.pegasys.pantheon.cli.options.NetworkingOptions; +import tech.pegasys.pantheon.cli.options.RocksDBOptions; import tech.pegasys.pantheon.cli.options.SynchronizerOptions; import tech.pegasys.pantheon.cli.rlp.RLPSubCommand; import tech.pegasys.pantheon.config.GenesisConfigFile; @@ -146,7 +147,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final CLIOptions networkingOptions = NetworkingOptions.create(); private final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); private final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create(); - private final RocksDbConfiguration.Builder rocksDbConfigurationBuilder; + private final RocksDBOptions rocksDBOptions = RocksDBOptions.create(); private final RunnerBuilder runnerBuilder; private final PantheonController.Builder controllerBuilderFactory; private final PantheonPluginContextImpl pantheonPluginContext; @@ -610,14 +611,12 @@ public PantheonCommand( final BlockImporter blockImporter, final RunnerBuilder runnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final RocksDbConfiguration.Builder rocksDbConfigurationBuilder, final PantheonPluginContextImpl pantheonPluginContext, final Map environment) { this.logger = logger; this.blockImporter = blockImporter; this.runnerBuilder = runnerBuilder; this.controllerBuilderFactory = controllerBuilderFactory; - this.rocksDbConfigurationBuilder = rocksDbConfigurationBuilder; this.pantheonPluginContext = pantheonPluginContext; this.environment = environment; } @@ -674,7 +673,7 @@ public void parse( "Synchronizer", synchronizerOptions, "RocksDB", - rocksDbConfigurationBuilder, + rocksDBOptions, "Ethereum Wire Protocol", ethProtocolOptions)); @@ -1082,7 +1081,7 @@ private SynchronizerConfiguration buildSyncConfig() { } private RocksDbConfiguration buildRocksDbConfiguration() { - return rocksDbConfigurationBuilder.databaseDir(dataDir().resolve(DATABASE_PATH)).build(); + return rocksDBOptions.toDomainObject().databaseDir(dataDir().resolve(DATABASE_PATH)).build(); } // Blockchain synchronisation from peers. diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/RocksDBOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/RocksDBOptions.java new file mode 100644 index 0000000000..de29b8c621 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/RocksDBOptions.java @@ -0,0 +1,97 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; + +import java.util.Arrays; +import java.util.List; + +import picocli.CommandLine; + +public class RocksDBOptions implements CLIOptions { + private static final String MAX_OPEN_FILES_FLAG = "--Xrocksdb-max-open-files"; + private static final String CACHE_CAPACITY_FLAG = "--Xrocksdb-cache-capacity"; + private static final String MAX_BACKGROUND_COMPACTIONS_FLAG = + "--Xrocksdb-max-background-compactions"; + private static final String BACKGROUND_THREAD_COUNT_FLAG = "--Xrocksdb-background-thread-count"; + + @CommandLine.Option( + names = {MAX_OPEN_FILES_FLAG}, + hidden = true, + defaultValue = "1024", + paramLabel = "", + description = "Max number of files RocksDB will open (default: ${DEFAULT-VALUE})") + int maxOpenFiles; + + @CommandLine.Option( + names = {CACHE_CAPACITY_FLAG}, + hidden = true, + defaultValue = "8388608", + paramLabel = "", + description = "Cache capacity of RocksDB (default: ${DEFAULT-VALUE})") + long cacheCapacity; + + @CommandLine.Option( + names = {MAX_BACKGROUND_COMPACTIONS_FLAG}, + hidden = true, + defaultValue = "4", + paramLabel = "", + description = "Maximum number of RocksDB background compactions (default: ${DEFAULT-VALUE})") + int maxBackgroundCompactions; + + @CommandLine.Option( + names = {BACKGROUND_THREAD_COUNT_FLAG}, + hidden = true, + defaultValue = "4", + paramLabel = "", + description = "Number of RocksDB background threads (default: ${DEFAULT-VALUE})") + int backgroundThreadCount; + + private RocksDBOptions() {} + + public static RocksDBOptions create() { + return new RocksDBOptions(); + } + + public static RocksDBOptions fromConfig(final RocksDbConfiguration config) { + final RocksDBOptions options = create(); + options.maxOpenFiles = config.getMaxOpenFiles(); + options.cacheCapacity = config.getCacheCapacity(); + options.maxBackgroundCompactions = config.getMaxBackgroundCompactions(); + options.backgroundThreadCount = config.getBackgroundThreadCount(); + return options; + } + + @Override + public RocksDbConfiguration.Builder toDomainObject() { + return RocksDbConfiguration.builder() + .maxOpenFiles(maxOpenFiles) + .cacheCapacity(cacheCapacity) + .maxBackgroundCompactions(maxBackgroundCompactions) + .backgroundThreadCount(backgroundThreadCount); + } + + @Override + public List getCLIOptions() { + return Arrays.asList( + MAX_OPEN_FILES_FLAG, + OptionParser.format(maxOpenFiles), + CACHE_CAPACITY_FLAG, + OptionParser.format(cacheCapacity), + MAX_BACKGROUND_COMPACTIONS_FLAG, + OptionParser.format(maxBackgroundCompactions), + BACKGROUND_THREAD_COUNT_FLAG, + OptionParser.format(backgroundThreadCount)); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index 6a60c2b73a..daaf4b2fb3 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -333,7 +333,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { private StorageProvider createKeyValueStorageProvider(final Path dbAhead) throws IOException { return RocksDbStorageProvider.create( - new RocksDbConfiguration.Builder().databaseDir(dbAhead).build(), new NoOpMetricsSystem()); + RocksDbConfiguration.builder().databaseDir(dbAhead).build(), new NoOpMetricsSystem()); } private JsonRpcConfiguration jsonRpcConfiguration() { diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index e99344a72f..126ef217ae 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -39,7 +39,6 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; -import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; import tech.pegasys.pantheon.util.bytes.BytesValue; @@ -90,8 +89,6 @@ public abstract class CommandTestAbstract { protected @Mock ProtocolSchedule mockProtocolSchedule; protected @Mock ProtocolContext mockProtocolContext; protected @Mock BlockBroadcaster mockBlockBroadcaster; - protected @Mock RocksDbConfiguration.Builder mockRocksDbConfBuilder; - protected @Mock RocksDbConfiguration mockRocksDbConf; protected @Mock PantheonController mockController; protected @Mock BlockImporter mockBlockImporter; protected @Mock Logger mockLogger; @@ -148,9 +145,6 @@ public void initMocks() throws Exception { when(mockEthProtocolManager.getBlockBroadcaster()).thenReturn(mockBlockBroadcaster); - when(mockRocksDbConfBuilder.databaseDir(any())).thenReturn(mockRocksDbConfBuilder); - when(mockRocksDbConfBuilder.build()).thenReturn(mockRocksDbConf); - when(mockRunnerBuilder.vertx(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.pantheonController(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.discovery(anyBoolean())).thenReturn(mockRunnerBuilder); @@ -212,7 +206,6 @@ private CommandLine.Model.CommandSpec parseCommand( mockBlockImporter, mockRunnerBuilder, mockControllerBuilderFactory, - mockRocksDbConfBuilder, keyLoader, mockPantheonPluginContext, environment); @@ -241,7 +234,6 @@ protected KeyLoader getKeyLoader() { final BlockImporter mockBlockImporter, final RunnerBuilder mockRunnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final RocksDbConfiguration.Builder mockRocksDbConfBuilder, final KeyLoader keyLoader, final PantheonPluginContextImpl pantheonPluginContext, final Map environment) { @@ -250,7 +242,6 @@ protected KeyLoader getKeyLoader() { mockBlockImporter, mockRunnerBuilder, controllerBuilderFactory, - mockRocksDbConfBuilder, pantheonPluginContext, environment); this.keyLoader = keyLoader; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java index 004cdfcf2d..6822b77a7f 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java @@ -16,6 +16,10 @@ import tech.pegasys.pantheon.cli.CommandTestAbstract; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.junit.Test; public abstract class AbstractCLIOptionsTest> @@ -52,7 +56,10 @@ private void getCLIOptions(final D domainObject) { parseCommand(cliOptions); final D actualDomainObject = getDomainObjectFromPantheonCommand(); - assertThat(actualDomainObject).isEqualToComparingFieldByField(domainObject); + + final List fieldsToIgnore = getFieldsToIgnore(); + final String[] ignored = fieldsToIgnore.toArray(new String[0]); + assertThat(actualDomainObject).isEqualToIgnoringGivenFields(domainObject, ignored); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -66,7 +73,10 @@ public void defaultValues() { final D actualDomainObject = getDomainObjectFromPantheonCommand(); // Check default values supplied by CLI match expected default values - final String[] ignoredDefaults = getFieldsWithComputedDefaults(); + final List fieldsToIgnore = new ArrayList<>(); + fieldsToIgnore.addAll(getFieldsToIgnore()); + fieldsToIgnore.addAll(getFieldsWithComputedDefaults()); + final String[] ignoredDefaults = fieldsToIgnore.toArray(new String[0]); assertThat(actualDomainObject) .isEqualToIgnoringGivenFields(defaultDomainObject, ignoredDefaults); } @@ -75,8 +85,12 @@ public void defaultValues() { abstract D createCustomizedDomainObject(); - protected String[] getFieldsWithComputedDefaults() { - return new String[] {}; + protected List getFieldsWithComputedDefaults() { + return Collections.emptyList(); + } + + protected List getFieldsToIgnore() { + return Collections.emptyList(); } abstract T optionsFromDomainObject(D domainObject); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java new file mode 100644 index 0000000000..12d3d12fdf --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.mockito.Mockito.verify; + +import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; + +import java.util.Arrays; +import java.util.List; + +import org.mockito.ArgumentCaptor; + +public class RocksDBOptionsTest + extends AbstractCLIOptionsTest { + + @Override + RocksDbConfiguration createDefaultDomainObject() { + return RocksDbConfiguration.builder().build(); + } + + @Override + RocksDbConfiguration createCustomizedDomainObject() { + return RocksDbConfiguration.builder() + .maxOpenFiles(RocksDbConfiguration.DEFAULT_MAX_OPEN_FILES + 1) + .cacheCapacity(RocksDbConfiguration.DEFAULT_CACHE_CAPACITY + 1) + .maxBackgroundCompactions(RocksDbConfiguration.DEFAULT_MAX_BACKGROUND_COMPACTIONS + 1) + .backgroundThreadCount(RocksDbConfiguration.DEFAULT_BACKGROUND_THREAD_COUNT + 1) + .build(); + } + + @Override + RocksDBOptions optionsFromDomainObject(final RocksDbConfiguration domainObject) { + return RocksDBOptions.fromConfig(domainObject); + } + + @Override + RocksDbConfiguration optionsToDomainObject(final RocksDBOptions options) { + return options.toDomainObject().build(); + } + + @Override + RocksDbConfiguration getDomainObjectFromPantheonCommand() { + final ArgumentCaptor captor = + ArgumentCaptor.forClass(RocksDbConfiguration.class); + verify(mockControllerBuilder).rocksDbConfiguration(captor.capture()); + return captor.getValue(); + } + + @Override + protected List getFieldsToIgnore() { + return Arrays.asList("databaseDir"); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java index 53141505c4..aa47d4c5af 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java @@ -16,6 +16,9 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; +import java.util.Arrays; +import java.util.List; + import com.google.common.collect.Range; public class SynchronizerOptionsTest @@ -63,8 +66,8 @@ SynchronizerConfiguration createCustomizedDomainObject() { } @Override - protected String[] getFieldsWithComputedDefaults() { - return new String[] {"maxTrailingPeers", "computationParallelism"}; + protected List getFieldsWithComputedDefaults() { + return Arrays.asList("maxTrailingPeers", "computationParallelism"); } @Override diff --git a/services/kvstore/build.gradle b/services/kvstore/build.gradle index e8203b74ca..5ab08e4006 100644 --- a/services/kvstore/build.gradle +++ b/services/kvstore/build.gradle @@ -33,7 +33,6 @@ dependencies { implementation project(':services:util') implementation 'com.google.guava:guava' - implementation 'info.picocli:picocli' implementation 'io.prometheus:simpleclient' implementation 'org.apache.logging.log4j:log4j-api' implementation 'org.rocksdb:rocksdbjni' diff --git a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbConfiguration.java b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbConfiguration.java index 66dbe91d72..7c18ed7468 100644 --- a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbConfiguration.java +++ b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbConfiguration.java @@ -16,35 +16,39 @@ import java.nio.file.Path; -import org.rocksdb.BlockBasedTableConfig; -import org.rocksdb.LRUCache; -import picocli.CommandLine; - public class RocksDbConfiguration { + public static final int DEFAULT_MAX_OPEN_FILES = 1024; + public static final long DEFAULT_CACHE_CAPACITY = 8388608; + public static final int DEFAULT_MAX_BACKGROUND_COMPACTIONS = 4; + public static final int DEFAULT_BACKGROUND_THREAD_COUNT = 4; private final Path databaseDir; private final int maxOpenFiles; - private final BlockBasedTableConfig blockBasedTableConfig; private final String label; private final int maxBackgroundCompactions; private final int backgroundThreadCount; + private final long cacheCapacity; - public RocksDbConfiguration( + private RocksDbConfiguration( final Path databaseDir, final int maxOpenFiles, final int maxBackgroundCompactions, final int backgroundThreadCount, - final LRUCache cache, + final long cacheCapacity, final String label) { this.maxBackgroundCompactions = maxBackgroundCompactions; this.backgroundThreadCount = backgroundThreadCount; RocksDbUtil.loadNativeLibrary(); this.databaseDir = databaseDir; this.maxOpenFiles = maxOpenFiles; - this.blockBasedTableConfig = new BlockBasedTableConfig().setBlockCache(cache); + this.cacheCapacity = cacheCapacity; this.label = label; } + public static Builder builder() { + return new Builder(); + } + public Path getDatabaseDir() { return databaseDir; } @@ -61,8 +65,8 @@ public int getBackgroundThreadCount() { return backgroundThreadCount; } - public BlockBasedTableConfig getBlockBasedTableConfig() { - return blockBasedTableConfig; + public long getCacheCapacity() { + return cacheCapacity; } public String getLabel() { @@ -72,41 +76,14 @@ public String getLabel() { public static class Builder { Path databaseDir; - LRUCache cache = null; String label = "blockchain"; - @CommandLine.Option( - names = {"--Xrocksdb-max-open-files"}, - hidden = true, - defaultValue = "1024", - paramLabel = "", - description = "Max number of files RocksDB will open (default: ${DEFAULT-VALUE})") - int maxOpenFiles; - - @CommandLine.Option( - names = {"--Xrocksdb-cache-capacity"}, - hidden = true, - defaultValue = "8388608", - paramLabel = "", - description = "Cache capacity of RocksDB (default: ${DEFAULT-VALUE})") - long cacheCapacity; - - @CommandLine.Option( - names = {"--Xrocksdb-max-background-compactions"}, - hidden = true, - defaultValue = "4", - paramLabel = "", - description = - "Maximum number of RocksDB background compactions (default: ${DEFAULT-VALUE})") - int maxBackgroundCompactions; - - @CommandLine.Option( - names = {"--Xrocksdb-background-thread-count"}, - hidden = true, - defaultValue = "4", - paramLabel = "", - description = "Number of RocksDB background threads (default: ${DEFAULT-VALUE})") - int backgroundThreadCount; + int maxOpenFiles = DEFAULT_MAX_OPEN_FILES; + long cacheCapacity = DEFAULT_CACHE_CAPACITY; + int maxBackgroundCompactions = DEFAULT_MAX_BACKGROUND_COMPACTIONS; + int backgroundThreadCount = DEFAULT_BACKGROUND_THREAD_COUNT; + + private Builder() {} public Builder databaseDir(final Path databaseDir) { this.databaseDir = databaseDir; @@ -138,17 +115,14 @@ public Builder backgroundThreadCount(final int backgroundThreadCount) { return this; } - private LRUCache createCache(final long cacheCapacity) { - RocksDbUtil.loadNativeLibrary(); - return new LRUCache(cacheCapacity); - } - public RocksDbConfiguration build() { - if (cache == null) { - cache = createCache(cacheCapacity); - } return new RocksDbConfiguration( - databaseDir, maxOpenFiles, maxBackgroundCompactions, backgroundThreadCount, cache, label); + databaseDir, + maxOpenFiles, + maxBackgroundCompactions, + backgroundThreadCount, + cacheCapacity, + label); } } } diff --git a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java index 3f8124b54c..46b2a23063 100644 --- a/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java +++ b/services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java @@ -27,6 +27,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.rocksdb.BlockBasedTableConfig; +import org.rocksdb.LRUCache; import org.rocksdb.Options; import org.rocksdb.RocksDBException; import org.rocksdb.Statistics; @@ -65,7 +67,7 @@ private RocksDbKeyValueStorage( new Options() .setCreateIfMissing(true) .setMaxOpenFiles(rocksDbConfiguration.getMaxOpenFiles()) - .setTableFormatConfig(rocksDbConfiguration.getBlockBasedTableConfig()) + .setTableFormatConfig(createBlockBasedTableConfig(rocksDbConfiguration)) .setMaxBackgroundCompactions(rocksDbConfiguration.getMaxBackgroundCompactions()) .setStatistics(stats); options.getEnv().setBackgroundThreads(rocksDbConfiguration.getBackgroundThreadCount()); @@ -136,6 +138,11 @@ private RocksDbKeyValueStorage( } } + private BlockBasedTableConfig createBlockBasedTableConfig(final RocksDbConfiguration config) { + final LRUCache cache = new LRUCache(config.getCacheCapacity()); + return new BlockBasedTableConfig().setBlockCache(cache); + } + @Override public Optional get(final BytesValue key) throws StorageException { throwIfClosed(); diff --git a/services/kvstore/src/test/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorageTest.java b/services/kvstore/src/test/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorageTest.java index 70c235f0ad..d49c59f78f 100644 --- a/services/kvstore/src/test/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorageTest.java +++ b/services/kvstore/src/test/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorageTest.java @@ -24,7 +24,7 @@ public class RocksDbKeyValueStorageTest extends AbstractKeyValueStorageTest { @Override protected KeyValueStorage createStore() throws Exception { return RocksDbKeyValueStorage.create( - new RocksDbConfiguration.Builder().databaseDir(folder.newFolder().toPath()).build(), + RocksDbConfiguration.builder().databaseDir(folder.newFolder().toPath()).build(), new NoOpMetricsSystem()); } } From 8febbefb5b7f394feaf68274cc599d9a00849423 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Fri, 28 Jun 2019 18:34:32 -0400 Subject: [PATCH 11/15] Clean up tests --- .../pantheon/cli/PantheonCommandTest.java | 53 ------------------- .../cli/options/AbstractCLIOptionsTest.java | 5 +- .../cli/options/EthProtocolOptionsTest.java | 28 ++++------ .../cli/options/NetworkingOptionsTest.java | 46 ++++++++++++++++ .../cli/options/SynchronizerOptionsTest.java | 9 ++-- 5 files changed, 65 insertions(+), 76 deletions(-) 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 d5be88c491..46413d50a1 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -46,7 +46,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; @@ -338,58 +337,6 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile() throws IOException assertThat(commandErrorOutput.toString()).isEmpty(); } - @Test - public void checkMaintainedConnectionsFrequencyFlag_isSet() { - parseCommand("--Xp2p-check-maintained-connections-frequency", "2"); - verify(mockRunnerBuilder) - .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - final NetworkingConfiguration networkingConfig = - networkingConfigurationArgumentCaptor.getValue(); - assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(2); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Test - public void checkMaintainedFrequencyConnectionsFlag_isNotSet() { - parseCommand(); - verify(mockRunnerBuilder) - .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - final NetworkingConfiguration networkingConfig = - networkingConfigurationArgumentCaptor.getValue(); - assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(60); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Test - public void initiateConnectionsFrequencyFlag_isSet() { - parseCommand("--Xp2p-initiate-connections-frequency", "2"); - verify(mockRunnerBuilder) - .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - final NetworkingConfiguration networkingConfig = - networkingConfigurationArgumentCaptor.getValue(); - assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(2); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Test - public void initiateConnectionsFrequencyFlag_isNotSet() { - parseCommand(); - verify(mockRunnerBuilder) - .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - final NetworkingConfiguration networkingConfig = - networkingConfigurationArgumentCaptor.getValue(); - assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(30); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - @Test public void nodePermissionsSmartContractWithoutOptionMustError() { parseCommand("--permissions-nodes-contract-address"); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java index 6822b77a7f..220855c789 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java @@ -37,7 +37,10 @@ public void fromDomainObject_customize() { private void fromDomainObject(final D domainObject) { final T options = optionsFromDomainObject(domainObject); final D domainObjectFromOptions = optionsToDomainObject(options); - assertThat(domainObjectFromOptions).isEqualToComparingFieldByField(domainObject); + + final List fieldsToIgnore = getFieldsToIgnore(); + final String[] ignored = fieldsToIgnore.toArray(new String[0]); + assertThat(domainObjectFromOptions).isEqualToIgnoringGivenFields(domainObject, ignored); } @Test diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java index a9a07e17ff..52cfa55043 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java @@ -28,9 +28,8 @@ public class EthProtocolOptionsTest public void parsesValidEwpMaxGetHeadersOptions() { parseCommand("--Xewp-max-get-headers", "13"); - verify(mockControllerBuilder) - .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); - final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + + final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); assertThat(config.getMaxGetBlockHeaders()).isEqualTo(13); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -38,7 +37,6 @@ public void parsesValidEwpMaxGetHeadersOptions() { @Test public void parsesInvalidEwpMaxGetHeadersOptionsShouldFail() { - parseCommand("--Xewp-max-get-headers", "-13"); verifyZeroInteractions(mockRunnerBuilder); assertThat(commandOutput.toString()).isEmpty(); @@ -49,11 +47,9 @@ public void parsesInvalidEwpMaxGetHeadersOptionsShouldFail() { @Test public void parsesValidEwpMaxGetBodiesOptions() { - parseCommand("--Xewp-max-get-bodies", "14"); - verify(mockControllerBuilder) - .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); - final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + + final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); assertThat(config.getMaxGetBlockBodies()).isEqualTo(14); assertThat(commandOutput.toString()).isEmpty(); @@ -62,7 +58,6 @@ public void parsesValidEwpMaxGetBodiesOptions() { @Test public void parsesInvalidEwpMaxGetBodiesOptionsShouldFail() { - parseCommand("--Xewp-max-get-bodies", "-14"); verifyZeroInteractions(mockRunnerBuilder); assertThat(commandOutput.toString()).isEmpty(); @@ -73,11 +68,9 @@ public void parsesInvalidEwpMaxGetBodiesOptionsShouldFail() { @Test public void parsesValidEwpMaxGetReceiptsOptions() { - parseCommand("--Xewp-max-get-receipts", "15"); - verify(mockControllerBuilder) - .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); - final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + + final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); assertThat(config.getMaxGetReceipts()).isEqualTo(15); assertThat(commandOutput.toString()).isEmpty(); @@ -86,8 +79,8 @@ public void parsesValidEwpMaxGetReceiptsOptions() { @Test public void parsesInvalidEwpMaxGetReceiptsOptionsShouldFail() { - parseCommand("--Xewp-max-get-receipts", "-15"); + verifyZeroInteractions(mockRunnerBuilder); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()) @@ -97,11 +90,9 @@ public void parsesInvalidEwpMaxGetReceiptsOptionsShouldFail() { @Test public void parsesValidEwpMaxGetNodeDataOptions() { - parseCommand("--Xewp-max-get-node-data", "16"); - verify(mockControllerBuilder) - .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); - final EthProtocolConfiguration config = ethProtocolConfigurationCaptor.getValue(); + + final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); assertThat(config.getMaxGetNodeData()).isEqualTo(16); assertThat(commandOutput.toString()).isEmpty(); @@ -110,7 +101,6 @@ public void parsesValidEwpMaxGetNodeDataOptions() { @Test public void parsesInvalidEwpMaxGetNodeDataOptionsShouldFail() { - parseCommand("--Xewp-max-get-node-data", "-16"); verifyZeroInteractions(mockRunnerBuilder); assertThat(commandOutput.toString()).isEmpty(); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java index 4d59e4cb41..3e5dc55100 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java @@ -12,13 +12,59 @@ */ package tech.pegasys.pantheon.cli.options; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; +import org.junit.Test; + public class NetworkingOptionsTest extends AbstractCLIOptionsTest { + @Test + public void checkMaintainedConnectionsFrequencyFlag_isSet() { + parseCommand("--Xp2p-check-maintained-connections-frequency", "2"); + + final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(2); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void checkMaintainedFrequencyConnectionsFlag_isNotSet() { + parseCommand(); + + final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(60); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void initiateConnectionsFrequencyFlag_isSet() { + parseCommand("--Xp2p-initiate-connections-frequency", "2"); + + final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(2); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void initiateConnectionsFrequencyFlag_isNotSet() { + parseCommand(); + final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(30); + + assertThat(commandErrorOutput.toString()).isEmpty(); + assertThat(commandOutput.toString()).isEmpty(); + } + @Override NetworkingConfiguration createDefaultDomainObject() { return NetworkingConfiguration.create(); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java index aa47d4c5af..d754fb2cd2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java @@ -34,9 +34,7 @@ SynchronizerConfiguration createCustomizedDomainObject() { return SynchronizerConfiguration.builder() .fastSyncPivotDistance(SynchronizerConfiguration.DEFAULT_PIVOT_DISTANCE_FROM_HEAD + 10) .fastSyncFullValidationRate(SynchronizerConfiguration.DEFAULT_FULL_VALIDATION_RATE / 2) - // Min peers are currently handled outside of SynchronizerOptions - // .fastSyncMinimumPeerCount(SynchronizerConfiguration.DEFAULT_FAST_SYNC_MINIMUM_PEERS - // + 2) + .fastSyncMinimumPeerCount(SynchronizerConfiguration.DEFAULT_FAST_SYNC_MINIMUM_PEERS + 2) .worldStateHashCountPerRequest( SynchronizerConfiguration.DEFAULT_WORLD_STATE_HASH_COUNT_PER_REQUEST + 2) .worldStateRequestParallelism( @@ -85,4 +83,9 @@ SynchronizerConfiguration getDomainObjectFromPantheonCommand() { verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); return syncConfigurationCaptor.getValue(); } + + @Override + protected List getFieldsToIgnore() { + return Arrays.asList("fastSyncMinimumPeerCount"); + } } From 2a382a63469914e1f8e135def87463b2ad56579b Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 2 Jul 2019 10:26:22 -0400 Subject: [PATCH 12/15] Create TransactionPoolOptions --- .../blockcreation/CliqueBlockCreatorTest.java | 9 +-- .../CliqueMinerExecutorTest.java | 7 +- .../ibft/support/TestContextBuilder.java | 3 +- .../blockcreation/IbftBlockCreatorTest.java | 6 +- .../blockcreation/IbftBlockCreatorTest.java | 3 +- .../BlockTransactionSelectorTest.java | 6 +- .../EthHashBlockCreatorTest.java | 6 +- .../EthHashMinerExecutorTest.java | 11 +++- ethereum/eth/build.gradle | 1 - .../eth/transactions/PendingTransactions.java | 3 - .../eth/transactions/TransactionPool.java | 1 - .../TransactionPoolConfiguration.java | 19 ++---- .../transactions/PendingTransactionsTest.java | 2 +- .../eth/transactions/TransactionPoolTest.java | 2 +- .../EthGetFilterChangesIntegrationTest.java | 3 +- .../java/tech/pegasys/pantheon/Pantheon.java | 2 - .../pegasys/pantheon/cli/PantheonCommand.java | 16 ++--- .../cli/options/TransactionPoolOptions.java | 59 +++++++++++++++++ .../pantheon/cli/CommandTestAbstract.java | 10 +-- .../pantheon/cli/PantheonCommandTest.java | 17 +---- .../options/TransactionPoolOptionsTest.java | 66 +++++++++++++++++++ 21 files changed, 183 insertions(+), 69 deletions(-) create mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptions.java create mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java index b3f7675468..abb4c9a09a 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockCreatorTest.java @@ -42,6 +42,7 @@ import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.MetricsSystem; @@ -114,7 +115,7 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() { coinbase, parent -> extraData, new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem), @@ -145,7 +146,7 @@ public void insertsValidVoteIntoConstructedBlock() { coinbase, parent -> extraData, new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem), @@ -175,7 +176,7 @@ public void insertsNoVoteWhenAuthInValidators() { coinbase, parent -> extraData, new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem), @@ -208,7 +209,7 @@ public void insertsNoVoteWhenAtEpoch() { coinbase, parent -> extraData, new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem), diff --git a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java index fc985806af..24b41d9ebf 100644 --- a/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java +++ b/consensus/clique/src/test/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueMinerExecutorTest.java @@ -37,6 +37,7 @@ import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.testutil.TestClock; @@ -91,7 +92,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() { Executors.newSingleThreadExecutor(), CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair), new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem), @@ -128,7 +129,7 @@ public void extraDataForNonEpochBlocksDoesNotContainValidaors() { Executors.newSingleThreadExecutor(), CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair), new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem), @@ -165,7 +166,7 @@ public void shouldUseLatestVanityData() { Executors.newSingleThreadExecutor(), CliqueProtocolSchedule.create(GENESIS_CONFIG_OPTIONS, proposerKeyPair), new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem), diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java index 6c352e08b5..a5a0d58b4d 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextBuilder.java @@ -62,6 +62,7 @@ import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.MetricsSystem; @@ -285,7 +286,7 @@ private static ControllerAndState createControllerAndFinalState( final PendingTransactions pendingTransactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, 1, clock, metricsSystem); + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, clock, metricsSystem); final IbftBlockCreatorFactory blockCreatorFactory = new IbftBlockCreatorFactory( diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java index 74aab08f71..3f50fb3a98 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/blockcreation/IbftBlockCreatorTest.java @@ -34,6 +34,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator; import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -83,7 +84,10 @@ public void createdBlockPassesValidationRulesAndHasAppropriateHashAndMixHash() { final PendingTransactions pendingTransactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem); + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, + 1, + TestClock.fixed(), + metricsSystem); final IbftBlockCreator blockCreator = new IbftBlockCreator( diff --git a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java index 133669ac84..a2eb08fc6a 100644 --- a/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java +++ b/consensus/ibftlegacy/src/test/java/tech/pegasys/pantheon/consensus/ibftlegacy/blockcreation/IbftBlockCreatorTest.java @@ -34,6 +34,7 @@ import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.BlockHeaderValidator; import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -98,7 +99,7 @@ public void headerProducedPassesValidationRules() { initialValidatorList) .encode(), new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem), diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java index c4b83353a7..3d16861f14 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/BlockTransactionSelectorTest.java @@ -37,6 +37,7 @@ import tech.pegasys.pantheon.ethereum.core.WorldUpdater; import tech.pegasys.pantheon.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.MainnetTransactionProcessor; import tech.pegasys.pantheon.ethereum.mainnet.MainnetTransactionProcessor.Result; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -68,7 +69,10 @@ public class BlockTransactionSelectorTest { private final PendingTransactions pendingTransactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem); + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, + 5, + TestClock.fixed(), + metricsSystem); private final Blockchain blockchain = new TestBlockchain(); private final DefaultMutableWorldState worldState = inMemoryWorldState(); private final Supplier isCancelled = () -> false; diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java index 06fc1cd707..83c192cbe1 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashBlockCreatorTest.java @@ -19,6 +19,7 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.EthHashSolver; import tech.pegasys.pantheon.ethereum.mainnet.EthHasher.Light; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolScheduleBuilder; @@ -66,7 +67,10 @@ public void createMainnetBlock1() throws IOException { final PendingTransactions pendingTransactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem); + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, + 1, + TestClock.fixed(), + metricsSystem); final EthHashBlockCreator blockCreator = new EthHashBlockCreator( diff --git a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashMinerExecutorTest.java b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashMinerExecutorTest.java index 3d7ad6db2a..3cd5b6a818 100644 --- a/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashMinerExecutorTest.java +++ b/ethereum/blockcreation/src/test/java/tech/pegasys/pantheon/ethereum/blockcreation/EthHashMinerExecutorTest.java @@ -17,6 +17,7 @@ import tech.pegasys.pantheon.ethereum.core.MiningParameters; import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.testutil.TestClock; @@ -36,7 +37,10 @@ public void startingMiningWithoutCoinbaseThrowsException() { final PendingTransactions pendingTransactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem); + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, + 1, + TestClock.fixed(), + metricsSystem); final EthHashMinerExecutor executor = new EthHashMinerExecutor( @@ -58,7 +62,10 @@ public void settingCoinbaseToNullThrowsException() { final PendingTransactions pendingTransactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem); + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, + 1, + TestClock.fixed(), + metricsSystem); final EthHashMinerExecutor executor = new EthHashMinerExecutor( diff --git a/ethereum/eth/build.gradle b/ethereum/eth/build.gradle index b61a03b06c..94000afb88 100644 --- a/ethereum/eth/build.gradle +++ b/ethereum/eth/build.gradle @@ -38,7 +38,6 @@ dependencies { implementation 'io.vertx:vertx-core' implementation 'com.google.guava:guava' - implementation 'info.picocli:picocli' compileOnly 'org.openjdk.jmh:jmh-generator-annprocess' diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java index 31e052a0ce..f3263ed831 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactions.java @@ -51,9 +51,6 @@ */ public class PendingTransactions { - public static final int MAX_PENDING_TRANSACTIONS = 4096; - public static final int DEFAULT_TX_RETENTION_HOURS = 13; - private final int maxTransactionRetentionHours; private final Clock clock; diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java index 8a6543f886..050996a282 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPool.java @@ -55,7 +55,6 @@ public class TransactionPool implements BlockAddedObserver { private static final Logger LOG = getLogger(); - public static final int DEFAULT_TX_MSG_KEEP_ALIVE = 60; private static final long SYNC_TOLERANCE = 100L; private static final String REMOTE = "remote"; diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolConfiguration.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolConfiguration.java index 3d53f95b31..b243b206e8 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolConfiguration.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolConfiguration.java @@ -14,9 +14,10 @@ import java.util.Objects; -import picocli.CommandLine; - public class TransactionPoolConfiguration { + public static final int DEFAULT_TX_MSG_KEEP_ALIVE = 60; + public static final int MAX_PENDING_TRANSACTIONS = 4096; + public static final int DEFAULT_TX_RETENTION_HOURS = 13; private final int txPoolMaxSize; private final int pendingTxRetentionPeriod; @@ -79,17 +80,9 @@ public static Builder builder() { } public static class Builder { - private int txPoolMaxSize = PendingTransactions.MAX_PENDING_TRANSACTIONS; - private int pendingTxRetentionPeriod = PendingTransactions.DEFAULT_TX_RETENTION_HOURS; - - @CommandLine.Option( - names = {"--Xincoming-tx-messages-keep-alive-seconds"}, - paramLabel = "", - hidden = true, - description = - "Keep alive of incoming transaction messages in seconds (default: ${DEFAULT-VALUE})", - arity = "1") - private Integer txMessageKeepAliveSeconds = TransactionPool.DEFAULT_TX_MSG_KEEP_ALIVE; + private int txPoolMaxSize = MAX_PENDING_TRANSACTIONS; + private int pendingTxRetentionPeriod = DEFAULT_TX_RETENTION_HOURS; + private Integer txMessageKeepAliveSeconds = DEFAULT_TX_MSG_KEEP_ALIVE; public Builder txPoolMaxSize(final int txPoolMaxSize) { this.txPoolMaxSize = txPoolMaxSize; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactionsTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactionsTest.java index 2d76fba0f8..5999f33c05 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactionsTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/PendingTransactionsTest.java @@ -51,7 +51,7 @@ public class PendingTransactionsTest { private final StubMetricsSystem metricsSystem = new StubMetricsSystem(); private final PendingTransactions transactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, MAX_TRANSACTIONS, TestClock.fixed(), metricsSystem); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java index 9886299ee6..faeaa55871 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TransactionPoolTest.java @@ -93,7 +93,7 @@ public class TransactionPoolTest { private final PendingTransactions transactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, MAX_TRANSACTIONS, TestClock.fixed(), metricsSystem); diff --git a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java index e57e30d409..edf78c4d00 100644 --- a/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java +++ b/ethereum/jsonrpc/src/integration-test/java/tech/pegasys/pantheon/ethereum/jsonrpc/methods/EthGetFilterChangesIntegrationTest.java @@ -38,6 +38,7 @@ import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPool.TransactionBatchAddedListener; +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterIdGenerator; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.filter.FilterManager; @@ -77,7 +78,7 @@ public class EthGetFilterChangesIntegrationTest { private final PendingTransactions transactions = new PendingTransactions( - PendingTransactions.DEFAULT_TX_RETENTION_HOURS, + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, MAX_TRANSACTIONS, TestClock.fixed(), metricsSystem); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index 6f6711afee..131314f02f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -16,7 +16,6 @@ import tech.pegasys.pantheon.cli.PantheonCommand; import tech.pegasys.pantheon.controller.PantheonController; -import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; import tech.pegasys.pantheon.util.BlockImporter; @@ -38,7 +37,6 @@ public static void main(final String... args) { new BlockImporter(), new RunnerBuilder(), new PantheonController.Builder(), - TransactionPoolConfiguration.builder(), new PantheonPluginContextImpl(), System.getenv()); 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 67ef8370b4..9f5424c364 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -43,6 +43,7 @@ import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.cli.options.RocksDBOptions; import tech.pegasys.pantheon.cli.options.SynchronizerOptions; +import tech.pegasys.pantheon.cli.options.TransactionPoolOptions; import tech.pegasys.pantheon.cli.rlp.RLPSubCommand; import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.controller.KeyPairUtil; @@ -53,7 +54,6 @@ import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; -import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import tech.pegasys.pantheon.ethereum.graphql.GraphQLConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; @@ -149,7 +149,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); private final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create(); private final RocksDBOptions rocksDBOptions = RocksDBOptions.create(); - private final TransactionPoolConfiguration.Builder transactionPoolConfigurationBuilder; + private final TransactionPoolOptions transactionPoolOptions = TransactionPoolOptions.create(); private final RunnerBuilder runnerBuilder; private final PantheonController.Builder controllerBuilderFactory; private final PantheonPluginContextImpl pantheonPluginContext; @@ -563,7 +563,7 @@ void setBannedNodeIds(final List values) { description = "Maximum number of pending transactions that will be kept in the transaction pool (default: ${DEFAULT-VALUE})", arity = "1") - private final Integer txPoolMaxSize = PendingTransactions.MAX_PENDING_TRANSACTIONS; + private final Integer txPoolMaxSize = TransactionPoolConfiguration.MAX_PENDING_TRANSACTIONS; @Option( names = {"--tx-pool-retention-hours"}, @@ -571,7 +571,8 @@ void setBannedNodeIds(final List values) { description = "Maximum retention period of pending transactions in hours (default: ${DEFAULT-VALUE})", arity = "1") - private final Integer pendingTxRetentionPeriod = PendingTransactions.DEFAULT_TX_RETENTION_HOURS; + private final Integer pendingTxRetentionPeriod = + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS; private EthNetworkConfig ethNetworkConfig; private JsonRpcConfiguration jsonRpcConfiguration; @@ -622,14 +623,12 @@ public PantheonCommand( final BlockImporter blockImporter, final RunnerBuilder runnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final TransactionPoolConfiguration.Builder transactionPoolConfigurationBuilder, final PantheonPluginContextImpl pantheonPluginContext, final Map environment) { this.logger = logger; this.blockImporter = blockImporter; this.runnerBuilder = runnerBuilder; this.controllerBuilderFactory = controllerBuilderFactory; - this.transactionPoolConfigurationBuilder = transactionPoolConfigurationBuilder; this.pantheonPluginContext = pantheonPluginContext; this.environment = environment; } @@ -714,7 +713,7 @@ private PantheonCommand handleUnstableOptions() { "Ethereum Wire Protocol", ethProtocolOptions, "TransactionPool", - transactionPoolConfigurationBuilder)); + transactionPoolOptions)); return this; } @@ -1136,7 +1135,8 @@ private RocksDbConfiguration buildRocksDbConfiguration() { } private TransactionPoolConfiguration buildTransactionPoolConfiguration() { - return transactionPoolConfigurationBuilder + return transactionPoolOptions + .toDomainObject() .txPoolMaxSize(txPoolMaxSize) .pendingTxRetentionPeriod(pendingTxRetentionPeriod) .build(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptions.java new file mode 100644 index 0000000000..a8e92575b8 --- /dev/null +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptions.java @@ -0,0 +1,59 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; + +import java.util.Arrays; +import java.util.List; + +import picocli.CommandLine; + +public class TransactionPoolOptions implements CLIOptions { + private static final String TX_MESSAGE_KEEP_ALIVE_SEC_FLAG = + "--Xincoming-tx-messages-keep-alive-seconds"; + + @CommandLine.Option( + names = {TX_MESSAGE_KEEP_ALIVE_SEC_FLAG}, + paramLabel = "", + hidden = true, + description = + "Keep alive of incoming transaction messages in seconds (default: ${DEFAULT-VALUE})", + arity = "1") + private Integer txMessageKeepAliveSeconds = + TransactionPoolConfiguration.DEFAULT_TX_MSG_KEEP_ALIVE; + + private TransactionPoolOptions() {} + + public static TransactionPoolOptions create() { + return new TransactionPoolOptions(); + } + + public static TransactionPoolOptions fromConfig(final TransactionPoolConfiguration config) { + final TransactionPoolOptions options = TransactionPoolOptions.create(); + options.txMessageKeepAliveSeconds = config.getTxMessageKeepAliveSeconds(); + return options; + } + + @Override + public TransactionPoolConfiguration.Builder toDomainObject() { + return TransactionPoolConfiguration.builder() + .txMessageKeepAliveSeconds(txMessageKeepAliveSeconds); + } + + @Override + public List getCLIOptions() { + return Arrays.asList( + TX_MESSAGE_KEEP_ALIVE_SEC_FLAG, OptionParser.format(txMessageKeepAliveSeconds)); + } +} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index 30a315bd82..1800ee73a8 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -94,12 +94,8 @@ public abstract class CommandTestAbstract { protected @Mock BlockImporter mockBlockImporter; protected @Mock Logger mockLogger; protected @Mock PantheonPluginContextImpl mockPantheonPluginContext; - protected TransactionPoolConfiguration.Builder mockTransactionPoolConfigurationBuilder = - TransactionPoolConfiguration.builder(); - @Mock TransactionPoolConfiguration mockTransactionPoolConfiguration; protected @Captor ArgumentCaptor> bytesValueCollectionCollector; - protected @Captor ArgumentCaptor> stringListArgumentCaptor; protected @Captor ArgumentCaptor pathArgumentCaptor; protected @Captor ArgumentCaptor fileArgumentCaptor; protected @Captor ArgumentCaptor stringArgumentCaptor; @@ -114,8 +110,7 @@ public abstract class CommandTestAbstract { protected @Captor ArgumentCaptor metricsConfigArgumentCaptor; protected @Captor ArgumentCaptor permissioningConfigurationArgumentCaptor; - protected @Captor ArgumentCaptor - transactionPoolConfigurationArgumentCaptor; + protected @Captor ArgumentCaptor transactionPoolConfigCaptor; @Rule public final TemporaryFolder temp = new TemporaryFolder(); @@ -211,7 +206,6 @@ private CommandLine.Model.CommandSpec parseCommand( mockBlockImporter, mockRunnerBuilder, mockControllerBuilderFactory, - mockTransactionPoolConfigurationBuilder, keyLoader, mockPantheonPluginContext, environment); @@ -240,7 +234,6 @@ protected KeyLoader getKeyLoader() { final BlockImporter mockBlockImporter, final RunnerBuilder mockRunnerBuilder, final PantheonController.Builder controllerBuilderFactory, - final TransactionPoolConfiguration.Builder mockTransactionPoolConfigurationBuilder, final KeyLoader keyLoader, final PantheonPluginContextImpl pantheonPluginContext, final Map environment) { @@ -249,7 +242,6 @@ protected KeyLoader getKeyLoader() { mockBlockImporter, mockRunnerBuilder, controllerBuilderFactory, - mockTransactionPoolConfigurationBuilder, pantheonPluginContext, environment); this.keyLoader = keyLoader; 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 2888fb5e92..2741f7558c 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -2542,26 +2542,13 @@ public void pendingTransactionRetentionPeriod() { final int pendingTxRetentionHours = 999; parseCommand("--tx-pool-retention-hours", String.valueOf(pendingTxRetentionHours)); verify(mockControllerBuilder) - .transactionPoolConfiguration(transactionPoolConfigurationArgumentCaptor.capture()); - assertThat(transactionPoolConfigurationArgumentCaptor.getValue().getPendingTxRetentionPeriod()) + .transactionPoolConfiguration(transactionPoolConfigCaptor.capture()); + assertThat(transactionPoolConfigCaptor.getValue().getPendingTxRetentionPeriod()) .isEqualTo(pendingTxRetentionHours); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); } - @Test - public void txMessageKeepAliveSeconds() { - final int txMessageKeepAliveSeconds = 999; - parseCommand( - "--Xincoming-tx-messages-keep-alive-seconds", String.valueOf(txMessageKeepAliveSeconds)); - verify(mockControllerBuilder) - .transactionPoolConfiguration(transactionPoolConfigurationArgumentCaptor.capture()); - assertThat(transactionPoolConfigurationArgumentCaptor.getValue().getTxMessageKeepAliveSeconds()) - .isEqualTo(txMessageKeepAliveSeconds); - assertThat(commandOutput.toString()).isEmpty(); - assertThat(commandErrorOutput.toString()).isEmpty(); - } - @Test public void txMessageKeepAliveSecondsWithInvalidInputShouldFail() { parseCommand("--Xincoming-tx-messages-keep-alive-seconds", "acbd"); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java new file mode 100644 index 0000000000..67c75c41a2 --- /dev/null +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.cli.options; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; + +import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; + +import org.junit.Test; + +public class TransactionPoolOptionsTest + extends AbstractCLIOptionsTest { + + @Test + public void txMessageKeepAliveSeconds() { + final int txMessageKeepAliveSeconds = 999; + parseCommand( + "--Xincoming-tx-messages-keep-alive-seconds", String.valueOf(txMessageKeepAliveSeconds)); + + final TransactionPoolConfiguration config = getDomainObjectFromPantheonCommand(); + assertThat(config.getTxMessageKeepAliveSeconds()).isEqualTo(txMessageKeepAliveSeconds); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).isEmpty(); + } + + @Override + TransactionPoolConfiguration createDefaultDomainObject() { + return TransactionPoolConfiguration.builder().build(); + } + + @Override + TransactionPoolConfiguration createCustomizedDomainObject() { + return TransactionPoolConfiguration.builder() + .txMessageKeepAliveSeconds(TransactionPoolConfiguration.DEFAULT_TX_MSG_KEEP_ALIVE + 1) + .build(); + } + + @Override + TransactionPoolOptions optionsFromDomainObject(final TransactionPoolConfiguration domainObject) { + return TransactionPoolOptions.fromConfig(domainObject); + } + + @Override + TransactionPoolConfiguration optionsToDomainObject(final TransactionPoolOptions options) { + return options.toDomainObject().build(); + } + + @Override + TransactionPoolConfiguration getDomainObjectFromPantheonCommand() { + verify(mockControllerBuilder) + .transactionPoolConfiguration(transactionPoolConfigCaptor.capture()); + return transactionPoolConfigCaptor.getValue(); + } +} From 1ef04cbb534ba65255498e7feb3f6c5468b0fd14 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 2 Jul 2019 10:33:32 -0400 Subject: [PATCH 13/15] Fix annotations --- .../pantheon/cli/CommandTestAbstract.java | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index 1800ee73a8..097b0f61b6 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -80,37 +80,39 @@ public abstract class CommandTestAbstract { private final PrintStream errPrintStream = new PrintStream(commandErrorOutput); private final HashMap environment = new HashMap<>(); - protected @Mock RunnerBuilder mockRunnerBuilder; - protected @Mock Runner mockRunner; - - protected @Mock PantheonController.Builder mockControllerBuilderFactory; - - protected @Mock PantheonControllerBuilder mockControllerBuilder; - protected @Mock EthProtocolManager mockEthProtocolManager; - protected @Mock ProtocolSchedule mockProtocolSchedule; - protected @Mock ProtocolContext mockProtocolContext; - protected @Mock BlockBroadcaster mockBlockBroadcaster; - protected @Mock PantheonController mockController; - protected @Mock BlockImporter mockBlockImporter; - protected @Mock Logger mockLogger; - protected @Mock PantheonPluginContextImpl mockPantheonPluginContext; - - protected @Captor ArgumentCaptor> bytesValueCollectionCollector; - protected @Captor ArgumentCaptor pathArgumentCaptor; - protected @Captor ArgumentCaptor fileArgumentCaptor; - protected @Captor ArgumentCaptor stringArgumentCaptor; - protected @Captor ArgumentCaptor intArgumentCaptor; - protected @Captor ArgumentCaptor ethNetworkConfigArgumentCaptor; - protected @Captor ArgumentCaptor networkingConfigurationArgumentCaptor; - protected @Captor ArgumentCaptor ethProtocolConfigurationCaptor; - protected @Captor ArgumentCaptor syncConfigurationCaptor; - protected @Captor ArgumentCaptor jsonRpcConfigArgumentCaptor; - protected @Captor ArgumentCaptor graphQLConfigArgumentCaptor; - protected @Captor ArgumentCaptor wsRpcConfigArgumentCaptor; - protected @Captor ArgumentCaptor metricsConfigArgumentCaptor; - protected @Captor ArgumentCaptor - permissioningConfigurationArgumentCaptor; - protected @Captor ArgumentCaptor transactionPoolConfigCaptor; + @Mock protected RunnerBuilder mockRunnerBuilder; + @Mock protected Runner mockRunner; + + @Mock protected PantheonController.Builder mockControllerBuilderFactory; + + @Mock protected PantheonControllerBuilder mockControllerBuilder; + @Mock protected EthProtocolManager mockEthProtocolManager; + @Mock protected ProtocolSchedule mockProtocolSchedule; + @Mock protected ProtocolContext mockProtocolContext; + @Mock protected BlockBroadcaster mockBlockBroadcaster; + @Mock protected PantheonController mockController; + @Mock protected BlockImporter mockBlockImporter; + @Mock protected Logger mockLogger; + @Mock protected PantheonPluginContextImpl mockPantheonPluginContext; + + @Captor protected ArgumentCaptor> bytesValueCollectionCollector; + @Captor protected ArgumentCaptor pathArgumentCaptor; + @Captor protected ArgumentCaptor fileArgumentCaptor; + @Captor protected ArgumentCaptor stringArgumentCaptor; + @Captor protected ArgumentCaptor intArgumentCaptor; + @Captor protected ArgumentCaptor ethNetworkConfigArgumentCaptor; + @Captor protected ArgumentCaptor networkingConfigurationArgumentCaptor; + @Captor protected ArgumentCaptor ethProtocolConfigurationCaptor; + @Captor protected ArgumentCaptor syncConfigurationCaptor; + @Captor protected ArgumentCaptor jsonRpcConfigArgumentCaptor; + @Captor protected ArgumentCaptor graphQLConfigArgumentCaptor; + @Captor protected ArgumentCaptor wsRpcConfigArgumentCaptor; + @Captor protected ArgumentCaptor metricsConfigArgumentCaptor; + + @Captor + protected ArgumentCaptor permissioningConfigurationArgumentCaptor; + + @Captor protected ArgumentCaptor transactionPoolConfigCaptor; @Rule public final TemporaryFolder temp = new TemporaryFolder(); From 51c33a3ac737c51f15a7368b7b60f8e582d2fa0d Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 2 Jul 2019 11:32:25 -0400 Subject: [PATCH 14/15] Simplify tests --- .../pegasys/pantheon/cli/PantheonCommand.java | 12 ++--- .../pantheon/cli/BlockSubCommandTest.java | 2 +- .../pantheon/cli/CommandTestAbstract.java | 47 ++++++++++++++----- .../pantheon/cli/PantheonCommandTest.java | 2 +- .../pantheon/cli/PasswordSubCommandTest.java | 2 +- .../pantheon/cli/PublicKeySubCommandTest.java | 2 +- .../cli/operator/OperatorSubCommandTest.java | 2 +- .../cli/options/AbstractCLIOptionsTest.java | 30 +++++------- .../cli/options/EthProtocolOptionsTest.java | 32 ++++++------- .../cli/options/NetworkingOptionsTest.java | 34 +++++++------- .../cli/options/RocksDBOptionsTest.java | 31 ++++-------- .../cli/options/SynchronizerOptionsTest.java | 32 +++++-------- .../options/TransactionPoolOptionsTest.java | 37 +++++++-------- .../pantheon/cli/rlp/RLPSubCommandTest.java | 2 +- .../pantheon/util/number/PositiveNumber.java | 19 ++++++++ 15 files changed, 144 insertions(+), 142 deletions(-) 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 9f5424c364..11a64514fa 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -38,7 +38,6 @@ import tech.pegasys.pantheon.cli.custom.JsonRPCWhitelistHostsProperty; import tech.pegasys.pantheon.cli.custom.RpcAuthFileValidator; import tech.pegasys.pantheon.cli.operator.OperatorSubCommand; -import tech.pegasys.pantheon.cli.options.CLIOptions; import tech.pegasys.pantheon.cli.options.EthProtocolOptions; import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.cli.options.RocksDBOptions; @@ -61,7 +60,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.StaticNodesParser; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; @@ -145,11 +143,11 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final BlockImporter blockImporter; - private final CLIOptions networkingOptions = NetworkingOptions.create(); - private final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); - private final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create(); - private final RocksDBOptions rocksDBOptions = RocksDBOptions.create(); - private final TransactionPoolOptions transactionPoolOptions = TransactionPoolOptions.create(); + final NetworkingOptions networkingOptions = NetworkingOptions.create(); + final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); + final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create(); + final RocksDBOptions rocksDBOptions = RocksDBOptions.create(); + final TransactionPoolOptions transactionPoolOptions = TransactionPoolOptions.create(); private final RunnerBuilder runnerBuilder; private final PantheonController.Builder controllerBuilderFactory; private final PantheonPluginContextImpl pantheonPluginContext; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/BlockSubCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/BlockSubCommandTest.java index cb2abe1a16..5a6f23c14a 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/BlockSubCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/BlockSubCommandTest.java @@ -55,7 +55,7 @@ public class BlockSubCommandTest extends CommandTestAbstract { // Block sub-command @Test public void blockSubCommandExistAnbHaveSubCommands() { - CommandSpec spec = parseCommand(); + CommandSpec spec = parseCommand().getSpec(); assertThat(spec.subcommands()).containsKeys(BLOCK_SUBCOMMAND_NAME); assertThat(spec.subcommands().get(BLOCK_SUBCOMMAND_NAME).getSubcommands()) .containsKeys(BLOCK_IMPORT_SUBCOMMAND_NAME); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index 097b0f61b6..76d54e4775 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -23,11 +23,15 @@ import tech.pegasys.pantheon.Runner; import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; +import tech.pegasys.pantheon.cli.options.EthProtocolOptions; +import tech.pegasys.pantheon.cli.options.NetworkingOptions; +import tech.pegasys.pantheon.cli.options.RocksDBOptions; +import tech.pegasys.pantheon.cli.options.SynchronizerOptions; +import tech.pegasys.pantheon.cli.options.TransactionPoolOptions; import tech.pegasys.pantheon.controller.PantheonController; import tech.pegasys.pantheon.controller.PantheonControllerBuilder; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.ProtocolContext; -import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.manager.EthProtocolManager; import tech.pegasys.pantheon.ethereum.eth.sync.BlockBroadcaster; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; @@ -36,7 +40,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; @@ -66,6 +69,7 @@ import org.mockito.junit.MockitoJUnitRunner; import picocli.CommandLine; import picocli.CommandLine.Help.Ansi; +import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.RunLast; @RunWith(MockitoJUnitRunner.class) @@ -101,8 +105,6 @@ public abstract class CommandTestAbstract { @Captor protected ArgumentCaptor stringArgumentCaptor; @Captor protected ArgumentCaptor intArgumentCaptor; @Captor protected ArgumentCaptor ethNetworkConfigArgumentCaptor; - @Captor protected ArgumentCaptor networkingConfigurationArgumentCaptor; - @Captor protected ArgumentCaptor ethProtocolConfigurationCaptor; @Captor protected ArgumentCaptor syncConfigurationCaptor; @Captor protected ArgumentCaptor jsonRpcConfigArgumentCaptor; @Captor protected ArgumentCaptor graphQLConfigArgumentCaptor; @@ -184,20 +186,19 @@ protected void setEnvironemntVariable(final String name, final String value) { environment.put(name, value); } - protected CommandLine.Model.CommandSpec parseCommand(final String... args) { + protected TestPantheonCommand parseCommand(final String... args) { return parseCommand(System.in, args); } - protected CommandLine.Model.CommandSpec parseCommand( - final KeyLoader keyLoader, final String... args) { + protected TestPantheonCommand parseCommand(final KeyLoader keyLoader, final String... args) { return parseCommand(keyLoader, System.in, args); } - protected CommandLine.Model.CommandSpec parseCommand(final InputStream in, final String... args) { + protected TestPantheonCommand parseCommand(final InputStream in, final String... args) { return parseCommand(f -> KeyPair.generate(), in, args); } - private CommandLine.Model.CommandSpec parseCommand( + private TestPantheonCommand parseCommand( final KeyLoader keyLoader, final InputStream in, final String... args) { // turn off ansi usage globally in picocli System.setProperty("picocli.ansi", "false"); @@ -218,11 +219,11 @@ private CommandLine.Model.CommandSpec parseCommand( pantheonCommand.exceptionHandler().useErr(errPrintStream).useAnsi(Ansi.OFF), in, args); - return pantheonCommand.spec; + return pantheonCommand; } @CommandLine.Command - static class TestPantheonCommand extends PantheonCommand { + public static class TestPantheonCommand extends PantheonCommand { @CommandLine.Spec CommandLine.Model.CommandSpec spec; private final KeyLoader keyLoader; @@ -248,5 +249,29 @@ protected KeyLoader getKeyLoader() { environment); this.keyLoader = keyLoader; } + + public CommandSpec getSpec() { + return spec; + } + + public RocksDBOptions getRocksDBOptions() { + return rocksDBOptions; + } + + public NetworkingOptions getNetworkingOptions() { + return networkingOptions; + } + + public SynchronizerOptions getSynchronizerOptions() { + return synchronizerOptions; + } + + public EthProtocolOptions getEthProtocolOptions() { + return ethProtocolOptions; + } + + public TransactionPoolOptions getTransactionPoolOptions() { + return transactionPoolOptions; + } } } 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 2741f7558c..8d97a487d2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -651,7 +651,7 @@ public void tomlThatConfiguresEverythingExceptPermissioningToml() throws IOExcep final Path toml = createTempFile("toml", Resources.toByteArray(configFile)); // Parse it. - final CommandLine.Model.CommandSpec spec = parseCommand("--config-file", toml.toString()); + final CommandLine.Model.CommandSpec spec = parseCommand("--config-file", toml.toString()).spec; final TomlParseResult tomlResult = Toml.parse(toml); // Verify we configured everything diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PasswordSubCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PasswordSubCommandTest.java index d4a8194e41..b4acac7bf2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PasswordSubCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PasswordSubCommandTest.java @@ -21,7 +21,7 @@ public class PasswordSubCommandTest extends CommandTestAbstract { @Test public void passwordSubCommandExistAnbHaveSubCommands() { - final CommandSpec spec = parseCommand(); + final CommandSpec spec = parseCommand().getSpec(); assertThat(spec.subcommands()).containsKeys("password"); assertThat(spec.subcommands().get("password").getSubcommands()).containsKeys("hash"); assertThat(commandOutput.toString()).isEmpty(); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PublicKeySubCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PublicKeySubCommandTest.java index 5f7e7a3476..c8226ca4aa 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PublicKeySubCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PublicKeySubCommandTest.java @@ -78,7 +78,7 @@ public class PublicKeySubCommandTest extends CommandTestAbstract { // public-key sub-command @Test public void publicKeySubCommandExistAnbHaveSubCommands() { - CommandSpec spec = parseCommand(); + CommandSpec spec = parseCommand().getSpec(); assertThat(spec.subcommands()).containsKeys(PUBLIC_KEY_SUBCOMMAND_NAME); assertThat(spec.subcommands().get(PUBLIC_KEY_SUBCOMMAND_NAME).getSubcommands()) .containsKeys(PUBLIC_KEY_EXPORT_SUBCOMMAND_NAME) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/operator/OperatorSubCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/operator/OperatorSubCommandTest.java index fa7601c46a..85d39a97ee 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/operator/OperatorSubCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/operator/OperatorSubCommandTest.java @@ -75,7 +75,7 @@ public void init() throws IOException { @Test public void operatorSubCommandExistAndHaveSubCommands() { - final CommandSpec spec = parseCommand(); + final CommandSpec spec = parseCommand().getSpec(); assertThat(spec.subcommands()).containsKeys(COMMAND_NAME); assertThat(spec.subcommands().get(COMMAND_NAME).getSubcommands()) .containsKeys(GENERATE_BLOCKCHAIN_CONFIG_SUBCOMMAND_NAME); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java index 220855c789..368026b147 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/AbstractCLIOptionsTest.java @@ -16,13 +16,12 @@ import tech.pegasys.pantheon.cli.CommandTestAbstract; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Test; -public abstract class AbstractCLIOptionsTest> +public abstract class AbstractCLIOptionsTest> extends CommandTestAbstract { @Test public void fromDomainObject_default() { @@ -36,7 +35,7 @@ public void fromDomainObject_customize() { private void fromDomainObject(final D domainObject) { final T options = optionsFromDomainObject(domainObject); - final D domainObjectFromOptions = optionsToDomainObject(options); + final D domainObjectFromOptions = options.toDomainObject(); final List fieldsToIgnore = getFieldsToIgnore(); final String[] ignored = fieldsToIgnore.toArray(new String[0]); @@ -57,12 +56,10 @@ private void getCLIOptions(final D domainObject) { T options = optionsFromDomainObject(domainObject); final String[] cliOptions = options.getCLIOptions().toArray(new String[0]); - parseCommand(cliOptions); - final D actualDomainObject = getDomainObjectFromPantheonCommand(); + final TestPantheonCommand cmd = parseCommand(cliOptions); + final T optionsFromCommand = getOptionsFromPantheonCommand(cmd); - final List fieldsToIgnore = getFieldsToIgnore(); - final String[] ignored = fieldsToIgnore.toArray(new String[0]); - assertThat(actualDomainObject).isEqualToIgnoringGivenFields(domainObject, ignored); + assertThat(optionsFromCommand).isEqualToComparingFieldByField(options); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -70,18 +67,15 @@ private void getCLIOptions(final D domainObject) { @Test public void defaultValues() { - parseCommand(); + final TestPantheonCommand cmd = parseCommand(); final D defaultDomainObject = createDefaultDomainObject(); - final D actualDomainObject = getDomainObjectFromPantheonCommand(); + final T defaultOptions = optionsFromDomainObject(defaultDomainObject); + final T optionsFromCommand = getOptionsFromPantheonCommand(cmd); // Check default values supplied by CLI match expected default values - final List fieldsToIgnore = new ArrayList<>(); - fieldsToIgnore.addAll(getFieldsToIgnore()); - fieldsToIgnore.addAll(getFieldsWithComputedDefaults()); - final String[] ignoredDefaults = fieldsToIgnore.toArray(new String[0]); - assertThat(actualDomainObject) - .isEqualToIgnoringGivenFields(defaultDomainObject, ignoredDefaults); + final String[] fieldsToIgnore = getFieldsWithComputedDefaults().toArray(new String[0]); + assertThat(optionsFromCommand).isEqualToIgnoringGivenFields(defaultOptions, fieldsToIgnore); } abstract D createDefaultDomainObject(); @@ -98,7 +92,5 @@ protected List getFieldsToIgnore() { abstract T optionsFromDomainObject(D domainObject); - abstract D optionsToDomainObject(T options); - - abstract D getDomainObjectFromPantheonCommand(); + abstract T getOptionsFromPantheonCommand(final TestPantheonCommand pantheonCommand); } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java index 52cfa55043..a49bc67d5b 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/EthProtocolOptionsTest.java @@ -13,7 +13,6 @@ package tech.pegasys.pantheon.cli.options; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import tech.pegasys.pantheon.ethereum.eth.EthProtocolConfiguration; @@ -27,9 +26,10 @@ public class EthProtocolOptionsTest @Test public void parsesValidEwpMaxGetHeadersOptions() { - parseCommand("--Xewp-max-get-headers", "13"); + final TestPantheonCommand cmd = parseCommand("--Xewp-max-get-headers", "13"); - final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); + final EthProtocolOptions options = getOptionsFromPantheonCommand(cmd); + final EthProtocolConfiguration config = options.toDomainObject(); assertThat(config.getMaxGetBlockHeaders()).isEqualTo(13); assertThat(commandOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -47,9 +47,10 @@ public void parsesInvalidEwpMaxGetHeadersOptionsShouldFail() { @Test public void parsesValidEwpMaxGetBodiesOptions() { - parseCommand("--Xewp-max-get-bodies", "14"); + final TestPantheonCommand cmd = parseCommand("--Xewp-max-get-bodies", "14"); - final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); + final EthProtocolOptions options = getOptionsFromPantheonCommand(cmd); + final EthProtocolConfiguration config = options.toDomainObject(); assertThat(config.getMaxGetBlockBodies()).isEqualTo(14); assertThat(commandOutput.toString()).isEmpty(); @@ -68,9 +69,10 @@ public void parsesInvalidEwpMaxGetBodiesOptionsShouldFail() { @Test public void parsesValidEwpMaxGetReceiptsOptions() { - parseCommand("--Xewp-max-get-receipts", "15"); + final TestPantheonCommand cmd = parseCommand("--Xewp-max-get-receipts", "15"); - final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); + final EthProtocolOptions options = getOptionsFromPantheonCommand(cmd); + final EthProtocolConfiguration config = options.toDomainObject(); assertThat(config.getMaxGetReceipts()).isEqualTo(15); assertThat(commandOutput.toString()).isEmpty(); @@ -90,9 +92,10 @@ public void parsesInvalidEwpMaxGetReceiptsOptionsShouldFail() { @Test public void parsesValidEwpMaxGetNodeDataOptions() { - parseCommand("--Xewp-max-get-node-data", "16"); + final TestPantheonCommand cmd = parseCommand("--Xewp-max-get-node-data", "16"); - final EthProtocolConfiguration config = getDomainObjectFromPantheonCommand(); + final EthProtocolOptions options = getOptionsFromPantheonCommand(cmd); + final EthProtocolConfiguration config = options.toDomainObject(); assertThat(config.getMaxGetNodeData()).isEqualTo(16); assertThat(commandOutput.toString()).isEmpty(); @@ -134,14 +137,7 @@ EthProtocolOptions optionsFromDomainObject(final EthProtocolConfiguration domain } @Override - EthProtocolConfiguration optionsToDomainObject(final EthProtocolOptions options) { - return options.toDomainObject(); - } - - @Override - EthProtocolConfiguration getDomainObjectFromPantheonCommand() { - verify(mockControllerBuilder) - .ethProtocolConfiguration(ethProtocolConfigurationCaptor.capture()); - return ethProtocolConfigurationCaptor.getValue(); + EthProtocolOptions getOptionsFromPantheonCommand(final TestPantheonCommand pantheonCommand) { + return pantheonCommand.getEthProtocolOptions(); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java index 3e5dc55100..5a0208e437 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java @@ -13,7 +13,6 @@ package tech.pegasys.pantheon.cli.options; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; @@ -24,9 +23,11 @@ public class NetworkingOptionsTest @Test public void checkMaintainedConnectionsFrequencyFlag_isSet() { - parseCommand("--Xp2p-check-maintained-connections-frequency", "2"); + final TestPantheonCommand cmd = + parseCommand("--Xp2p-check-maintained-connections-frequency", "2"); - final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + final NetworkingOptions options = cmd.getNetworkingOptions(); + final NetworkingConfiguration networkingConfig = options.toDomainObject(); assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(2); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -35,9 +36,10 @@ public void checkMaintainedConnectionsFrequencyFlag_isSet() { @Test public void checkMaintainedFrequencyConnectionsFlag_isNotSet() { - parseCommand(); + final TestPantheonCommand cmd = parseCommand(); - final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + final NetworkingOptions options = cmd.getNetworkingOptions(); + final NetworkingConfiguration networkingConfig = options.toDomainObject(); assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(60); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -46,9 +48,10 @@ public void checkMaintainedFrequencyConnectionsFlag_isNotSet() { @Test public void initiateConnectionsFrequencyFlag_isSet() { - parseCommand("--Xp2p-initiate-connections-frequency", "2"); + final TestPantheonCommand cmd = parseCommand("--Xp2p-initiate-connections-frequency", "2"); - final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + final NetworkingOptions options = cmd.getNetworkingOptions(); + final NetworkingConfiguration networkingConfig = options.toDomainObject(); assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(2); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -57,8 +60,10 @@ public void initiateConnectionsFrequencyFlag_isSet() { @Test public void initiateConnectionsFrequencyFlag_isNotSet() { - parseCommand(); - final NetworkingConfiguration networkingConfig = getDomainObjectFromPantheonCommand(); + final TestPantheonCommand cmd = parseCommand(); + + final NetworkingOptions options = cmd.getNetworkingOptions(); + final NetworkingConfiguration networkingConfig = options.toDomainObject(); assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(30); assertThat(commandErrorOutput.toString()).isEmpty(); @@ -86,14 +91,7 @@ NetworkingOptions optionsFromDomainObject(final NetworkingConfiguration domainOb } @Override - NetworkingConfiguration optionsToDomainObject(final NetworkingOptions options) { - return options.toDomainObject(); - } - - @Override - NetworkingConfiguration getDomainObjectFromPantheonCommand() { - verify(mockRunnerBuilder) - .networkingConfiguration(networkingConfigurationArgumentCaptor.capture()); - return networkingConfigurationArgumentCaptor.getValue(); + NetworkingOptions getOptionsFromPantheonCommand(final TestPantheonCommand pantheonCommand) { + return pantheonCommand.getNetworkingOptions(); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java index 75c118f0e1..a3c7528db7 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/RocksDBOptionsTest.java @@ -12,49 +12,36 @@ */ package tech.pegasys.pantheon.cli.options; -import static org.mockito.Mockito.verify; - import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import java.util.Arrays; import java.util.List; -import org.mockito.ArgumentCaptor; - public class RocksDBOptionsTest - extends AbstractCLIOptionsTest { + extends AbstractCLIOptionsTest { @Override - RocksDbConfiguration createDefaultDomainObject() { - return RocksDbConfiguration.builder().build(); + RocksDbConfiguration.Builder createDefaultDomainObject() { + return RocksDbConfiguration.builder(); } @Override - RocksDbConfiguration createCustomizedDomainObject() { + RocksDbConfiguration.Builder createCustomizedDomainObject() { return RocksDbConfiguration.builder() .maxOpenFiles(RocksDbConfiguration.DEFAULT_MAX_OPEN_FILES + 1) .cacheCapacity(RocksDbConfiguration.DEFAULT_CACHE_CAPACITY + 1) .maxBackgroundCompactions(RocksDbConfiguration.DEFAULT_MAX_BACKGROUND_COMPACTIONS + 1) - .backgroundThreadCount(RocksDbConfiguration.DEFAULT_BACKGROUND_THREAD_COUNT + 1) - .build(); - } - - @Override - RocksDBOptions optionsFromDomainObject(final RocksDbConfiguration domainObject) { - return RocksDBOptions.fromConfig(domainObject); + .backgroundThreadCount(RocksDbConfiguration.DEFAULT_BACKGROUND_THREAD_COUNT + 1); } @Override - RocksDbConfiguration optionsToDomainObject(final RocksDBOptions options) { - return options.toDomainObject().build(); + RocksDBOptions optionsFromDomainObject(final RocksDbConfiguration.Builder domainObject) { + return RocksDBOptions.fromConfig(domainObject.build()); } @Override - RocksDbConfiguration getDomainObjectFromPantheonCommand() { - final ArgumentCaptor captor = - ArgumentCaptor.forClass(RocksDbConfiguration.class); - verify(mockControllerBuilder).rocksDbConfiguration(captor.capture()); - return captor.getValue(); + RocksDBOptions getOptionsFromPantheonCommand(final TestPantheonCommand command) { + return command.getRocksDBOptions(); } @Override diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java index d754fb2cd2..78eb96db16 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/SynchronizerOptionsTest.java @@ -12,8 +12,6 @@ */ package tech.pegasys.pantheon.cli.options; -import static org.mockito.Mockito.verify; - import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import java.util.Arrays; @@ -22,15 +20,15 @@ import com.google.common.collect.Range; public class SynchronizerOptionsTest - extends AbstractCLIOptionsTest { + extends AbstractCLIOptionsTest { @Override - SynchronizerConfiguration createDefaultDomainObject() { - return SynchronizerConfiguration.builder().build(); + SynchronizerConfiguration.Builder createDefaultDomainObject() { + return SynchronizerConfiguration.builder(); } @Override - SynchronizerConfiguration createCustomizedDomainObject() { + SynchronizerConfiguration.Builder createCustomizedDomainObject() { return SynchronizerConfiguration.builder() .fastSyncPivotDistance(SynchronizerConfiguration.DEFAULT_PIVOT_DISTANCE_FROM_HEAD + 10) .fastSyncFullValidationRate(SynchronizerConfiguration.DEFAULT_FULL_VALIDATION_RATE / 2) @@ -59,8 +57,7 @@ SynchronizerConfiguration createCustomizedDomainObject() { SynchronizerConfiguration.DEFAULT_DOWNLOADER_CHAIN_SEGMENT_SIZE + 2) .downloaderParallelism(SynchronizerConfiguration.DEFAULT_DOWNLOADER_PARALLELISM + 2) .transactionsParallelism(SynchronizerConfiguration.DEFAULT_TRANSACTIONS_PARALLELISM + 2) - .computationParallelism(SynchronizerConfiguration.DEFAULT_COMPUTATION_PARALLELISM + 2) - .build(); + .computationParallelism(SynchronizerConfiguration.DEFAULT_COMPUTATION_PARALLELISM + 2); } @Override @@ -69,23 +66,18 @@ protected List getFieldsWithComputedDefaults() { } @Override - SynchronizerOptions optionsFromDomainObject(final SynchronizerConfiguration domainObject) { - return SynchronizerOptions.fromConfig(domainObject); - } - - @Override - SynchronizerConfiguration optionsToDomainObject(final SynchronizerOptions options) { - return options.toDomainObject().build(); + SynchronizerOptions getOptionsFromPantheonCommand(final TestPantheonCommand pantheonCommand) { + return pantheonCommand.getSynchronizerOptions(); } @Override - SynchronizerConfiguration getDomainObjectFromPantheonCommand() { - verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); - return syncConfigurationCaptor.getValue(); + protected List getFieldsToIgnore() { + return Arrays.asList("fastSyncMinimumPeerCount"); } @Override - protected List getFieldsToIgnore() { - return Arrays.asList("fastSyncMinimumPeerCount"); + SynchronizerOptions optionsFromDomainObject( + final SynchronizerConfiguration.Builder domainObject) { + return SynchronizerOptions.fromConfig(domainObject.build()); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java index 67c75c41a2..426854dbf8 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/TransactionPoolOptionsTest.java @@ -13,22 +13,24 @@ package tech.pegasys.pantheon.cli.options; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.verify; import tech.pegasys.pantheon.ethereum.eth.transactions.TransactionPoolConfiguration; import org.junit.Test; public class TransactionPoolOptionsTest - extends AbstractCLIOptionsTest { + extends AbstractCLIOptionsTest { @Test public void txMessageKeepAliveSeconds() { final int txMessageKeepAliveSeconds = 999; - parseCommand( - "--Xincoming-tx-messages-keep-alive-seconds", String.valueOf(txMessageKeepAliveSeconds)); + final TestPantheonCommand cmd = + parseCommand( + "--Xincoming-tx-messages-keep-alive-seconds", + String.valueOf(txMessageKeepAliveSeconds)); - final TransactionPoolConfiguration config = getDomainObjectFromPantheonCommand(); + final TransactionPoolOptions options = getOptionsFromPantheonCommand(cmd); + final TransactionPoolConfiguration config = options.toDomainObject().build(); assertThat(config.getTxMessageKeepAliveSeconds()).isEqualTo(txMessageKeepAliveSeconds); assertThat(commandOutput.toString()).isEmpty(); @@ -36,31 +38,24 @@ public void txMessageKeepAliveSeconds() { } @Override - TransactionPoolConfiguration createDefaultDomainObject() { - return TransactionPoolConfiguration.builder().build(); + TransactionPoolConfiguration.Builder createDefaultDomainObject() { + return TransactionPoolConfiguration.builder(); } @Override - TransactionPoolConfiguration createCustomizedDomainObject() { + TransactionPoolConfiguration.Builder createCustomizedDomainObject() { return TransactionPoolConfiguration.builder() - .txMessageKeepAliveSeconds(TransactionPoolConfiguration.DEFAULT_TX_MSG_KEEP_ALIVE + 1) - .build(); + .txMessageKeepAliveSeconds(TransactionPoolConfiguration.DEFAULT_TX_MSG_KEEP_ALIVE + 1); } @Override - TransactionPoolOptions optionsFromDomainObject(final TransactionPoolConfiguration domainObject) { - return TransactionPoolOptions.fromConfig(domainObject); + TransactionPoolOptions optionsFromDomainObject( + final TransactionPoolConfiguration.Builder domainObject) { + return TransactionPoolOptions.fromConfig(domainObject.build()); } @Override - TransactionPoolConfiguration optionsToDomainObject(final TransactionPoolOptions options) { - return options.toDomainObject().build(); - } - - @Override - TransactionPoolConfiguration getDomainObjectFromPantheonCommand() { - verify(mockControllerBuilder) - .transactionPoolConfiguration(transactionPoolConfigCaptor.capture()); - return transactionPoolConfigCaptor.getValue(); + TransactionPoolOptions getOptionsFromPantheonCommand(final TestPantheonCommand pantheonCommand) { + return pantheonCommand.getTransactionPoolOptions(); } } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/rlp/RLPSubCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/rlp/RLPSubCommandTest.java index 93c1bae29c..c5a5244fd2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/rlp/RLPSubCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/rlp/RLPSubCommandTest.java @@ -65,7 +65,7 @@ public class RLPSubCommandTest extends CommandTestAbstract { // RLP sub-command @Test public void rlpSubCommandExistAnbHaveSubCommands() { - final CommandSpec spec = parseCommand(); + final CommandSpec spec = parseCommand().getSpec(); assertThat(spec.subcommands()).containsKeys(RLP_SUBCOMMAND_NAME); assertThat(spec.subcommands().get(RLP_SUBCOMMAND_NAME).getSubcommands()) .containsKeys(RLP_ENCODE_SUBCOMMAND_NAME); diff --git a/util/src/main/java/tech/pegasys/pantheon/util/number/PositiveNumber.java b/util/src/main/java/tech/pegasys/pantheon/util/number/PositiveNumber.java index 04a5a1aa45..66a0835695 100644 --- a/util/src/main/java/tech/pegasys/pantheon/util/number/PositiveNumber.java +++ b/util/src/main/java/tech/pegasys/pantheon/util/number/PositiveNumber.java @@ -15,6 +15,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static java.lang.Integer.parseInt; +import java.util.Objects; + public class PositiveNumber { private int value; @@ -46,4 +48,21 @@ public static PositiveNumber fromInt(final int val) { public int getValue() { return value; } + + @Override + public boolean equals(final Object o) { + if (o == this) { + return true; + } + if (!(o instanceof PositiveNumber)) { + return false; + } + final PositiveNumber that = (PositiveNumber) o; + return value == that.value; + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } From f415317d385411cb57ea964550e0a10450d992db Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 2 Jul 2019 11:38:28 -0400 Subject: [PATCH 15/15] Remove NetworkingOptions --- .../acceptance/dsl/node/PantheonNode.java | 8 -- .../dsl/node/ProcessPantheonNodeRunner.java | 5 - .../dsl/node/ThreadPantheonNodeRunner.java | 1 - .../PantheonFactoryConfiguration.java | 8 -- .../PantheonFactoryConfigurationBuilder.java | 9 -- .../configuration/PantheonNodeFactory.java | 1 - .../PrivacyPantheonFactoryConfiguration.java | 3 - ...cyPantheonFactoryConfigurationBuilder.java | 1 - .../privacy/PrivacyPantheonNodeFactory.java | 1 - .../acceptance/dsl/privacy/PrivacyNode.java | 3 - .../p2p/config/NetworkingConfiguration.java | 32 +----- .../p2p/network/DefaultP2PNetwork.java | 8 +- .../tech/pegasys/pantheon/RunnerBuilder.java | 14 +-- .../pegasys/pantheon/cli/PantheonCommand.java | 5 - .../cli/options/NetworkingOptions.java | 79 --------------- .../pantheon/cli/CommandTestAbstract.java | 6 -- .../cli/options/NetworkingOptionsTest.java | 97 ------------------- 17 files changed, 9 insertions(+), 272 deletions(-) delete mode 100644 pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java delete mode 100644 pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index 894bbfc0cc..21b17968e4 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -24,7 +24,6 @@ import tech.pegasys.pantheon.ethereum.core.Util; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; @@ -79,7 +78,6 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea private final KeyPair keyPair; private final Properties portsProperties = new Properties(); private final Boolean p2pEnabled; - private final NetworkingConfiguration networkingConfiguration; private final String name; private final MiningParameters miningParameters; @@ -114,7 +112,6 @@ public PantheonNode( final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, - final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -142,7 +139,6 @@ public PantheonNode( this.genesisConfigProvider = genesisConfigProvider; this.devMode = devMode; this.p2pEnabled = p2pEnabled; - this.networkingConfiguration = networkingConfiguration; this.discoveryEnabled = discoveryEnabled; plugins.forEach( pluginName -> { @@ -476,10 +472,6 @@ public boolean isP2pEnabled() { return p2pEnabled; } - public NetworkingConfiguration getNetworkingConfiguration() { - return networkingConfiguration; - } - @Override public boolean isBootnodeEligible() { return bootnodeEligible; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java index 10da4b6972..081bc8cfc4 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ProcessPantheonNodeRunner.java @@ -14,7 +14,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; -import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; @@ -144,10 +143,6 @@ public void startNode(final PantheonNode node) { if (!node.isP2pEnabled()) { params.add("--p2p-enabled"); params.add("false"); - } else { - final List networkConfigParams = - NetworkingOptions.fromConfig(node.getNetworkingConfiguration()).getCLIOptions(); - params.addAll(networkConfigParams); } node.getPermissioningConfiguration() 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 4ff4ea2f4c..267eee6f31 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 @@ -145,7 +145,6 @@ public void startNode(final PantheonNode node) { .p2pAdvertisedHost(node.getHostName()) .p2pListenPort(0) .maxPeers(25) - .networkingConfiguration(node.getNetworkingConfiguration()) .jsonRpcConfiguration(node.jsonRpcConfiguration()) .webSocketConfiguration(node.webSocketConfiguration()) .dataDir(node.homeDirectory()) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java index d3aea06527..1e486075fc 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfiguration.java @@ -16,7 +16,6 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider; @@ -37,7 +36,6 @@ public class PantheonFactoryConfiguration { private final boolean devMode; private final GenesisConfigurationProvider genesisConfigProvider; private final boolean p2pEnabled; - private final NetworkingConfiguration networkingConfiguration; private final boolean discoveryEnabled; private final boolean bootnodeEligible; private final List plugins; @@ -55,7 +53,6 @@ public PantheonFactoryConfiguration( final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, - final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -71,7 +68,6 @@ public PantheonFactoryConfiguration( this.devMode = devMode; this.genesisConfigProvider = genesisConfigProvider; this.p2pEnabled = p2pEnabled; - this.networkingConfiguration = networkingConfiguration; this.discoveryEnabled = discoveryEnabled; this.bootnodeEligible = bootnodeEligible; this.plugins = plugins; @@ -126,10 +122,6 @@ public boolean isP2pEnabled() { return p2pEnabled; } - public NetworkingConfiguration getNetworkingConfiguration() { - return networkingConfiguration; - } - public boolean isBootnodeEligible() { return bootnodeEligible; } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java index c0bec820f1..a673c26b30 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonFactoryConfigurationBuilder.java @@ -20,7 +20,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.genesis.GenesisConfigurationProvider; @@ -46,18 +45,11 @@ public class PantheonFactoryConfigurationBuilder { private boolean devMode = true; private GenesisConfigurationProvider genesisConfigProvider = ignore -> Optional.empty(); private Boolean p2pEnabled = true; - private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create(); private boolean discoveryEnabled = true; private boolean bootnodeEligible = true; private List plugins = new ArrayList<>(); private List extraCLIOptions = new ArrayList<>(); - public PantheonFactoryConfigurationBuilder() { - // Check connections more frequently during acceptance tests to cut down on - // intermittent failures due to the fact that we're running over a real network - networkingConfiguration.setInitiateConnectionsFrequency(5); - } - public PantheonFactoryConfigurationBuilder name(final String name) { this.name = name; return this; @@ -200,7 +192,6 @@ public PantheonFactoryConfiguration build() { devMode, genesisConfigProvider, p2pEnabled, - networkingConfiguration, discoveryEnabled, bootnodeEligible, plugins, diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java index 9606263d87..aded2d7499 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/PantheonNodeFactory.java @@ -44,7 +44,6 @@ public PantheonNode create(final PantheonFactoryConfiguration config) throws IOE config.isDevMode(), config.getGenesisConfigProvider(), config.isP2pEnabled(), - config.getNetworkingConfiguration(), config.isDiscoveryEnabled(), config.isBootnodeEligible(), config.getPlugins(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java index f9fd3aac1b..c379e963e9 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfiguration.java @@ -17,7 +17,6 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.configuration.PantheonFactoryConfiguration; @@ -42,7 +41,6 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, - final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -60,7 +58,6 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur devMode, genesisConfigProvider, p2pEnabled, - networkingConfiguration, discoveryEnabled, bootnodeEligible, plugins, diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java index 34aeef9639..927062c3e6 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonFactoryConfigurationBuilder.java @@ -44,7 +44,6 @@ public PrivacyPantheonFactoryConfiguration build() { config.isDevMode(), config.getGenesisConfigProvider(), config.isP2pEnabled(), - config.getNetworkingConfiguration(), config.isDiscoveryEnabled(), config.isBootnodeEligible(), config.getPlugins(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java index 9971d92f2f..b7f43f4479 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/configuration/privacy/PrivacyPantheonNodeFactory.java @@ -40,7 +40,6 @@ private static PrivacyNode create(final PrivacyPantheonFactoryConfiguration conf config.isDevMode(), config.getGenesisConfigProvider(), config.isP2pEnabled(), - config.getNetworkingConfiguration(), config.isDiscoveryEnabled(), config.isBootnodeEligible(), config.getPlugins(), diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java index 867fe2371c..10de64e65d 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivacyNode.java @@ -22,7 +22,6 @@ import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; @@ -56,7 +55,6 @@ public PrivacyNode( final boolean devMode, final GenesisConfigurationProvider genesisConfigProvider, final boolean p2pEnabled, - final NetworkingConfiguration networkingConfiguration, final boolean discoveryEnabled, final boolean bootnodeEligible, final List plugins, @@ -75,7 +73,6 @@ public PrivacyNode( devMode, genesisConfigProvider, p2pEnabled, - networkingConfiguration, discoveryEnabled, bootnodeEligible, plugins, diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java index 44d503d6c1..e2392a13f0 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/NetworkingConfiguration.java @@ -12,19 +12,13 @@ */ package tech.pegasys.pantheon.ethereum.p2p.config; -import static com.google.common.base.Preconditions.checkArgument; - import java.util.Objects; public class NetworkingConfiguration { - public static final int DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC = 30; - public static final int DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC = 60; - private DiscoveryConfiguration discovery = new DiscoveryConfiguration(); private RlpxConfiguration rlpx = new RlpxConfiguration(); - private int initiateConnectionsFrequencySec = DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC; - private int checkMaintainedConnectionsFrequencySec = - DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC; + + private NetworkingConfiguration() {} public static NetworkingConfiguration create() { return new NetworkingConfiguration(); @@ -48,28 +42,6 @@ public NetworkingConfiguration setRlpx(final RlpxConfiguration rlpx) { return this; } - public int getInitiateConnectionsFrequencySec() { - return initiateConnectionsFrequencySec; - } - - public NetworkingConfiguration setInitiateConnectionsFrequency( - final int initiateConnectionsFrequency) { - checkArgument(initiateConnectionsFrequency > 0); - this.initiateConnectionsFrequencySec = initiateConnectionsFrequency; - return this; - } - - public int getCheckMaintainedConnectionsFrequencySec() { - return checkMaintainedConnectionsFrequencySec; - } - - public NetworkingConfiguration setCheckMaintainedConnectionsFrequency( - final int checkMaintainedConnectionsFrequency) { - checkArgument(checkMaintainedConnectionsFrequency > 0); - this.checkMaintainedConnectionsFrequencySec = checkMaintainedConnectionsFrequency; - return this; - } - @Override public boolean equals(final Object o) { if (o == this) { diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java index b8b2713ca9..de69148d98 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java @@ -181,14 +181,10 @@ public void start() { peerBondedObserverId = OptionalLong.of(peerDiscoveryAgent.observePeerBondedEvents(this::handlePeerBondedEvent)); - // Periodically check maintained connections - final int checkMaintainedConnectionsSec = config.getCheckMaintainedConnectionsFrequencySec(); peerConnectionScheduler.scheduleWithFixedDelay( - this::checkMaintainedConnectionPeers, 2, checkMaintainedConnectionsSec, TimeUnit.SECONDS); - // Periodically initiate outgoing connections to discovered peers - final int checkConnectionsSec = config.getInitiateConnectionsFrequencySec(); + this::checkMaintainedConnectionPeers, 2, 60, TimeUnit.SECONDS); peerConnectionScheduler.scheduleWithFixedDelay( - this::attemptPeerConnections, checkConnectionsSec, checkConnectionsSec, TimeUnit.SECONDS); + this::attemptPeerConnections, 30, 30, TimeUnit.SECONDS); } @Override diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index d0bddac3c8..2ae37745a6 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -105,7 +105,6 @@ public class RunnerBuilder { private Vertx vertx; private PantheonController pantheonController; - private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create(); private Collection bannedNodeIds = new ArrayList<>(); private boolean p2pEnabled = true; private boolean discovery; @@ -148,12 +147,6 @@ public RunnerBuilder ethNetworkConfig(final EthNetworkConfig ethNetworkConfig) { return this; } - public RunnerBuilder networkingConfiguration( - final NetworkingConfiguration networkingConfiguration) { - this.networkingConfiguration = networkingConfiguration; - return this; - } - public RunnerBuilder p2pAdvertisedHost(final String p2pAdvertisedHost) { this.p2pAdvertisedHost = p2pAdvertisedHost; return this; @@ -257,7 +250,10 @@ public Runner build() { .setMaxPeers(maxPeers) .setSupportedProtocols(subProtocols) .setClientId(PantheonInfo.version()); - networkingConfiguration.setRlpx(rlpxConfiguration).setDiscovery(discoveryConfiguration); + final NetworkingConfiguration networkConfig = + NetworkingConfiguration.create() + .setRlpx(rlpxConfiguration) + .setDiscovery(discoveryConfiguration); final PeerPermissionsBlacklist bannedNodes = PeerPermissionsBlacklist.create(); bannedNodeIds.forEach(bannedNodes::add); @@ -287,7 +283,7 @@ public Runner build() { DefaultP2PNetwork.builder() .vertx(vertx) .keyPair(keyPair) - .config(networkingConfiguration) + .config(networkConfig) .peerPermissions(peerPermissions) .metricsSystem(metricsSystem) .supportedCapabilities(caps) 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 11a64514fa..fbce3e1563 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -39,7 +39,6 @@ import tech.pegasys.pantheon.cli.custom.RpcAuthFileValidator; import tech.pegasys.pantheon.cli.operator.OperatorSubCommand; import tech.pegasys.pantheon.cli.options.EthProtocolOptions; -import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.cli.options.RocksDBOptions; import tech.pegasys.pantheon.cli.options.SynchronizerOptions; import tech.pegasys.pantheon.cli.options.TransactionPoolOptions; @@ -143,7 +142,6 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private final BlockImporter blockImporter; - final NetworkingOptions networkingOptions = NetworkingOptions.create(); final SynchronizerOptions synchronizerOptions = SynchronizerOptions.create(); final EthProtocolOptions ethProtocolOptions = EthProtocolOptions.create(); final RocksDBOptions rocksDBOptions = RocksDBOptions.create(); @@ -702,8 +700,6 @@ private PantheonCommand handleUnstableOptions() { UnstableOptionsSubCommand.createUnstableOptions( commandLine, ImmutableMap.of( - "P2P Network", - networkingOptions, "Synchronizer", synchronizerOptions, "RocksDB", @@ -1171,7 +1167,6 @@ private void synchronize( .p2pAdvertisedHost(p2pAdvertisedHost) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) - .networkingConfiguration(networkingOptions.toDomainObject()) .graphQLConfiguration(graphQLConfiguration) .jsonRpcConfiguration(jsonRpcConfiguration) .webSocketConfiguration(webSocketConfiguration) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java deleted file mode 100644 index 888133aab6..0000000000 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/options/NetworkingOptions.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2019 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.pantheon.cli.options; - -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; - -import java.util.Arrays; -import java.util.List; - -import picocli.CommandLine; - -public class NetworkingOptions implements CLIOptions { - private final String INITIATE_CONNECTIONS_FREQUENCY_FLAG = - "--Xp2p-initiate-connections-frequency"; - private final String CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG = - "--Xp2p-check-maintained-connections-frequency"; - - @CommandLine.Option( - names = INITIATE_CONNECTIONS_FREQUENCY_FLAG, - hidden = true, - defaultValue = "30", - paramLabel = "", - description = - "The frequency (in seconds) at which to initiate new outgoing connections (default: ${DEFAULT-VALUE})") - private int initiateConnectionsFrequencySec = - NetworkingConfiguration.DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC; - - @CommandLine.Option( - names = CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, - hidden = true, - defaultValue = "60", - paramLabel = "", - description = - "The frequency (in seconds) at which to check maintained connections (default: ${DEFAULT-VALUE})") - private int checkMaintainedConnectionsFrequencySec = - NetworkingConfiguration.DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC; - - private NetworkingOptions() {} - - public static NetworkingOptions create() { - return new NetworkingOptions(); - } - - public static NetworkingOptions fromConfig(final NetworkingConfiguration networkingConfig) { - final NetworkingOptions cliOptions = new NetworkingOptions(); - cliOptions.checkMaintainedConnectionsFrequencySec = - networkingConfig.getCheckMaintainedConnectionsFrequencySec(); - cliOptions.initiateConnectionsFrequencySec = - networkingConfig.getInitiateConnectionsFrequencySec(); - return cliOptions; - } - - @Override - public NetworkingConfiguration toDomainObject() { - NetworkingConfiguration config = NetworkingConfiguration.create(); - config.setCheckMaintainedConnectionsFrequency(checkMaintainedConnectionsFrequencySec); - config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec); - return config; - } - - @Override - public List getCLIOptions() { - return Arrays.asList( - CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG, - OptionParser.format(checkMaintainedConnectionsFrequencySec), - INITIATE_CONNECTIONS_FREQUENCY_FLAG, - OptionParser.format(initiateConnectionsFrequencySec)); - } -} diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index 76d54e4775..9748f08be7 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -24,7 +24,6 @@ import tech.pegasys.pantheon.RunnerBuilder; import tech.pegasys.pantheon.cli.PublicKeySubCommand.KeyLoader; import tech.pegasys.pantheon.cli.options.EthProtocolOptions; -import tech.pegasys.pantheon.cli.options.NetworkingOptions; import tech.pegasys.pantheon.cli.options.RocksDBOptions; import tech.pegasys.pantheon.cli.options.SynchronizerOptions; import tech.pegasys.pantheon.cli.options.TransactionPoolOptions; @@ -153,7 +152,6 @@ public void initMocks() throws Exception { when(mockRunnerBuilder.pantheonController(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.discovery(anyBoolean())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.ethNetworkConfig(any())).thenReturn(mockRunnerBuilder); - when(mockRunnerBuilder.networkingConfiguration(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.p2pAdvertisedHost(anyString())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.p2pListenPort(anyInt())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.maxPeers(anyInt())).thenReturn(mockRunnerBuilder); @@ -258,10 +256,6 @@ public RocksDBOptions getRocksDBOptions() { return rocksDBOptions; } - public NetworkingOptions getNetworkingOptions() { - return networkingOptions; - } - public SynchronizerOptions getSynchronizerOptions() { return synchronizerOptions; } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java deleted file mode 100644 index 5a0208e437..0000000000 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/options/NetworkingOptionsTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2019 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.pantheon.cli.options; - -import static org.assertj.core.api.Assertions.assertThat; - -import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; - -import org.junit.Test; - -public class NetworkingOptionsTest - extends AbstractCLIOptionsTest { - - @Test - public void checkMaintainedConnectionsFrequencyFlag_isSet() { - final TestPantheonCommand cmd = - parseCommand("--Xp2p-check-maintained-connections-frequency", "2"); - - final NetworkingOptions options = cmd.getNetworkingOptions(); - final NetworkingConfiguration networkingConfig = options.toDomainObject(); - assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(2); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Test - public void checkMaintainedFrequencyConnectionsFlag_isNotSet() { - final TestPantheonCommand cmd = parseCommand(); - - final NetworkingOptions options = cmd.getNetworkingOptions(); - final NetworkingConfiguration networkingConfig = options.toDomainObject(); - assertThat(networkingConfig.getCheckMaintainedConnectionsFrequencySec()).isEqualTo(60); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Test - public void initiateConnectionsFrequencyFlag_isSet() { - final TestPantheonCommand cmd = parseCommand("--Xp2p-initiate-connections-frequency", "2"); - - final NetworkingOptions options = cmd.getNetworkingOptions(); - final NetworkingConfiguration networkingConfig = options.toDomainObject(); - assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(2); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Test - public void initiateConnectionsFrequencyFlag_isNotSet() { - final TestPantheonCommand cmd = parseCommand(); - - final NetworkingOptions options = cmd.getNetworkingOptions(); - final NetworkingConfiguration networkingConfig = options.toDomainObject(); - assertThat(networkingConfig.getInitiateConnectionsFrequencySec()).isEqualTo(30); - - assertThat(commandErrorOutput.toString()).isEmpty(); - assertThat(commandOutput.toString()).isEmpty(); - } - - @Override - NetworkingConfiguration createDefaultDomainObject() { - return NetworkingConfiguration.create(); - } - - @Override - NetworkingConfiguration createCustomizedDomainObject() { - final NetworkingConfiguration config = NetworkingConfiguration.create(); - config.setInitiateConnectionsFrequency( - NetworkingConfiguration.DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC + 10); - config.setCheckMaintainedConnectionsFrequency( - NetworkingConfiguration.DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC + 10); - return config; - } - - @Override - NetworkingOptions optionsFromDomainObject(final NetworkingConfiguration domainObject) { - return NetworkingOptions.fromConfig(domainObject); - } - - @Override - NetworkingOptions getOptionsFromPantheonCommand(final TestPantheonCommand pantheonCommand) { - return pantheonCommand.getNetworkingOptions(); - } -}