Skip to content

Commit

Permalink
cleanup from PR 4178 (hyperledger#4266)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
3 people authored and eum602 committed Nov 3, 2023
1 parent 68e05da commit 8f4e10c
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
private final BlockBroadcaster blockBroadcaster;
private final List<PeerValidator> peerValidators;
private final Optional<MergePeerFilter> mergePeerFilter;
private final int maxMessageSize;

public EthProtocolManager(
final Blockchain blockchain,
Expand Down Expand Up @@ -102,8 +101,6 @@ public EthProtocolManager(
this.ethMessages = ethMessages;
this.ethContext = ethContext;

this.maxMessageSize = ethereumWireProtocolConfiguration.getMaxMessageSize();

this.blockBroadcaster = new BlockBroadcaster(ethContext);

supportedCapabilities = calculateCapabilities(fastSyncEnabled);
Expand Down Expand Up @@ -284,14 +281,6 @@ public void processMessage(final Capability cap, final Message message) {
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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ public CompletableFuture<Integer> start(final int tcpPort) {
}
}

public Optional<PeerDiscoveryController> getPeerDiscoveryController() {
return controller;
}

public void updateNodeRecord() {
if (!config.isActive()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void onMessage(final Packet packet, final DiscoveryPeer sender) {
.ifPresent(
interaction -> {
bondingPeers.invalidate(peer.getId());
addBondedPeerToPeerTable(peer);
addToPeerTable(peer);
recursivePeerRefreshState.onBondingComplete(peer);
Optional.ofNullable(cachedEnrRequests.getIfPresent(peer.getId()))
.ifPresent(cachedEnrRequest -> processEnrRequest(peer, cachedEnrRequest));
Expand Down Expand Up @@ -386,7 +386,7 @@ private List<DiscoveryPeer> getPeersFromNeighborsPacket(final Packet packet) {
.collect(Collectors.toList());
}

private boolean addBondedPeerToPeerTable(final DiscoveryPeer peer) {
private boolean addToPeerTable(final DiscoveryPeer peer) {
if (!peerPermissions.isAllowedInPeerTable(peer)) {
return false;
}
Expand All @@ -403,16 +403,8 @@ private boolean addBondedPeerToPeerTable(final DiscoveryPeer peer) {
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);
Expand Down Expand Up @@ -469,7 +461,7 @@ RecursivePeerRefreshState getRecursivePeerRefreshState() {
*/
private void refreshTable() {
final Bytes target = Peer.randomId();
final List<DiscoveryPeer> initialPeers = peerTable.nearestPeers(Peer.randomId(), 16);
final List<DiscoveryPeer> initialPeers = peerTable.nearestBondedPeers(Peer.randomId(), 16);
recursivePeerRefreshState.start(initialPeers, target);
lastRefreshTime = System.currentTimeMillis();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,6 @@ public List<DiscoveryPeer> nearestBondedPeers(final Bytes target, final int limi
.collect(toList());
}

/**
* Returns the <code>limit</code> 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 <code>limit</code> closest peers, at most.
*/
public List<DiscoveryPeer> 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<DiscoveryPeer> streamAllPeers() {
return Arrays.stream(table).flatMap(e -> e.getPeers().stream());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -215,7 +214,7 @@ public void start() {
.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()
Expand All @@ -229,7 +228,7 @@ public void start() {
disco,
createDaemonListener(),
0L,
1800000L,
600000L,
config.getDnsDiscoveryServerOverride().orElse(null));
dnsDaemon.start();
});
Expand Down Expand Up @@ -350,14 +349,7 @@ DNSDaemonListener createDaemonListener() {
peers.add(peer);
}
if (!peers.isEmpty()) {
final Optional<PeerDiscoveryController> 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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void subscribeUpdate(final PermissionsUpdateCallback callback) {

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean isPermitted(final Peer localNode, final Peer remotePeer, final Ac
}

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;
}
Expand All @@ -101,7 +101,7 @@ private boolean allowOutboundBonding(final Peer localNode, final Peer remotePeer
}

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;
}
Expand Down

0 comments on commit 8f4e10c

Please sign in to comment.