Search in sources :

Example 1 with MAX_QUERY_RETRIES_PER_PEER

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();
    });
}
Also used : Logger(org.slf4j.Logger) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) SyncTargetManager(org.hyperledger.besu.ethereum.eth.sync.SyncTargetManager) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) LoggerFactory(org.slf4j.LoggerFactory) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) CompletableFuture(java.util.concurrent.CompletableFuture) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) List(java.util.List) RetryingGetHeaderFromPeerByNumberTask(org.hyperledger.besu.ethereum.eth.sync.tasks.RetryingGetHeaderFromPeerByNumberTask) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Optional(java.util.Optional) WorldStateStorage(org.hyperledger.besu.ethereum.worldstate.WorldStateStorage) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) MAX_QUERY_RETRIES_PER_PEER(org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotBlockRetriever.MAX_QUERY_RETRIES_PER_PEER) DisconnectReason(org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) RetryingGetHeaderFromPeerByNumberTask(org.hyperledger.besu.ethereum.eth.sync.tasks.RetryingGetHeaderFromPeerByNumberTask) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Aggregations

List (java.util.List)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)1 EthPeer (org.hyperledger.besu.ethereum.eth.manager.EthPeer)1 SyncTargetManager (org.hyperledger.besu.ethereum.eth.sync.SyncTargetManager)1 SynchronizerConfiguration (org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration)1 MAX_QUERY_RETRIES_PER_PEER (org.hyperledger.besu.ethereum.eth.sync.fastsync.PivotBlockRetriever.MAX_QUERY_RETRIES_PER_PEER)1 RetryingGetHeaderFromPeerByNumberTask (org.hyperledger.besu.ethereum.eth.sync.tasks.RetryingGetHeaderFromPeerByNumberTask)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1 DisconnectReason (org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason)1 WorldStateStorage (org.hyperledger.besu.ethereum.worldstate.WorldStateStorage)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1