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;
}
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));
}
Aggregations