From 1617b5b801bb67e7a1c9632e3c6e172c1920c317 Mon Sep 17 00:00:00 2001 From: mbaxter Date: Wed, 20 Mar 2019 18:21:16 -0400 Subject: [PATCH] Refresh peer table while we have fewer than maxPeers connected (#1142) Signed-off-by: Adrian Sutton --- .../pantheon/ethereum/core/Synchronizer.java | 2 -- .../ethereum/eth/sync/DefaultSynchronizer.java | 11 ----------- .../ethereum/eth/transactions/TestNode.java | 1 - .../ethereum/p2p/netty/NettyP2PNetwork.java | 12 ++++-------- .../pantheon/ethereum/p2p/NettyP2PNetworkTest.java | 14 -------------- .../p2p/NetworkingServiceLifecycleTest.java | 11 ----------- .../java/tech/pegasys/pantheon/RunnerBuilder.java | 1 - 7 files changed, 4 insertions(+), 48 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java index 7362ee15a9..a0516e0578 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java @@ -25,8 +25,6 @@ public interface Synchronizer { */ Optional getSyncStatus(); - boolean hasSufficientPeers(); - long observeSyncStatus(final SyncStatusListener listener); boolean removeObserver(long observerId); diff --git a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java index 5b8711f407..0fd7e61883 100644 --- a/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java @@ -40,8 +40,6 @@ public class DefaultSynchronizer implements Synchronizer { private static final Logger LOG = LogManager.getLogger(); - private final SynchronizerConfiguration syncConfig; - private final EthContext ethContext; private final SyncState syncState; private final AtomicBoolean started = new AtomicBoolean(false); private final BlockPropagationManager blockPropagationManager; @@ -58,8 +56,6 @@ public class DefaultSynchronizer implements Synchronizer { final SyncState syncState, final Path dataDirectory, final MetricsSystem metricsSystem) { - this.syncConfig = syncConfig; - this.ethContext = ethContext; this.syncState = syncState; this.blockPropagationManager = @@ -151,13 +147,6 @@ public class DefaultSynchronizer implements Synchronizer { return Optional.of(syncState.syncStatus()); } - @Override - public boolean hasSufficientPeers() { - final int requiredPeerCount = - fastSynchronizer.isPresent() ? syncConfig.getFastSyncMinimumPeerCount() : 1; - return ethContext.getEthPeers().availablePeerCount() >= requiredPeerCount; - } - @Override public long observeSyncStatus(final SyncStatusListener listener) { checkNotNull(listener); diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java index c86b3a3bda..308df45d1a 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java @@ -120,7 +120,6 @@ public class TestNode implements Closeable { this.kp, networkingConfiguration, capabilities, - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java index 04337385c5..d944fd68f9 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java @@ -15,6 +15,7 @@ package tech.pegasys.pantheon.ethereum.p2p.netty; import static com.google.common.base.Preconditions.checkState; import tech.pegasys.pantheon.crypto.SECP256K1; +import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.chain.BlockAddedEvent; import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.p2p.PeerNotPermittedException; @@ -28,7 +29,6 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryAgent; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryEvent.PeerBondedEvent; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryEvent.PeerDroppedEvent; import tech.pegasys.pantheon.ethereum.p2p.discovery.VertxPeerDiscoveryAgent; -import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerRequirement; import tech.pegasys.pantheon.ethereum.p2p.peers.Endpoint; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist; @@ -173,10 +173,9 @@ public class NettyP2PNetwork implements P2PNetwork { public NettyP2PNetwork( final Vertx vertx, - final SECP256K1.KeyPair keyPair, + final KeyPair keyPair, final NetworkingConfiguration config, final List supportedCapabilities, - final PeerRequirement peerRequirement, final PeerBlacklist peerBlacklist, final MetricsSystem metricsSystem, final Optional nodeWhitelistController, @@ -186,7 +185,6 @@ public class NettyP2PNetwork implements P2PNetwork { keyPair, config, supportedCapabilities, - peerRequirement, peerBlacklist, metricsSystem, nodeWhitelistController, @@ -206,7 +204,6 @@ public class NettyP2PNetwork implements P2PNetwork { * @param config The network configuration to use. * @param supportedCapabilities The wire protocol capabilities to advertise to connected peers. * @param peerBlacklist The peers with which this node will not connect - * @param peerRequirement Queried to determine if enough peers are currently connected. * @param metricsSystem The metrics system to capture metrics with. * @param nodeLocalConfigPermissioningController local file config for permissioning * @param nodePermissioningController Controls node permissioning. @@ -217,13 +214,13 @@ public class NettyP2PNetwork implements P2PNetwork { final SECP256K1.KeyPair keyPair, final NetworkingConfiguration config, final List supportedCapabilities, - final PeerRequirement peerRequirement, final PeerBlacklist peerBlacklist, final MetricsSystem metricsSystem, final Optional nodeLocalConfigPermissioningController, final Optional nodePermissioningController, final Blockchain blockchain) { + maxPeers = config.getRlpx().getMaxPeers(); connections = new PeerConnectionRegistry(metricsSystem); this.peerBlacklist = peerBlacklist; this.peerMaintainConnectionList = new HashSet<>(); @@ -232,7 +229,7 @@ public class NettyP2PNetwork implements P2PNetwork { vertx, keyPair, config.getDiscovery(), - peerRequirement, + () -> connections.size() >= maxPeers, peerBlacklist, nodeLocalConfigPermissioningController, nodePermissioningController); @@ -262,7 +259,6 @@ public class NettyP2PNetwork implements P2PNetwork { subscribeDisconnect(peerBlacklist); subscribeDisconnect(connections); - maxPeers = config.getRlpx().getMaxPeers(); this.keyPair = keyPair; this.subProtocols = config.getSupportedProtocols(); diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java index 322152b22a..6bf9362f55 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java @@ -118,7 +118,6 @@ public final class NettyP2PNetworkTest { .setSupportedProtocols(subProtocol()) .setRlpx(RlpxConfiguration.create().setBindPort(0)), singletonList(cap), - () -> false, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -132,7 +131,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setDiscovery(noDiscovery), singletonList(cap), - () -> false, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -174,7 +172,6 @@ public final class NettyP2PNetworkTest { .setDiscovery(noDiscovery) .setRlpx(RlpxConfiguration.create().setBindPort(0)), capabilities, - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -188,7 +185,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setDiscovery(noDiscovery), capabilities, - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -245,7 +241,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0).setMaxPeers(maxPeers)) .setSupportedProtocols(subProtocol), cap, - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -259,7 +254,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setSupportedProtocols(subProtocol), cap, - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -273,7 +267,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setSupportedProtocols(subProtocol), cap, - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -329,7 +322,6 @@ public final class NettyP2PNetworkTest { .setSupportedProtocols(subprotocol1) .setRlpx(RlpxConfiguration.create().setBindPort(0)), singletonList(cap1), - () -> false, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -343,7 +335,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setDiscovery(noDiscovery), singletonList(cap2), - () -> false, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -386,7 +377,6 @@ public final class NettyP2PNetworkTest { .setSupportedProtocols(subprotocol) .setRlpx(RlpxConfiguration.create().setBindPort(0)), singletonList(cap), - () -> false, localBlacklist, new NoOpMetricsSystem(), Optional.empty(), @@ -400,7 +390,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setDiscovery(noDiscovery), singletonList(cap), - () -> false, remoteBlacklist, new NoOpMetricsSystem(), Optional.empty(), @@ -481,7 +470,6 @@ public final class NettyP2PNetworkTest { .setSupportedProtocols(subprotocol) .setRlpx(RlpxConfiguration.create().setBindPort(0)), singletonList(cap), - () -> false, localBlacklist, new NoOpMetricsSystem(), Optional.of(localWhitelistController), @@ -496,7 +484,6 @@ public final class NettyP2PNetworkTest { .setRlpx(RlpxConfiguration.create().setBindPort(0)) .setDiscovery(noDiscovery), singletonList(cap), - () -> false, remoteBlacklist, new NoOpMetricsSystem(), Optional.empty(), @@ -867,7 +854,6 @@ public final class NettyP2PNetworkTest { keyPair, networkingConfiguration, singletonList(cap), - () -> false, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NetworkingServiceLifecycleTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NetworkingServiceLifecycleTest.java index 9635009d77..7898a8f4d9 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NetworkingServiceLifecycleTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NetworkingServiceLifecycleTest.java @@ -55,7 +55,6 @@ public class NetworkingServiceLifecycleTest { keyPair, config, emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -86,7 +85,6 @@ public class NetworkingServiceLifecycleTest { keyPair, config, emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -107,7 +105,6 @@ public class NetworkingServiceLifecycleTest { keyPair, config, emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -128,7 +125,6 @@ public class NetworkingServiceLifecycleTest { keyPair, config, emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -145,7 +141,6 @@ public class NetworkingServiceLifecycleTest { null, configWithRandomPorts(), emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -163,7 +158,6 @@ public class NetworkingServiceLifecycleTest { keyPair, configWithRandomPorts(), emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -183,7 +177,6 @@ public class NetworkingServiceLifecycleTest { keyPair, configWithRandomPorts(), emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -194,7 +187,6 @@ public class NetworkingServiceLifecycleTest { keyPair, configWithRandomPorts(), emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -215,7 +207,6 @@ public class NetworkingServiceLifecycleTest { keyPair, configWithRandomPorts(), emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -231,7 +222,6 @@ public class NetworkingServiceLifecycleTest { keyPair, config, emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), @@ -262,7 +252,6 @@ public class NetworkingServiceLifecycleTest { keyPair, configWithRandomPorts(), emptyList(), - () -> true, new PeerBlacklist(), new NoOpMetricsSystem(), Optional.empty(), diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index d73ff18ea3..21694b10b9 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -270,7 +270,6 @@ public class RunnerBuilder { keyPair, networkConfig, caps, - synchronizer::hasSufficientPeers, peerBlacklist, metricsSystem, nodeWhitelistController,