use of tech.pegasys.teku.beacon.sync.forward.multipeer.chains.TargetChains in project teku by ConsenSys.
the class MultipeerSyncService method create.
public static MultipeerSyncService create(final AsyncRunnerFactory asyncRunnerFactory, final AsyncRunner asyncRunner, final TimeProvider timeProvider, final RecentChainData recentChainData, final PendingPool<SignedBeaconBlock> pendingBlocks, final P2PNetwork<Eth2Peer> p2pNetwork, final BlockImporter blockImporter, final Spec spec) {
LOG.info("Using multipeer sync");
final EventThread eventThread = new AsyncRunnerEventThread("sync", asyncRunnerFactory);
final TargetChains finalizedTargetChains = new TargetChains();
final TargetChains nonfinalizedTargetChains = new TargetChains();
final BatchSync batchSync = BatchSync.create(eventThread, asyncRunner, recentChainData, new BatchImporter(blockImporter, asyncRunner), new BatchFactory(eventThread, new PeerScoringConflictResolutionStrategy()), Constants.SYNC_BATCH_SIZE, MultipeerCommonAncestorFinder.create(recentChainData, eventThread, spec), timeProvider);
final SyncController syncController = new SyncController(eventThread, new OrderedAsyncRunner(asyncRunner), recentChainData, new SyncTargetSelector(recentChainData, pendingBlocks, finalizedTargetChains, nonfinalizedTargetChains, spec.getSlotsPerEpoch(recentChainData.getCurrentSlot().orElse(UInt64.ZERO))), batchSync);
final PeerChainTracker peerChainTracker = new PeerChainTracker(recentChainData.getSpec(), eventThread, p2pNetwork, new SyncSourceFactory(asyncRunner, timeProvider), finalizedTargetChains, nonfinalizedTargetChains);
peerChainTracker.subscribeToTargetChainUpdates(syncController::onTargetChainsUpdated);
final SyncStallDetector syncStallDetector = new SyncStallDetector(spec, eventThread, asyncRunner, timeProvider, syncController, batchSync, recentChainData);
return new MultipeerSyncService(eventThread, recentChainData, peerChainTracker, syncController, syncStallDetector);
}
use of tech.pegasys.teku.beacon.sync.forward.multipeer.chains.TargetChains in project teku by ConsenSys.
the class BatchSyncTest method shouldFailSyncWhenTargetChainHasNoPeersAndThereAreNoOutstandingRequests.
@Test
void shouldFailSyncWhenTargetChainHasNoPeersAndThereAreNoOutstandingRequests() {
final TargetChains targetChains = new TargetChains();
targetChains.onPeerStatusUpdated(syncSource, targetChain.getChainHead());
targetChain = targetChains.streamChains().findFirst().orElseThrow();
// Start the sync
final SafeFuture<SyncResult> result = sync.syncToChain(targetChain);
// Then the last peer is moved off that chain but we keep waiting for pending requests
targetChains.onPeerDisconnected(syncSource);
assertThat(result).isNotDone();
final int originalBatchCount = batches.size();
// Next time the sync progresses, it aborts because there are no more peers.
batches.receiveBlocks(batches.get(0));
assertThat(result).isCompletedWithValue(SyncResult.FAILED);
// No more batches created
assertThat(batches).hasSize(originalBatchCount);
}
Aggregations