Search in sources :

Example 1 with MaxRetriesReachedException

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();
        }
    });
}
Also used : MaxRetriesReachedException(org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException)

Example 2 with MaxRetriesReachedException

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();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) List(java.util.List) MaxRetriesReachedException(org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException) Test(org.junit.Test)

Aggregations

MaxRetriesReachedException (org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException)2 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)1 Block (org.hyperledger.besu.ethereum.core.Block)1 RespondingEthPeer (org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)1 Test (org.junit.Test)1