From a5bf37c1ec3581fa26b88fa456077f3ad6b1cf65 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:58:01 +1000 Subject: [PATCH] cleanup from PR 4178 (#4266) Signed-off-by: Stefan Co-authored-by: Sally MacFarlane Co-authored-by: Sally MacFarlane --- .../eth/manager/EthProtocolManager.java | 11 ----------- .../p2p/discovery/PeerDiscoveryAgent.java | 4 ---- .../internal/PeerDiscoveryController.java | 14 +++----------- .../p2p/discovery/internal/PeerTable.java | 17 ----------------- .../ethereum/p2p/network/DefaultP2PNetwork.java | 14 +++----------- .../p2p/permissions/PeerPermissions.java | 2 +- .../node/PeerPermissionsAdapter.java | 4 ++-- 7 files changed, 9 insertions(+), 57 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 1dc80b1023..cdacc183b5 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -72,7 +72,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { private final BlockBroadcaster blockBroadcaster; private final List peerValidators; private final Optional mergePeerFilter; - private final int maxMessageSize; public EthProtocolManager( final Blockchain blockchain, @@ -102,8 +101,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { this.ethMessages = ethMessages; this.ethContext = ethContext; - this.maxMessageSize = ethereumWireProtocolConfiguration.getMaxMessageSize(); - this.blockBroadcaster = new BlockBroadcaster(ethContext); supportedCapabilities = calculateCapabilities(fastSyncEnabled); @@ -284,14 +281,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { return; } - if (messageData.getSize() > this.maxMessageSize) { - LOG.debug( - "Peer {} sent a message with size {}, larger than the max message size {}", - ethPeer, - messageData.getSize(), - this.maxMessageSize); - } - // This will handle responses ethPeers.dispatchMessage(ethPeer, ethMessage, getSupportedProtocol()); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java index df1f6df077..96937a5130 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java @@ -179,10 +179,6 @@ public abstract class PeerDiscoveryAgent { } } - public Optional getPeerDiscoveryController() { - return controller; - } - public void updateNodeRecord() { if (!config.isActive()) { return; diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java index 556d3ee951..0df580859f 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java @@ -320,7 +320,7 @@ public class PeerDiscoveryController { .ifPresent( interaction -> { bondingPeers.invalidate(peer.getId()); - addBondedPeerToPeerTable(peer); + addToPeerTable(peer); recursivePeerRefreshState.onBondingComplete(peer); Optional.ofNullable(cachedEnrRequests.getIfPresent(peer.getId())) .ifPresent(cachedEnrRequest -> processEnrRequest(peer, cachedEnrRequest)); @@ -386,7 +386,7 @@ public class PeerDiscoveryController { .collect(Collectors.toList()); } - private boolean addBondedPeerToPeerTable(final DiscoveryPeer peer) { + private boolean addToPeerTable(final DiscoveryPeer peer) { if (!peerPermissions.isAllowedInPeerTable(peer)) { return false; } @@ -403,16 +403,8 @@ public class PeerDiscoveryController { notifyPeerBonded(peer, now); } - return addToPeerTable(peer); - } - - public boolean addToPeerTable(final DiscoveryPeer peer) { final PeerTable.AddResult result = peerTable.tryAdd(peer); - if (result.getOutcome() == PeerTable.AddResult.AddOutcome.SELF) { - return false; - } - if (result.getOutcome() == PeerTable.AddResult.AddOutcome.ALREADY_EXISTED) { // Bump peer. peerTable.tryEvict(peer); @@ -469,7 +461,7 @@ public class PeerDiscoveryController { */ private void refreshTable() { final Bytes target = Peer.randomId(); - final List initialPeers = peerTable.nearestPeers(Peer.randomId(), 16); + final List initialPeers = peerTable.nearestBondedPeers(Peer.randomId(), 16); recursivePeerRefreshState.start(initialPeers, target); lastRefreshTime = System.currentTimeMillis(); } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerTable.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerTable.java index dee6e0cf99..e153acbfc2 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerTable.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerTable.java @@ -200,23 +200,6 @@ public class PeerTable { .collect(toList()); } - /** - * Returns the limit peers (at most) closest to the provided target, based on the XOR - * distance between the keccak-256 hash of the ID and the keccak-256 hash of the target. - * - * @param target The target node ID. - * @param limit The amount of results to return. - * @return The limit closest peers, at most. - */ - public List nearestPeers(final Bytes target, final int limit) { - final Bytes keccak256 = Hash.keccak256(target); - return streamAllPeers() - .sorted( - comparingInt((peer) -> PeerDistanceCalculator.distance(peer.keccak256(), keccak256))) - .limit(limit) - .collect(toList()); - } - public Stream streamAllPeers() { return Arrays.stream(table).flatMap(e -> e.getPeers().stream()); } 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 35b29c89b4..44d783fa39 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 @@ -25,7 +25,6 @@ import org.hyperledger.besu.ethereum.p2p.discovery.PeerDiscoveryAgent; import org.hyperledger.besu.ethereum.p2p.discovery.PeerDiscoveryEvent.PeerBondedEvent; import org.hyperledger.besu.ethereum.p2p.discovery.PeerDiscoveryStatus; import org.hyperledger.besu.ethereum.p2p.discovery.VertxPeerDiscoveryAgent; -import org.hyperledger.besu.ethereum.p2p.discovery.internal.PeerDiscoveryController; import org.hyperledger.besu.ethereum.p2p.peers.DefaultPeerPrivileges; import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl; import org.hyperledger.besu.ethereum.p2p.peers.LocalNode; @@ -215,7 +214,7 @@ public class DefaultP2PNetwork implements P2PNetwork { .ifPresent( disco -> { // These lists are updated every 12h - // We retrieve the list every 30 minutes (1800000 msec) + // We retrieve the list every 10 minutes (600000 msec) LOG.info("Starting DNS discovery with URL {}", disco); config .getDnsDiscoveryServerOverride() @@ -229,7 +228,7 @@ public class DefaultP2PNetwork implements P2PNetwork { disco, createDaemonListener(), 0L, - 1800000L, + 600000L, config.getDnsDiscoveryServerOverride().orElse(null)); dnsDaemon.start(); }); @@ -350,14 +349,7 @@ public class DefaultP2PNetwork implements P2PNetwork { peers.add(peer); } if (!peers.isEmpty()) { - final Optional peerDiscoveryController = - peerDiscoveryAgent.getPeerDiscoveryController(); - if (peerDiscoveryController.isPresent()) { - final PeerDiscoveryController controller = peerDiscoveryController.get(); - LOG.debug("Adding {} DNS peers to PeerTable", peers.size()); - peers.forEach(controller::addToPeerTable); - peers.forEach(rlpxAgent::connect); - } + peers.stream().forEach(peerDiscoveryAgent::bond); } }; } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/permissions/PeerPermissions.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/permissions/PeerPermissions.java index 9b8a14ac71..7a98390b7f 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/permissions/PeerPermissions.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/permissions/PeerPermissions.java @@ -125,7 +125,7 @@ public abstract class PeerPermissions implements AutoCloseable { @Override public boolean isPermitted(final Peer localNode, final Peer remotePeer, final Action action) { - for (PeerPermissions permission : permissions) { + for (final PeerPermissions permission : permissions) { if (!permission.isPermitted(localNode, remotePeer, action)) { return false; } diff --git a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/node/PeerPermissionsAdapter.java b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/node/PeerPermissionsAdapter.java index 6c87827cb6..f5fbb89e80 100644 --- a/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/node/PeerPermissionsAdapter.java +++ b/ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/node/PeerPermissionsAdapter.java @@ -87,7 +87,7 @@ public class PeerPermissionsAdapter extends PeerPermissions { } private boolean allowOutboundBonding(final Peer localNode, final Peer remotePeer) { - boolean outboundMessagingAllowed = outboundIsPermitted(localNode, remotePeer); + final boolean outboundMessagingAllowed = outboundIsPermitted(localNode, remotePeer); if (!nodePermissioningController.getSyncStatusNodePermissioningProvider().isPresent()) { return outboundMessagingAllowed; } @@ -101,7 +101,7 @@ public class PeerPermissionsAdapter extends PeerPermissions { } private boolean allowOutboundNeighborsRequests(final Peer localNode, final Peer remotePeer) { - boolean outboundMessagingAllowed = outboundIsPermitted(localNode, remotePeer); + final boolean outboundMessagingAllowed = outboundIsPermitted(localNode, remotePeer); if (!nodePermissioningController.getSyncStatusNodePermissioningProvider().isPresent()) { return outboundMessagingAllowed; }