From 28273793d7e798078e4e0526da1cc4dfdb05ea4d Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Fri, 15 Jul 2022 14:24:14 +1000 Subject: [PATCH] Add experimental config option to enable v5 discovery (#4103) * Add experimental config option to enable v5 discovery Signed-off-by: Gabriel Trintinalia Co-authored-by: Gabriel Trintinalia Co-authored-by: Sally MacFarlane --- .../org/hyperledger/besu/RunnerBuilder.java | 2 ++ .../options/unstable/NetworkingOptions.java | 10 +++++++- .../cli/options/NetworkingOptionsTest.java | 24 +++++++++++++++++++ .../p2p/config/DiscoveryConfiguration.java | 9 +++++++ .../p2p/network/DefaultP2PNetwork.java | 4 ++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index cae72b0022..a21408a80d 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -419,6 +419,8 @@ public class RunnerBuilder { } discoveryConfiguration.setBootnodes(bootstrap); discoveryConfiguration.setDnsDiscoveryURL(ethNetworkConfig.getDnsDiscoveryUrl()); + discoveryConfiguration.setDiscoveryV5Enabled( + networkingConfiguration.getDiscovery().isDiscoveryV5Enabled()); } else { discoveryConfiguration.setActive(false); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java index 2b634cf36a..bb0045d612 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java @@ -30,6 +30,7 @@ public class NetworkingOptions implements CLIOptions { 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 { "DNS server host to use for doing DNS Discovery of peers, rather than the machine's configured DNS server") private Optional 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 { config.setCheckMaintainedConnectionsFrequency(checkMaintainedConnectionsFrequencySec); config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec); config.setDnsDiscoveryServerOverride(dnsDiscoveryServerOverride); - + config.getDiscovery().setDiscoveryV5Enabled(isPeerDiscoveryV5Enabled); return config; } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java index 4bb39f7b52..330bbc524a 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java @@ -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(); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java index 9fa2563750..3b4bdb8f36 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/DiscoveryConfiguration.java @@ -31,6 +31,7 @@ public class DiscoveryConfiguration { private int bucketSize = 16; private List 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) { diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java index e51e3b44e8..afbf787283 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java @@ -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();