Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Refresh peer table while we have fewer than maxPeers connected (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaxter authored Mar 20, 2019
1 parent f6c03a2 commit cdcccc9
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface Synchronizer {
*/
Optional<SyncStatus> getSyncStatus();

boolean hasSufficientPeers();

long observeSyncStatus(final SyncStatusListener listener);

boolean removeObserver(long observerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class DefaultSynchronizer<C> 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<C> blockPropagationManager;
Expand All @@ -58,8 +56,6 @@ public DefaultSynchronizer(
final SyncState syncState,
final Path dataDirectory,
final MetricsSystem metricsSystem) {
this.syncConfig = syncConfig;
this.ethContext = ethContext;
this.syncState = syncState;

this.blockPropagationManager =
Expand Down Expand Up @@ -151,13 +147,6 @@ public Optional<SyncStatus> getSyncStatus() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public TestNode(
this.kp,
networkingConfiguration,
capabilities,
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand All @@ -28,7 +29,6 @@
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;
Expand Down Expand Up @@ -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<Capability> supportedCapabilities,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final MetricsSystem metricsSystem,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
Expand All @@ -186,7 +185,6 @@ public NettyP2PNetwork(
keyPair,
config,
supportedCapabilities,
peerRequirement,
peerBlacklist,
metricsSystem,
nodeWhitelistController,
Expand All @@ -206,7 +204,6 @@ public NettyP2PNetwork(
* @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.
Expand All @@ -217,13 +214,13 @@ public NettyP2PNetwork(
final SECP256K1.KeyPair keyPair,
final NetworkingConfiguration config,
final List<Capability> supportedCapabilities,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final MetricsSystem metricsSystem,
final Optional<NodeLocalConfigPermissioningController> nodeLocalConfigPermissioningController,
final Optional<NodePermissioningController> nodePermissioningController,
final Blockchain blockchain) {

maxPeers = config.getRlpx().getMaxPeers();
connections = new PeerConnectionRegistry(metricsSystem);
this.peerBlacklist = peerBlacklist;
this.peerMaintainConnectionList = new HashSet<>();
Expand All @@ -232,7 +229,7 @@ public NettyP2PNetwork(
vertx,
keyPair,
config.getDiscovery(),
peerRequirement,
() -> connections.size() >= maxPeers,
peerBlacklist,
nodeLocalConfigPermissioningController,
nodePermissioningController);
Expand Down Expand Up @@ -262,7 +259,6 @@ public NettyP2PNetwork(
subscribeDisconnect(peerBlacklist);
subscribeDisconnect(connections);

maxPeers = config.getRlpx().getMaxPeers();
this.keyPair = keyPair;
this.subProtocols = config.getSupportedProtocols();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public void handshaking() throws Exception {
.setSupportedProtocols(subProtocol())
.setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap),
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -132,7 +131,6 @@ public void handshaking() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery),
singletonList(cap),
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -174,7 +172,6 @@ public void preventMultipleConnections() throws Exception {
.setDiscovery(noDiscovery)
.setRlpx(RlpxConfiguration.create().setBindPort(0)),
capabilities,
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -188,7 +185,6 @@ public void preventMultipleConnections() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery),
capabilities,
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -245,7 +241,6 @@ public void limitMaxPeers() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0).setMaxPeers(maxPeers))
.setSupportedProtocols(subProtocol),
cap,
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -259,7 +254,6 @@ public void limitMaxPeers() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setSupportedProtocols(subProtocol),
cap,
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -273,7 +267,6 @@ public void limitMaxPeers() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setSupportedProtocols(subProtocol),
cap,
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -329,7 +322,6 @@ public void rejectPeerWithNoSharedCaps() throws Exception {
.setSupportedProtocols(subprotocol1)
.setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap1),
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -343,7 +335,6 @@ public void rejectPeerWithNoSharedCaps() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery),
singletonList(cap2),
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -386,7 +377,6 @@ public void rejectIncomingConnectionFromBlacklistedPeer() throws Exception {
.setSupportedProtocols(subprotocol)
.setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap),
() -> false,
localBlacklist,
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -400,7 +390,6 @@ public void rejectIncomingConnectionFromBlacklistedPeer() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery),
singletonList(cap),
() -> false,
remoteBlacklist,
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -481,7 +470,6 @@ public void rejectIncomingConnectionFromNonWhitelistedPeer() throws Exception {
.setSupportedProtocols(subprotocol)
.setRlpx(RlpxConfiguration.create().setBindPort(0)),
singletonList(cap),
() -> false,
localBlacklist,
new NoOpMetricsSystem(),
Optional.of(localWhitelistController),
Expand All @@ -496,7 +484,6 @@ public void rejectIncomingConnectionFromNonWhitelistedPeer() throws Exception {
.setRlpx(RlpxConfiguration.create().setBindPort(0))
.setDiscovery(noDiscovery),
singletonList(cap),
() -> false,
remoteBlacklist,
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -867,7 +854,6 @@ private NettyP2PNetwork mockNettyP2PNetwork() {
keyPair,
networkingConfiguration,
singletonList(cap),
() -> false,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void createPeerDiscoveryAgent() {
keyPair,
config,
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -86,7 +85,6 @@ public void createPeerDiscoveryAgent_NullHost() throws IOException {
keyPair,
config,
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -107,7 +105,6 @@ public void createPeerDiscoveryAgent_InvalidHost() throws IOException {
keyPair,
config,
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -128,7 +125,6 @@ public void createPeerDiscoveryAgent_InvalidPort() throws IOException {
keyPair,
config,
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -145,7 +141,6 @@ public void createPeerDiscoveryAgent_NullKeyPair() throws IOException {
null,
configWithRandomPorts(),
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -163,7 +158,6 @@ public void startStopPeerDiscoveryAgent() {
keyPair,
configWithRandomPorts(),
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -183,7 +177,6 @@ public void startDiscoveryAgentBackToBack() {
keyPair,
configWithRandomPorts(),
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -194,7 +187,6 @@ public void startDiscoveryAgentBackToBack() {
keyPair,
configWithRandomPorts(),
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -215,7 +207,6 @@ public void startDiscoveryPortInUse() {
keyPair,
configWithRandomPorts(),
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand All @@ -231,7 +222,6 @@ public void startDiscoveryPortInUse() {
keyPair,
config,
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down Expand Up @@ -262,7 +252,6 @@ public void createPeerDiscoveryAgent_NoActivePeers() {
keyPair,
configWithRandomPorts(),
emptyList(),
() -> true,
new PeerBlacklist(),
new NoOpMetricsSystem(),
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ public Runner build() {
keyPair,
networkConfig,
caps,
synchronizer::hasSufficientPeers,
peerBlacklist,
metricsSystem,
nodeWhitelistController,
Expand Down

0 comments on commit cdcccc9

Please sign in to comment.