Search in sources :

Example 1 with EventChannels

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);
}
Also used : MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) BeaconChainEventAdapter(tech.pegasys.teku.validator.beaconnode.BeaconChainEventAdapter) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) MetricRecordingValidatorApiChannel(tech.pegasys.teku.validator.beaconnode.metrics.MetricRecordingValidatorApiChannel) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) RepeatingTaskScheduler(tech.pegasys.teku.infrastructure.async.timed.RepeatingTaskScheduler) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) TimeBasedEventAdapter(tech.pegasys.teku.validator.beaconnode.TimeBasedEventAdapter)

Example 2 with EventChannels

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);
}
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 3 with EventChannels

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;
}
Also used : BlockDutyFactory(tech.pegasys.teku.validator.client.duties.BlockDutyFactory) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig) Random(java.util.Random) LocalSlashingProtector(tech.pegasys.teku.core.signatures.LocalSlashingProtector) ArrayList(java.util.ArrayList) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) PublicKeyLoader(tech.pegasys.teku.validator.client.loader.PublicKeyLoader) SlotBasedScheduledDuties(tech.pegasys.teku.validator.client.duties.SlotBasedScheduledDuties) JsonProvider(tech.pegasys.teku.provider.JsonProvider) ChainHeadTracker(tech.pegasys.teku.validator.client.duties.synccommittee.ChainHeadTracker) BeaconCommitteeSubscriptions(tech.pegasys.teku.validator.client.duties.BeaconCommitteeSubscriptions) Spec(tech.pegasys.teku.spec.Spec) Path(java.nio.file.Path) Service(tech.pegasys.teku.service.serviceutils.Service) ProposerConfigProvider(tech.pegasys.teku.validator.client.proposerconfig.ProposerConfigProvider) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ValidatorLogger(tech.pegasys.teku.infrastructure.logging.ValidatorLogger) SyncDataAccessor(tech.pegasys.teku.infrastructure.io.SyncDataAccessor) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) ServiceConfig(tech.pegasys.teku.service.serviceutils.ServiceConfig) BeaconNodeApi(tech.pegasys.teku.validator.beaconnode.BeaconNodeApi) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) InProcessBeaconNodeApi(tech.pegasys.teku.validator.eventadapter.InProcessBeaconNodeApi) OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) SlashingProtector(tech.pegasys.teku.core.signatures.SlashingProtector) SystemSignalListener(tech.pegasys.teku.infrastructure.io.SystemSignalListener) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) ProposerConfigLoader(tech.pegasys.teku.validator.client.proposerconfig.loader.ProposerConfigLoader) SlashingProtectionLogger(tech.pegasys.teku.validator.client.loader.SlashingProtectionLogger) Optional(java.util.Optional) RemoteBeaconNodeApi(tech.pegasys.teku.validator.remote.RemoteBeaconNodeApi) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) LogManager(org.apache.logging.log4j.LogManager) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) ValidatorTimingChannel(tech.pegasys.teku.validator.api.ValidatorTimingChannel) AttestationDutyFactory(tech.pegasys.teku.validator.client.duties.attestations.AttestationDutyFactory) ValidatorRestApi(tech.pegasys.teku.validator.client.restapi.ValidatorRestApi) RestApi(tech.pegasys.teku.infrastructure.restapi.RestApi) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) GenesisDataProvider(tech.pegasys.teku.validator.beaconnode.GenesisDataProvider) BeaconNodeApi(tech.pegasys.teku.validator.beaconnode.BeaconNodeApi) InProcessBeaconNodeApi(tech.pegasys.teku.validator.eventadapter.InProcessBeaconNodeApi) RemoteBeaconNodeApi(tech.pegasys.teku.validator.remote.RemoteBeaconNodeApi) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) ValidatorLoader(tech.pegasys.teku.validator.client.loader.ValidatorLoader) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) ValidatorRestApiConfig(tech.pegasys.teku.validator.client.restapi.ValidatorRestApiConfig)

Example 4 with EventChannels

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);
}
Also used : RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil)

Aggregations

EventChannels (tech.pegasys.teku.infrastructure.events.EventChannels)4 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)2 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)2 Eth2P2PNetworkBuilder (tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder)2 Spec (tech.pegasys.teku.spec.Spec)2 BeaconChainUtil (tech.pegasys.teku.statetransition.BeaconChainUtil)2 MemoryOnlyRecentChainData (tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData)2 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)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 LocalSlashingProtector (tech.pegasys.teku.core.signatures.LocalSlashingProtector)1