From 832886d19cb2ef8bcbd45d7bb900cb6504195807 Mon Sep 17 00:00:00 2001 From: Nischal Sharma Date: Mon, 17 Apr 2023 06:43:21 +0530 Subject: [PATCH] Improved error message when verifying enode syntax with xdns-enabled (#5346) * updated error message Signed-off-by: Nischal Sharma --------- Signed-off-by: Nischal Sharma Co-authored-by: Sally MacFarlane --- ...rmissioningConfigurationValidatorTest.java | 5 ++--- .../besu/ethereum/p2p/peers/EnodeURLImpl.java | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java b/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java index d4e916d390..a5d84149fe 100644 --- a/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java +++ b/besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java @@ -212,7 +212,7 @@ public class LocalPermissioningConfigurationValidatorTest { Files.write(toml, Resources.toByteArray(configFile)); final ImmutableEnodeDnsConfiguration enodeDnsConfiguration = - ImmutableEnodeDnsConfiguration.builder().dnsEnabled(false).updateEnabled(false).build(); + ImmutableEnodeDnsConfiguration.builder().dnsEnabled(true).updateEnabled(false).build(); assertThatThrownBy( () -> @@ -224,7 +224,6 @@ public class LocalPermissioningConfigurationValidatorTest { toml.toAbsolutePath().toString())) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( - "Invalid enode URL syntax 'enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@hostname:4567'. " - + "Enode URL should have the following format 'enode://@:[?discport=]'. Invalid ip address."); + "Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false."); } } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java index 93a849481f..b94012b5d6 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java @@ -80,13 +80,20 @@ public class EnodeURLImpl implements EnodeURL { checkStringArgumentNotEmpty(value, "Invalid empty value."); return fromURI(URI.create(value), enodeDnsConfiguration); } catch (final IllegalArgumentException e) { - String message = - String.format( - "Invalid enode URL syntax '%s'. Enode URL should have the following format 'enode://@:[?discport=]'.", - value); - if (e.getMessage() != null) { - message += " " + e.getMessage(); + String message = ""; + if (enodeDnsConfiguration.dnsEnabled() && !enodeDnsConfiguration.updateEnabled()) { + message = + "Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false."; + } else { + message = + String.format( + "Invalid enode URL syntax '%s'. Enode URL should have the following format 'enode://@:[?discport=]'.", + value); + if (e.getMessage() != null) { + message += " " + e.getMessage(); + } } + throw new IllegalArgumentException(message, e); } }