diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmer.java index 8ceafb63730..9b3b40f8a8c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmer.java @@ -39,7 +39,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -175,7 +174,6 @@ private CompletableFuture executePivotQuery(final long blockNumber) // Stop loop if this task is done return CompletableFuture.failedFuture(new CancellationException()); } - final Optional query = createPivotQuery(blockNumber); final CompletableFuture pivotHeaderFuture; if (query.isPresent()) { @@ -187,12 +185,18 @@ private CompletableFuture executePivotQuery(final long blockNumber) LOG.debug("No peer currently available to query for block {}.", blockNumber); pivotHeaderFuture = ethContext - .getEthPeers() - .waitForPeer((peer) -> !pivotBlockQueriesByPeerId.containsKey(peer.nodeId())) - .orTimeout(5, TimeUnit.SECONDS) - // Ignore result, ensure even a timeout will result in calling executePivotQuery - .handle((r, e) -> null) - .thenCompose(res -> executePivotQuery(blockNumber)); + .getScheduler() + .scheduleFutureTask( + () -> + ethContext + .getEthPeers() + .waitForPeer( + (peer) -> !pivotBlockQueriesByPeerId.containsKey(peer.nodeId())) + // Ignore result, ensure even a timeout will result in calling + // executePivotQuery + .handle((r, e) -> null) + .thenCompose(res -> executePivotQuery(blockNumber)), + Duration.ofSeconds(5)); } return pivotHeaderFuture; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java index a1f07d36bbc..9cd23a54bdf 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java @@ -164,6 +164,7 @@ public void shouldIgnorePeersThatDoNotHaveThePivotBlock(final DataStorageFormat // Add new peer that we can query final RespondingEthPeer respondingPeerB = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000); + EthProtocolManagerTestUtil.runPendingFutures(ethProtocolManager); respondingPeerB.respond(responder); // We need one more responsive peer before we're done @@ -174,6 +175,7 @@ public void shouldIgnorePeersThatDoNotHaveThePivotBlock(final DataStorageFormat // Add new peer that we can query final RespondingEthPeer respondingPeerC = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000); + EthProtocolManagerTestUtil.runPendingFutures(ethProtocolManager); respondingPeerC.respond(responder); assertThat(badPeerA.hasOutstandingRequests()).isFalse(); assertThat(badPeerB.hasOutstandingRequests()).isFalse();