use of org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotBlockRetriever.MAX_QUERY_RETRIES_PER_PEER in project besu by hyperledger.
the class FastSyncTargetManager method confirmPivotBlockHeader.
private CompletableFuture<Optional<EthPeer>> confirmPivotBlockHeader(final EthPeer bestPeer) {
final BlockHeader pivotBlockHeader = fastSyncState.getPivotBlockHeader().get();
final RetryingGetHeaderFromPeerByNumberTask task = RetryingGetHeaderFromPeerByNumberTask.forSingleNumber(protocolSchedule, ethContext, metricsSystem, pivotBlockHeader.getNumber(), MAX_QUERY_RETRIES_PER_PEER);
task.assignPeer(bestPeer);
return ethContext.getScheduler().timeout(task).thenCompose(result -> {
if (peerHasDifferentPivotBlock(result)) {
if (!hasPivotChanged(pivotBlockHeader)) {
// if the pivot block has not changed, then warn and disconnect this peer
LOG.warn("Best peer has wrong pivot block (#{}) expecting {} but received {}. Disconnect: {}", pivotBlockHeader.getNumber(), pivotBlockHeader.getHash(), result.size() == 1 ? result.get(0).getHash() : "invalid response", bestPeer);
bestPeer.disconnect(DisconnectReason.USELESS_PEER);
return CompletableFuture.completedFuture(Optional.<EthPeer>empty());
}
LOG.debug("Retrying best peer {} with new pivot block {}", bestPeer.getShortNodeId(), pivotBlockHeader.toLogString());
return confirmPivotBlockHeader(bestPeer);
} else {
return CompletableFuture.completedFuture(Optional.of(bestPeer));
}
}).exceptionally(error -> {
LOG.debug("Could not confirm best peer had pivot block", error);
return Optional.empty();
});
}
Aggregations