Skip to content

Commit

Permalink
Remove NetworkingOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaxter committed Jul 2, 2019
1 parent 51c33a3 commit f415317
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> plugins,
Expand Down Expand Up @@ -142,7 +139,6 @@ public PantheonNode(
this.genesisConfigProvider = genesisConfigProvider;
this.devMode = devMode;
this.p2pEnabled = p2pEnabled;
this.networkingConfiguration = networkingConfiguration;
this.discoveryEnabled = discoveryEnabled;
plugins.forEach(
pluginName -> {
Expand Down Expand Up @@ -476,10 +472,6 @@ 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,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;
Expand Down Expand Up @@ -144,10 +143,6 @@ 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,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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> plugins;
Expand All @@ -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<String> plugins,
Expand All @@ -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;
Expand Down Expand Up @@ -126,10 +122,6 @@ 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,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;
Expand All @@ -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<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 @@ -200,7 +192,6 @@ 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,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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> plugins,
Expand All @@ -60,7 +58,6 @@ 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,7 +44,6 @@ 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,7 +40,6 @@ 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,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;
Expand Down Expand Up @@ -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<String> plugins,
Expand All @@ -75,7 +73,6 @@ public PrivacyNode(
devMode,
genesisConfigProvider,
p2pEnabled,
networkingConfiguration,
discoveryEnabled,
bootnodeEligible,
plugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ 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 @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -287,7 +283,7 @@ public Runner build() {
DefaultP2PNetwork.builder()
.vertx(vertx)
.keyPair(keyPair)
.config(networkingConfiguration)
.config(networkConfig)
.peerPermissions(peerPermissions)
.metricsSystem(metricsSystem)
.supportedCapabilities(caps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -702,8 +700,6 @@ private PantheonCommand handleUnstableOptions() {
UnstableOptionsSubCommand.createUnstableOptions(
commandLine,
ImmutableMap.of(
"P2P Network",
networkingOptions,
"Synchronizer",
synchronizerOptions,
"RocksDB",
Expand Down Expand Up @@ -1171,7 +1167,6 @@ 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 f415317

Please sign in to comment.