Skip to content

Commit

Permalink
Add experimental config option to enable v5 discovery (hyperledger#4103)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored and eum602 committed Nov 3, 2023
1 parent 8526f4b commit 30b55f8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ public Runner build() {
}
discoveryConfiguration.setBootnodes(bootstrap);
discoveryConfiguration.setDnsDiscoveryURL(ethNetworkConfig.getDnsDiscoveryUrl());
discoveryConfiguration.setDiscoveryV5Enabled(
networkingConfiguration.getDiscovery().isDiscoveryV5Enabled());
} else {
discoveryConfiguration.setActive(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand All @@ -81,7 +89,7 @@ public NetworkingConfiguration toDomainObject() {
config.setCheckMaintainedConnectionsFrequency(checkMaintainedConnectionsFrequencySec);
config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec);
config.setDnsDiscoveryServerOverride(dnsDiscoveryServerOverride);

config.getDiscovery().setDiscoveryV5Enabled(isPeerDiscoveryV5Enabled);
return config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ public void checkDnsServerOverrideFlag_isNotSet() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -113,6 +114,14 @@ public DiscoveryConfiguration setDnsDiscoveryURL(final String dnsDiscoveryURL) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public void start() {
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();
Expand Down

0 comments on commit 30b55f8

Please sign in to comment.