PAN-2860 - Ignore discport during static node permissioning check (#1631)

- Update SyncStatusNodePermissioningProvider to use URI (without discovery port) instead of EnodeURI to allow optimised permission checking of static nodes
- Add EnodeURL.toURIWithoutDiscoveryPort 
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Usman Saleem 5 years ago committed by GitHub
parent 0e961994cb
commit 70f561421b
  1. 9
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java
  2. 11
      ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.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
*

@ -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<EnodeURL> fixedNodes = new HashSet<>();
private final Set<URI> 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 {

Loading…
Cancel
Save