Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental config option to enable v5 discovery #4103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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