diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java index 0ca0c4be4b..20e3b720e2 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java @@ -155,6 +155,15 @@ public class EnodeURL { } } + public URI toURIWithoutDiscoveryPort() { + final String uri = + String.format( + "enode://%s@%s:%d", + nodeId.toUnprefixedString(), InetAddresses.toUriString(ip), getListeningPortOrZero()); + + return URI.create(uri); + } + /** * Returns the discovery port only if it differs from the listening port * diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java index 170d57af01..271e756c6b 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java @@ -22,14 +22,16 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.PantheonMetricCategory; +import java.net.URI; import java.util.Collection; -import java.util.HashSet; import java.util.OptionalLong; +import java.util.Set; +import java.util.stream.Collectors; public class SyncStatusNodePermissioningProvider implements NodePermissioningProvider { private final Synchronizer synchronizer; - private final Collection fixedNodes = new HashSet<>(); + private final Set fixedNodes; private final Counter checkCounter; private final Counter checkCounterPermitted; private final Counter checkCounterUnpermitted; @@ -44,7 +46,8 @@ public class SyncStatusNodePermissioningProvider implements NodePermissioningPro this.synchronizer = synchronizer; long id = this.synchronizer.observeSyncStatus(this::handleSyncStatusUpdate); this.syncStatusObserverId = OptionalLong.of(id); - this.fixedNodes.addAll(fixedNodes); + this.fixedNodes = + fixedNodes.stream().map(EnodeURL::toURIWithoutDiscoveryPort).collect(Collectors.toSet()); metricsSystem.createIntegerGauge( PantheonMetricCategory.PERMISSIONING, @@ -103,7 +106,7 @@ public class SyncStatusNodePermissioningProvider implements NodePermissioningPro return true; } else { checkCounter.inc(); - if (fixedNodes.stream().anyMatch(p -> EnodeURL.sameListeningEndpoint(p, destinationEnode))) { + if (fixedNodes.contains(destinationEnode.toURIWithoutDiscoveryPort())) { checkCounterPermitted.inc(); return true; } else {