use of tech.pegasys.teku.beacon.sync.forward.ForwardSyncService in project teku by ConsenSys.
the class SyncingNodeManager method create.
@SuppressWarnings("FutureReturnValueIgnored")
public static SyncingNodeManager create(final AsyncRunner asyncRunner, Eth2P2PNetworkFactory networkFactory, final List<BLSKeyPair> validatorKeys, Consumer<Eth2P2PNetworkBuilder> configureNetwork) throws Exception {
final Spec spec = TestSpecFactory.createMinimalPhase0();
final EventChannels eventChannels = EventChannels.createSyncChannels(TEST_EXCEPTION_HANDLER, new NoOpMetricsSystem());
final RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
final BeaconChainUtil chainUtil = BeaconChainUtil.create(spec, recentChainData, validatorKeys);
chainUtil.initializeStorage();
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
BlockImporter blockImporter = new BlockImporter(spec, eventChannels.getPublisher(BlockImportNotifications.class), recentChainData, forkChoice, WeakSubjectivityFactory.lenientValidator(), new StubExecutionEngineChannel(spec));
BlockValidator blockValidator = new BlockValidator(spec, recentChainData);
final PendingPool<SignedBeaconBlock> pendingBlocks = PendingPool.createForBlocks(spec);
final FutureItems<SignedBeaconBlock> futureBlocks = FutureItems.create(SignedBeaconBlock::getSlot);
BlockManager blockManager = new BlockManager(recentChainData, blockImporter, pendingBlocks, futureBlocks, blockValidator);
eventChannels.subscribe(SlotEventsChannel.class, blockManager).subscribe(BlockImportChannel.class, blockManager).subscribe(BlockImportNotifications.class, blockManager).subscribe(FinalizedCheckpointChannel.class, pendingBlocks);
final Eth2P2PNetworkBuilder networkBuilder = networkFactory.builder().spec(spec).eventChannels(eventChannels).recentChainData(recentChainData).gossipedBlockProcessor(blockManager::validateAndImportBlock);
configureNetwork.accept(networkBuilder);
final Eth2P2PNetwork eth2P2PNetwork = networkBuilder.startNetwork();
SyncManager syncManager = SyncManager.create(asyncRunner, eth2P2PNetwork, recentChainData, blockImporter, new NoOpMetricsSystem(), spec);
ForwardSyncService syncService = new SinglePeerSyncService(syncManager, recentChainData);
final FetchRecentBlocksService recentBlockFetcher = FetchRecentBlocksService.create(asyncRunner, eth2P2PNetwork, pendingBlocks, syncService);
recentBlockFetcher.subscribeBlockFetched(blockManager::importBlock);
blockManager.subscribeToReceivedBlocks((block, executionOptimistic) -> recentBlockFetcher.cancelRecentBlockRequest(block.getRoot()));
recentBlockFetcher.start().join();
blockManager.start().join();
syncService.start().join();
return new SyncingNodeManager(eventChannels, recentChainData, chainUtil, eth2P2PNetwork, syncService);
}
use of tech.pegasys.teku.beacon.sync.forward.ForwardSyncService in project teku by ConsenSys.
the class SyncServiceFactory method create.
private SyncService create() {
if (!syncConfig.isSyncEnabled()) {
return new NoopSyncService();
}
final ForwardSyncService forwardSyncService = createForwardSyncService();
final FetchRecentBlocksService recentBlockFetcher = FetchRecentBlocksService.create(asyncRunner, p2pNetwork, pendingBlocks, forwardSyncService);
final SyncStateTracker syncStateTracker = createSyncStateTracker(forwardSyncService);
final HistoricalBlockSyncService historicalBlockSyncService = createHistoricalSyncService(syncStateTracker);
return new DefaultSyncService(forwardSyncService, recentBlockFetcher, syncStateTracker, historicalBlockSyncService);
}
Aggregations