Refresh peer table while we have fewer than maxPeers connected (#1142)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
mbaxter 6 years ago committed by GitHub
parent 1cd9e10b86
commit 1617b5b801
  1. 2
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/core/Synchronizer.java
  2. 11
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/DefaultSynchronizer.java
  3. 1
      ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/transactions/TestNode.java
  4. 12
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/netty/NettyP2PNetwork.java
  5. 14
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NettyP2PNetworkTest.java
  6. 11
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/NetworkingServiceLifecycleTest.java
  7. 1
      pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java

@ -25,8 +25,6 @@ public interface Synchronizer {
*/ */
Optional<SyncStatus> getSyncStatus(); Optional<SyncStatus> getSyncStatus();
boolean hasSufficientPeers();
long observeSyncStatus(final SyncStatusListener listener); long observeSyncStatus(final SyncStatusListener listener);
boolean removeObserver(long observerId); boolean removeObserver(long observerId);

@ -40,8 +40,6 @@ public class DefaultSynchronizer<C> implements Synchronizer {
private static final Logger LOG = LogManager.getLogger(); private static final Logger LOG = LogManager.getLogger();
private final SynchronizerConfiguration syncConfig;
private final EthContext ethContext;
private final SyncState syncState; private final SyncState syncState;
private final AtomicBoolean started = new AtomicBoolean(false); private final AtomicBoolean started = new AtomicBoolean(false);
private final BlockPropagationManager<C> blockPropagationManager; private final BlockPropagationManager<C> blockPropagationManager;
@ -58,8 +56,6 @@ public class DefaultSynchronizer<C> implements Synchronizer {
final SyncState syncState, final SyncState syncState,
final Path dataDirectory, final Path dataDirectory,
final MetricsSystem metricsSystem) { final MetricsSystem metricsSystem) {
this.syncConfig = syncConfig;
this.ethContext = ethContext;
this.syncState = syncState; this.syncState = syncState;
this.blockPropagationManager = this.blockPropagationManager =
@ -151,13 +147,6 @@ public class DefaultSynchronizer<C> implements Synchronizer {
return Optional.of(syncState.syncStatus()); return Optional.of(syncState.syncStatus());
} }
@Override
public boolean hasSufficientPeers() {
final int requiredPeerCount =
fastSynchronizer.isPresent() ? syncConfig.getFastSyncMinimumPeerCount() : 1;
return ethContext.getEthPeers().availablePeerCount() >= requiredPeerCount;
}
@Override @Override
public long observeSyncStatus(final SyncStatusListener listener) { public long observeSyncStatus(final SyncStatusListener listener) {
checkNotNull(listener); checkNotNull(listener);

@ -120,7 +120,6 @@ public class TestNode implements Closeable {
this.kp, this.kp,
networkingConfiguration, networkingConfiguration,
capabilities, capabilities,
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),

@ -15,6 +15,7 @@ package tech.pegasys.pantheon.ethereum.p2p.netty;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import tech.pegasys.pantheon.crypto.SECP256K1; 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.BlockAddedEvent;
import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.p2p.PeerNotPermittedException; 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.PeerBondedEvent;
import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryEvent.PeerDroppedEvent; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryEvent.PeerDroppedEvent;
import tech.pegasys.pantheon.ethereum.p2p.discovery.VertxPeerDiscoveryAgent; 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.Endpoint;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
@ -173,10 +173,9 @@ public class NettyP2PNetwork implements P2PNetwork {
public NettyP2PNetwork( public NettyP2PNetwork(
final Vertx vertx, final Vertx vertx,
final SECP256K1.KeyPair keyPair, final KeyPair keyPair,
final NetworkingConfiguration config, final NetworkingConfiguration config,
final List<Capability> supportedCapabilities, final List<Capability> supportedCapabilities,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist, final PeerBlacklist peerBlacklist,
final MetricsSystem metricsSystem, final MetricsSystem metricsSystem,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController, final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
@ -186,7 +185,6 @@ public class NettyP2PNetwork implements P2PNetwork {
keyPair, keyPair,
config, config,
supportedCapabilities, supportedCapabilities,
peerRequirement,
peerBlacklist, peerBlacklist,
metricsSystem, metricsSystem,
nodeWhitelistController, nodeWhitelistController,
@ -206,7 +204,6 @@ public class NettyP2PNetwork implements P2PNetwork {
* @param config The network configuration to use. * @param config The network configuration to use.
* @param supportedCapabilities The wire protocol capabilities to advertise to connected peers. * @param supportedCapabilities The wire protocol capabilities to advertise to connected peers.
* @param peerBlacklist The peers with which this node will not connect * @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 metricsSystem The metrics system to capture metrics with.
* @param nodeLocalConfigPermissioningController local file config for permissioning * @param nodeLocalConfigPermissioningController local file config for permissioning
* @param nodePermissioningController Controls node permissioning. * @param nodePermissioningController Controls node permissioning.
@ -217,13 +214,13 @@ public class NettyP2PNetwork implements P2PNetwork {
final SECP256K1.KeyPair keyPair, final SECP256K1.KeyPair keyPair,
final NetworkingConfiguration config, final NetworkingConfiguration config,
final List<Capability> supportedCapabilities, final List<Capability> supportedCapabilities,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist, final PeerBlacklist peerBlacklist,
final MetricsSystem metricsSystem, final MetricsSystem metricsSystem,
final Optional<NodeLocalConfigPermissioningController> nodeLocalConfigPermissioningController, final Optional<NodeLocalConfigPermissioningController> nodeLocalConfigPermissioningController,
final Optional<NodePermissioningController> nodePermissioningController, final Optional<NodePermissioningController> nodePermissioningController,
final Blockchain blockchain) { final Blockchain blockchain) {
maxPeers = config.getRlpx().getMaxPeers();
connections = new PeerConnectionRegistry(metricsSystem); connections = new PeerConnectionRegistry(metricsSystem);
this.peerBlacklist = peerBlacklist; this.peerBlacklist = peerBlacklist;
this.peerMaintainConnectionList = new HashSet<>(); this.peerMaintainConnectionList = new HashSet<>();
@ -232,7 +229,7 @@ public class NettyP2PNetwork implements P2PNetwork {
vertx, vertx,
keyPair, keyPair,
config.getDiscovery(), config.getDiscovery(),
peerRequirement, () -> connections.size() >= maxPeers,
peerBlacklist, peerBlacklist,
nodeLocalConfigPermissioningController, nodeLocalConfigPermissioningController,
nodePermissioningController); nodePermissioningController);
@ -262,7 +259,6 @@ public class NettyP2PNetwork implements P2PNetwork {
subscribeDisconnect(peerBlacklist); subscribeDisconnect(peerBlacklist);
subscribeDisconnect(connections); subscribeDisconnect(connections);
maxPeers = config.getRlpx().getMaxPeers();
this.keyPair = keyPair; this.keyPair = keyPair;
this.subProtocols = config.getSupportedProtocols(); this.subProtocols = config.getSupportedProtocols();

@ -118,7 +118,6 @@ public final class NettyP2PNetworkTest {
.setSupportedProtocols(subProtocol()) .setSupportedProtocols(subProtocol())
.setRlpx(RlpxConfiguration.create().setBindPort(0)), .setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap), singletonList(cap),
() -> false,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -132,7 +131,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery), .setDiscovery(noDiscovery),
singletonList(cap), singletonList(cap),
() -> false,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -174,7 +172,6 @@ public final class NettyP2PNetworkTest {
.setDiscovery(noDiscovery) .setDiscovery(noDiscovery)
.setRlpx(RlpxConfiguration.create().setBindPort(0)), .setRlpx(RlpxConfiguration.create().setBindPort(0)),
capabilities, capabilities,
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -188,7 +185,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery), .setDiscovery(noDiscovery),
capabilities, capabilities,
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -245,7 +241,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0).setMaxPeers(maxPeers)) .setRlpx(RlpxConfiguration.create().setBindPort(0).setMaxPeers(maxPeers))
.setSupportedProtocols(subProtocol), .setSupportedProtocols(subProtocol),
cap, cap,
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -259,7 +254,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setSupportedProtocols(subProtocol), .setSupportedProtocols(subProtocol),
cap, cap,
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -273,7 +267,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setSupportedProtocols(subProtocol), .setSupportedProtocols(subProtocol),
cap, cap,
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -329,7 +322,6 @@ public final class NettyP2PNetworkTest {
.setSupportedProtocols(subprotocol1) .setSupportedProtocols(subprotocol1)
.setRlpx(RlpxConfiguration.create().setBindPort(0)), .setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap1), singletonList(cap1),
() -> false,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -343,7 +335,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery), .setDiscovery(noDiscovery),
singletonList(cap2), singletonList(cap2),
() -> false,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -386,7 +377,6 @@ public final class NettyP2PNetworkTest {
.setSupportedProtocols(subprotocol) .setSupportedProtocols(subprotocol)
.setRlpx(RlpxConfiguration.create().setBindPort(0)), .setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap), singletonList(cap),
() -> false,
localBlacklist, localBlacklist,
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -400,7 +390,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery), .setDiscovery(noDiscovery),
singletonList(cap), singletonList(cap),
() -> false,
remoteBlacklist, remoteBlacklist,
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -481,7 +470,6 @@ public final class NettyP2PNetworkTest {
.setSupportedProtocols(subprotocol) .setSupportedProtocols(subprotocol)
.setRlpx(RlpxConfiguration.create().setBindPort(0)), .setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap), singletonList(cap),
() -> false,
localBlacklist, localBlacklist,
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.of(localWhitelistController), Optional.of(localWhitelistController),
@ -496,7 +484,6 @@ public final class NettyP2PNetworkTest {
.setRlpx(RlpxConfiguration.create().setBindPort(0)) .setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery), .setDiscovery(noDiscovery),
singletonList(cap), singletonList(cap),
() -> false,
remoteBlacklist, remoteBlacklist,
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -867,7 +854,6 @@ public final class NettyP2PNetworkTest {
keyPair, keyPair,
networkingConfiguration, networkingConfiguration,
singletonList(cap), singletonList(cap),
() -> false,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),

@ -55,7 +55,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
config, config,
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -86,7 +85,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
config, config,
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -107,7 +105,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
config, config,
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -128,7 +125,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
config, config,
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -145,7 +141,6 @@ public class NetworkingServiceLifecycleTest {
null, null,
configWithRandomPorts(), configWithRandomPorts(),
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -163,7 +158,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
configWithRandomPorts(), configWithRandomPorts(),
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -183,7 +177,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
configWithRandomPorts(), configWithRandomPorts(),
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -194,7 +187,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
configWithRandomPorts(), configWithRandomPorts(),
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -215,7 +207,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
configWithRandomPorts(), configWithRandomPorts(),
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -231,7 +222,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
config, config,
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),
@ -262,7 +252,6 @@ public class NetworkingServiceLifecycleTest {
keyPair, keyPair,
configWithRandomPorts(), configWithRandomPorts(),
emptyList(), emptyList(),
() -> true,
new PeerBlacklist(), new PeerBlacklist(),
new NoOpMetricsSystem(), new NoOpMetricsSystem(),
Optional.empty(), Optional.empty(),

@ -270,7 +270,6 @@ public class RunnerBuilder {
keyPair, keyPair,
networkConfig, networkConfig,
caps, caps,
synchronizer::hasSufficientPeers,
peerBlacklist, peerBlacklist,
metricsSystem, metricsSystem,
nodeWhitelistController, nodeWhitelistController,

Loading…
Cancel
Save