Search in sources :

Example 1 with ChainHeadEstimate

use of org.hyperledger.besu.ethereum.eth.manager.ChainHeadEstimate in project besu by hyperledger.

the class SyncStateTest method mockChainIsBetterThan.

private EthPeer mockChainIsBetterThan(final EthPeer peer, final boolean isBetter) {
    final ChainState chainState = spy(peer.chainState());
    final ChainHeadEstimate chainStateSnapshot = spy(peer.chainStateSnapshot());
    lenient().doReturn(isBetter).when(chainState).chainIsBetterThan(any());
    lenient().doReturn(isBetter).when(chainStateSnapshot).chainIsBetterThan(any());
    final EthPeer mockedPeer = spy(peer);
    lenient().doReturn(chainStateSnapshot).when(chainState).getSnapshot();
    lenient().doReturn(chainStateSnapshot).when(mockedPeer).chainStateSnapshot();
    lenient().doReturn(chainState).when(mockedPeer).chainState();
    return mockedPeer;
}
Also used : ChainHeadEstimate(org.hyperledger.besu.ethereum.eth.manager.ChainHeadEstimate) ChainState(org.hyperledger.besu.ethereum.eth.manager.ChainState) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)

Example 2 with ChainHeadEstimate

use of org.hyperledger.besu.ethereum.eth.manager.ChainHeadEstimate in project besu by hyperledger.

the class SyncState method checkInSync.

private synchronized void checkInSync() {
    final ChainHead localChain = getLocalChainHead();
    final Optional<ChainHeadEstimate> syncTargetChain = getSyncTargetChainHead();
    final Optional<ChainHeadEstimate> bestPeerChain = getBestPeerChainHead();
    // Remove listener when we've found a peer.
    newPeerListenerId.ifPresent(listenerId -> {
        ethPeers.unsubscribeConnect(listenerId);
        newPeerListenerId = Optional.empty();
    });
    inSyncTrackers.values().forEach((syncTracker) -> syncTracker.checkState(localChain, syncTargetChain, bestPeerChain));
}
Also used : ChainHeadEstimate(org.hyperledger.besu.ethereum.eth.manager.ChainHeadEstimate) ChainHead(org.hyperledger.besu.ethereum.chain.ChainHead)

Aggregations

ChainHeadEstimate (org.hyperledger.besu.ethereum.eth.manager.ChainHeadEstimate)2 ChainHead (org.hyperledger.besu.ethereum.chain.ChainHead)1 ChainState (org.hyperledger.besu.ethereum.eth.manager.ChainState)1 EthPeer (org.hyperledger.besu.ethereum.eth.manager.EthPeer)1 RespondingEthPeer (org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)1