Search in sources :

Example 1 with BlockManager

use of tech.pegasys.teku.statetransition.block.BlockManager 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);
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) SlotEventsChannel(tech.pegasys.teku.ethereum.events.SlotEventsChannel) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) BlockValidator(tech.pegasys.teku.statetransition.validation.BlockValidator) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) FetchRecentBlocksService(tech.pegasys.teku.beacon.sync.gossip.FetchRecentBlocksService) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) SinglePeerSyncService(tech.pegasys.teku.beacon.sync.forward.singlepeer.SinglePeerSyncService) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) SyncManager(tech.pegasys.teku.beacon.sync.forward.singlepeer.SyncManager) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) ForwardSyncService(tech.pegasys.teku.beacon.sync.forward.ForwardSyncService) BlockManager(tech.pegasys.teku.statetransition.block.BlockManager) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) Spec(tech.pegasys.teku.spec.Spec) Eth2P2PNetwork(tech.pegasys.teku.networking.eth2.Eth2P2PNetwork)

Example 2 with BlockManager

use of tech.pegasys.teku.statetransition.block.BlockManager in project teku by ConsenSys.

the class BeaconChainController method initBlockManager.

public void initBlockManager() {
    LOG.debug("BeaconChainController.initBlockManager()");
    final FutureItems<SignedBeaconBlock> futureBlocks = FutureItems.create(SignedBeaconBlock::getSlot);
    BlockValidator blockValidator = new BlockValidator(spec, recentChainData);
    if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) {
        blockManager = new ReexecutingExecutionPayloadBlockManager(recentChainData, blockImporter, pendingBlocks, futureBlocks, blockValidator, beaconAsyncRunner);
    } else {
        blockManager = new BlockManager(recentChainData, blockImporter, pendingBlocks, futureBlocks, blockValidator);
    }
    eventChannels.subscribe(SlotEventsChannel.class, blockManager).subscribe(BlockImportChannel.class, blockManager).subscribe(BlockImportNotifications.class, blockManager);
}
Also used : ReexecutingExecutionPayloadBlockManager(tech.pegasys.teku.statetransition.block.ReexecutingExecutionPayloadBlockManager) BlockManager(tech.pegasys.teku.statetransition.block.BlockManager) ReexecutingExecutionPayloadBlockManager(tech.pegasys.teku.statetransition.block.ReexecutingExecutionPayloadBlockManager) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BlockValidator(tech.pegasys.teku.statetransition.validation.BlockValidator) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel)

Aggregations

SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 BlockManager (tech.pegasys.teku.statetransition.block.BlockManager)2 MergeTransitionBlockValidator (tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator)2 BlockValidator (tech.pegasys.teku.statetransition.validation.BlockValidator)2 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 ForwardSyncService (tech.pegasys.teku.beacon.sync.forward.ForwardSyncService)1 SinglePeerSyncService (tech.pegasys.teku.beacon.sync.forward.singlepeer.SinglePeerSyncService)1 SyncManager (tech.pegasys.teku.beacon.sync.forward.singlepeer.SyncManager)1 FetchRecentBlocksService (tech.pegasys.teku.beacon.sync.gossip.FetchRecentBlocksService)1 SlotEventsChannel (tech.pegasys.teku.ethereum.events.SlotEventsChannel)1 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)1 EventChannels (tech.pegasys.teku.infrastructure.events.EventChannels)1 Eth2P2PNetwork (tech.pegasys.teku.networking.eth2.Eth2P2PNetwork)1 Eth2P2PNetworkBuilder (tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder)1 Spec (tech.pegasys.teku.spec.Spec)1 StubExecutionEngineChannel (tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel)1 BeaconChainUtil (tech.pegasys.teku.statetransition.BeaconChainUtil)1 BlockImportChannel (tech.pegasys.teku.statetransition.block.BlockImportChannel)1 BlockImportNotifications (tech.pegasys.teku.statetransition.block.BlockImportNotifications)1 BlockImporter (tech.pegasys.teku.statetransition.block.BlockImporter)1