use of tech.pegasys.teku.infrastructure.events.EventChannels in project teku by ConsenSys.
the class InProcessBeaconNodeApi method create.
public static BeaconNodeApi create(final ServiceConfig services, final AsyncRunner asyncRunner, final boolean generateEarlyAttestations, final Spec spec) {
final MetricsSystem metricsSystem = services.getMetricsSystem();
final EventChannels eventChannels = services.getEventChannels();
final ValidatorApiChannel validatorApiChannel = new MetricRecordingValidatorApiChannel(metricsSystem, eventChannels.getPublisher(ValidatorApiChannel.class, asyncRunner));
final ValidatorTimingChannel validatorTimingChannel = eventChannels.getPublisher(ValidatorTimingChannel.class);
final TimeBasedEventAdapter timeBasedEventAdapter = new TimeBasedEventAdapter(new GenesisDataProvider(asyncRunner, validatorApiChannel), new RepeatingTaskScheduler(asyncRunner, services.getTimeProvider()), services.getTimeProvider(), validatorTimingChannel, spec);
final BeaconChainEventAdapter beaconChainEventAdapter = new IndependentTimerEventChannelEventAdapter(eventChannels, generateEarlyAttestations, timeBasedEventAdapter, validatorTimingChannel);
return new InProcessBeaconNodeApi(validatorApiChannel, beaconChainEventAdapter);
}
use of tech.pegasys.teku.infrastructure.events.EventChannels 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.infrastructure.events.EventChannels in project teku by ConsenSys.
the class ValidatorClientService method create.
public static ValidatorClientService create(final ServiceConfig services, final ValidatorClientConfiguration config) {
final EventChannels eventChannels = services.getEventChannels();
final AsyncRunner asyncRunner = services.createAsyncRunner("validator");
final boolean generateEarlyAttestations = config.getValidatorConfig().generateEarlyAttestations();
final BeaconNodeApi beaconNodeApi = config.getValidatorConfig().getBeaconNodeApiEndpoint().map(endpoint -> RemoteBeaconNodeApi.create(services, asyncRunner, endpoint, config.getSpec(), generateEarlyAttestations)).orElseGet(() -> InProcessBeaconNodeApi.create(services, asyncRunner, generateEarlyAttestations, config.getSpec()));
final ValidatorApiChannel validatorApiChannel = beaconNodeApi.getValidatorApi();
final GenesisDataProvider genesisDataProvider = new GenesisDataProvider(asyncRunner, validatorApiChannel);
final ForkProvider forkProvider = new ForkProvider(config.getSpec(), genesisDataProvider);
final ValidatorLoader validatorLoader = createValidatorLoader(config, asyncRunner, services);
final ValidatorRestApiConfig validatorApiConfig = config.getValidatorRestApiConfig();
Optional<RestApi> validatorRestApi = Optional.empty();
if (validatorApiConfig.isRestApiEnabled()) {
validatorRestApi = Optional.of(ValidatorRestApi.create(validatorApiConfig, new ActiveKeyManager(validatorLoader, services.getEventChannels().getPublisher(ValidatorTimingChannel.class)), services.getDataDirLayout()));
} else {
LOG.info("validator-api-enabled is false, not starting rest api.");
}
ValidatorClientService validatorClientService = new ValidatorClientService(eventChannels, validatorLoader, beaconNodeApi, validatorRestApi, forkProvider, config.getSpec(), services.getMetricsSystem());
asyncRunner.runAsync(() -> validatorClientService.initializeValidators(config, validatorApiChannel, asyncRunner)).propagateTo(validatorClientService.initializationComplete);
return validatorClientService;
}
use of tech.pegasys.teku.infrastructure.events.EventChannels in project teku by ConsenSys.
the class NodeManager method create.
public static NodeManager create(final Spec spec, Eth2P2PNetworkFactory networkFactory, final List<BLSKeyPair> validatorKeys, Consumer<Eth2P2PNetworkBuilder> configureNetwork) throws Exception {
final EventChannels eventChannels = EventChannels.createSyncChannels(ChannelExceptionHandler.THROWING_HANDLER, new NoOpMetricsSystem());
final RecentChainData storageClient = MemoryOnlyRecentChainData.create(spec);
final BeaconChainUtil chainUtil = BeaconChainUtil.create(spec, storageClient, validatorKeys);
chainUtil.initializeStorage();
final Eth2P2PNetworkBuilder networkBuilder = networkFactory.builder().spec(spec).eventChannels(eventChannels).recentChainData(storageClient);
configureNetwork.accept(networkBuilder);
final BlockGossipChannel blockGossipChannel = eventChannels.getPublisher(BlockGossipChannel.class);
final Eth2P2PNetwork eth2P2PNetwork = networkBuilder.startNetwork();
return new NodeManager(blockGossipChannel, storageClient, chainUtil, eth2P2PNetwork);
}
Aggregations