Add experimental config option to enable v5 discovery (#4103)

* Add experimental config option to enable v5 discovery

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>

Co-authored-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/4161/head
Gabriel-Trintinalia 2 years ago committed by GitHub
parent 0d1d36afc0
commit 28273793d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
  2. 10
      besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java
  3. 24
      besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java
  4. 9
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java
  5. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java

@ -419,6 +419,8 @@ public class RunnerBuilder {
}
discoveryConfiguration.setBootnodes(bootstrap);
discoveryConfiguration.setDnsDiscoveryURL(ethNetworkConfig.getDnsDiscoveryUrl());
discoveryConfiguration.setDiscoveryV5Enabled(
networkingConfiguration.getDiscovery().isDiscoveryV5Enabled());
} else {
discoveryConfiguration.setActive(false);
}

@ -30,6 +30,7 @@ public class NetworkingOptions implements CLIOptions<NetworkingConfiguration> {
private final String CHECK_MAINTAINED_CONNECTIONS_FREQUENCY_FLAG =
"--Xp2p-check-maintained-connections-frequency";
private final String DNS_DISCOVERY_SERVER_OVERRIDE_FLAG = "--Xp2p-dns-discovery-server";
private final String DISCOVERY_PROTOCOL_V5_ENABLED = "--Xv5-discovery-enabled";
@CommandLine.Option(
names = INITIATE_CONNECTIONS_FREQUENCY_FLAG,
@ -58,6 +59,13 @@ public class NetworkingOptions implements CLIOptions<NetworkingConfiguration> {
"DNS server host to use for doing DNS Discovery of peers, rather than the machine's configured DNS server")
private Optional<String> dnsDiscoveryServerOverride = Optional.empty();
@CommandLine.Option(
names = DISCOVERY_PROTOCOL_V5_ENABLED,
hidden = true,
defaultValue = "false",
description = "Whether to enable P2P Discovery Protocol v5 (default: ${DEFAULT-VALUE})")
private final Boolean isPeerDiscoveryV5Enabled = false;
private NetworkingOptions() {}
public static NetworkingOptions create() {
@ -81,7 +89,7 @@ public class NetworkingOptions implements CLIOptions<NetworkingConfiguration> {
config.setCheckMaintainedConnectionsFrequency(checkMaintainedConnectionsFrequencySec);
config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec);
config.setDnsDiscoveryServerOverride(dnsDiscoveryServerOverride);
config.getDiscovery().setDiscoveryV5Enabled(isPeerDiscoveryV5Enabled);
return config;
}

@ -101,6 +101,30 @@ public class NetworkingOptionsTest
assertThat(commandOutput.toString(UTF_8)).isEmpty();
}
@Test
public void checkDiscoveryV5Enabled_isSet() {
final TestBesuCommand cmd = parseCommand("--Xv5-discovery-enabled");
final NetworkingOptions options = cmd.getNetworkingOptions();
final NetworkingConfiguration networkingConfig = options.toDomainObject();
assertThat(networkingConfig.getDiscovery().isDiscoveryV5Enabled()).isTrue();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
}
@Test
public void checkDiscoveryV5Enabled_isNotSet() {
final TestBesuCommand cmd = parseCommand();
final NetworkingOptions options = cmd.getNetworkingOptions();
final NetworkingConfiguration networkingConfig = options.toDomainObject();
assertThat(networkingConfig.getDiscovery().isDiscoveryV5Enabled()).isFalse();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
assertThat(commandOutput.toString(UTF_8)).isEmpty();
}
@Override
NetworkingConfiguration createDefaultDomainObject() {
return NetworkingConfiguration.create();

@ -31,6 +31,7 @@ public class DiscoveryConfiguration {
private int bucketSize = 16;
private List<EnodeURL> bootnodes = new ArrayList<>();
private String dnsDiscoveryURL;
private boolean discoveryV5Enabled = false;
public static DiscoveryConfiguration create() {
return new DiscoveryConfiguration();
@ -113,6 +114,14 @@ public class DiscoveryConfiguration {
return this;
}
public boolean isDiscoveryV5Enabled() {
return discoveryV5Enabled;
}
public void setDiscoveryV5Enabled(final boolean discoveryV5Enabled) {
this.discoveryV5Enabled = discoveryV5Enabled;
}
@Override
public boolean equals(final Object o) {
if (o == this) {

@ -204,6 +204,10 @@ public class DefaultP2PNetwork implements P2PNetwork {
return;
}
if (config.getDiscovery().isDiscoveryV5Enabled()) {
LOG.warn("Discovery Protocol v5 is not available");
}
final String address = config.getDiscovery().getAdvertisedHost();
final int configuredDiscoveryPort = config.getDiscovery().getBindPort();
final int configuredRlpxPort = config.getRlpx().getBindPort();

Loading…
Cancel
Save