cleanup from PR 4178 (#4266)

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>
pull/4347/head
Stefan Pingel 2 years ago committed by GitHub
parent 8ee253982c
commit a5bf37c1ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java
  2. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgent.java
  3. 14
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java
  4. 17
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerTable.java
  5. 14
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java
  6. 2
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/permissions/PeerPermissions.java
  7. 4
      ethereum/permissioning/src/main/java/org/hyperledger/besu/ethereum/permissioning/node/PeerPermissionsAdapter.java

@ -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,
@ -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());

@ -179,10 +179,6 @@ public abstract class PeerDiscoveryAgent {
}
}
public Optional<PeerDiscoveryController> getPeerDiscoveryController() {
return controller;
}
public void updateNodeRecord() {
if (!config.isActive()) {
return;

@ -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<DiscoveryPeer> initialPeers = peerTable.nearestPeers(Peer.randomId(), 16);
final List<DiscoveryPeer> initialPeers = peerTable.nearestBondedPeers(Peer.randomId(), 16);
recursivePeerRefreshState.start(initialPeers, target);
lastRefreshTime = System.currentTimeMillis();
}

@ -200,23 +200,6 @@ public class PeerTable {
.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());
}

@ -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> 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);
}
};
}

@ -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;
}

@ -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;
}

Loading…
Cancel
Save