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

Commit

Permalink
[PAN-2797] Check connections more frequently during acceptance tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaxter authored Jul 3, 2019
1 parent ac6ad0b commit 67ac7d7
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> plugins,
Expand Down Expand Up @@ -139,6 +142,7 @@ public PantheonNode(
this.genesisConfigProvider = genesisConfigProvider;
this.devMode = devMode;
this.p2pEnabled = p2pEnabled;
this.networkingConfiguration = networkingConfiguration;
this.discoveryEnabled = discoveryEnabled;
plugins.forEach(
pluginName -> {
Expand Down Expand Up @@ -472,6 +476,10 @@ public boolean isP2pEnabled() {
return p2pEnabled;
}

public NetworkingConfiguration getNetworkingConfiguration() {
return networkingConfiguration;
}

@Override
public boolean isBootnodeEligible() {
return bootnodeEligible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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;
Expand Down Expand Up @@ -143,6 +144,10 @@ public void startNode(final PantheonNode node) {
if (!node.isP2pEnabled()) {
params.add("--p2p-enabled");
params.add("false");
} else {
final List<String> networkConfigParams =
NetworkingOptions.fromConfig(node.getNetworkingConfiguration()).getCLIOptions();
params.addAll(networkConfigParams);
}

node.getPermissioningConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> plugins;
Expand All @@ -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<String> plugins,
Expand All @@ -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;
Expand Down Expand Up @@ -122,6 +126,10 @@ public boolean isP2pEnabled() {
return p2pEnabled;
}

public NetworkingConfiguration getNetworkingConfiguration() {
return networkingConfiguration;
}

public boolean isBootnodeEligible() {
return bootnodeEligible;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> plugins = new ArrayList<>();
private List<String> 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;
Expand Down Expand Up @@ -192,6 +200,7 @@ public PantheonFactoryConfiguration build() {
devMode,
genesisConfigProvider,
p2pEnabled,
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
plugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> plugins,
Expand All @@ -58,6 +60,7 @@ public class PrivacyPantheonFactoryConfiguration extends PantheonFactoryConfigur
devMode,
genesisConfigProvider,
p2pEnabled,
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
plugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public PrivacyPantheonFactoryConfiguration build() {
config.isDevMode(),
config.getGenesisConfigProvider(),
config.isP2pEnabled(),
config.getNetworkingConfiguration(),
config.isDiscoveryEnabled(),
config.isBootnodeEligible(),
config.getPlugins(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> plugins,
Expand All @@ -73,6 +75,7 @@ public PrivacyNode(
devMode,
genesisConfigProvider,
p2pEnabled,
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
plugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
*/
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 NetworkingConfiguration() {}
private int initiateConnectionsFrequencySec = DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC;
private int checkMaintainedConnectionsFrequencySec =
DEFAULT_CHECK_MAINTAINED_CONNECTSION_FREQUENCY_SEC;

public static NetworkingConfiguration create() {
return new NetworkingConfiguration();
Expand All @@ -42,6 +48,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public class RunnerBuilder {
private Vertx vertx;
private PantheonController<?> pantheonController;

private NetworkingConfiguration networkingConfiguration = NetworkingConfiguration.create();
private Collection<BytesValue> bannedNodeIds = new ArrayList<>();
private boolean p2pEnabled = true;
private boolean discovery;
Expand Down Expand Up @@ -147,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;
Expand Down Expand Up @@ -250,10 +257,7 @@ public Runner build() {
.setMaxPeers(maxPeers)
.setSupportedProtocols(subProtocols)
.setClientId(PantheonInfo.version());
final NetworkingConfiguration networkConfig =
NetworkingConfiguration.create()
.setRlpx(rlpxConfiguration)
.setDiscovery(discoveryConfiguration);
networkingConfiguration.setRlpx(rlpxConfiguration).setDiscovery(discoveryConfiguration);

final PeerPermissionsBlacklist bannedNodes = PeerPermissionsBlacklist.create();
bannedNodeIds.forEach(bannedNodes::add);
Expand Down Expand Up @@ -283,7 +287,7 @@ public Runner build() {
DefaultP2PNetwork.builder()
.vertx(vertx)
.keyPair(keyPair)
.config(networkConfig)
.config(networkingConfiguration)
.peerPermissions(peerPermissions)
.metricsSystem(metricsSystem)
.supportedCapabilities(caps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tech.pegasys.pantheon.cli.custom.RpcAuthFileValidator;
import tech.pegasys.pantheon.cli.error.PantheonExceptionHandler;
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;
Expand Down Expand Up @@ -150,6 +151,7 @@ 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();
Expand Down Expand Up @@ -676,6 +678,8 @@ private PantheonCommand handleUnstableOptions() {
UnstableOptionsSubCommand.createUnstableOptions(
commandLine,
ImmutableMap.of(
"P2P Network",
networkingOptions,
"Synchronizer",
synchronizerOptions,
"RocksDB",
Expand Down Expand Up @@ -1143,6 +1147,7 @@ private void synchronize(
.p2pAdvertisedHost(p2pAdvertisedHost)
.p2pListenPort(p2pListenPort)
.maxPeers(maxPeers)
.networkingConfiguration(networkingOptions.toDomainObject())
.graphQLConfiguration(graphQLConfiguration)
.jsonRpcConfiguration(jsonRpcConfiguration)
.webSocketConfiguration(webSocketConfiguration)
Expand Down
Loading

0 comments on commit 67ac7d7

Please sign in to comment.