Replace the use of a disconnect listener with EthPeer.isDisconnected (#1197)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Adrian Sutton 6 years ago committed by GitHub
parent d2379329ee
commit f326bde7e8
  1. 3
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/ChainDownloader.java
  2. 20
      ethereum/eth/src/main/java/tech/pegasys/pantheon/ethereum/eth/sync/SyncTargetManager.java

@ -144,7 +144,7 @@ public class ChainDownloader<C> {
} }
private CompletableFuture<List<BlockHeader>> pullCheckpointHeaders(final SyncTarget syncTarget) { private CompletableFuture<List<BlockHeader>> pullCheckpointHeaders(final SyncTarget syncTarget) {
return syncTargetManager.isSyncTargetDisconnected() return syncTarget.peer().isDisconnected()
? CompletableFuture.completedFuture(emptyList()) ? CompletableFuture.completedFuture(emptyList())
: checkpointHeaderManager.pullCheckpointHeaders(syncTarget); : checkpointHeaderManager.pullCheckpointHeaders(syncTarget);
} }
@ -196,7 +196,6 @@ public class ChainDownloader<C> {
private void clearSyncTarget(final SyncTarget syncTarget) { private void clearSyncTarget(final SyncTarget syncTarget) {
chainSegmentTimeouts = 0; chainSegmentTimeouts = 0;
checkpointHeaderManager.clearSyncTarget(); checkpointHeaderManager.clearSyncTarget();
syncTargetManager.clearSyncTarget(syncTarget);
syncState.clearSyncTarget(); syncState.clearSyncTarget();
} }

@ -34,8 +34,6 @@ public abstract class SyncTargetManager<C> {
private static final Logger LOG = LogManager.getLogger(); private static final Logger LOG = LogManager.getLogger();
private volatile long syncTargetDisconnectListenerId;
private volatile boolean syncTargetDisconnected = false;
private final SynchronizerConfiguration config; private final SynchronizerConfiguration config;
private final ProtocolSchedule<C> protocolSchedule; private final ProtocolSchedule<C> protocolSchedule;
private final ProtocolContext<C> protocolContext; private final ProtocolContext<C> protocolContext;
@ -93,8 +91,6 @@ public abstract class SyncTargetManager<C> {
"Found common ancestor with peer {} at block {}", "Found common ancestor with peer {} at block {}",
bestPeer, bestPeer,
target.getNumber()); target.getNumber());
syncTargetDisconnectListenerId =
bestPeer.subscribeDisconnect(this::onSyncTargetPeerDisconnect);
return completedFuture(syncTarget); return completedFuture(syncTarget);
}) })
.thenCompose( .thenCompose(
@ -124,20 +120,6 @@ public abstract class SyncTargetManager<C> {
.timeout(WaitForPeerTask.create(ethContext, metricsSystem), Duration.ofSeconds(5)); .timeout(WaitForPeerTask.create(ethContext, metricsSystem), Duration.ofSeconds(5));
} }
private void onSyncTargetPeerDisconnect(final EthPeer ethPeer) {
LOG.info("Sync target disconnected: {}", ethPeer);
syncTargetDisconnected = true;
}
public boolean isSyncTargetDisconnected() {
return syncTargetDisconnected;
}
public void clearSyncTarget(final SyncTarget syncTarget) {
syncTarget.peer().unsubscribeDisconnect(syncTargetDisconnectListenerId);
syncTargetDisconnected = false;
}
public abstract boolean shouldSwitchSyncTarget(final SyncTarget currentTarget); public abstract boolean shouldSwitchSyncTarget(final SyncTarget currentTarget);
public abstract boolean shouldContinueDownloading(); public abstract boolean shouldContinueDownloading();
@ -146,6 +128,6 @@ public abstract class SyncTargetManager<C> {
public boolean syncTargetCanProvideMoreBlocks(final SyncTarget syncTarget) { public boolean syncTargetCanProvideMoreBlocks(final SyncTarget syncTarget) {
final EthPeer currentSyncingPeer = syncTarget.peer(); final EthPeer currentSyncingPeer = syncTarget.peer();
return !isSyncTargetDisconnected() && !isSyncTargetReached(currentSyncingPeer); return !currentSyncingPeer.isDisconnected() && !isSyncTargetReached(currentSyncingPeer);
} }
} }

Loading…
Cancel
Save