use of org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException in project besu by hyperledger.
the class AbstractRetryingPeerTask method executeTask.
@Override
protected void executeTask() {
if (result.isDone()) {
// Return if task is done
return;
}
if (retryCount > maxRetries) {
result.completeExceptionally(new MaxRetriesReachedException());
return;
}
retryCount += 1;
executePeerTask(assignedPeer).whenComplete((peerResult, error) -> {
if (error != null) {
handleTaskError(error);
} else {
// If we get a partial success, reset the retry counter.
if (!isEmptyResponse.test(peerResult)) {
retryCount = 0;
}
executeTaskTimed();
}
});
}
use of org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException in project besu by hyperledger.
the class BackwardSyncStepTest method shouldNotRequestHeaderBeforeLastFinalizedBlock.
@Test
public void shouldNotRequestHeaderBeforeLastFinalizedBlock() throws Exception {
final MutableBlockchain localBlockchain = context.getProtocolContext().getBlockchain();
extendBlockchain(REMOTE_HEIGHT + 2, localBlockchain);
localBlockchain.setFinalized(localBlockchain.getBlockHashByNumber(REMOTE_HEIGHT + 1).orElseThrow());
BackwardSyncStep step = new BackwardSyncStep(context, createBackwardChain(REMOTE_HEIGHT - 1));
final Block lookingForBlock = getBlockByNumber(REMOTE_HEIGHT - 2);
final RespondingEthPeer.Responder responder = RespondingEthPeer.blockchainResponder(remoteBlockchain);
final CompletableFuture<List<BlockHeader>> future = step.requestHeaders(lookingForBlock.getHeader().getHash());
ScheduledExecutorService schedExecutor = Executors.newScheduledThreadPool(2);
schedExecutor.submit(() -> peer.respondWhileOtherThreadsWork(responder, () -> !future.isDone()));
schedExecutor.scheduleWithFixedDelay(ethScheduler::expirePendingTimeouts, 0, 100, TimeUnit.MILLISECONDS);
future.handle((r, t) -> {
if (t == null || !(t.getCause() instanceof MaxRetriesReachedException)) {
failBecauseExceptionWasNotThrown(MaxRetriesReachedException.class);
}
return r;
}).thenRun(schedExecutor::shutdownNow).join();
}
Aggregations