From a73606c095325f89aa32c19b0788089315f26dde Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 5 Jun 2024 20:08:52 +0400 Subject: [PATCH 01/27] Add EventChannelSubscriber --- .../events/EventChannelSubscriber.java | 6 ++++++ .../teku/infrastructure/events/EventChannels.java | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java diff --git a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java new file mode 100644 index 00000000000..8e21d8c2d6c --- /dev/null +++ b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java @@ -0,0 +1,6 @@ +package tech.pegasys.teku.infrastructure.events; + +public interface EventChannelSubscriber { + + void subscribe(T listener); +} diff --git a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java index 74f210f1a18..7d19e7cfec5 100644 --- a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java +++ b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java @@ -84,6 +84,10 @@ public EventChannels subscribe( return subscribeMultithreaded(channelInterface, subscriber, 1); } + public EventChannelSubscriber createSubscriber(final Class channelInterface) { + return createSubscriberMultithreaded(channelInterface, 1); + } + /** * Adds a subscriber to this channel where events are handled by multiple threads concurrently. * @@ -99,10 +103,17 @@ public EventChannels subscribe( */ public EventChannels subscribeMultithreaded( final Class channelInterface, final T subscriber, final int requestedParallelism) { - getChannel(channelInterface).subscribeMultithreaded(subscriber, requestedParallelism); + createSubscriberMultithreaded(channelInterface,requestedParallelism).subscribe(subscriber); return this; } + public EventChannelSubscriber createSubscriberMultithreaded( + final Class channelInterface, final int requestedParallelism) { + return listener -> + getChannel(channelInterface).subscribeMultithreaded(listener, requestedParallelism); + } + + @SuppressWarnings("unchecked") private EventChannel getChannel(final Class channelInterface) { return (EventChannel) channels.computeIfAbsent(channelInterface, eventChannelFactory); From 330b4cd476677edd8d204311f7385ebe5a47cadf Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 7 Jun 2024 18:47:13 +0400 Subject: [PATCH 02/27] Narrow down parameter from EventChannels to EventChannelSubscriber --- .../executionlayer/ExecutionLayerBlockManagerFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java b/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java index 6030dc5f6d4..59feb9e8027 100644 --- a/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java +++ b/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java @@ -15,16 +15,16 @@ import tech.pegasys.teku.ethereum.events.SlotEventsChannel; import tech.pegasys.teku.ethereum.executionlayer.ExecutionLayerBlockProductionManagerImpl; -import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager; import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; public class ExecutionLayerBlockManagerFactory { public static ExecutionLayerBlockProductionManager create( - final ExecutionLayerChannel executionLayerManager, final EventChannels eventChannels) { + final ExecutionLayerChannel executionLayerManager, final EventChannelSubscriber slotEventsChannelSubscriber) { final ExecutionLayerBlockProductionManagerImpl executionLayerBlockProductionManager = new ExecutionLayerBlockProductionManagerImpl(executionLayerManager); - eventChannels.subscribe(SlotEventsChannel.class, executionLayerBlockProductionManager); + slotEventsChannelSubscriber.subscribe(executionLayerBlockProductionManager); return executionLayerBlockProductionManager; } From e73895dec0d6bc02e9a54715f70aa1107b37aa6e Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 7 Jun 2024 18:47:51 +0400 Subject: [PATCH 03/27] Initial version of Dagger modules (no Dagger compile check) --- services/beaconchain/build.gradle | 3 + .../beaconchain/BeaconChainController.java | 15 +- .../beaconchain/init/AsyncRunnerModule.java | 85 ++++++ .../beaconchain/init/BeaconConfigModule.java | 51 ++++ .../beaconchain/init/BeaconModule.java | 175 ++++++++++++ .../services/beaconchain/init/BlobModule.java | 78 ++++++ .../beaconchain/init/ChannelsModule.java | 160 +++++++++++ .../beaconchain/init/CryptoModule.java | 57 ++++ .../beaconchain/init/DataProviderModule.java | 163 +++++++++++ .../init/ExternalDependenciesModule.java | 28 ++ .../beaconchain/init/ForkChoiceModule.java | 100 +++++++ .../beaconchain/init/LoggingModule.java | 35 +++ .../beaconchain/init/MetricsModule.java | 231 ++++++++++++++++ .../services/beaconchain/init/MiscModule.java | 15 + .../beaconchain/init/NetworkModule.java | 127 +++++++++ .../beaconchain/init/PoolAndCachesModule.java | 261 ++++++++++++++++++ .../services/beaconchain/init/PowModule.java | 130 +++++++++ .../beaconchain/init/ServiceConfigModule.java | 54 ++++ .../services/beaconchain/init/SpecModule.java | 40 +++ .../beaconchain/init/StorageModule.java | 58 ++++ .../beaconchain/init/SubnetsModule.java | 100 +++++++ .../services/beaconchain/init/SyncModule.java | 120 ++++++++ .../beaconchain/init/ValidatorModule.java | 252 +++++++++++++++++ .../beaconchain/init/VerifyModule.java | 143 ++++++++++ 24 files changed, 2480 insertions(+), 1 deletion(-) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java diff --git a/services/beaconchain/build.gradle b/services/beaconchain/build.gradle index fc903a0a4ff..db629004ecd 100644 --- a/services/beaconchain/build.gradle +++ b/services/beaconchain/build.gradle @@ -34,6 +34,9 @@ dependencies { implementation project(':validator:api') implementation project(':validator:client') + implementation 'com.google.dagger:dagger:2.51.1' + annotationProcessor 'com.google.dagger:dagger-compiler:2.51.1' + testImplementation testFixtures(project(':storage')) testImplementation testFixtures(project(':ethereum:spec')) testImplementation testFixtures(project(':ethereum:statetransition')) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index 30693219b62..b899d98dcfe 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -682,6 +682,7 @@ protected void initProposerSlashingPool() { blockImporter.subscribeToVerifiedBlockProposerSlashings(proposerSlashingPool::removeAll); } + // TODO protected void initSlashingEventsSubscriptions() { if (beaconConfig.validatorConfig().isShutdownWhenValidatorSlashedEnabled()) { final ValidatorTimingChannel validatorTimingChannel = @@ -776,6 +777,7 @@ protected void initCombinedChainDataClient() { recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); } + // TODO protected SafeFuture initWeakSubjectivity( final StorageQueryChannel queryChannel, final StorageUpdateChannel updateChannel) { return wsInitializer @@ -884,7 +886,8 @@ protected void initSubnetSubscriber() { public void initExecutionLayerBlockProductionManager() { LOG.debug("BeaconChainController.initExecutionLayerBlockProductionManager()"); this.executionLayerBlockProductionManager = - ExecutionLayerBlockManagerFactory.create(executionLayer, eventChannels); + ExecutionLayerBlockManagerFactory.create( + executionLayer, eventChannels.createSubscriber(SlotEventsChannel.class)); } public void initRewardCalculator() { @@ -985,6 +988,7 @@ public void initValidatorApiHandler() { } } + // TODO protected void initGenesisHandler() { if (!recentChainData.isPreGenesis()) { // We already have a genesis block - no need for a genesis handler @@ -1290,6 +1294,7 @@ public void initSyncService() { state -> p2pNetwork.onSyncStateChanged(state.isInSync(), state.isOptimistic())); } + //TODO protected void initOperationsReOrgManager() { LOG.debug("BeaconChainController.initOperationsReOrgManager()"); OperationsReOrgManager operationsReOrgManager = @@ -1304,6 +1309,7 @@ protected void initOperationsReOrgManager() { eventChannels.subscribe(ChainHeadChannel.class, operationsReOrgManager); } + // TODO protected void initValidatorIndexCacheTracker() { LOG.debug("BeaconChainController.initValidatorIndexCacheTracker()"); final ValidatorIndexCacheTracker validatorIndexCacheTracker = @@ -1357,6 +1363,7 @@ private Optional getProposerDefaultFeeRecipient() { return defaultFeeRecipient; } + // TODO protected void setupInitialState(final RecentChainData client) { final Eth2NetworkConfiguration networkConfiguration = beaconConfig.eth2NetworkConfig(); @@ -1404,6 +1411,7 @@ protected void setupInitialState(final RecentChainData client) { } } + // TODO private Optional tryLoadingAnchorPointFromInitialState( final Eth2NetworkConfiguration networkConfiguration) { Optional initialAnchor = Optional.empty(); @@ -1425,10 +1433,12 @@ private Optional tryLoadingAnchorPointFromInitialState( return initialAnchor; } + // TODO protected Optional attemptToLoadAnchorPoint(final Optional initialState) { return wsInitializer.loadInitialAnchorPoint(spec, initialState); } + // TODO protected void setupInteropState() { final InteropConfig config = beaconConfig.interopConfig(); STATUS_LOG.generatingMockStartGenesis( @@ -1466,6 +1476,7 @@ protected void setupInteropState() { genesisState.getGenesisTime()); } + // TODO protected void onStoreInitialized() { UInt64 genesisTime = recentChainData.getGenesisTime(); UInt64 currentTime = timeProvider.getTimeInSeconds(); @@ -1490,6 +1501,7 @@ protected UInt64 getCurrentSlot(final UInt64 genesisTime, final UInt64 currentTi return spec.getCurrentSlot(currentTime, genesisTime); } + // TODO protected void validateChain(final UInt64 currentSlot) { weakSubjectivityValidator .validateChainIsConsistentWithWSCheckpoint(combinedChainDataClient) @@ -1511,6 +1523,7 @@ protected void validateChain(final UInt64 currentSlot) { }); } + // TODO private void onTick() { if (recentChainData.isPreGenesis()) { return; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java new file mode 100644 index 00000000000..9e96cc4648f --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java @@ -0,0 +1,85 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; + +import javax.inject.Qualifier; +import javax.inject.Singleton; + +@Module +public interface AsyncRunnerModule { + + @Qualifier + @interface BeaconAsyncRunner {} + + @Qualifier + @interface EventAsyncRunner {} + + @Qualifier + @interface NetworkAsyncRunner {} + + @Qualifier + @interface OperationPoolAsyncRunner {} + + @Qualifier + @interface ForkChoiceExecutor {} + + @Qualifier + @interface ForkChoiceNotifierExecutor {} + + @Provides + @Singleton + @BeaconAsyncRunner + static AsyncRunner beaconAsyncRunner( + AsyncRunnerFactory asyncRunnerFactory, Eth2NetworkConfiguration eth2NetworkConfig) { + return asyncRunnerFactory.create( + "beaconchain", + eth2NetworkConfig.getAsyncBeaconChainMaxThreads(), + eth2NetworkConfig.getAsyncBeaconChainMaxQueue()); + } + + @Provides + @Singleton + @NetworkAsyncRunner + static AsyncRunner networkAsyncRunner( + AsyncRunnerFactory asyncRunnerFactory, Eth2NetworkConfiguration eth2NetworkConfig) { + return asyncRunnerFactory.create( + "p2p", + eth2NetworkConfig.getAsyncP2pMaxThreads(), + eth2NetworkConfig.getAsyncP2pMaxQueue()); + } + + @Provides + @Singleton + @EventAsyncRunner + static AsyncRunner eventAsyncRunner(AsyncRunnerFactory asyncRunnerFactory) { + return asyncRunnerFactory.create("events", 10); + } + + @Provides + @Singleton + @OperationPoolAsyncRunner + static AsyncRunner operationPoolAsyncRunner(AsyncRunnerFactory asyncRunnerFactory) { + return asyncRunnerFactory.create("operationPoolUpdater", 1); + } + + @Provides + @Singleton + @ForkChoiceExecutor + static AsyncRunnerEventThread forkChoiceExecutor(AsyncRunnerFactory asyncRunnerFactory) { + return new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); + } + + @Provides + @Singleton + @ForkChoiceNotifierExecutor + static AsyncRunnerEventThread forkChoiceNotifierExecutor(AsyncRunnerFactory asyncRunnerFactory) { + return new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); + } + + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java new file mode 100644 index 00000000000..a6c42987a55 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java @@ -0,0 +1,51 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig; +import tech.pegasys.teku.networking.eth2.P2PConfig; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; +import tech.pegasys.teku.services.powchain.PowchainConfiguration; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.storage.store.StoreConfig; +import tech.pegasys.teku.validator.api.ValidatorConfig; + +@Module +public interface BeaconConfigModule { + + @Provides + static Eth2NetworkConfiguration eth2NetworkConfig(BeaconChainConfiguration config){ + return config.eth2NetworkConfig(); + } + + @Provides + static StoreConfig storeConfig(BeaconChainConfiguration config){ + return config.storeConfig(); + } + + @Provides + static PowchainConfiguration powchainConfig(BeaconChainConfiguration config){ + return config.powchainConfig(); + } + + @Provides + static P2PConfig p2pConfig(BeaconChainConfiguration config){ + return config.p2pConfig(); + } + + @Provides + static ValidatorConfig validatorConfig(BeaconChainConfiguration config){ + return config.validatorConfig(); + } + + @Provides + static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config){ + return config.beaconRestApiConfig(); + } + + @Provides + static Spec spec(BeaconChainConfiguration config){ + return config.getSpec(); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java new file mode 100644 index 00000000000..71037a23704 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -0,0 +1,175 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.execution.types.Eth1Address; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.services.beaconchain.SlotProcessor; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.PoolAndCachesModule.InvalidBlockRoots; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; +import tech.pegasys.teku.statetransition.EpochCachePrimer; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.block.BlockImportChannel; +import tech.pegasys.teku.statetransition.block.BlockImportMetrics; +import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.block.FailedExecutionPool; +import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceStateProvider; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; +import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; +import tech.pegasys.teku.statetransition.util.FutureItems; +import tech.pegasys.teku.statetransition.util.PendingPool; +import tech.pegasys.teku.statetransition.validation.BlockGossipValidator; +import tech.pegasys.teku.statetransition.validation.BlockValidator; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; + +import javax.inject.Singleton; +import java.util.Map; +import java.util.Optional; + +import static tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG; + +@Module +public interface BeaconModule { + + @Provides + @Singleton + static EpochCachePrimer epochCachePrimer( + Spec spec, + RecentChainData recentChainData, + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + return new EpochCachePrimer(spec, recentChainData, beaconAsyncRunner); + } + + @Provides + @Singleton + static SlotProcessor slotProcessor( + Spec spec, + RecentChainData recentChainData, + SyncService syncService, + ForkChoiceTrigger forkChoiceTrigger, + ForkChoiceNotifier forkChoiceNotifier, + Eth2P2PNetwork p2pNetwork, + SlotEventsChannel slotEventsChannelPublisher, + EpochCachePrimer epochCachePrimer) { + return new SlotProcessor( + spec, + recentChainData, + syncService, + forkChoiceTrigger, + forkChoiceNotifier, + p2pNetwork, + slotEventsChannelPublisher, + epochCachePrimer); + } + + @Provides + @Singleton + static BlockImporter blockImporter( + Spec spec, + RecentChainData recentChainData, + ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher, + ForkChoice forkChoice, + WeakSubjectivityValidator weakSubjectivityValidator, + ExecutionLayerChannel executionLayer) { + return new BlockImporter( + spec, + receivedBlockEventsChannelPublisher, + recentChainData, + forkChoice, + weakSubjectivityValidator, + executionLayer); + } + + @Provides + @Singleton + static BlockManager blockManager( + Spec spec, + EventLogger eventLogger, + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, + TimeProvider timeProvider, + RecentChainData recentChainData, + BlockValidator blockValidator, + BlockImporter blockImporter, + BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + PendingPool pendingBlocks, + @InvalidBlockRoots Map invalidBlockRoots, + Optional blockImportMetrics, + FutureItems futureBlocks, + EventChannelSubscriberslotEventsChannelSubscriber, + EventChannelSubscriber blockImportChannelSubscriber, + EventChannelSubscriber receivedBlockEventsChannelSubscriber + ) { + + BlockManager blockManager = + new BlockManager( + recentChainData, + blockImporter, + blockBlobSidecarsTrackersPool, + pendingBlocks, + futureBlocks, + invalidBlockRoots, + blockValidator, + timeProvider, + eventLogger, + blockImportMetrics); + + // TODO void dependency + if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + final FailedExecutionPool failedExecutionPool = + new FailedExecutionPool(blockManager, beaconAsyncRunner); + blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); + } + slotEventsChannelSubscriber.subscribe(blockManager); + blockImportChannelSubscriber.subscribe(blockManager); + receivedBlockEventsChannelSubscriber.subscribe(blockManager); + + return blockManager; + } + + @Provides + @Singleton + static ProposersDataManager proposersDataManager( + Eth2NetworkConfiguration eth2NetworkConfig, + Spec spec, + MetricsSystem metricsSystem, + @AsyncRunnerModule.ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor, + ExecutionLayerChannel executionLayer, + RecentChainData recentChainData, + EventChannelSubscriber slotEventsChannelSubscriber, + @PowModule.ProposerDefaultFeeRecipient Optional proposerDefaultFeeRecipient) { + + ProposersDataManager proposersDataManager = + new ProposersDataManager( + forkChoiceNotifierExecutor, + spec, + metricsSystem, + executionLayer, + recentChainData, + proposerDefaultFeeRecipient, + eth2NetworkConfig.isForkChoiceUpdatedAlwaysSendPayloadAttributes()); + slotEventsChannelSubscriber.subscribe(proposersDataManager); + return proposersDataManager; + } + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java new file mode 100644 index 00000000000..a15d40305a7 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java @@ -0,0 +1,78 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import java.util.Map; +import javax.inject.Singleton; +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.kzg.KZG; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.PoolAndCachesModule.InvalidBlobSidecarRoots; +import tech.pegasys.teku.services.beaconchain.init.PoolAndCachesModule.InvalidBlockRoots; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; +import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; +import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManagerImpl; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.util.FutureItems; +import tech.pegasys.teku.statetransition.validation.BlobSidecarGossipValidator; +import tech.pegasys.teku.statetransition.validation.GossipValidationHelper; +import tech.pegasys.teku.statetransition.validation.InternalValidationResult; +import tech.pegasys.teku.storage.client.RecentChainData; + +@Module +public interface BlobModule { + + @Provides + @Singleton + static BlobSidecarGossipValidator provideBlobSidecarGossipValidator( + Spec spec, + KZG kzg, + @InvalidBlockRoots Map invalidBlockRoots, + GossipValidationHelper gossipValidationHelper + ) { + final MiscHelpersDeneb miscHelpers = + MiscHelpersDeneb.required(spec.forMilestone(SpecMilestone.DENEB).miscHelpers()); + return BlobSidecarGossipValidator.create( + spec, invalidBlockRoots, gossipValidationHelper, miscHelpers, kzg); + } + + + @Provides + @Singleton + static BlobSidecarManager provideBlobSidecarManager( + Spec spec, + KZG kzg, + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, + RecentChainData recentChainData, + EventChannelSubscriber slotEventsChannelSubscriber, + BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + BlobSidecarGossipValidator blobSidecarGossipValidator, + @InvalidBlobSidecarRoots Map invalidBlobSidecarRoots, + FutureItems futureBlobSidecars + ) { + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + final BlobSidecarManagerImpl blobSidecarManagerImpl = + new BlobSidecarManagerImpl( + spec, + beaconAsyncRunner, + recentChainData, + blockBlobSidecarsTrackersPool, + blobSidecarGossipValidator, + kzg, + futureBlobSidecars, + invalidBlobSidecarRoots); + slotEventsChannelSubscriber.subscribe(blobSidecarManagerImpl); + + return blobSidecarManagerImpl; + } else { + return BlobSidecarManager.NOOP; + } + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java new file mode 100644 index 00000000000..169d73b4f3f --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java @@ -0,0 +1,160 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; +import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionChannel; +import tech.pegasys.teku.ethereum.pow.api.Eth1EventsChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipChannel; +import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.statetransition.block.BlockImportChannel; +import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; +import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; +import tech.pegasys.teku.storage.api.ChainHeadChannel; +import tech.pegasys.teku.storage.api.CombinedStorageChannel; +import tech.pegasys.teku.storage.api.Eth1DepositStorageChannel; +import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; +import tech.pegasys.teku.validator.api.ValidatorApiChannel; + +import static tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG; + +@Module +public interface ChannelsModule { + + // Publishers + + @Provides + static SlotEventsChannel slotEventsChannel(EventChannels eventChannels) { + return eventChannels.getPublisher(SlotEventsChannel.class); + } + + @Provides + static ExecutionLayerChannel executionLayerChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(ExecutionLayerChannel.class, asyncRunner); + } + + @Provides + static BlockImportChannel blockImportChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(BlockImportChannel.class, asyncRunner); + } + + @Provides + static CombinedStorageChannel combinedStorageChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(CombinedStorageChannel.class, asyncRunner); + } + + @Provides + static ValidatorApiChannel validatorApiChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(ValidatorApiChannel.class, asyncRunner); + } + + @Provides + static ActiveValidatorChannel activeValidatorChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(ActiveValidatorChannel.class, asyncRunner); + } + + @Provides + static Eth1DepositStorageChannel eth1DepositStorageChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(Eth1DepositStorageChannel.class, asyncRunner); + } + + @Provides + static ExecutionClientVersionChannel executionClientVersionChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(ExecutionClientVersionChannel.class); + } + + @Provides + static BlockGossipChannel blockGossipChannel(EventChannels eventChannels) { + return eventChannels.getPublisher(BlockGossipChannel.class); + } + + @Provides + static BlobSidecarGossipChannel blobSidecarGossipChannel(EventChannels eventChannels, Spec spec) { + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + return eventChannels.getPublisher(BlobSidecarGossipChannel.class); + } else { + return BlobSidecarGossipChannel.NOOP; + } + } + + @Provides + static ReceivedBlockEventsChannel receivedBlockEventsChannel(EventChannels eventChannels) { + return eventChannels.getPublisher(ReceivedBlockEventsChannel.class); + } + + @Provides + static CoalescingChainHeadChannel coalescingChainHeadChannel(EventChannels eventChannels, EventLogger eventLogger) { + return + new CoalescingChainHeadChannel( + eventChannels.getPublisher(ChainHeadChannel.class), eventLogger); + + } + + + // Subscribers + + @Provides + static EventChannelSubscriber slotEventsChannelSubscriber( + EventChannels eventChannels) { + return eventChannels.createSubscriber(SlotEventsChannel.class); + } + + @Provides + static EventChannelSubscriber finalizedCheckpointChannelSubscriber( + EventChannels eventChannels) { + return eventChannels.createSubscriber(FinalizedCheckpointChannel.class); + } + + @Provides + static EventChannelSubscriber chainHeadChannelSubscriber( + EventChannels eventChannels) { + return eventChannels.createSubscriber(ChainHeadChannel.class); + } + + @Provides + static EventChannelSubscriber eth1EventsChannelSubscriber( + EventChannels eventChannels) { + return eventChannels.createSubscriber(Eth1EventsChannel.class); + } + + @Provides + static EventChannelSubscriber + executionClientVersionChannelSubscriber(EventChannels eventChannels) { + return eventChannels.createSubscriber(ExecutionClientVersionChannel.class); + } + + @Provides + static EventChannelSubscriber + executionClientEventsChannelSubscriber(EventChannels eventChannels) { + return eventChannels.createSubscriber(ExecutionClientEventsChannel.class); + } + + @Provides + static EventChannelSubscriber receivedBlockEventsChannelSubscriber( + EventChannels eventChannels) { + return eventChannels.createSubscriber(ReceivedBlockEventsChannel.class); + } + + @Provides + static EventChannelSubscriber blockImportChannelSubscriber( + EventChannels eventChannels) { + return eventChannels.createSubscriber(BlockImportChannel.class); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java new file mode 100644 index 00000000000..f2dd4c85f43 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java @@ -0,0 +1,57 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; +import tech.pegasys.teku.kzg.KZG; +import tech.pegasys.teku.networking.eth2.P2PConfig; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; + +import javax.inject.Singleton; + +@Module +public interface CryptoModule { + + @Provides + @Singleton + static SignatureVerificationService signatureVerificationService( + P2PConfig p2PConfig, + MetricsSystem metricsSystem, + AsyncRunnerFactory asyncRunnerFactory, + @AsyncRunnerModule.BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + return new AggregatingSignatureVerificationService( + metricsSystem, + asyncRunnerFactory, + beaconAsyncRunner, + p2PConfig.getBatchVerifyMaxThreads(), + p2PConfig.getBatchVerifyQueueCapacity(), + p2PConfig.getBatchVerifyMaxBatchSize(), + p2PConfig.isBatchVerifyStrictThreadLimitEnabled()); + } + + @Provides + @Singleton + static KZG provideKzg(Eth2NetworkConfiguration eth2NetworkConfig, Spec spec) { + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + KZG kzg = KZG.getInstance(); + final String trustedSetupFile = + eth2NetworkConfig + .getTrustedSetup() + .orElseThrow( + () -> + new InvalidConfigurationException( + "Trusted setup should be configured when Deneb is enabled")); + kzg.loadTrustedSetup(trustedSetupFile); + return kzg; + } else { + return KZG.NOOP; + } + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java new file mode 100644 index 00000000000..1fa9728c4c2 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java @@ -0,0 +1,163 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import java.util.Optional; +import java.util.function.IntSupplier; +import javax.inject.Singleton; +import tech.pegasys.teku.api.DataProvider; +import tech.pegasys.teku.api.ExecutionClientDataProvider; +import tech.pegasys.teku.api.RewardCalculator; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.beaconrestapi.BeaconRestApi; +import tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig; +import tech.pegasys.teku.beaconrestapi.JsonTypeDefinitionBeaconRestApi; +import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.EventAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.LoggingModule.InitLogger; +import tech.pegasys.teku.services.beaconchain.init.ServiceConfigModule.RejectedExecutionCountSupplier; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; +import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache; +import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.api.ValidatorApiChannel; +import tech.pegasys.teku.validator.coordinator.DepositProvider; +import tech.pegasys.teku.validator.coordinator.Eth1DataCache; +import tech.pegasys.teku.validator.coordinator.Eth1DataProvider; + +@Module +public interface DataProviderModule { + + record LivenessTrackingStatus(boolean enabled) {} + + @Provides + @Singleton + static Eth1DataProvider eth1DataProvider( + Eth1DataCache eth1DataCache, DepositProvider depositProvider) { + return new Eth1DataProvider(eth1DataCache, depositProvider); + } + + @Provides + @Singleton + static ExecutionClientDataProvider executionClientDataProvider( + DataProvider dataProvider, + EventChannelSubscriber executionClientEventsChannelSubscriber) { + + final ExecutionClientDataProvider executionClientDataProvider = + dataProvider.getExecutionClientDataProvider(); + executionClientEventsChannelSubscriber.subscribe(executionClientDataProvider); + return executionClientDataProvider; + } + + @Provides + @Singleton + static Optional beaconRestApi( + InitLogger initLogger, + Spec spec, + BeaconRestApiConfig beaconRestApiConfig, + @EventAsyncRunner AsyncRunner eventAsyncRunner, + TimeProvider timeProvider, + Eth1DataProvider eth1DataProvider, + DataProvider dataProvider, + EventChannels eventChannels, + LivenessTrackingStatus livenessTrackingStatus) { + if (!beaconRestApiConfig.isRestApiEnabled()) { + initLogger.logger().info("rest-api-enabled is false, not starting rest api."); + return Optional.empty(); + } + + BeaconRestApi beaconRestApi = + new JsonTypeDefinitionBeaconRestApi( + dataProvider, + eth1DataProvider, + beaconRestApiConfig, + eventChannels, + eventAsyncRunner, + timeProvider, + spec); + + if (livenessTrackingStatus.enabled()) { + final int initialValidatorsCount = + spec.getGenesisSpec().getConfig().getMinGenesisActiveValidatorCount(); + eventChannels.subscribe( + ActiveValidatorChannel.class, new ActiveValidatorCache(spec, initialValidatorsCount)); + } + return Optional.of(beaconRestApi); + } + + @Provides + @Singleton + static DataProvider dataProvider( + Spec spec, + BeaconChainConfiguration beaconConfig, + RecentChainData recentChainData, + CombinedChainDataClient combinedChainDataClient, + RewardCalculator rewardCalculator, + Eth2P2PNetwork p2pNetwork, + SyncService syncService, + ValidatorApiChannel validatorApiChannel, + ActiveValidatorChannel activeValidatorChannel, + AggregatingAttestationPool attestationPool, + BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + AttestationManager attestationManager, + OperationPool attesterSlashingPool, + OperationPool proposerSlashingPool, + OperationPool voluntaryExitPool, + OperationPool blsToExecutionChangePool, + SyncCommitteeContributionPool syncCommitteeContributionPool, + ProposersDataManager proposersDataManager, + ForkChoiceNotifier forkChoiceNotifier, + LivenessTrackingStatus livenessTrackingStatus, + @RejectedExecutionCountSupplier IntSupplier rejectedExecutionCountSupplier) { + + // TODO adopt Dagger instead of DataProvider.builder() + return DataProvider.builder() + .spec(spec) + .recentChainData(recentChainData) + .combinedChainDataClient(combinedChainDataClient) + .rewardCalculator(rewardCalculator) + .p2pNetwork(p2pNetwork) + .syncService(syncService) + .validatorApiChannel(validatorApiChannel) + .attestationPool(attestationPool) + .blockBlobSidecarsTrackersPool(blockBlobSidecarsTrackersPool) + .attestationManager(attestationManager) + .isLivenessTrackingEnabled(livenessTrackingStatus.enabled()) + .activeValidatorChannel(activeValidatorChannel) + .attesterSlashingPool(attesterSlashingPool) + .proposerSlashingPool(proposerSlashingPool) + .voluntaryExitPool(voluntaryExitPool) + .blsToExecutionChangePool(blsToExecutionChangePool) + .syncCommitteeContributionPool(syncCommitteeContributionPool) + .proposersDataManager(proposersDataManager) + .forkChoiceNotifier(forkChoiceNotifier) + .rejectedExecutionSupplier(rejectedExecutionCountSupplier) + .build(); + } + + @Provides + static LivenessTrackingStatus livenessTrackingStatus( + BeaconChainConfiguration beaconConfig) { + return new LivenessTrackingStatus( + beaconConfig.beaconRestApiConfig().isBeaconLivenessTrackingEnabled() + || beaconConfig.validatorConfig().isDoppelgangerDetectionEnabled()); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java new file mode 100644 index 00000000000..d50e854eaf0 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java @@ -0,0 +1,28 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.service.serviceutils.ServiceConfig; +import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; + +@Module +public class ExternalDependenciesModule { + + private final ServiceConfig serviceConfig; + private final BeaconChainConfiguration beaconConfig; + + public ExternalDependenciesModule(ServiceConfig serviceConfig, BeaconChainConfiguration beaconConfig) { + this.serviceConfig = serviceConfig; + this.beaconConfig = beaconConfig; + } + + @Provides + ServiceConfig provideServiceConfig() { + return serviceConfig; + } + + @Provides + BeaconChainConfiguration provideBeaconChainConfiguration() { + return beaconConfig; + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java new file mode 100644 index 00000000000..3022295405a --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java @@ -0,0 +1,100 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.execution.types.Eth1Address; +import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; +import tech.pegasys.teku.services.beaconchain.init.PowModule.ProposerDefaultFeeRecipient; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceStateProvider; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; +import tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator; +import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; +import tech.pegasys.teku.statetransition.forkchoice.TickProcessor; +import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.storage.client.RecentChainData; + +import javax.inject.Singleton; +import java.util.Optional; + +@Module +public interface ForkChoiceModule { + + @Provides + @Singleton + static ForkChoice forkChoice( + Spec spec, + Eth2NetworkConfiguration eth2NetworkConfig, + @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, + MetricsSystem metricsSystem, + RecentChainData recentChainData, + BlobSidecarManager blobSidecarManager, + ForkChoiceNotifier forkChoiceNotifier, + ForkChoiceStateProvider forkChoiceStateProvider, + P2PDebugDataDumper p2pDebugDataDumper, + MergeTransitionBlockValidator mergeTransitionBlockValidator) { + return new ForkChoice( + spec, + forkChoiceExecutor, + recentChainData, + blobSidecarManager, + forkChoiceNotifier, + forkChoiceStateProvider, + // TODO to revise + new TickProcessor(spec, recentChainData), + mergeTransitionBlockValidator, + eth2NetworkConfig.isForkChoiceLateBlockReorgEnabled(), + p2pDebugDataDumper, + metricsSystem); + } + + @Provides + @Singleton + static ForkChoiceTrigger forkChoiceTrigger(ForkChoice forkChoice) { + return new ForkChoiceTrigger(forkChoice); + } + + @Provides + @Singleton + static ForkChoiceStateProvider forkChoiceStateProvider( + @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, + RecentChainData recentChainData) { + return new ForkChoiceStateProvider(forkChoiceExecutor, recentChainData); + } + + @Provides + @Singleton + static ForkChoiceNotifier forkChoiceNotifier( + Spec spec, + @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor, + TimeProvider timeProvider, + ProposersDataManager proposersDataManager, + ExecutionLayerChannel executionLayer, + RecentChainData recentChainData, + ForkChoiceStateProvider forkChoiceStateProvider) { + + forkChoiceNotifierExecutor.start(); // TODO why ? + + return + new ForkChoiceNotifierImpl( + forkChoiceStateProvider, + forkChoiceNotifierExecutor, + timeProvider, + spec, + executionLayer, + recentChainData, + proposersDataManager); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java new file mode 100644 index 00000000000..fa4846bcce6 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java @@ -0,0 +1,35 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; +import tech.pegasys.teku.services.beaconchain.BeaconChainController; + +import javax.inject.Singleton; + +@Module +public interface LoggingModule { + + record InitLogger(Logger logger) {} + + @Provides + @Singleton + static StatusLogger statusLogger() { + return StatusLogger.STATUS_LOG; + } + + @Provides + @Singleton + static EventLogger eventLogger() { + return EventLogger.EVENT_LOG; + } + + @Provides + @Singleton + static InitLogger initLogger() { + return new InitLogger(LogManager.getLogger(BeaconChainController.class)); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java new file mode 100644 index 00000000000..b724b0772ab --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java @@ -0,0 +1,231 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionAndPublishingPerformanceFactory; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; +import tech.pegasys.teku.infrastructure.metrics.MetricsConfig; +import tech.pegasys.teku.infrastructure.metrics.SettableGauge; +import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge; +import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.services.beaconchain.BeaconChainMetrics; +import tech.pegasys.teku.services.beaconchain.SlotProcessor; +import tech.pegasys.teku.services.beaconchain.SyncCommitteeMetrics; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.statetransition.block.BlockImportMetrics; +import tech.pegasys.teku.statetransition.util.FutureItems; +import tech.pegasys.teku.storage.api.ChainHeadChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.api.ValidatorConfig; +import tech.pegasys.teku.validator.api.ValidatorPerformanceTrackingMode; +import tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker; +import tech.pegasys.teku.validator.coordinator.DutyMetrics; +import tech.pegasys.teku.validator.coordinator.Eth1DataCache; +import tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.NoOpPerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.SyncCommitteePerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.ValidatorPerformanceMetrics; + +import javax.inject.Qualifier; +import javax.inject.Singleton; + +import java.util.Optional; + +import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; +import static tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory.BEACON; +import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; + +@Module +public interface MetricsModule { + + @Qualifier + @interface FutureItemsMetric {} + + @Qualifier + @interface SubnetSubscriptionsMetric {} + + @Qualifier + @interface PerformanceTrackerTimings {} + + @Provides + @Singleton + @FutureItemsMetric + static SettableLabelledGauge futureItemsMetric(MetricsSystem metricsSystem) { + return SettableLabelledGauge.create( + metricsSystem, + BEACON, + "future_items_size", + "Current number of items held for future slots, labelled by type", + "type"); + } + + @Provides + @Singleton + @SubnetSubscriptionsMetric + static SettableLabelledGauge provideSubnetSubscriptionsMetric(MetricsSystem metricsSystem) { + return SettableLabelledGauge.create( + metricsSystem, + TekuMetricCategory.NETWORK, + "subnet_subscriptions", + "Tracks attestations subnet subscriptions", + "type"); + } + + @Provides + @Singleton + @PerformanceTrackerTimings + static SettableGauge providePerformanceTrackerTimings(MetricsSystem metricsSystem) { + return SettableGauge.create( + metricsSystem, + BEACON, + "performance_tracker_timings", + "Tracks how much time (in millis) performance tracker takes to perform calculations"); + } + + @Provides + @Singleton + static FutureItems provideFutureBlobSidecars( + @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { + return FutureItems.create(BlobSidecar::getSlot, futureItemsMetric, "blob_sidecars"); + } + + @Provides + @Singleton + static ValidatorPerformanceMetrics provideValidatorPerformanceMetrics( + MetricsSystem metricsSystem) { + return new ValidatorPerformanceMetrics(metricsSystem); + } + + @Provides + @Singleton + static PerformanceTracker providePerformanceTracker( + Spec spec, + ValidatorConfig validatorConfig, + CombinedChainDataClient combinedChainDataClient, + @PerformanceTrackerTimings SettableGauge performanceTrackerTimings, + EventChannelSubscriber slotEventsChannelSubscriber, + ValidatorPerformanceMetrics validatorPerformanceMetrics, + ActiveValidatorTracker activeValidatorTracker, + StatusLogger statusLogger) { + ValidatorPerformanceTrackingMode mode = validatorConfig.getValidatorPerformanceTrackingMode(); + if (mode.isEnabled()) { + DefaultPerformanceTracker performanceTracker = + new DefaultPerformanceTracker( + combinedChainDataClient, + statusLogger, + validatorPerformanceMetrics, + validatorConfig.getValidatorPerformanceTrackingMode(), + activeValidatorTracker, + new SyncCommitteePerformanceTracker(spec, combinedChainDataClient), + spec, + performanceTrackerTimings); + slotEventsChannelSubscriber.subscribe(performanceTracker); + return performanceTracker; + } else { + return new NoOpPerformanceTracker(); + } + } + + // TODO not used + @Provides + @Singleton + static SyncCommitteeMetrics provideSyncCommitteeMetrics( + Spec spec, + RecentChainData recentChainData, + MetricsSystem metricsSystem, + EventChannelSubscriber slotEventsChannelSubscriber, + EventChannelSubscriber chainHeadChannelSubscriber) { + SyncCommitteeMetrics syncCommitteeMetrics = + new SyncCommitteeMetrics(spec, recentChainData, metricsSystem); + slotEventsChannelSubscriber.subscribe(syncCommitteeMetrics); + chainHeadChannelSubscriber.subscribe(syncCommitteeMetrics); + return syncCommitteeMetrics; + } + + // TODO not used + @Provides + @Singleton + static BeaconChainMetrics provideBeaconChainMetrics( + Spec spec, + MetricsSystem metricsSystem, + RecentChainData recentChainData, + SlotProcessor slotProcessor, + Eth2P2PNetwork p2pNetwork, + Eth1DataCache eth1DataCache, + EventChannelSubscriber slotEventsChannelSubscriber) { + + final BeaconChainMetrics beaconChainMetrics = + new BeaconChainMetrics( + spec, + recentChainData, + slotProcessor.getNodeSlot(), + metricsSystem, + p2pNetwork, + eth1DataCache); + slotEventsChannelSubscriber.subscribe(beaconChainMetrics); + return beaconChainMetrics; + } + + @Provides + @Singleton + static BlockProductionAndPublishingPerformanceFactory + blockProductionAndPublishingPerformanceFactory( + TimeProvider timeProvider, RecentChainData recentChainData, MetricsConfig metricsConfig) { + return new BlockProductionAndPublishingPerformanceFactory( + timeProvider, + (slot) -> secondsToMillis(recentChainData.computeTimeAtSlot(slot)), + metricsConfig.isBlockProductionAndPublishingPerformanceEnabled(), + metricsConfig.getBlockProductionPerformanceWarningLocalThreshold(), + metricsConfig.getBlockProductionPerformanceWarningBuilderThreshold(), + metricsConfig.getBlockPublishingPerformanceWarningLocalThreshold(), + metricsConfig.getBlockPublishingPerformanceWarningBuilderThreshold()); + } + + @Provides + @Singleton + static DutyMetrics dutyMetrics( + MetricsSystem metricsSystem, + Spec spec, + TimeProvider timeProvider, + RecentChainData recentChainData) { + return DutyMetrics.create(metricsSystem, timeProvider, recentChainData, spec); + } + + @Provides + @Singleton + static FutureItems futureAttestations( + @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { + return FutureItems.create( + ValidatableAttestation::getEarliestSlotForForkChoiceProcessing, + UInt64.valueOf(3), + futureItemsMetric, + "attestations"); + } + + @Provides + @Singleton + static FutureItems futureBlocks( + @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { + return FutureItems.create(SignedBeaconBlock::getSlot, futureItemsMetric, "blocks"); + } + + @Provides + @Singleton + static Optional blockImportMetrics( + MetricsConfig metricsConfig, MetricsSystem metricsSystem) { + return metricsConfig.isBlockPerformanceEnabled() + ? Optional.of(BlockImportMetrics.create(metricsSystem)) + : Optional.empty(); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java new file mode 100644 index 00000000000..d9fdad44d21 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java @@ -0,0 +1,15 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import javax.inject.Singleton; +import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; +import tech.pegasys.teku.kzg.KZG; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; + +@Module +public interface MiscModule { + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java new file mode 100644 index 00000000000..578f754d260 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java @@ -0,0 +1,127 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.io.PortAvailability; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.kzg.KZG; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder; +import tech.pegasys.teku.networking.eth2.P2PConfig; +import tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork; +import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.NetworkAsyncRunner; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.statetransition.LocalOperationAcceptedFilter; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; +import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.store.KeyValueStore; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; + +import javax.inject.Singleton; +import java.util.Optional; + +@Module +public interface NetworkModule { + + @Provides + static Eth2P2PNetworkBuilder eth2P2PNetworkBuilder() { + return Eth2P2PNetworkBuilder.create(); + } + + @Provides + @Singleton + static Eth2P2PNetwork eth2P2PNetwork( + Spec spec, + P2PConfig p2pConfig, + MetricsSystem metricsSystem, + @NetworkAsyncRunner AsyncRunner networkAsyncRunner, + TimeProvider timeProvider, + EventChannels eventChannels, + KeyValueStore keyValueStore, + Eth2P2PNetworkBuilder eth2P2PNetworkBuilder, + CombinedChainDataClient combinedChainDataClient, + BlockManager blockManager, + BlobSidecarManager blobSidecarManager, + AttestationManager attestationManager, + OperationPool attesterSlashingPool, + OperationPool proposerSlashingPool, + OperationPool voluntaryExitPool, + SyncCommitteeContributionPool syncCommitteeContributionPool, + SyncCommitteeMessagePool syncCommitteeMessagePool, + OperationPool blsToExecutionChangePool, + KZG kzg, + WeakSubjectivityValidator weakSubjectivityValidator, + P2PDebugDataDumper p2pDebugDataDumper + ) { + if (!p2pConfig.getNetworkConfig().isEnabled()) { + return new NoOpEth2P2PNetwork(spec); + } + + DiscoveryConfig discoveryConfig = p2pConfig.getDiscoveryConfig(); + final Optional maybeUdpPort = + discoveryConfig.isDiscoveryEnabled() + ? Optional.of(discoveryConfig.getListenUdpPort()) + : Optional.empty(); + + PortAvailability.checkPortsAvailable( + p2pConfig.getNetworkConfig().getListenPort(), maybeUdpPort); + + // TODO adopt Dagger instead of eth2P2PNetworkBuilder() + Eth2P2PNetwork p2pNetwork = eth2P2PNetworkBuilder + .config(p2pConfig) + .eventChannels(eventChannels) + .combinedChainDataClient(combinedChainDataClient) + .gossipedBlockProcessor(blockManager::validateAndImportBlock) + .gossipedBlobSidecarProcessor(blobSidecarManager::validateAndPrepareForBlockImport) + .gossipedAttestationProcessor(attestationManager::addAttestation) + .gossipedAggregateProcessor(attestationManager::addAggregate) + .gossipedAttesterSlashingProcessor(attesterSlashingPool::addRemote) + .gossipedProposerSlashingProcessor(proposerSlashingPool::addRemote) + .gossipedVoluntaryExitProcessor(voluntaryExitPool::addRemote) + .gossipedSignedContributionAndProofProcessor(syncCommitteeContributionPool::addRemote) + .gossipedSyncCommitteeMessageProcessor(syncCommitteeMessagePool::addRemote) + .gossipedSignedBlsToExecutionChangeProcessor(blsToExecutionChangePool::addRemote) + .processedAttestationSubscriptionProvider( + attestationManager::subscribeToAttestationsToSend) + .metricsSystem(metricsSystem) + .timeProvider(timeProvider) + .asyncRunner(networkAsyncRunner) + .keyValueStore(keyValueStore) + .requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()) + .specProvider(spec) + .kzg(kzg) + .recordMessageArrival(true) + .p2pDebugDataDumper(p2pDebugDataDumper) + .build(); + + syncCommitteeMessagePool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeMessage)); + syncCommitteeContributionPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeContribution)); + proposerSlashingPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishProposerSlashing)); + attesterSlashingPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishAttesterSlashing)); + voluntaryExitPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishVoluntaryExit)); + blsToExecutionChangePool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishSignedBlsToExecutionChange)); + + return p2pNetwork; + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java new file mode 100644 index 00000000000..55b622c86f9 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java @@ -0,0 +1,261 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.collections.LimitedMap; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.OperationPoolAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.SpecModule.SchemaSupplier; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.capella.BeaconBlockBodySchemaCapella; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.spec.datastructures.operations.VoluntaryExit; +import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; +import tech.pegasys.teku.statetransition.MappedOperationPool; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.SimpleOperationPool; +import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.block.BlockImportChannel; +import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils; +import tech.pegasys.teku.statetransition.util.BlockBlobSidecarsTrackersPoolImpl; +import tech.pegasys.teku.statetransition.util.PendingPool; +import tech.pegasys.teku.statetransition.util.PoolFactory; +import tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator; +import tech.pegasys.teku.statetransition.validation.InternalValidationResult; +import tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator; +import tech.pegasys.teku.statetransition.validation.SignedBlsToExecutionChangeValidator; +import tech.pegasys.teku.statetransition.validation.VoluntaryExitValidator; +import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; +import tech.pegasys.teku.storage.client.RecentChainData; + +import javax.inject.Qualifier; +import javax.inject.Singleton; +import java.util.Comparator; +import java.util.Map; +import java.util.Optional; + +import static tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool.DEFAULT_MAXIMUM_ATTESTATION_COUNT; + +@Module +public interface PoolAndCachesModule { + + @Qualifier + @interface InvalidBlockRoots {} + + @Qualifier + @interface InvalidBlobSidecarRoots {} + + @Provides + @Singleton + static PoolFactory poolFactory(MetricsSystem metricsSystem) { + return new PoolFactory(metricsSystem); + } + + @Provides + @Singleton + static PendingPool pendingBlocksPool( + Spec spec, + PoolFactory poolFactory, + EventChannelSubscriber channelSubscriber) { + PendingPool pool = poolFactory.createPendingPoolForBlocks(spec); + channelSubscriber.subscribe(pool); + return pool; + } + + @Provides + @Singleton + @InvalidBlockRoots + static Map invalidBlockRoots() { + return LimitedMap.createSynchronizedLRU(500); + } + + @Provides + @Singleton + @InvalidBlobSidecarRoots + static Map invalidBlobSidecarRoots() { + return LimitedMap.createSynchronizedLRU(500); + } + + @Provides + @Singleton + static BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool( + Spec spec, + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, + TimeProvider timeProvider, + RecentChainData recentChainData, + BlockImportChannel blockImportChannel, + PoolFactory poolFactory, + EventChannelSubscriber finalizedCheckpointChannelSubscriber) { + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + final BlockBlobSidecarsTrackersPoolImpl pool = + poolFactory.createPoolForBlockBlobSidecarsTrackers( + blockImportChannel, spec, timeProvider, beaconAsyncRunner, recentChainData); + finalizedCheckpointChannelSubscriber.subscribe(pool); + return pool; + } else { + return BlockBlobSidecarsTrackersPool.NOOP; + } + } + + @Provides + @Singleton + static OperationPool attesterSlashingPool( + MetricsSystem metricsSystem, + SchemaSupplier> beaconBlockSchemaSupplier, + BlockImporter blockImporter, + AttesterSlashingValidator attesterSlashingValidator, + ForkChoice forkChoice) { + OperationPool attesterSlashingPool = + new SimpleOperationPool<>( + "AttesterSlashingPool", + metricsSystem, + beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getAttesterSlashingsSchema), + attesterSlashingValidator, + // Prioritise slashings that include more validators at a time + Comparator.comparingInt( + slashing -> slashing.getIntersectingValidatorIndices().size()) + .reversed()); + blockImporter.subscribeToVerifiedBlockAttesterSlashings(attesterSlashingPool::removeAll); + attesterSlashingPool.subscribeOperationAdded(forkChoice::onAttesterSlashing); + return attesterSlashingPool; + } + + @Provides + @Singleton + static OperationPool proposerSlashingPool( + MetricsSystem metricsSystem, + SchemaSupplier> beaconBlockSchemaSupplier, + BlockImporter blockImporter, + ProposerSlashingValidator validator) { + SimpleOperationPool proposerSlashingPool = + new SimpleOperationPool<>( + "ProposerSlashingPool", + metricsSystem, + beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getProposerSlashingsSchema), + validator); + blockImporter.subscribeToVerifiedBlockProposerSlashings(proposerSlashingPool::removeAll); + return proposerSlashingPool; + } + + @Provides + @Singleton + static OperationPool voluntaryExitPool( + MetricsSystem metricsSystem, + @OperationPoolAsyncRunner AsyncRunner operationPoolAsyncRunner, + TimeProvider timeProvider, + SchemaSupplier> beaconBlockSchemaSupplier, + BlockImporter blockImporter, + VoluntaryExitValidator validator) { + MappedOperationPool voluntaryExitPool = + new MappedOperationPool<>( + "VoluntaryExitPool", + metricsSystem, + beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getVoluntaryExitsSchema), + validator, + operationPoolAsyncRunner, + timeProvider); + blockImporter.subscribeToVerifiedBlockVoluntaryExits(voluntaryExitPool::removeAll); + return voluntaryExitPool; + } + + @Provides + @Singleton + static OperationPool signedBlsToExecutionChangePool( + MetricsSystem metricsSystem, + @OperationPoolAsyncRunner AsyncRunner operationPoolAsyncRunner, + TimeProvider timeProvider, + SchemaSupplier> beaconBlockSchemaSupplier, + BlockImporter blockImporter, + SignedBlsToExecutionChangeValidator validator) { + OperationPool blsToExecutionChangePool = + new MappedOperationPool<>( + "SignedBlsToExecutionChangePool", + metricsSystem, + beaconBlockSchemaSupplier + .andThen(BeaconBlockBodySchema::toVersionCapella) + .andThen(Optional::orElseThrow) + .andThen(BeaconBlockBodySchemaCapella::getBlsToExecutionChangesSchema), + validator, + operationPoolAsyncRunner, + timeProvider); + blockImporter.subscribeToVerifiedBlockBlsToExecutionChanges( + blsToExecutionChangePool::removeAll); + return blsToExecutionChangePool; + } + + @Provides + @Singleton + static PendingPool pendingAttestationPool( + Spec spec, + PoolFactory poolFactory, + EventChannelSubscriber finalizedCheckpointChannelSubscriber) { + final PendingPool pendingAttestations = + poolFactory.createPendingPoolForAttestations(spec); + finalizedCheckpointChannelSubscriber.subscribe(pendingAttestations); + return pendingAttestations; + } + + @Provides + @Singleton + static SyncCommitteeContributionPool syncCommitteeContributionPool( + Spec spec, + SignedContributionAndProofValidator signedContributionAndProofValidator, + EventChannelSubscriber slotEventsChannelSubscriber) { + SyncCommitteeContributionPool syncCommitteeContributionPool = + new SyncCommitteeContributionPool(spec, signedContributionAndProofValidator); + + slotEventsChannelSubscriber.subscribe(syncCommitteeContributionPool); + return syncCommitteeContributionPool; + } + + @Provides + @Singleton + static SyncCommitteeMessagePool syncCommitteeMessagePool( + Spec spec, + SyncCommitteeMessageValidator syncCommitteeMessageValidator, + EventChannelSubscriber slotEventsChannelSubscriber) { + SyncCommitteeMessagePool syncCommitteeMessagePool = + new SyncCommitteeMessagePool(spec, syncCommitteeMessageValidator); + slotEventsChannelSubscriber.subscribe(syncCommitteeMessagePool); + return syncCommitteeMessagePool; + } + + @Provides + @Singleton + static AggregatingAttestationPool aggregatingAttestationPool( + Spec spec, + RecentChainData recentChainData, + MetricsSystem metricsSystem, + BlockImporter blockImporter, + EventChannelSubscriber slotEventsChannelSubscriber) { + AggregatingAttestationPool attestationPool = + new AggregatingAttestationPool( + spec, recentChainData, metricsSystem, DEFAULT_MAXIMUM_ATTESTATION_COUNT); + slotEventsChannelSubscriber.subscribe(attestationPool); + blockImporter.subscribeToVerifiedBlockAttestations( + attestationPool::onAttestationsIncludedInBlock); + return attestationPool; + } + + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java new file mode 100644 index 00000000000..a31ad09b32f --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java @@ -0,0 +1,130 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import java.util.Optional; +import javax.inject.Qualifier; +import javax.inject.Singleton; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.execution.types.Eth1Address; +import tech.pegasys.teku.ethereum.pow.api.Eth1EventsChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.powchain.PowchainConfiguration; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; +import tech.pegasys.teku.storage.api.Eth1DepositStorageChannel; +import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; +import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.api.ValidatorConfig; +import tech.pegasys.teku.validator.coordinator.DepositProvider; +import tech.pegasys.teku.validator.coordinator.Eth1DataCache; +import tech.pegasys.teku.validator.coordinator.Eth1VotingPeriod; + +import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; + +@Module +public interface PowModule { + + @Qualifier + @interface ProposerDefaultFeeRecipient{ + +} + + @Provides + @Singleton + static Optional provideTerminalPowBlockMonitor( + Spec spec, + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, + TimeProvider timeProvider, + ExecutionLayerChannel executionLayer, + RecentChainData recentChainData, + ForkChoiceNotifier forkChoiceNotifier, + EventLogger eventLogger) { + if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + return Optional.of( + new TerminalPowBlockMonitor( + executionLayer, + spec, + recentChainData, + forkChoiceNotifier, + beaconAsyncRunner, + eventLogger, + timeProvider)); + } else { + return Optional.empty(); + } + } + + @Provides + @Singleton + static Eth1DataCache provideEth1DataCache(Spec spec, MetricsSystem metricsSystem) { + return new Eth1DataCache(spec, metricsSystem, new Eth1VotingPeriod(spec)); + } + + @Provides + @Singleton + static DepositProvider provideDepositProvider( + Spec spec, + PowchainConfiguration powchainConfig, + MetricsSystem metricsSystem, + RecentChainData recentChainData, + Eth1DataCache eth1DataCache, + StorageUpdateChannel storageUpdateChannel, + Eth1DepositStorageChannel eth1DepositStorageChannel, + EventChannelSubscriber eth1EventsChannelSubscriber, + EventChannelSubscriber finalizedCheckpointChannelSubscriber, + EventChannelSubscriber slotEventsChannelSubscriber, + EventLogger eventLogger + ) { + DepositProvider depositProvider = + new DepositProvider( + metricsSystem, + recentChainData, + eth1DataCache, + storageUpdateChannel, + eth1DepositStorageChannel, + spec, + eventLogger, + powchainConfig.useMissingDepositEventLogging()); + eth1EventsChannelSubscriber.subscribe(depositProvider); + finalizedCheckpointChannelSubscriber.subscribe(depositProvider); + slotEventsChannelSubscriber.subscribe(depositProvider); + + return depositProvider; + } + + @Provides + @Singleton + @ProposerDefaultFeeRecipient + static Optional proposerDefaultFeeRecipient( + Spec spec, + ValidatorConfig validatorConfig, + BeaconRestApiConfig restApiConfig, + StatusLogger statusLogger + ) { + if (!spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + return Optional.of(Eth1Address.ZERO); + } + + final Optional defaultFeeRecipient = + validatorConfig.getProposerDefaultFeeRecipient(); + + if (defaultFeeRecipient.isEmpty() && restApiConfig.isRestApiEnabled()) { + statusLogger.warnMissingProposerDefaultFeeRecipientWithRestAPIEnabled(); + } + + return defaultFeeRecipient; + } + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java new file mode 100644 index 00000000000..150ae8134d4 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java @@ -0,0 +1,54 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.service.serviceutils.ServiceConfig; +import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; + +import javax.inject.Qualifier; +import javax.inject.Singleton; +import java.util.function.IntSupplier; + +@Module +public interface ServiceConfigModule { + + @Qualifier + @interface RejectedExecutionCountSupplier {} + + @Provides + static DataDirLayout provideDataDirLayout(ServiceConfig config){ + return config.getDataDirLayout(); + } + + @Provides + static AsyncRunnerFactory provideAsyncRunnerFactory(ServiceConfig config){ + return config.getAsyncRunnerFactory(); + } + + @Provides + static TimeProvider provideTimeProvider(ServiceConfig config){ + return config.getTimeProvider(); + } + + @Provides + static EventChannels provideEventChannels(ServiceConfig config){ + return config.getEventChannels(); + } + + @Provides + static MetricsSystem provideMetricsSystem(ServiceConfig config){ + return config.getMetricsSystem(); + } + + @Provides + @Singleton + @RejectedExecutionCountSupplier + static IntSupplier provideRejectedExecutionCountSupplier(ServiceConfig config) { + return config.getRejectedExecutionsSupplier(); + } + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java new file mode 100644 index 00000000000..47476458885 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -0,0 +1,40 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.api.RewardCalculator; +import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; +import tech.pegasys.teku.spec.logic.common.util.BlockRewardCalculatorUtil; + +import javax.inject.Singleton; +import java.util.function.Function; + +@Module +public interface SpecModule { + + @FunctionalInterface + interface SchemaSupplier> extends Function { + + @Override + default T apply(UInt64 slot) { + return getSchemaAtSlot(slot); + } + + T getSchemaAtSlot(UInt64 slot); + } + + @Provides + @Singleton + static SchemaSupplier> provideBeaconBlockBodySchemaSupplier(Spec spec) { + return slot -> spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockBodySchema(); + } + + @Provides + @Singleton + static RewardCalculator provideRewardCalculator(Spec spec) { + return new RewardCalculator(spec, new BlockRewardCalculatorUtil(spec)); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java new file mode 100644 index 00000000000..71799771922 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -0,0 +1,58 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Binds; +import dagger.Module; +import dagger.Provides; +import org.apache.tuweni.bytes.Bytes; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.storage.api.CombinedStorageChannel; +import tech.pegasys.teku.storage.api.StorageQueryChannel; +import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.EarliestAvailableBlockSlot; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.storage.store.FileKeyValueStore; +import tech.pegasys.teku.storage.store.KeyValueStore; +import tech.pegasys.teku.storage.store.StoreConfig; + +import javax.inject.Singleton; + +@Module +public interface StorageModule { + + String KEY_VALUE_STORE_SUBDIRECTORY = "kvstore"; + + @Binds + StorageQueryChannel bindStorageQueryChannel(CombinedStorageChannel combinedStorageChannel); + + @Binds + StorageUpdateChannel bindStorageUpdateChannel(CombinedStorageChannel combinedStorageChannel); + + @Provides + @Singleton + static KeyValueStore keyValueStore(DataDirLayout dataDirLayout) { + return new FileKeyValueStore( + dataDirLayout.getBeaconDataDirectory().resolve(KEY_VALUE_STORE_SUBDIRECTORY)); + } + + @Provides + @Singleton + static EarliestAvailableBlockSlot earliestAvailableBlockSlot( + StoreConfig storeConfig, TimeProvider timeProvider, StorageQueryChannel storageQueryChannel) { + return new EarliestAvailableBlockSlot( + storageQueryChannel, timeProvider, storeConfig.getEarliestAvailableBlockSlotFrequency()); + } + + @Provides + @Singleton + static CombinedChainDataClient combinedChainDataClient( + Spec spec, + StorageQueryChannel storageQueryChannel, + RecentChainData recentChainData, + EarliestAvailableBlockSlot earliestAvailableBlockSlot) { + return new CombinedChainDataClient( + recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java new file mode 100644 index 00000000000..56b01fcb5ef --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java @@ -0,0 +1,100 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.networking.eth2.P2PConfig; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AllSubnetsSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AllSyncCommitteeSubscriptions; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.NodeBasedStableSubnetSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.StableSubnetSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager; +import tech.pegasys.teku.spec.Spec; + +import javax.inject.Singleton; + +@Module +public interface SubnetsModule { + + @Provides + @Singleton + static AttestationTopicSubscriber provideAttestationTopicSubscriber( + @MetricsModule.SubnetSubscriptionsMetric SettableLabelledGauge subnetSubscriptionsMetric, + Spec spec, + P2PConfig p2pConfig, + EventChannelSubscriber slotEventsChannelSubscriber, + Eth2P2PNetwork p2pNetwork) { + AttestationTopicSubscriber attestationTopicSubscriber = + new AttestationTopicSubscriber(spec, p2pNetwork, subnetSubscriptionsMetric); + if (p2pConfig.isSubscribeAllSubnetsEnabled()) { + slotEventsChannelSubscriber.subscribe(attestationTopicSubscriber); + } + return attestationTopicSubscriber; + } + + @Provides + @Singleton + static SyncCommitteeSubscriptionManager provideSyncCommitteeSubscriptionManager( + Spec spec, + P2PConfig p2pConfig, + EventChannelSubscriber slotEventsChannelSubscriber, + Eth2P2PNetwork p2pNetwork) { + SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager = + p2pConfig.isSubscribeAllSubnetsEnabled() + ? new AllSyncCommitteeSubscriptions(p2pNetwork, spec) + : new SyncCommitteeSubscriptionManager(p2pNetwork); + slotEventsChannelSubscriber.subscribe(syncCommitteeSubscriptionManager); + return syncCommitteeSubscriptionManager; + } + + @Provides + @Singleton + static StableSubnetSubscriber stableSubnetSubscriber( + Spec spec, + P2PConfig p2pConfig, + Eth2P2PNetwork p2pNetwork, + AttestationTopicSubscriber attestationTopicSubscriber, + EventChannelSubscriber slotEventsChannelSubscriber, + LoggingModule.InitLogger logger) { + final StableSubnetSubscriber stableSubnetSubscriber; + if (p2pConfig.isSubscribeAllSubnetsEnabled()) { + logger.logger().info("Subscribing to all attestation subnets"); + stableSubnetSubscriber = + AllSubnetsSubscriber.create(attestationTopicSubscriber, spec.getNetworkingConfig()); + } else { + if (p2pNetwork.getDiscoveryNodeId().isPresent()) { + stableSubnetSubscriber = + new NodeBasedStableSubnetSubscriber( + attestationTopicSubscriber, spec, p2pNetwork.getDiscoveryNodeId().get()); + } else { + logger + .logger() + .warn("Discovery nodeId is not defined, disabling stable subnet subscriptions"); + stableSubnetSubscriber = StableSubnetSubscriber.NOOP; + } + } + slotEventsChannelSubscriber.subscribe(stableSubnetSubscriber); + return stableSubnetSubscriber; + } + + @Provides + @Singleton + static SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager( + Spec spec, P2PConfig p2pConfig, + EventChannelSubscriber slotEventsChannelSubscriber, + Eth2P2PNetwork p2pNetwork) { + + final SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager; + if (p2pConfig.isSubscribeAllSubnetsEnabled()) { + syncCommitteeSubscriptionManager = new AllSyncCommitteeSubscriptions(p2pNetwork, spec); + slotEventsChannelSubscriber.subscribe(syncCommitteeSubscriptionManager); + } else { + syncCommitteeSubscriptionManager = new SyncCommitteeSubscriptionManager(p2pNetwork); + } + return syncCommitteeSubscriptionManager; + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java new file mode 100644 index 00000000000..8454538b403 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java @@ -0,0 +1,120 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.beacon.sync.DefaultSyncServiceFactory; +import tech.pegasys.teku.beacon.sync.SyncConfig; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.beacon.sync.SyncServiceFactory; +import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; +import tech.pegasys.teku.statetransition.util.PendingPool; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.coordinator.DepositProvider; + +import javax.inject.Singleton; +import java.time.Duration; +import java.util.Optional; + +@Module +public interface SyncModule { + + @Provides + @Singleton + static SyncServiceFactory syncServiceFactory( + Spec spec, + SyncConfig syncConfig, + Eth2NetworkConfiguration eth2NetworkConfig, + MetricsSystem metricsSystem, + AsyncRunnerFactory asyncRunnerFactory, + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, + TimeProvider timeProvider, + RecentChainData recentChainData, + CombinedChainDataClient combinedChainDataClient, + StorageUpdateChannel storageUpdateChannel, + Eth2P2PNetwork p2pNetwork, + BlockImporter blockImporter, + BlobSidecarManager blobSidecarManager, + PendingPool pendingBlocksPool, + BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + SignatureVerificationService signatureVerificationService) { + return new DefaultSyncServiceFactory( + syncConfig, + eth2NetworkConfig.getNetworkBoostrapConfig().getGenesisState(), + metricsSystem, + asyncRunnerFactory, + beaconAsyncRunner, + timeProvider, + recentChainData, + combinedChainDataClient, + storageUpdateChannel, + p2pNetwork, + blockImporter, + blobSidecarManager, + pendingBlocksPool, + blockBlobSidecarsTrackersPool, + eth2NetworkConfig.getStartupTargetPeerCount(), + signatureVerificationService, + Duration.ofSeconds(eth2NetworkConfig.getStartupTimeoutSeconds()), + spec); + } + + @Provides + @Singleton + static SyncService syncService( + SyncServiceFactory syncServiceFactory, + EventChannels eventChannels, + ForkChoice forkChoice, + ForkChoiceNotifier forkChoiceNotifier, + DepositProvider depositProvider, + Optional terminalPowBlockMonitor, + Eth2P2PNetwork p2pNetwork, + CoalescingChainHeadChannel coalescingChainHeadChannel) { + SyncService syncService = syncServiceFactory.create(eventChannels); + + // chainHeadChannel subscription + syncService.getForwardSync().subscribeToSyncChanges(coalescingChainHeadChannel); + + // forkChoiceNotifier subscription + syncService.subscribeToSyncStateChangesAndUpdate( + syncState -> forkChoiceNotifier.onSyncingStatusChanged(syncState.isInSync())); + + // depositProvider subscription + syncService.subscribeToSyncStateChangesAndUpdate( + syncState -> depositProvider.onSyncingStatusChanged(syncState.isInSync())); + + // forkChoice subscription + forkChoice.subscribeToOptimisticHeadChangesAndUpdate(syncService.getOptimisticSyncSubscriber()); + + // terminalPowBlockMonitor subscription + terminalPowBlockMonitor.ifPresent( + monitor -> + syncService.subscribeToSyncStateChangesAndUpdate( + syncState -> monitor.onNodeSyncStateChanged(syncState.isInSync()))); + + // p2pNetwork subscription so gossip can be enabled and disabled appropriately + syncService.subscribeToSyncStateChangesAndUpdate( + state -> p2pNetwork.onSyncStateChanged(state.isInSync(), state.isOptimistic())); + + return syncService; + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java new file mode 100644 index 00000000000..d39d617b4e6 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -0,0 +1,252 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import javax.inject.Singleton; +import tech.pegasys.teku.api.ChainDataProvider; +import tech.pegasys.teku.api.DataProvider; +import tech.pegasys.teku.api.RewardCalculator; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionChannel; +import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionProvider; +import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionAndPublishingPerformanceFactory; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipChannel; +import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager; +import tech.pegasys.teku.services.executionlayer.ExecutionLayerBlockManagerFactory; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.block.BlockImportChannel; +import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; +import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; +import tech.pegasys.teku.statetransition.util.FutureItems; +import tech.pegasys.teku.statetransition.util.PendingPool; +import tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator; +import tech.pegasys.teku.statetransition.validation.AttestationValidator; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.api.ValidatorConfig; +import tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker; +import tech.pegasys.teku.validator.coordinator.BlockFactory; +import tech.pegasys.teku.validator.coordinator.BlockOperationSelectorFactory; +import tech.pegasys.teku.validator.coordinator.DepositProvider; +import tech.pegasys.teku.validator.coordinator.DutyMetrics; +import tech.pegasys.teku.validator.coordinator.Eth1DataCache; +import tech.pegasys.teku.validator.coordinator.GraffitiBuilder; +import tech.pegasys.teku.validator.coordinator.MilestoneBasedBlockFactory; +import tech.pegasys.teku.validator.coordinator.ValidatorApiHandler; +import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; + +@Module +public interface ValidatorModule { + + @Provides + @Singleton + static ActiveValidatorTracker provideActiveValidatorTracker( + Spec spec, EventChannelSubscriber slotEventsChannelSubscriber) { + ActiveValidatorTracker activeValidatorTracker = new ActiveValidatorTracker(spec); + slotEventsChannelSubscriber.subscribe(activeValidatorTracker); + return activeValidatorTracker; + } + + @Provides + @Singleton + static ExecutionLayerBlockProductionManager provideExecutionLayerBlockProductionManager( + ExecutionLayerChannel executionLayer, + EventChannelSubscriber slotEventsChannelSubscriber) { + + return ExecutionLayerBlockManagerFactory.create(executionLayer, slotEventsChannelSubscriber); + } + + @Provides + @Singleton + static GraffitiBuilder provideGraffitiBuilder( + ValidatorConfig validatorConfig, + EventChannelSubscriber + executionClientVersionChannelSubscriber) { + GraffitiBuilder graffitiBuilder = + new GraffitiBuilder( + validatorConfig.getClientGraffitiAppendFormat(), + validatorConfig.getGraffitiProvider().get()); + executionClientVersionChannelSubscriber.subscribe(graffitiBuilder); + return graffitiBuilder; + } + + @Provides + @Singleton + static GraffitiBuilder provideGraffitiBuilder( + GraffitiBuilder graffitiBuilder, + ExecutionLayerChannel executionLayer, + ExecutionClientVersionChannel executionClientVersionChannelPublisher, + EventChannelSubscriber executionClientEventsChannelSubscriber) { + + final ExecutionClientVersionProvider executionClientVersionProvider = + new ExecutionClientVersionProvider( + executionLayer, + executionClientVersionChannelPublisher, + graffitiBuilder.getConsensusClientVersion()); + executionClientEventsChannelSubscriber.subscribe(executionClientVersionProvider); + return graffitiBuilder; + } + + @Provides + @Singleton + static BlockOperationSelectorFactory provideBlockOperationSelectorFactory( + Spec spec, + AggregatingAttestationPool attestationPool, + OperationPool attesterSlashingPool, + OperationPool proposerSlashingPool, + OperationPool voluntaryExitPool, + OperationPool blsToExecutionChangePool, + SyncCommitteeContributionPool syncCommitteeContributionPool, + DepositProvider depositProvider, + Eth1DataCache eth1DataCache, + ForkChoiceNotifier forkChoiceNotifier, + ExecutionLayerBlockProductionManager executionLayerBlockProductionManager, + GraffitiBuilder graffitiBuilder) { + + return new BlockOperationSelectorFactory( + spec, + attestationPool, + attesterSlashingPool, + proposerSlashingPool, + voluntaryExitPool, + blsToExecutionChangePool, + syncCommitteeContributionPool, + depositProvider, + eth1DataCache, + graffitiBuilder, + forkChoiceNotifier, + executionLayerBlockProductionManager); + } + + @Provides + @Singleton + static BlockFactory blockFactory( + Spec spec, BlockOperationSelectorFactory blockOperationSelectorFactory) { + return new MilestoneBasedBlockFactory(spec, blockOperationSelectorFactory); + } + + @Provides + @Singleton + static ChainDataProvider chainDataProvider( + Spec spec, + RecentChainData recentChainData, + CombinedChainDataClient combinedChainDataClient, + RewardCalculator rewardCalculator) { + return new ChainDataProvider(spec, recentChainData, combinedChainDataClient, rewardCalculator); + } + + @Provides + @Singleton + static ValidatorApiHandler validatorApiHandler( + Spec spec, + ChainDataProvider chainDataProvider, + DataProvider dataProvider, + CombinedChainDataClient combinedChainDataClient, + SyncService syncService, + BlockFactory blockFactory, + BlockImportChannel blockImportChannel, + BlockGossipChannel blockGossipChannel, + BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + BlobSidecarGossipChannel blobSidecarGossipChannel, + AggregatingAttestationPool attestationPool, + AttestationManager attestationManager, + AttestationTopicSubscriber attestationTopicSubscriber, + ActiveValidatorTracker activeValidatorTracker, + DutyMetrics dutyMetrics, + PerformanceTracker performanceTracker, + ForkChoiceTrigger forkChoiceTrigger, + ProposersDataManager proposersDataManager, + SyncCommitteeMessagePool syncCommitteeMessagePool, + SyncCommitteeContributionPool syncCommitteeContributionPool, + SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager, + BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory) { + return new ValidatorApiHandler( + chainDataProvider, + dataProvider.getNodeDataProvider(), + combinedChainDataClient, + syncService, + blockFactory, + blockImportChannel, + blockGossipChannel, + blockBlobSidecarsTrackersPool, + blobSidecarGossipChannel, + attestationPool, + attestationManager, + attestationTopicSubscriber, + activeValidatorTracker, + dutyMetrics, + performanceTracker, + spec, + forkChoiceTrigger, + proposersDataManager, + syncCommitteeMessagePool, + syncCommitteeContributionPool, + syncCommitteeSubscriptionManager, + blockProductionPerformanceFactory); + } + + @Provides + @Singleton + static AttestationManager attestationManager( + Spec spec, + BlockImporter blockImporter, + AggregateAttestationValidator aggregateValidator, + PendingPool pendingAttestations, + FutureItems futureAttestations, + ForkChoice forkChoice, + AggregatingAttestationPool attestationPool, + AttestationValidator attestationValidator, + SignatureVerificationService signatureVerificationService, + ActiveValidatorChannel activeValidatorChannel, + EventChannelSubscriber slotEventsChannelSubscriber, + EventChannelSubscriber receivedBlockEventsChannelSubscriber) { + + // TODO + blockImporter.subscribeToVerifiedBlockAttestations( + (slot, attestations) -> + attestations.forEach( + attestation -> + aggregateValidator.addSeenAggregate( + ValidatableAttestation.from(spec, attestation)))); + + AttestationManager attestationManager = + AttestationManager.create( + pendingAttestations, + futureAttestations, + forkChoice, + attestationPool, + attestationValidator, + aggregateValidator, + signatureVerificationService, + activeValidatorChannel); + + slotEventsChannelSubscriber.subscribe(attestationManager); + receivedBlockEventsChannelSubscriber.subscribe(attestationManager); + + return attestationManager; + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java new file mode 100644 index 00000000000..17caa71f4a6 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java @@ -0,0 +1,143 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; +import tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator; +import tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils; +import tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator; +import tech.pegasys.teku.statetransition.validation.AttestationValidator; +import tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator; +import tech.pegasys.teku.statetransition.validation.BlockGossipValidator; +import tech.pegasys.teku.statetransition.validation.BlockValidator; +import tech.pegasys.teku.statetransition.validation.GossipValidationHelper; +import tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator; +import tech.pegasys.teku.statetransition.validation.SignedBlsToExecutionChangeValidator; +import tech.pegasys.teku.statetransition.validation.VoluntaryExitValidator; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.storage.client.RecentChainData; + +import javax.inject.Singleton; + +@Module +public interface VerifyModule { + @Provides + @Singleton + static GossipValidationHelper provideGossipValidationHelper( + Spec spec, RecentChainData recentChainData) { + return new GossipValidationHelper(spec, recentChainData); + } + + @Provides + @Singleton + static AttesterSlashingValidator provideAttesterSlashingValidator( + Spec spec, RecentChainData recentChainData) { + return new AttesterSlashingValidator(recentChainData, spec); + } + + @Provides + @Singleton + static ProposerSlashingValidator provideProposerSlashingValidator( + Spec spec, RecentChainData recentChainData) { + return new ProposerSlashingValidator(spec, recentChainData); + } + + @Provides + @Singleton + static VoluntaryExitValidator provideVoluntaryExitValidator( + Spec spec, RecentChainData recentChainData) { + return new VoluntaryExitValidator(spec, recentChainData); + } + + @Provides + @Singleton + static SignedBlsToExecutionChangeValidator provideSignedBlsToExecutionChangeValidator( + Spec spec, + TimeProvider timeProvider, + RecentChainData recentChainData, + SignatureVerificationService signatureVerificationService) { + return new SignedBlsToExecutionChangeValidator( + spec, timeProvider, recentChainData, signatureVerificationService); + } + + @Provides + @Singleton + static MergeTransitionBlockValidator provideMergeTransitionBlockValidator( + Spec spec, RecentChainData recentChainData, ExecutionLayerChannel executionLayer) { + return new MergeTransitionBlockValidator(spec, recentChainData, executionLayer); + } + + @Provides + @Singleton + static AttestationValidator attestationValidator( + Spec spec, + RecentChainData recentChainData, + SignatureVerificationService signatureVerificationService, + MetricsSystem metricsSystem) { + return new AttestationValidator( + spec, recentChainData, signatureVerificationService, metricsSystem); + } + + @Provides + @Singleton + static AggregateAttestationValidator aggregateAttestationValidator( + Spec spec, + AttestationValidator attestationValidator, + SignatureVerificationService signatureVerificationService) { + return new AggregateAttestationValidator( + spec, attestationValidator, signatureVerificationService); + } + + @Provides + @Singleton + static SyncCommitteeStateUtils syncCommitteeStateUtils( + Spec spec, RecentChainData recentChainData) { + return new SyncCommitteeStateUtils(spec, recentChainData); + } + + @Provides + @Singleton + static SignedContributionAndProofValidator signedContributionAndProofValidator( + Spec spec, + TimeProvider timeProvider, + RecentChainData recentChainData, + SyncCommitteeStateUtils syncCommitteeStateUtils, + SignatureVerificationService signatureVerificationService) { + return new SignedContributionAndProofValidator( + spec, recentChainData, syncCommitteeStateUtils, timeProvider, signatureVerificationService); + } + + @Provides + @Singleton + static SyncCommitteeMessageValidator syncCommitteeMessageValidator( + Spec spec, + TimeProvider timeProvider, + RecentChainData recentChainData, + SyncCommitteeStateUtils syncCommitteeStateUtils, + SignatureVerificationService signatureVerificationService) { + return new SyncCommitteeMessageValidator( + spec, recentChainData, syncCommitteeStateUtils, signatureVerificationService, timeProvider); + } + + @Provides + @Singleton + static BlockGossipValidator blockGossipValidator( + Spec spec, + GossipValidationHelper gossipValidationHelper, + ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher) { + return new BlockGossipValidator( + spec, gossipValidationHelper, receivedBlockEventsChannelPublisher); + } + + @Provides + @Singleton + static BlockValidator blockValidator(BlockGossipValidator blockGossipValidator) { + return new BlockValidator(blockGossipValidator); + } +} From a7639aead930dcee80c7e2fd6f9ba0654ab92432 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 19 Jun 2024 18:03:04 +0400 Subject: [PATCH 04/27] Add RecentChainData async creation and initialization. Add WSModule --- .../beaconchain/BeaconChainController.java | 15 +- .../beaconchain/init/BeaconConfigModule.java | 6 + .../beaconchain/init/ChannelsModule.java | 27 +- .../beaconchain/init/CryptoModule.java | 3 +- .../services/beaconchain/init/SpecModule.java | 12 + .../beaconchain/init/StorageModule.java | 231 +++++++++++++++++- .../services/beaconchain/init/SyncModule.java | 7 +- .../beaconchain/init/ValidatorModule.java | 8 + .../services/beaconchain/init/WSModule.java | 81 ++++++ 9 files changed, 373 insertions(+), 17 deletions(-) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index b899d98dcfe..a099c63bfc7 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -334,6 +334,7 @@ public BeaconChainController( "type"); } + // TODO @Override protected SafeFuture doStart() { LOG.debug("Starting {}", this.getClass().getSimpleName()); @@ -344,6 +345,7 @@ protected SafeFuture doStart() { beaconRestAPI.map(BeaconRestApi::start).orElse(SafeFuture.completedFuture(null))); } + // TODO protected void startServices() { final RecentBlocksFetcher recentBlocksFetcher = syncService.getRecentBlocksFetcher(); recentBlocksFetcher.subscribeBlockFetched( @@ -385,6 +387,7 @@ protected void startServices() { }); } + // TODO @Override protected SafeFuture doStop() { LOG.debug("Stopping {}", this.getClass().getSimpleName()); @@ -401,11 +404,13 @@ protected SafeFuture doStop() { } protected SafeFuture initialize() { + + timerService = new TimerService(this::onTick); // TODO + final StoreConfig storeConfig = beaconConfig.storeConfig(); coalescingChainHeadChannel = new CoalescingChainHeadChannel( eventChannels.getPublisher(ChainHeadChannel.class), EVENT_LOG); - timerService = new TimerService(this::onTick); final CombinedStorageChannel combinedStorageChannel = eventChannels.getPublisher(CombinedStorageChannel.class, beaconAsyncRunner); @@ -458,10 +463,13 @@ protected SafeFuture initialize() { .thenRun(this::initAll) .thenRun( () -> { + // TODO recentChainData.subscribeStoreInitialized(this::onStoreInitialized); recentChainData.subscribeBestBlockInitialized(this::startServices); }) - .thenCompose(__ -> timerService.start()); + .thenCompose(__ -> + timerService.start() // TODO + ); } private boolean isUsingCustomInitialState() { @@ -1411,7 +1419,6 @@ protected void setupInitialState(final RecentChainData client) { } } - // TODO private Optional tryLoadingAnchorPointFromInitialState( final Eth2NetworkConfiguration networkConfiguration) { Optional initialAnchor = Optional.empty(); @@ -1433,12 +1440,10 @@ private Optional tryLoadingAnchorPointFromInitialState( return initialAnchor; } - // TODO protected Optional attemptToLoadAnchorPoint(final Optional initialState) { return wsInitializer.loadInitialAnchorPoint(spec, initialState); } - // TODO protected void setupInteropState() { final InteropConfig config = beaconConfig.interopConfig(); STATUS_LOG.generatingMockStartGenesis( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java index a6c42987a55..1617e42263d 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java @@ -10,6 +10,7 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.storage.store.StoreConfig; import tech.pegasys.teku.validator.api.ValidatorConfig; +import tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig; @Module public interface BeaconConfigModule { @@ -48,4 +49,9 @@ static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config){ static Spec spec(BeaconChainConfiguration config){ return config.getSpec(); } + + @Provides + static WeakSubjectivityConfig weakSubjectivityConfig(BeaconChainConfiguration config) { + return config.weakSubjectivity(); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java index 169d73b4f3f..e9aa36a61ab 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java @@ -24,9 +24,9 @@ import tech.pegasys.teku.storage.api.CombinedStorageChannel; import tech.pegasys.teku.storage.api.Eth1DepositStorageChannel; import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; +import tech.pegasys.teku.storage.api.VoteUpdateChannel; import tech.pegasys.teku.validator.api.ValidatorApiChannel; - -import static tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG; +import tech.pegasys.teku.validator.api.ValidatorTimingChannel; @Module public interface ChannelsModule { @@ -75,8 +75,7 @@ static Eth1DepositStorageChannel eth1DepositStorageChannel( } @Provides - static ExecutionClientVersionChannel executionClientVersionChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + static ExecutionClientVersionChannel executionClientVersionChannel(EventChannels eventChannels) { return eventChannels.getPublisher(ExecutionClientVersionChannel.class); } @@ -100,13 +99,25 @@ static ReceivedBlockEventsChannel receivedBlockEventsChannel(EventChannels event } @Provides - static CoalescingChainHeadChannel coalescingChainHeadChannel(EventChannels eventChannels, EventLogger eventLogger) { - return - new CoalescingChainHeadChannel( - eventChannels.getPublisher(ChainHeadChannel.class), eventLogger); + static ChainHeadChannel chainHeadChannel(EventChannels eventChannels) { + return eventChannels.getPublisher(ChainHeadChannel.class); + } + + @Provides + static VoteUpdateChannel voteUpdateChannel(EventChannels eventChannels) { + return eventChannels.getPublisher(VoteUpdateChannel.class); + } + @Provides + static FinalizedCheckpointChannel finalizedCheckpointChannel( + EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + return eventChannels.getPublisher(FinalizedCheckpointChannel.class, asyncRunner); } + @Provides + static ValidatorTimingChannel validatorTimingChannel(EventChannels eventChannels) { + return eventChannels.getPublisher(ValidatorTimingChannel.class); + } // Subscribers diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java index f2dd4c85f43..aab9cef2321 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java @@ -9,6 +9,7 @@ import tech.pegasys.teku.kzg.KZG; import tech.pegasys.teku.networking.eth2.P2PConfig; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService; @@ -25,7 +26,7 @@ static SignatureVerificationService signatureVerificationService( P2PConfig p2PConfig, MetricsSystem metricsSystem, AsyncRunnerFactory asyncRunnerFactory, - @AsyncRunnerModule.BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { return new AggregatingSignatureVerificationService( metricsSystem, asyncRunnerFactory, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index 47476458885..d85fdaa8ec5 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -4,6 +4,7 @@ import dagger.Provides; import tech.pegasys.teku.api.RewardCalculator; import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema; +import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; @@ -15,6 +16,11 @@ @Module public interface SpecModule { + @FunctionalInterface + interface CurrentSlotProvider { + UInt64 getCurrentSlot(UInt64 genesisTime); + } + @FunctionalInterface interface SchemaSupplier> extends Function { @@ -37,4 +43,10 @@ static SchemaSupplier> provideBeaconBlockBodySchemaSupp static RewardCalculator provideRewardCalculator(Spec spec) { return new RewardCalculator(spec, new BlockRewardCalculatorUtil(spec)); } + + @Provides + @Singleton + static CurrentSlotProvider currentSlotProvider(Spec spec, TimeProvider timeProvider) { + return genesisTime -> spec.getCurrentSlot(timeProvider.getTimeInSeconds(), genesisTime); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index 71799771922..483a0543201 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -1,23 +1,57 @@ package tech.pegasys.teku.services.beaconchain.init; +import com.fasterxml.jackson.databind.ObjectMapper; import dagger.Binds; +import dagger.Lazy; import dagger.Module; import dagger.Provides; + +import javax.inject.Inject; +import javax.inject.Singleton; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.async.SafeFuture; +import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; +import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.networks.StateBoostrapConfig; import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; +import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; +import tech.pegasys.teku.services.beaconchain.WeakSubjectivityInitializer; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.SpecModule.CurrentSlotProvider; +import tech.pegasys.teku.services.beaconchain.init.WSModule.WeakSubjectivityPeriodValidator; import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; +import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder; +import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.storage.api.ChainHeadChannel; import tech.pegasys.teku.storage.api.CombinedStorageChannel; +import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; import tech.pegasys.teku.storage.api.StorageQueryChannel; import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.api.VoteUpdateChannel; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.EarliestAvailableBlockSlot; import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.storage.client.StorageBackedRecentChainData; +import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider; import tech.pegasys.teku.storage.store.FileKeyValueStore; import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.storage.store.StoreConfig; +import tech.pegasys.teku.validator.api.InteropConfig; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; -import javax.inject.Singleton; +import java.io.IOException; +import java.util.Optional; + +import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; @Module public interface StorageModule { @@ -40,7 +74,9 @@ static KeyValueStore keyValueStore(DataDirLayout dataDirLayout) { @Provides @Singleton static EarliestAvailableBlockSlot earliestAvailableBlockSlot( - StoreConfig storeConfig, TimeProvider timeProvider, StorageQueryChannel storageQueryChannel) { + StoreConfig storeConfig, + TimeProvider timeProvider, + StorageQueryChannel storageQueryChannel) { return new EarliestAvailableBlockSlot( storageQueryChannel, timeProvider, storeConfig.getEarliestAvailableBlockSlotFrequency()); } @@ -55,4 +91,195 @@ static CombinedChainDataClient combinedChainDataClient( return new CombinedChainDataClient( recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); } + + @Provides + @Singleton + static SafeFuture recentChainDataFuture( + @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, + TimeProvider timeProvider, + MetricsSystem metricsSystem, + Spec spec, + StoreConfig storeConfig, + StorageQueryChannel storageQueryChannel, + StorageUpdateChannel storageUpdateChannel, + BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + VoteUpdateChannel voteUpdateChannel, + FinalizedCheckpointChannel finalizedCheckpointChannel, + ChainHeadChannel chainHeadChannel, + ValidatorIsConnectedProvider validatorIsConnectedProvider) { + + return StorageBackedRecentChainData.create( + metricsSystem, + storeConfig, + beaconAsyncRunner, + timeProvider, + blockBlobSidecarsTrackersPool::getBlock, + blockBlobSidecarsTrackersPool::getBlobSidecar, + storageQueryChannel, + storageUpdateChannel, + voteUpdateChannel, + finalizedCheckpointChannel, + chainHeadChannel, + validatorIsConnectedProvider, + spec); + } + + @Provides + @Singleton + // TODO producer ? + static RecentChainData recentChainData( + Eth2NetworkConfiguration eth2NetworkConfig, + SafeFuture recentChainDataFuture, + StatusLogger statusLogger, + Lazy weakSubjectivityPeriodValidator, + Lazy recentChainDataStateInitializer) { + + RecentChainData recentChainData = recentChainDataFuture.join(); + + boolean isAllowSyncOutsideWeakSubjectivityPeriod = + eth2NetworkConfig.getNetworkBoostrapConfig().isAllowSyncOutsideWeakSubjectivityPeriod(); + boolean isUsingCustomInitialState = + eth2NetworkConfig.getNetworkBoostrapConfig().isUsingCustomInitialState(); + + if (isAllowSyncOutsideWeakSubjectivityPeriod) { + statusLogger.warnIgnoringWeakSubjectivityPeriod(); + } + + // Setup chain storage + if (recentChainData.isPreGenesis()) { + recentChainDataStateInitializer.get().setupInitialState(recentChainData); + } else { + if (isUsingCustomInitialState) { + statusLogger.warnInitialStateIgnored(); + } + if (!isAllowSyncOutsideWeakSubjectivityPeriod) { + weakSubjectivityPeriodValidator.get().validate(recentChainData); + } + } + + return recentChainData; + } + + class RecentChainDataStateInitializer { + + @Inject TimeProvider timeProvider; + @Inject BeaconChainConfiguration beaconConfig; + @Inject Spec spec; + @Inject CurrentSlotProvider currentSlotProvider; + @Inject WeakSubjectivityInitializer weakSubjectivityInitializer; + @Inject EventLogger eventLogger; + @Inject StatusLogger statusLogger; + + public void setupInitialState(RecentChainData recentChainData) { + + final Optional initialAnchor = + tryLoadingAnchorPointFromInitialState(beaconConfig.eth2NetworkConfig()) + .or( + () -> + attemptToLoadAnchorPoint( + beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().getGenesisState())); + + /* + If flag to allow sync outside of weak subjectivity period has been set, we pass an instance of + WeakSubjectivityPeriodCalculator to the WeakSubjectivityInitializer. Otherwise, we pass an Optional.empty(). + */ + boolean isAllowSyncOutsideWeakSubjectivityPeriod = + beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().isAllowSyncOutsideWeakSubjectivityPeriod(); + + final Optional maybeWsCalculator; + if (isAllowSyncOutsideWeakSubjectivityPeriod) { + maybeWsCalculator = Optional.empty(); + } else { + maybeWsCalculator = + Optional.of(WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity())); + } + + // Validate + initialAnchor.ifPresent( + anchor -> { + final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(anchor.getState().getGenesisTime()); + weakSubjectivityInitializer.validateInitialAnchor(anchor, currentSlot, spec, maybeWsCalculator); + }); + + if (initialAnchor.isPresent()) { + final AnchorPoint anchor = initialAnchor.get(); + recentChainData.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds()); + if (anchor.isGenesis()) { + eventLogger.genesisEvent( + anchor.getStateRoot(), + recentChainData.getBestBlockRoot().orElseThrow(), + anchor.getState().getGenesisTime()); + } + } else if (beaconConfig.interopConfig().isInteropEnabled()) { + setupInteropState(recentChainData); + } else if (!beaconConfig.powchainConfig().isEnabled()) { + throw new InvalidConfigurationException( + "ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state" + + "."); + } + } + + private Optional tryLoadingAnchorPointFromInitialState( + final Eth2NetworkConfiguration networkConfiguration) { + Optional initialAnchor = Optional.empty(); + + try { + initialAnchor = + attemptToLoadAnchorPoint( + networkConfiguration.getNetworkBoostrapConfig().getInitialState()); + } catch (final InvalidConfigurationException e) { + final StateBoostrapConfig stateBoostrapConfig = + networkConfiguration.getNetworkBoostrapConfig(); + if (stateBoostrapConfig.isUsingCustomInitialState() + && !stateBoostrapConfig.isUsingCheckpointSync()) { + throw e; + } + statusLogger.warnFailedToLoadInitialState(e.getMessage()); + } + + return initialAnchor; + } + + protected Optional attemptToLoadAnchorPoint(final Optional initialState) { + return weakSubjectivityInitializer.loadInitialAnchorPoint(spec, initialState); + } + + protected void setupInteropState(RecentChainData recentChainData) { + final InteropConfig config = beaconConfig.interopConfig(); + statusLogger.generatingMockStartGenesis( + config.getInteropGenesisTime(), config.getInteropNumberOfValidators()); + + Optional executionPayloadHeader = Optional.empty(); + if (config.getInteropGenesisPayloadHeader().isPresent()) { + try { + executionPayloadHeader = + Optional.of( + spec.deserializeJsonExecutionPayloadHeader( + new ObjectMapper(), + config.getInteropGenesisPayloadHeader().get().toFile(), + GENESIS_SLOT)); + } catch (IOException e) { + throw new RuntimeException( + "Unable to load payload header from " + config.getInteropGenesisPayloadHeader().get(), + e); + } + } + + final BeaconState genesisState = + new GenesisStateBuilder() + .spec(spec) + .genesisTime(config.getInteropGenesisTime()) + .addMockValidators(config.getInteropNumberOfValidators()) + .executionPayloadHeader(executionPayloadHeader) + .build(); + + recentChainData.initializeFromGenesis(genesisState, timeProvider.getTimeInSeconds()); + + eventLogger.genesisEvent( + genesisState.hashTreeRoot(), + recentChainData.getBestBlockRoot().orElseThrow(), + genesisState.getGenesisTime()); + } + + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java index 8454538b403..4c6bd423864 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java @@ -11,6 +11,7 @@ import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; @@ -26,6 +27,7 @@ import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; import tech.pegasys.teku.statetransition.util.PendingPool; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.storage.api.ChainHeadChannel; import tech.pegasys.teku.storage.api.StorageUpdateChannel; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; @@ -88,10 +90,13 @@ static SyncService syncService( DepositProvider depositProvider, Optional terminalPowBlockMonitor, Eth2P2PNetwork p2pNetwork, - CoalescingChainHeadChannel coalescingChainHeadChannel) { + ChainHeadChannel chainHeadChannelPublisher, + EventLogger eventLogger) { SyncService syncService = syncServiceFactory.create(eventChannels); // chainHeadChannel subscription + CoalescingChainHeadChannel coalescingChainHeadChannel = + new CoalescingChainHeadChannel(chainHeadChannelPublisher, eventLogger); syncService.getForwardSync().subscribeToSyncChanges(coalescingChainHeadChannel); // forkChoiceNotifier subscription diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index d39d617b4e6..c585fc11890 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -17,6 +17,7 @@ import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; import tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber; import tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager; +import tech.pegasys.teku.services.beaconchain.ValidatorIsConnectedProviderImpl; import tech.pegasys.teku.services.executionlayer.ExecutionLayerBlockManagerFactory; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation; @@ -47,6 +48,7 @@ import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider; import tech.pegasys.teku.validator.api.ValidatorConfig; import tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker; import tech.pegasys.teku.validator.coordinator.BlockFactory; @@ -249,4 +251,10 @@ static AttestationManager attestationManager( return attestationManager; } + + @Provides + @Singleton + static ValidatorIsConnectedProvider validatorIsConnectedProvider(ForkChoiceNotifier forkChoiceNotifier) { + return new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java new file mode 100644 index 00000000000..3d7eb7ed653 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java @@ -0,0 +1,81 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Module; +import dagger.Provides; +import tech.pegasys.teku.infrastructure.async.SafeFuture; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.services.beaconchain.WeakSubjectivityInitializer; +import tech.pegasys.teku.services.beaconchain.init.SpecModule.CurrentSlotProvider; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; +import tech.pegasys.teku.storage.api.StorageQueryChannel; +import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; +import tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig; + +import javax.inject.Singleton; + +@Module +public interface WSModule { + + interface WeakSubjectivityPeriodValidator { + void validate(RecentChainData recentChainData); + } + + @Provides + @Singleton + static WeakSubjectivityInitializer weakSubjectivityInitializer() { + return new WeakSubjectivityInitializer(); + } + + @Provides + @Singleton + static SafeFuture weakSubjectivityConfigFuture( + WeakSubjectivityInitializer weakSubjectivityInitializer, + WeakSubjectivityConfig weakSubjectivityConfig, + StorageQueryChannel storageQueryChannel, + StorageUpdateChannel storageUpdateChannel + ) { + return weakSubjectivityInitializer.finalizeAndStoreConfig( + weakSubjectivityConfig, storageQueryChannel, storageUpdateChannel); + } + + @Provides + @Singleton + // TODO producer ? + static WeakSubjectivityConfig weakSubjectivityConfig( + SafeFuture weakSubjectivityConfigFuture + ) { + return weakSubjectivityConfigFuture.join(); + } + + @Provides + @Singleton + static WeakSubjectivityValidator weakSubjectivityValidator( + WeakSubjectivityConfig weakSubjectivityConfig + ) { + return WeakSubjectivityValidator.moderate(weakSubjectivityConfig); + } + + @Provides + @Singleton + static WeakSubjectivityPeriodValidator weakSubjectivityPeriodValidator( + Spec spec, + CurrentSlotProvider currentSlotProvider, + WeakSubjectivityConfig weakSubjectivityConfig, + WeakSubjectivityInitializer weakSubjectivityInitializer) { + return client -> { + final AnchorPoint latestFinalizedAnchor = client.getStore().getLatestFinalized(); + final UInt64 currentSlot = + currentSlotProvider.getCurrentSlot(client.getGenesisTime()); + final WeakSubjectivityCalculator wsCalculator = + WeakSubjectivityCalculator.create(weakSubjectivityConfig); + weakSubjectivityInitializer.validateAnchorIsWithinWeakSubjectivityPeriod( + latestFinalizedAnchor, currentSlot, spec, wsCalculator); + }; + } +} From 40acba3756fb05ce8fd05573880bb17bd299657b Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Thu, 20 Jun 2024 13:53:26 +0400 Subject: [PATCH 05/27] Complete BeaconChainController Dagger draft --- .../OperationsReOrgManager.java | 4 +- .../beaconchain/BeaconChainController.java | 17 +- .../beaconchain/init/AsyncRunnerModule.java | 14 +- .../beaconchain/init/BeaconModule.java | 130 +++++++++++-- .../services/beaconchain/init/BlobModule.java | 4 +- .../beaconchain/init/CryptoModule.java | 2 +- .../beaconchain/init/ForkChoiceModule.java | 6 +- .../services/beaconchain/init/MainModule.java | 180 ++++++++++++++++++ .../beaconchain/init/MetricsModule.java | 31 ++- .../services/beaconchain/init/MiscModule.java | 15 -- .../beaconchain/init/PoolAndCachesModule.java | 9 +- .../services/beaconchain/init/PowModule.java | 19 +- .../init/RecentChainDataStateInitializer.java | 156 +++++++++++++++ .../beaconchain/init/ServiceConfigModule.java | 12 +- .../services/beaconchain/init/SpecModule.java | 20 +- .../beaconchain/init/StorageModule.java | 172 ++++------------- .../beaconchain/init/SubnetsModule.java | 20 +- .../services/beaconchain/init/SyncModule.java | 43 +++++ .../beaconchain/init/ValidatorModule.java | 30 ++- .../beaconchain/init/VerifyModule.java | 12 +- .../services/beaconchain/init/WSModule.java | 35 ++++ 21 files changed, 684 insertions(+), 247 deletions(-) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java delete mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java index ab604876478..eb2d37add6e 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java @@ -43,7 +43,7 @@ public class OperationsReOrgManager implements ChainHeadChannel { private final OperationPool attesterSlashingPool; private final AttestationManager attestationManager; private final AggregatingAttestationPool attestationPool; - private final MappedOperationPool blsToExecutionOperationPool; + private final OperationPool blsToExecutionOperationPool; private final RecentChainData recentChainData; public OperationsReOrgManager( @@ -52,7 +52,7 @@ public OperationsReOrgManager( final OperationPool exitPool, final AggregatingAttestationPool attestationPool, final AttestationManager attestationManager, - final MappedOperationPool blsToExecutionOperationPool, + final OperationPool blsToExecutionOperationPool, final RecentChainData recentChainData) { this.exitPool = exitPool; this.proposerSlashingPool = proposerSlashingPool; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index a099c63bfc7..1989071b384 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -334,7 +334,6 @@ public BeaconChainController( "type"); } - // TODO @Override protected SafeFuture doStart() { LOG.debug("Starting {}", this.getClass().getSimpleName()); @@ -345,7 +344,6 @@ protected SafeFuture doStart() { beaconRestAPI.map(BeaconRestApi::start).orElse(SafeFuture.completedFuture(null))); } - // TODO protected void startServices() { final RecentBlocksFetcher recentBlocksFetcher = syncService.getRecentBlocksFetcher(); recentBlocksFetcher.subscribeBlockFetched( @@ -387,7 +385,6 @@ protected void startServices() { }); } - // TODO @Override protected SafeFuture doStop() { LOG.debug("Stopping {}", this.getClass().getSimpleName()); @@ -405,7 +402,7 @@ protected SafeFuture doStop() { protected SafeFuture initialize() { - timerService = new TimerService(this::onTick); // TODO + timerService = new TimerService(this::onTick); final StoreConfig storeConfig = beaconConfig.storeConfig(); coalescingChainHeadChannel = @@ -463,12 +460,11 @@ protected SafeFuture initialize() { .thenRun(this::initAll) .thenRun( () -> { - // TODO recentChainData.subscribeStoreInitialized(this::onStoreInitialized); recentChainData.subscribeBestBlockInitialized(this::startServices); }) .thenCompose(__ -> - timerService.start() // TODO + timerService.start() ); } @@ -690,7 +686,6 @@ protected void initProposerSlashingPool() { blockImporter.subscribeToVerifiedBlockProposerSlashings(proposerSlashingPool::removeAll); } - // TODO protected void initSlashingEventsSubscriptions() { if (beaconConfig.validatorConfig().isShutdownWhenValidatorSlashedEnabled()) { final ValidatorTimingChannel validatorTimingChannel = @@ -785,7 +780,6 @@ protected void initCombinedChainDataClient() { recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); } - // TODO protected SafeFuture initWeakSubjectivity( final StorageQueryChannel queryChannel, final StorageUpdateChannel updateChannel) { return wsInitializer @@ -996,7 +990,6 @@ public void initValidatorApiHandler() { } } - // TODO protected void initGenesisHandler() { if (!recentChainData.isPreGenesis()) { // We already have a genesis block - no need for a genesis handler @@ -1302,7 +1295,6 @@ public void initSyncService() { state -> p2pNetwork.onSyncStateChanged(state.isInSync(), state.isOptimistic())); } - //TODO protected void initOperationsReOrgManager() { LOG.debug("BeaconChainController.initOperationsReOrgManager()"); OperationsReOrgManager operationsReOrgManager = @@ -1317,7 +1309,6 @@ protected void initOperationsReOrgManager() { eventChannels.subscribe(ChainHeadChannel.class, operationsReOrgManager); } - // TODO protected void initValidatorIndexCacheTracker() { LOG.debug("BeaconChainController.initValidatorIndexCacheTracker()"); final ValidatorIndexCacheTracker validatorIndexCacheTracker = @@ -1371,7 +1362,6 @@ private Optional getProposerDefaultFeeRecipient() { return defaultFeeRecipient; } - // TODO protected void setupInitialState(final RecentChainData client) { final Eth2NetworkConfiguration networkConfiguration = beaconConfig.eth2NetworkConfig(); @@ -1481,7 +1471,6 @@ protected void setupInteropState() { genesisState.getGenesisTime()); } - // TODO protected void onStoreInitialized() { UInt64 genesisTime = recentChainData.getGenesisTime(); UInt64 currentTime = timeProvider.getTimeInSeconds(); @@ -1506,7 +1495,6 @@ protected UInt64 getCurrentSlot(final UInt64 genesisTime, final UInt64 currentTi return spec.getCurrentSlot(currentTime, genesisTime); } - // TODO protected void validateChain(final UInt64 currentSlot) { weakSubjectivityValidator .validateChainIsConsistentWithWSCheckpoint(combinedChainDataClient) @@ -1528,7 +1516,6 @@ protected void validateChain(final UInt64 currentSlot) { }); } - // TODO private void onTick() { if (recentChainData.isPreGenesis()) { return; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java index 9e96cc4648f..1c532b1466b 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java @@ -48,9 +48,7 @@ static AsyncRunner beaconAsyncRunner( static AsyncRunner networkAsyncRunner( AsyncRunnerFactory asyncRunnerFactory, Eth2NetworkConfiguration eth2NetworkConfig) { return asyncRunnerFactory.create( - "p2p", - eth2NetworkConfig.getAsyncP2pMaxThreads(), - eth2NetworkConfig.getAsyncP2pMaxQueue()); + "p2p", eth2NetworkConfig.getAsyncP2pMaxThreads(), eth2NetworkConfig.getAsyncP2pMaxQueue()); } @Provides @@ -71,15 +69,17 @@ static AsyncRunner operationPoolAsyncRunner(AsyncRunnerFactory asyncRunnerFactor @Singleton @ForkChoiceExecutor static AsyncRunnerEventThread forkChoiceExecutor(AsyncRunnerFactory asyncRunnerFactory) { - return new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); + AsyncRunnerEventThread forkChoiceExecutor = + new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); + return forkChoiceExecutor; } @Provides @Singleton @ForkChoiceNotifierExecutor static AsyncRunnerEventThread forkChoiceNotifierExecutor(AsyncRunnerFactory asyncRunnerFactory) { - return new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); + AsyncRunnerEventThread forkChoiceNotifierExecutor = + new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); + return forkChoiceNotifierExecutor; } - - } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java index 71037a23704..80f1731469e 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -11,18 +11,32 @@ import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; import tech.pegasys.teku.services.beaconchain.SlotProcessor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; +import tech.pegasys.teku.services.beaconchain.init.MetricsModule.TickProcessingPerformanceRecordFactory; import tech.pegasys.teku.services.beaconchain.init.PoolAndCachesModule.InvalidBlockRoots; +import tech.pegasys.teku.services.beaconchain.init.PowModule.ProposerDefaultFeeRecipient; +import tech.pegasys.teku.services.timer.TimerService; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; import tech.pegasys.teku.statetransition.EpochCachePrimer; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.OperationsReOrgManager; +import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; import tech.pegasys.teku.statetransition.block.BlockImportChannel; import tech.pegasys.teku.statetransition.block.BlockImportMetrics; @@ -32,14 +46,13 @@ import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceStateProvider; import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; +import tech.pegasys.teku.statetransition.forkchoice.TickProcessingPerformance; import tech.pegasys.teku.statetransition.util.FutureItems; import tech.pegasys.teku.statetransition.util.PendingPool; -import tech.pegasys.teku.statetransition.validation.BlockGossipValidator; import tech.pegasys.teku.statetransition.validation.BlockValidator; +import tech.pegasys.teku.storage.api.ChainHeadChannel; import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @@ -47,11 +60,22 @@ import java.util.Map; import java.util.Optional; -import static tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG; +import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; +import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds; @Module public interface BeaconModule { + @FunctionalInterface + interface TickHandler { + void onTick(); + } + + @FunctionalInterface + interface GenesisTimeTracker { + void update(); + } + @Provides @Singleton static EpochCachePrimer epochCachePrimer( @@ -106,7 +130,6 @@ static BlockImporter blockImporter( static BlockManager blockManager( Spec spec, EventLogger eventLogger, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, TimeProvider timeProvider, RecentChainData recentChainData, BlockValidator blockValidator, @@ -116,10 +139,10 @@ static BlockManager blockManager( @InvalidBlockRoots Map invalidBlockRoots, Optional blockImportMetrics, FutureItems futureBlocks, - EventChannelSubscriberslotEventsChannelSubscriber, + FailedExecutionPool failedExecutionPool, + EventChannelSubscriber slotEventsChannelSubscriber, EventChannelSubscriber blockImportChannelSubscriber, - EventChannelSubscriber receivedBlockEventsChannelSubscriber - ) { + EventChannelSubscriber receivedBlockEventsChannelSubscriber) { BlockManager blockManager = new BlockManager( @@ -134,10 +157,7 @@ static BlockManager blockManager( eventLogger, blockImportMetrics); - // TODO void dependency if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { - final FailedExecutionPool failedExecutionPool = - new FailedExecutionPool(blockManager, beaconAsyncRunner); blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); } slotEventsChannelSubscriber.subscribe(blockManager); @@ -153,11 +173,11 @@ static ProposersDataManager proposersDataManager( Eth2NetworkConfiguration eth2NetworkConfig, Spec spec, MetricsSystem metricsSystem, - @AsyncRunnerModule.ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor, + @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor, ExecutionLayerChannel executionLayer, RecentChainData recentChainData, EventChannelSubscriber slotEventsChannelSubscriber, - @PowModule.ProposerDefaultFeeRecipient Optional proposerDefaultFeeRecipient) { + @ProposerDefaultFeeRecipient Optional proposerDefaultFeeRecipient) { ProposersDataManager proposersDataManager = new ProposersDataManager( @@ -172,4 +192,88 @@ static ProposersDataManager proposersDataManager( return proposersDataManager; } + @Provides + @Singleton + static OperationsReOrgManager operationsReOrgManager( + OperationPool attesterSlashingPool, + OperationPool proposerSlashingPool, + OperationPool voluntaryExitPool, + AggregatingAttestationPool attestationPool, + AttestationManager attestationManager, + OperationPool blsToExecutionChangePool, + RecentChainData recentChainData, + EventChannelSubscriber chainHeadChannelSubscriber) { + + OperationsReOrgManager operationsReOrgManager = + new OperationsReOrgManager( + proposerSlashingPool, + attesterSlashingPool, + voluntaryExitPool, + attestationPool, + attestationManager, + blsToExecutionChangePool, + recentChainData); + chainHeadChannelSubscriber.subscribe(operationsReOrgManager); + return operationsReOrgManager; + } + + @Provides + @Singleton + static TickHandler tickHandler( + TimeProvider timeProvider, + RecentChainData recentChainData, + ForkChoice forkChoice, + SlotProcessor slotProcessor, + TickProcessingPerformanceRecordFactory tickProcessingPerformanceRecordFactory, + GenesisTimeTracker genesisTimeTracker) { + return () -> { + if (recentChainData.isPreGenesis()) { + return; + } + + final UInt64 currentTimeMillis = timeProvider.getTimeInMillis(); + final Optional performanceRecord = + tickProcessingPerformanceRecordFactory.create(); + + forkChoice.onTick(currentTimeMillis, performanceRecord); + + genesisTimeTracker.update(); + + slotProcessor.onTick(currentTimeMillis, performanceRecord); + performanceRecord.ifPresent(TickProcessingPerformance::complete); + }; + } + + @Provides + @Singleton + static TimerService timerService(TickHandler tickHandler) { + return new TimerService(tickHandler::onTick); + } + + @Provides + @Singleton + static GenesisTimeTracker genesisTimeTracker( + TimeProvider timeProvider, + RecentChainData recentChainData, + Eth2P2PNetwork p2pNetwork, + StatusLogger statusLogger) { + return new GenesisTimeTracker() { + private UInt64 lastUpdateTime = UInt64.ZERO; + + @Override + public void update() { + final UInt64 genesisTime = recentChainData.getGenesisTime(); + final UInt64 currentTimeMillis = timeProvider.getTimeInMillis(); + final UInt64 currentTimeSeconds = millisToSeconds(currentTimeMillis); + if (genesisTime.isGreaterThan(currentTimeSeconds)) { + // notify every 10 minutes + if (lastUpdateTime.plus(600L).isLessThanOrEqualTo(currentTimeSeconds)) { + lastUpdateTime = currentTimeSeconds; + statusLogger.timeUntilGenesis( + genesisTime.minus(currentTimeSeconds).longValue(), p2pNetwork.getPeerCount()); + } + } + } + }; + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java index a15d40305a7..4331295e601 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java @@ -31,7 +31,7 @@ public interface BlobModule { @Provides @Singleton - static BlobSidecarGossipValidator provideBlobSidecarGossipValidator( + static BlobSidecarGossipValidator blobSidecarGossipValidator( Spec spec, KZG kzg, @InvalidBlockRoots Map invalidBlockRoots, @@ -46,7 +46,7 @@ static BlobSidecarGossipValidator provideBlobSidecarGossipValidator( @Provides @Singleton - static BlobSidecarManager provideBlobSidecarManager( + static BlobSidecarManager blobSidecarManager( Spec spec, KZG kzg, @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java index aab9cef2321..a96f9ec79e0 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java @@ -39,7 +39,7 @@ static SignatureVerificationService signatureVerificationService( @Provides @Singleton - static KZG provideKzg(Eth2NetworkConfiguration eth2NetworkConfig, Spec spec) { + static KZG kzg(Eth2NetworkConfiguration eth2NetworkConfig, Spec spec) { if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { KZG kzg = KZG.getInstance(); final String trustedSetupFile = diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java index 3022295405a..746c32735dd 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java @@ -44,6 +44,7 @@ static ForkChoice forkChoice( ForkChoiceNotifier forkChoiceNotifier, ForkChoiceStateProvider forkChoiceStateProvider, P2PDebugDataDumper p2pDebugDataDumper, + TickProcessor tickProcessor, MergeTransitionBlockValidator mergeTransitionBlockValidator) { return new ForkChoice( spec, @@ -52,8 +53,7 @@ static ForkChoice forkChoice( blobSidecarManager, forkChoiceNotifier, forkChoiceStateProvider, - // TODO to revise - new TickProcessor(spec, recentChainData), + tickProcessor, mergeTransitionBlockValidator, eth2NetworkConfig.isForkChoiceLateBlockReorgEnabled(), p2pDebugDataDumper, @@ -85,8 +85,6 @@ static ForkChoiceNotifier forkChoiceNotifier( RecentChainData recentChainData, ForkChoiceStateProvider forkChoiceStateProvider) { - forkChoiceNotifierExecutor.start(); // TODO why ? - return new ForkChoiceNotifierImpl( forkChoiceStateProvider, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java new file mode 100644 index 00000000000..e0c6785730c --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -0,0 +1,180 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Lazy; +import dagger.Module; +import dagger.Provides; +import javax.inject.Singleton; + +import dagger.multibindings.IntoSet; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.beacon.sync.gossip.blobs.RecentBlobSidecarsFetcher; +import tech.pegasys.teku.beacon.sync.gossip.blocks.RecentBlocksFetcher; +import tech.pegasys.teku.beaconrestapi.BeaconRestApi; +import tech.pegasys.teku.infrastructure.async.SafeFuture; +import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; +import tech.pegasys.teku.services.powchain.PowchainConfiguration; +import tech.pegasys.teku.services.timer.TimerService; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.OperationsReOrgManager; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; +import tech.pegasys.teku.statetransition.genesis.GenesisHandler; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.api.ValidatorConfig; +import tech.pegasys.teku.validator.api.ValidatorTimingChannel; +import tech.pegasys.teku.validator.coordinator.ValidatorIndexCacheTracker; + +import java.util.Optional; +import java.util.Set; + +@Module +public interface MainModule { + + /** Dummy class returned by the dependency which requires just initialization */ + class VoidInitializer {} + + interface ServiceStarter { + SafeFuture start(); + } + + interface ServiceStopper { + SafeFuture stop(); + } + + @Provides + @IntoSet + static VoidInitializer initSlashingEventsSubscriptions( + ValidatorConfig validatorConfig, + ValidatorTimingChannel validatorTimingChannel, + OperationPool attesterSlashingPool, + OperationPool proposerSlashingPool) { + if (validatorConfig.isShutdownWhenValidatorSlashedEnabled()) { + attesterSlashingPool.subscribeOperationAdded( + (operation, validationStatus, fromNetwork) -> + validatorTimingChannel.onAttesterSlashing(operation)); + proposerSlashingPool.subscribeOperationAdded( + (operation, validationStatus, fromNetwork) -> + validatorTimingChannel.onProposerSlashing(operation)); + } + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer initGenesisHandler( + RecentChainData recentChainData, + Lazy genesisHandler, + PowchainConfiguration powchainConfig, + StatusLogger statusLogger) { + if (!recentChainData.isPreGenesis()) { + // We already have a genesis block - no need for a genesis handler + } else if (!powchainConfig.isEnabled()) { + // We're pre-genesis but no eth1 endpoint is set + throw new IllegalStateException("ETH1 is disabled, but no initial state is set."); + } else { + statusLogger.loadingGenesisFromEth1Chain(); + genesisHandler.get(); + } + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer initOperationsReOrgManager(OperationsReOrgManager operationsReOrgManager) { + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer initValidatorIndexCacheTracker( + ValidatorIndexCacheTracker validatorIndexCacheTracker) { + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer initRecentBlocksFetcher(RecentBlocksFetcher recentBlocksFetcher) { + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer initRecentBlobSidecarsFetcher( + RecentBlobSidecarsFetcher recentBlocksFetcher) { + return new VoidInitializer(); + } + + @Provides + @Singleton + static ServiceStarter serviceStarter( + Set allInitializers, + Optional beaconRestApi, + SyncService syncService, + BlockManager blockManager, + AttestationManager attestationManager, + Eth2P2PNetwork p2pNetwork, + TimerService timerService, + Optional terminalPowBlockMonitor, + @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, + @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor) { + return () -> + SafeFuture.fromRunnable( + () -> { + forkChoiceExecutor.start(); + forkChoiceNotifierExecutor.start(); + }) + .thenCompose( + __ -> + SafeFuture.allOf( + syncService.start(), + blockManager.start(), + attestationManager.start(), + p2pNetwork.start(), + SafeFuture.fromRunnable( + () -> + terminalPowBlockMonitor.ifPresent(TerminalPowBlockMonitor::start)))) + .thenCompose(__ -> timerService.start().thenApply(___ -> null)) + .thenCompose( + __ -> + beaconRestApi + .map(BeaconRestApi::start) + .orElse(SafeFuture.completedFuture(null)) + .thenApply(___ -> null)); + } + + @Provides + @Singleton + static ServiceStarter serviceStopper( + Optional beaconRestApi, + SyncService syncService, + BlockManager blockManager, + AttestationManager attestationManager, + Eth2P2PNetwork p2pNetwork, + TimerService timerService, + Optional terminalPowBlockMonitor, + @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, + @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor) { + return () -> + SafeFuture.allOf( + beaconRestApi.map(BeaconRestApi::stop).orElse(SafeFuture.completedFuture(null)), + syncService.stop(), + blockManager.stop(), + attestationManager.stop(), + p2pNetwork.stop(), + timerService.stop(), + SafeFuture.fromRunnable( + () -> terminalPowBlockMonitor.ifPresent(TerminalPowBlockMonitor::stop))) + .thenRun( + () -> { + forkChoiceExecutor.stop(); + forkChoiceNotifierExecutor.stop(); + }); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java index b724b0772ab..41be0ffaa6f 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java @@ -22,6 +22,7 @@ import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.statetransition.block.BlockImportMetrics; +import tech.pegasys.teku.statetransition.forkchoice.TickProcessingPerformance; import tech.pegasys.teku.statetransition.util.FutureItems; import tech.pegasys.teku.storage.api.ChainHeadChannel; import tech.pegasys.teku.storage.client.CombinedChainDataClient; @@ -49,6 +50,11 @@ @Module public interface MetricsModule { + @FunctionalInterface + interface TickProcessingPerformanceRecordFactory { + Optional create(); + } + @Qualifier @interface FutureItemsMetric {} @@ -73,7 +79,7 @@ static SettableLabelledGauge futureItemsMetric(MetricsSystem metricsSystem) { @Provides @Singleton @SubnetSubscriptionsMetric - static SettableLabelledGauge provideSubnetSubscriptionsMetric(MetricsSystem metricsSystem) { + static SettableLabelledGauge subnetSubscriptionsMetric(MetricsSystem metricsSystem) { return SettableLabelledGauge.create( metricsSystem, TekuMetricCategory.NETWORK, @@ -85,7 +91,7 @@ static SettableLabelledGauge provideSubnetSubscriptionsMetric(MetricsSystem metr @Provides @Singleton @PerformanceTrackerTimings - static SettableGauge providePerformanceTrackerTimings(MetricsSystem metricsSystem) { + static SettableGauge performanceTrackerTimings(MetricsSystem metricsSystem) { return SettableGauge.create( metricsSystem, BEACON, @@ -95,21 +101,21 @@ static SettableGauge providePerformanceTrackerTimings(MetricsSystem metricsSyste @Provides @Singleton - static FutureItems provideFutureBlobSidecars( + static FutureItems futureBlobSidecars( @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { return FutureItems.create(BlobSidecar::getSlot, futureItemsMetric, "blob_sidecars"); } @Provides @Singleton - static ValidatorPerformanceMetrics provideValidatorPerformanceMetrics( + static ValidatorPerformanceMetrics validatorPerformanceMetrics( MetricsSystem metricsSystem) { return new ValidatorPerformanceMetrics(metricsSystem); } @Provides @Singleton - static PerformanceTracker providePerformanceTracker( + static PerformanceTracker performanceTracker( Spec spec, ValidatorConfig validatorConfig, CombinedChainDataClient combinedChainDataClient, @@ -140,7 +146,7 @@ static PerformanceTracker providePerformanceTracker( // TODO not used @Provides @Singleton - static SyncCommitteeMetrics provideSyncCommitteeMetrics( + static SyncCommitteeMetrics syncCommitteeMetrics( Spec spec, RecentChainData recentChainData, MetricsSystem metricsSystem, @@ -156,7 +162,7 @@ static SyncCommitteeMetrics provideSyncCommitteeMetrics( // TODO not used @Provides @Singleton - static BeaconChainMetrics provideBeaconChainMetrics( + static BeaconChainMetrics beaconChainMetrics( Spec spec, MetricsSystem metricsSystem, RecentChainData recentChainData, @@ -228,4 +234,15 @@ static Optional blockImportMetrics( ? Optional.of(BlockImportMetrics.create(metricsSystem)) : Optional.empty(); } + + @Provides + @Singleton + static TickProcessingPerformanceRecordFactory tickProcessingPerformanceRecordFactory( + TimeProvider timeProvider, MetricsConfig metricsConfig) { + return () -> + metricsConfig.isTickPerformanceEnabled() + ? Optional.of( + new TickProcessingPerformance(timeProvider, timeProvider.getTimeInMillis())) + : Optional.empty(); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java deleted file mode 100644 index d9fdad44d21..00000000000 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MiscModule.java +++ /dev/null @@ -1,15 +0,0 @@ -package tech.pegasys.teku.services.beaconchain.init; - -import dagger.Module; -import dagger.Provides; -import javax.inject.Singleton; -import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; -import tech.pegasys.teku.kzg.KZG; -import tech.pegasys.teku.networks.Eth2NetworkConfiguration; -import tech.pegasys.teku.spec.Spec; -import tech.pegasys.teku.spec.SpecMilestone; - -@Module -public interface MiscModule { - -} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java index 55b622c86f9..702dce541fe 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java @@ -31,6 +31,8 @@ import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; import tech.pegasys.teku.statetransition.block.BlockImportChannel; import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.block.FailedExecutionPool; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; @@ -257,5 +259,10 @@ static AggregatingAttestationPool aggregatingAttestationPool( return attestationPool; } - + @Provides + @Singleton + static FailedExecutionPool failedExecutionPool( + BlockManager blockManager, @BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + return new FailedExecutionPool(blockManager, beaconAsyncRunner); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java index a31ad09b32f..b94f4b14d28 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java @@ -22,6 +22,7 @@ import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; +import tech.pegasys.teku.statetransition.genesis.GenesisHandler; import tech.pegasys.teku.storage.api.Eth1DepositStorageChannel; import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; import tech.pegasys.teku.storage.api.StorageUpdateChannel; @@ -43,7 +44,7 @@ public interface PowModule { @Provides @Singleton - static Optional provideTerminalPowBlockMonitor( + static Optional terminalPowBlockMonitor( Spec spec, @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, TimeProvider timeProvider, @@ -68,13 +69,13 @@ static Optional provideTerminalPowBlockMonitor( @Provides @Singleton - static Eth1DataCache provideEth1DataCache(Spec spec, MetricsSystem metricsSystem) { + static Eth1DataCache eth1DataCache(Spec spec, MetricsSystem metricsSystem) { return new Eth1DataCache(spec, metricsSystem, new Eth1VotingPeriod(spec)); } @Provides @Singleton - static DepositProvider provideDepositProvider( + static DepositProvider depositProvider( Spec spec, PowchainConfiguration powchainConfig, MetricsSystem metricsSystem, @@ -127,4 +128,16 @@ static Optional proposerDefaultFeeRecipient( return defaultFeeRecipient; } + @Provides + @Singleton + static GenesisHandler genesisHandler( + TimeProvider timeProvider, + Spec spec, + RecentChainData recentChainData, + EventChannelSubscriber eth1EventsChannelSubscriber + ) { + GenesisHandler genesisHandler = new GenesisHandler(recentChainData, timeProvider, spec); + eth1EventsChannelSubscriber.subscribe(genesisHandler); + return genesisHandler; + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java new file mode 100644 index 00000000000..a55bf43c18f --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java @@ -0,0 +1,156 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import com.fasterxml.jackson.databind.ObjectMapper; +import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; +import tech.pegasys.teku.infrastructure.logging.EventLogger; +import tech.pegasys.teku.infrastructure.logging.StatusLogger; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.networks.StateBoostrapConfig; +import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; +import tech.pegasys.teku.services.beaconchain.WeakSubjectivityInitializer; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; +import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder; +import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.validator.api.InteropConfig; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; + +import javax.inject.Inject; +import java.io.IOException; +import java.util.Optional; + +import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; + +public class RecentChainDataStateInitializer { + + @Inject TimeProvider timeProvider; + @Inject BeaconChainConfiguration beaconConfig; + @Inject Spec spec; + @Inject SpecModule.CurrentSlotProvider currentSlotProvider; + @Inject WeakSubjectivityInitializer weakSubjectivityInitializer; + @Inject EventLogger eventLogger; + @Inject StatusLogger statusLogger; + + public void setupInitialState(RecentChainData recentChainData) { + + final Optional initialAnchor = + tryLoadingAnchorPointFromInitialState(beaconConfig.eth2NetworkConfig()) + .or( + () -> + attemptToLoadAnchorPoint( + beaconConfig + .eth2NetworkConfig() + .getNetworkBoostrapConfig() + .getGenesisState())); + + /* + If flag to allow sync outside of weak subjectivity period has been set, we pass an instance of + WeakSubjectivityPeriodCalculator to the WeakSubjectivityInitializer. Otherwise, we pass an Optional.empty(). + */ + boolean isAllowSyncOutsideWeakSubjectivityPeriod = + beaconConfig + .eth2NetworkConfig() + .getNetworkBoostrapConfig() + .isAllowSyncOutsideWeakSubjectivityPeriod(); + + final Optional maybeWsCalculator; + if (isAllowSyncOutsideWeakSubjectivityPeriod) { + maybeWsCalculator = Optional.empty(); + } else { + maybeWsCalculator = + Optional.of(WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity())); + } + + // Validate + initialAnchor.ifPresent( + anchor -> { + final UInt64 currentSlot = + currentSlotProvider.getCurrentSlot(anchor.getState().getGenesisTime()); + weakSubjectivityInitializer.validateInitialAnchor( + anchor, currentSlot, spec, maybeWsCalculator); + }); + + if (initialAnchor.isPresent()) { + final AnchorPoint anchor = initialAnchor.get(); + recentChainData.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds()); + if (anchor.isGenesis()) { + eventLogger.genesisEvent( + anchor.getStateRoot(), + recentChainData.getBestBlockRoot().orElseThrow(), + anchor.getState().getGenesisTime()); + } + } else if (beaconConfig.interopConfig().isInteropEnabled()) { + setupInteropState(recentChainData); + } else if (!beaconConfig.powchainConfig().isEnabled()) { + throw new InvalidConfigurationException( + "ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state" + + "."); + } + } + + private Optional tryLoadingAnchorPointFromInitialState( + final Eth2NetworkConfiguration networkConfiguration) { + Optional initialAnchor = Optional.empty(); + + try { + initialAnchor = + attemptToLoadAnchorPoint( + networkConfiguration.getNetworkBoostrapConfig().getInitialState()); + } catch (final InvalidConfigurationException e) { + final StateBoostrapConfig stateBoostrapConfig = + networkConfiguration.getNetworkBoostrapConfig(); + if (stateBoostrapConfig.isUsingCustomInitialState() + && !stateBoostrapConfig.isUsingCheckpointSync()) { + throw e; + } + statusLogger.warnFailedToLoadInitialState(e.getMessage()); + } + + return initialAnchor; + } + + protected Optional attemptToLoadAnchorPoint(final Optional initialState) { + return weakSubjectivityInitializer.loadInitialAnchorPoint(spec, initialState); + } + + protected void setupInteropState(RecentChainData recentChainData) { + final InteropConfig config = beaconConfig.interopConfig(); + statusLogger.generatingMockStartGenesis( + config.getInteropGenesisTime(), config.getInteropNumberOfValidators()); + + Optional executionPayloadHeader = Optional.empty(); + if (config.getInteropGenesisPayloadHeader().isPresent()) { + try { + executionPayloadHeader = + Optional.of( + spec.deserializeJsonExecutionPayloadHeader( + new ObjectMapper(), + config.getInteropGenesisPayloadHeader().get().toFile(), + GENESIS_SLOT)); + } catch (IOException e) { + throw new RuntimeException( + "Unable to load payload header from " + config.getInteropGenesisPayloadHeader().get(), + e); + } + } + + final BeaconState genesisState = + new GenesisStateBuilder() + .spec(spec) + .genesisTime(config.getInteropGenesisTime()) + .addMockValidators(config.getInteropNumberOfValidators()) + .executionPayloadHeader(executionPayloadHeader) + .build(); + + recentChainData.initializeFromGenesis(genesisState, timeProvider.getTimeInSeconds()); + + eventLogger.genesisEvent( + genesisState.hashTreeRoot(), + recentChainData.getBestBlockRoot().orElseThrow(), + genesisState.getGenesisTime()); + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java index 150ae8134d4..f30f895c734 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java @@ -20,34 +20,34 @@ public interface ServiceConfigModule { @interface RejectedExecutionCountSupplier {} @Provides - static DataDirLayout provideDataDirLayout(ServiceConfig config){ + static DataDirLayout dataDirLayout(ServiceConfig config){ return config.getDataDirLayout(); } @Provides - static AsyncRunnerFactory provideAsyncRunnerFactory(ServiceConfig config){ + static AsyncRunnerFactory asyncRunnerFactory(ServiceConfig config){ return config.getAsyncRunnerFactory(); } @Provides - static TimeProvider provideTimeProvider(ServiceConfig config){ + static TimeProvider timeProvider(ServiceConfig config){ return config.getTimeProvider(); } @Provides - static EventChannels provideEventChannels(ServiceConfig config){ + static EventChannels eventChannels(ServiceConfig config){ return config.getEventChannels(); } @Provides - static MetricsSystem provideMetricsSystem(ServiceConfig config){ + static MetricsSystem metricsSystem(ServiceConfig config){ return config.getMetricsSystem(); } @Provides @Singleton @RejectedExecutionCountSupplier - static IntSupplier provideRejectedExecutionCountSupplier(ServiceConfig config) { + static IntSupplier rejectedExecutionCountSupplier(ServiceConfig config) { return config.getRejectedExecutionsSupplier(); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index d85fdaa8ec5..3c97963c062 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -16,9 +16,11 @@ @Module public interface SpecModule { - @FunctionalInterface interface CurrentSlotProvider { + UInt64 getCurrentSlot(UInt64 genesisTime); + + UInt64 getCurrentSlot(UInt64 genesisTime, UInt64 currentTime); } @FunctionalInterface @@ -34,19 +36,29 @@ default T apply(UInt64 slot) { @Provides @Singleton - static SchemaSupplier> provideBeaconBlockBodySchemaSupplier(Spec spec) { + static SchemaSupplier> beaconBlockBodySchemaSupplier(Spec spec) { return slot -> spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockBodySchema(); } @Provides @Singleton - static RewardCalculator provideRewardCalculator(Spec spec) { + static RewardCalculator rewardCalculator(Spec spec) { return new RewardCalculator(spec, new BlockRewardCalculatorUtil(spec)); } @Provides @Singleton static CurrentSlotProvider currentSlotProvider(Spec spec, TimeProvider timeProvider) { - return genesisTime -> spec.getCurrentSlot(timeProvider.getTimeInSeconds(), genesisTime); + return new CurrentSlotProvider() { + @Override + public UInt64 getCurrentSlot(UInt64 genesisTime) { + return getCurrentSlot(timeProvider.getTimeInSeconds(), genesisTime); + } + + @Override + public UInt64 getCurrentSlot(UInt64 genesisTime, UInt64 currentTime) { + return spec.getCurrentSlot(genesisTime, currentTime); + } + }; } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index 483a0543201..eb938ebb7ee 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -1,35 +1,27 @@ package tech.pegasys.teku.services.beaconchain.init; -import com.fasterxml.jackson.databind.ObjectMapper; import dagger.Binds; import dagger.Lazy; import dagger.Module; import dagger.Provides; -import javax.inject.Inject; import javax.inject.Singleton; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.SafeFuture; -import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; -import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.infrastructure.logging.StatusLogger; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; -import tech.pegasys.teku.networks.StateBoostrapConfig; import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; -import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; -import tech.pegasys.teku.services.beaconchain.WeakSubjectivityInitializer; +import tech.pegasys.teku.services.beaconchain.SlotProcessor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; +import tech.pegasys.teku.services.beaconchain.init.BeaconModule.GenesisTimeTracker; import tech.pegasys.teku.services.beaconchain.init.SpecModule.CurrentSlotProvider; import tech.pegasys.teku.services.beaconchain.init.WSModule.WeakSubjectivityPeriodValidator; +import tech.pegasys.teku.services.beaconchain.init.WSModule.WeakSubjectivityStoreChainValidator; import tech.pegasys.teku.spec.Spec; -import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; -import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder; -import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; -import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; import tech.pegasys.teku.storage.api.ChainHeadChannel; import tech.pegasys.teku.storage.api.CombinedStorageChannel; @@ -45,19 +37,19 @@ import tech.pegasys.teku.storage.store.FileKeyValueStore; import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.storage.store.StoreConfig; -import tech.pegasys.teku.validator.api.InteropConfig; -import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; +import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; -import java.io.IOException; -import java.util.Optional; - -import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; +import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; @Module public interface StorageModule { String KEY_VALUE_STORE_SUBDIRECTORY = "kvstore"; + interface OnStoreInitializedHandler { + void handle(); + } + @Binds StorageQueryChannel bindStorageQueryChannel(CombinedStorageChannel combinedStorageChannel); @@ -132,7 +124,8 @@ static RecentChainData recentChainData( SafeFuture recentChainDataFuture, StatusLogger statusLogger, Lazy weakSubjectivityPeriodValidator, - Lazy recentChainDataStateInitializer) { + Lazy recentChainDataStateInitializer, + OnStoreInitializedHandler onStoreInitializedHandler) { RecentChainData recentChainData = recentChainDataFuture.join(); @@ -157,129 +150,34 @@ static RecentChainData recentChainData( } } + recentChainData.subscribeStoreInitialized(onStoreInitializedHandler::handle); + return recentChainData; } - class RecentChainDataStateInitializer { - - @Inject TimeProvider timeProvider; - @Inject BeaconChainConfiguration beaconConfig; - @Inject Spec spec; - @Inject CurrentSlotProvider currentSlotProvider; - @Inject WeakSubjectivityInitializer weakSubjectivityInitializer; - @Inject EventLogger eventLogger; - @Inject StatusLogger statusLogger; - - public void setupInitialState(RecentChainData recentChainData) { - - final Optional initialAnchor = - tryLoadingAnchorPointFromInitialState(beaconConfig.eth2NetworkConfig()) - .or( - () -> - attemptToLoadAnchorPoint( - beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().getGenesisState())); - - /* - If flag to allow sync outside of weak subjectivity period has been set, we pass an instance of - WeakSubjectivityPeriodCalculator to the WeakSubjectivityInitializer. Otherwise, we pass an Optional.empty(). - */ - boolean isAllowSyncOutsideWeakSubjectivityPeriod = - beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().isAllowSyncOutsideWeakSubjectivityPeriod(); - - final Optional maybeWsCalculator; - if (isAllowSyncOutsideWeakSubjectivityPeriod) { - maybeWsCalculator = Optional.empty(); + @Provides + @Singleton + static OnStoreInitializedHandler onStoreInitializedHandler( + TimeProvider timeProvider, + RecentChainData recentChainData, + CurrentSlotProvider currentSlotProvider, + Lazy weakSubjectivityStoreChainValidator, + Lazy genesisTimeTracker, + SlotProcessor slotProcessor, + PerformanceTracker performanceTracker + ) { + return () -> { + UInt64 genesisTime = recentChainData.getGenesisTime(); + UInt64 currentTime = timeProvider.getTimeInSeconds(); + final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(genesisTime, currentTime); + if (currentTime.compareTo(genesisTime) >= 0) { + // Validate that we're running within the weak subjectivity period + weakSubjectivityStoreChainValidator.get().validate(currentSlot); } else { - maybeWsCalculator = - Optional.of(WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity())); - } - - // Validate - initialAnchor.ifPresent( - anchor -> { - final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(anchor.getState().getGenesisTime()); - weakSubjectivityInitializer.validateInitialAnchor(anchor, currentSlot, spec, maybeWsCalculator); - }); - - if (initialAnchor.isPresent()) { - final AnchorPoint anchor = initialAnchor.get(); - recentChainData.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds()); - if (anchor.isGenesis()) { - eventLogger.genesisEvent( - anchor.getStateRoot(), - recentChainData.getBestBlockRoot().orElseThrow(), - anchor.getState().getGenesisTime()); - } - } else if (beaconConfig.interopConfig().isInteropEnabled()) { - setupInteropState(recentChainData); - } else if (!beaconConfig.powchainConfig().isEnabled()) { - throw new InvalidConfigurationException( - "ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state" - + "."); + genesisTimeTracker.get().update(); } - } - - private Optional tryLoadingAnchorPointFromInitialState( - final Eth2NetworkConfiguration networkConfiguration) { - Optional initialAnchor = Optional.empty(); - - try { - initialAnchor = - attemptToLoadAnchorPoint( - networkConfiguration.getNetworkBoostrapConfig().getInitialState()); - } catch (final InvalidConfigurationException e) { - final StateBoostrapConfig stateBoostrapConfig = - networkConfiguration.getNetworkBoostrapConfig(); - if (stateBoostrapConfig.isUsingCustomInitialState() - && !stateBoostrapConfig.isUsingCheckpointSync()) { - throw e; - } - statusLogger.warnFailedToLoadInitialState(e.getMessage()); - } - - return initialAnchor; - } - - protected Optional attemptToLoadAnchorPoint(final Optional initialState) { - return weakSubjectivityInitializer.loadInitialAnchorPoint(spec, initialState); - } - - protected void setupInteropState(RecentChainData recentChainData) { - final InteropConfig config = beaconConfig.interopConfig(); - statusLogger.generatingMockStartGenesis( - config.getInteropGenesisTime(), config.getInteropNumberOfValidators()); - - Optional executionPayloadHeader = Optional.empty(); - if (config.getInteropGenesisPayloadHeader().isPresent()) { - try { - executionPayloadHeader = - Optional.of( - spec.deserializeJsonExecutionPayloadHeader( - new ObjectMapper(), - config.getInteropGenesisPayloadHeader().get().toFile(), - GENESIS_SLOT)); - } catch (IOException e) { - throw new RuntimeException( - "Unable to load payload header from " + config.getInteropGenesisPayloadHeader().get(), - e); - } - } - - final BeaconState genesisState = - new GenesisStateBuilder() - .spec(spec) - .genesisTime(config.getInteropGenesisTime()) - .addMockValidators(config.getInteropNumberOfValidators()) - .executionPayloadHeader(executionPayloadHeader) - .build(); - - recentChainData.initializeFromGenesis(genesisState, timeProvider.getTimeInSeconds()); - - eventLogger.genesisEvent( - genesisState.hashTreeRoot(), - recentChainData.getBestBlockRoot().orElseThrow(), - genesisState.getGenesisTime()); - } - + slotProcessor.setCurrentSlot(currentSlot); + performanceTracker.start(currentSlot); + }; } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java index 56b01fcb5ef..4fe81b7ebc4 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java @@ -22,7 +22,7 @@ public interface SubnetsModule { @Provides @Singleton - static AttestationTopicSubscriber provideAttestationTopicSubscriber( + static AttestationTopicSubscriber attestationTopicSubscriber( @MetricsModule.SubnetSubscriptionsMetric SettableLabelledGauge subnetSubscriptionsMetric, Spec spec, P2PConfig p2pConfig, @@ -36,21 +36,6 @@ static AttestationTopicSubscriber provideAttestationTopicSubscriber( return attestationTopicSubscriber; } - @Provides - @Singleton - static SyncCommitteeSubscriptionManager provideSyncCommitteeSubscriptionManager( - Spec spec, - P2PConfig p2pConfig, - EventChannelSubscriber slotEventsChannelSubscriber, - Eth2P2PNetwork p2pNetwork) { - SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager = - p2pConfig.isSubscribeAllSubnetsEnabled() - ? new AllSyncCommitteeSubscriptions(p2pNetwork, spec) - : new SyncCommitteeSubscriptionManager(p2pNetwork); - slotEventsChannelSubscriber.subscribe(syncCommitteeSubscriptionManager); - return syncCommitteeSubscriptionManager; - } - @Provides @Singleton static StableSubnetSubscriber stableSubnetSubscriber( @@ -84,7 +69,8 @@ static StableSubnetSubscriber stableSubnetSubscriber( @Provides @Singleton static SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager( - Spec spec, P2PConfig p2pConfig, + Spec spec, + P2PConfig p2pConfig, EventChannelSubscriber slotEventsChannelSubscriber, Eth2P2PNetwork p2pNetwork) { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java index 4c6bd423864..66af0d6d0c8 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java @@ -8,8 +8,11 @@ import tech.pegasys.teku.beacon.sync.SyncService; import tech.pegasys.teku.beacon.sync.SyncServiceFactory; import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; +import tech.pegasys.teku.beacon.sync.gossip.blobs.RecentBlobSidecarsFetcher; +import tech.pegasys.teku.beacon.sync.gossip.blocks.RecentBlocksFetcher; import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; import tech.pegasys.teku.infrastructure.events.EventChannels; import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.infrastructure.time.TimeProvider; @@ -19,9 +22,14 @@ import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; +import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.block.BlockImportChannel; import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; @@ -122,4 +130,39 @@ static SyncService syncService( return syncService; } + + @Provides + @Singleton + static RecentBlocksFetcher recentBlocksFetcher( + SyncService syncService, + BlockManager blockManager, + EventChannelSubscriber receivedBlockEventsChannelSubscriber, + LoggingModule.InitLogger initLogger) { + final RecentBlocksFetcher recentBlocksFetcher = syncService.getRecentBlocksFetcher(); + recentBlocksFetcher.subscribeBlockFetched( + (block) -> + blockManager + .importBlock( + block, BroadcastValidationLevel.NOT_REQUIRED, Optional.of(BlobSidecarManager.RemoteOrigin.RPC)) + .thenCompose(BlockImportChannel.BlockImportAndBroadcastValidationResults::blockImportResult) + .finish(err -> initLogger.logger().error("Failed to process recently fetched block.", err))); + receivedBlockEventsChannelSubscriber.subscribe(recentBlocksFetcher); + return recentBlocksFetcher; + } + + @Provides + @Singleton + static RecentBlobSidecarsFetcher recentBlocksFetcher( + SyncService syncService, + BlobSidecarManager blobSidecarManager) { + final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher = + syncService.getRecentBlobSidecarsFetcher(); + recentBlobSidecarsFetcher.subscribeBlobSidecarFetched( + (blobSidecar) -> blobSidecarManager.prepareForBlockImport(blobSidecar, BlobSidecarManager.RemoteOrigin.RPC)); + blobSidecarManager.subscribeToReceivedBlobSidecar( + blobSidecar -> + recentBlobSidecarsFetcher.cancelRecentBlobSidecarRequest( + new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()))); + return recentBlobSidecarsFetcher; + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index c585fc11890..5853dd414f2 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -3,6 +3,8 @@ import dagger.Module; import dagger.Provides; import javax.inject.Singleton; + +import dagger.multibindings.IntoSet; import tech.pegasys.teku.api.ChainDataProvider; import tech.pegasys.teku.api.DataProvider; import tech.pegasys.teku.api.RewardCalculator; @@ -46,6 +48,7 @@ import tech.pegasys.teku.statetransition.validation.AttestationValidator; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; +import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider; @@ -59,6 +62,7 @@ import tech.pegasys.teku.validator.coordinator.GraffitiBuilder; import tech.pegasys.teku.validator.coordinator.MilestoneBasedBlockFactory; import tech.pegasys.teku.validator.coordinator.ValidatorApiHandler; +import tech.pegasys.teku.validator.coordinator.ValidatorIndexCacheTracker; import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; @Module @@ -66,7 +70,7 @@ public interface ValidatorModule { @Provides @Singleton - static ActiveValidatorTracker provideActiveValidatorTracker( + static ActiveValidatorTracker activeValidatorTracker( Spec spec, EventChannelSubscriber slotEventsChannelSubscriber) { ActiveValidatorTracker activeValidatorTracker = new ActiveValidatorTracker(spec); slotEventsChannelSubscriber.subscribe(activeValidatorTracker); @@ -75,7 +79,7 @@ static ActiveValidatorTracker provideActiveValidatorTracker( @Provides @Singleton - static ExecutionLayerBlockProductionManager provideExecutionLayerBlockProductionManager( + static ExecutionLayerBlockProductionManager executionLayerBlockProductionManager( ExecutionLayerChannel executionLayer, EventChannelSubscriber slotEventsChannelSubscriber) { @@ -84,7 +88,7 @@ static ExecutionLayerBlockProductionManager provideExecutionLayerBlockProduction @Provides @Singleton - static GraffitiBuilder provideGraffitiBuilder( + static GraffitiBuilder graffitiBuilder( ValidatorConfig validatorConfig, EventChannelSubscriber executionClientVersionChannelSubscriber) { @@ -98,7 +102,7 @@ static GraffitiBuilder provideGraffitiBuilder( @Provides @Singleton - static GraffitiBuilder provideGraffitiBuilder( + static ExecutionClientVersionProvider executionClientVersionProvider( GraffitiBuilder graffitiBuilder, ExecutionLayerChannel executionLayer, ExecutionClientVersionChannel executionClientVersionChannelPublisher, @@ -110,12 +114,12 @@ static GraffitiBuilder provideGraffitiBuilder( executionClientVersionChannelPublisher, graffitiBuilder.getConsensusClientVersion()); executionClientEventsChannelSubscriber.subscribe(executionClientVersionProvider); - return graffitiBuilder; + return executionClientVersionProvider; } @Provides @Singleton - static BlockOperationSelectorFactory provideBlockOperationSelectorFactory( + static BlockOperationSelectorFactory blockOperationSelectorFactory( Spec spec, AggregatingAttestationPool attestationPool, OperationPool attesterSlashingPool, @@ -254,7 +258,19 @@ static AttestationManager attestationManager( @Provides @Singleton - static ValidatorIsConnectedProvider validatorIsConnectedProvider(ForkChoiceNotifier forkChoiceNotifier) { + static ValidatorIsConnectedProvider validatorIsConnectedProvider( + ForkChoiceNotifier forkChoiceNotifier) { return new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier); } + + @Provides + @Singleton + static ValidatorIndexCacheTracker validatorIndexCacheTracker( + RecentChainData recentChainData, + EventChannelSubscriber finalizedCheckpointChannelSubscriber) { + final ValidatorIndexCacheTracker validatorIndexCacheTracker = + new ValidatorIndexCacheTracker(recentChainData); + finalizedCheckpointChannelSubscriber.subscribe(validatorIndexCacheTracker); + return validatorIndexCacheTracker; + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java index 17caa71f4a6..c2a0073d73e 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java @@ -29,35 +29,35 @@ public interface VerifyModule { @Provides @Singleton - static GossipValidationHelper provideGossipValidationHelper( + static GossipValidationHelper gossipValidationHelper( Spec spec, RecentChainData recentChainData) { return new GossipValidationHelper(spec, recentChainData); } @Provides @Singleton - static AttesterSlashingValidator provideAttesterSlashingValidator( + static AttesterSlashingValidator attesterSlashingValidator( Spec spec, RecentChainData recentChainData) { return new AttesterSlashingValidator(recentChainData, spec); } @Provides @Singleton - static ProposerSlashingValidator provideProposerSlashingValidator( + static ProposerSlashingValidator proposerSlashingValidator( Spec spec, RecentChainData recentChainData) { return new ProposerSlashingValidator(spec, recentChainData); } @Provides @Singleton - static VoluntaryExitValidator provideVoluntaryExitValidator( + static VoluntaryExitValidator voluntaryExitValidator( Spec spec, RecentChainData recentChainData) { return new VoluntaryExitValidator(spec, recentChainData); } @Provides @Singleton - static SignedBlsToExecutionChangeValidator provideSignedBlsToExecutionChangeValidator( + static SignedBlsToExecutionChangeValidator signedBlsToExecutionChangeValidator( Spec spec, TimeProvider timeProvider, RecentChainData recentChainData, @@ -68,7 +68,7 @@ static SignedBlsToExecutionChangeValidator provideSignedBlsToExecutionChangeVali @Provides @Singleton - static MergeTransitionBlockValidator provideMergeTransitionBlockValidator( + static MergeTransitionBlockValidator mergeTransitionBlockValidator( Spec spec, RecentChainData recentChainData, ExecutionLayerChannel executionLayer) { return new MergeTransitionBlockValidator(spec, recentChainData, executionLayer); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java index 3d7eb7ed653..53b88c0c73e 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java @@ -12,6 +12,7 @@ import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; import tech.pegasys.teku.storage.api.StorageQueryChannel; import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @@ -19,6 +20,8 @@ import javax.inject.Singleton; +import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; + @Module public interface WSModule { @@ -26,6 +29,10 @@ interface WeakSubjectivityPeriodValidator { void validate(RecentChainData recentChainData); } + interface WeakSubjectivityStoreChainValidator { + void validate(UInt64 currentSlot); + } + @Provides @Singleton static WeakSubjectivityInitializer weakSubjectivityInitializer() { @@ -78,4 +85,32 @@ static WeakSubjectivityPeriodValidator weakSubjectivityPeriodValidator( latestFinalizedAnchor, currentSlot, spec, wsCalculator); }; } + + @Provides + @Singleton + static WeakSubjectivityStoreChainValidator weakSubjectivityStoreChainValidator( + WeakSubjectivityValidator weakSubjectivityValidator, + CombinedChainDataClient combinedChainDataClient, + RecentChainData recentChainData) { + return currentSlot -> { + weakSubjectivityValidator + .validateChainIsConsistentWithWSCheckpoint(combinedChainDataClient) + .thenCompose( + __ -> + SafeFuture.of( + () -> recentChainData.getStore().retrieveFinalizedCheckpointAndState())) + .thenAccept( + finalizedCheckpointState -> { + final UInt64 slot = currentSlot.max(recentChainData.getCurrentSlot().orElse(ZERO)); + weakSubjectivityValidator.validateLatestFinalizedCheckpoint( + finalizedCheckpointState, slot); + }) + .finish( + err -> { + weakSubjectivityValidator.handleValidationFailure( + "Encountered an error while trying to validate latest finalized checkpoint", err); + throw new RuntimeException(err); + }); + }; + } } From 4815f6688b77becdc69cb1273c3c77e087936fbb Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Thu, 20 Jun 2024 15:03:25 +0400 Subject: [PATCH 06/27] Fix compile errors --- .../teku/services/beaconchain/init/SpecModule.java | 2 +- .../teku/services/beaconchain/init/SyncModule.java | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index 3c97963c062..3041c0582fe 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -52,7 +52,7 @@ static CurrentSlotProvider currentSlotProvider(Spec spec, TimeProvider timeProvi return new CurrentSlotProvider() { @Override public UInt64 getCurrentSlot(UInt64 genesisTime) { - return getCurrentSlot(timeProvider.getTimeInSeconds(), genesisTime); + return getCurrentSlot(genesisTime, timeProvider.getTimeInSeconds()); } @Override diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java index 66af0d6d0c8..e1273749dbd 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java @@ -2,6 +2,9 @@ import dagger.Module; import dagger.Provides; +import java.time.Duration; +import java.util.Optional; +import javax.inject.Singleton; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.beacon.sync.DefaultSyncServiceFactory; import tech.pegasys.teku.beacon.sync.SyncConfig; @@ -18,7 +21,6 @@ import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; -import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; @@ -41,10 +43,6 @@ import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.validator.coordinator.DepositProvider; -import javax.inject.Singleton; -import java.time.Duration; -import java.util.Optional; - @Module public interface SyncModule { @@ -152,7 +150,7 @@ static RecentBlocksFetcher recentBlocksFetcher( @Provides @Singleton - static RecentBlobSidecarsFetcher recentBlocksFetcher( + static RecentBlobSidecarsFetcher recentBlobSidecarsFetcher( SyncService syncService, BlobSidecarManager blobSidecarManager) { final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher = From b1009038380be611dea204ffd3407f81856fcec6 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Thu, 20 Jun 2024 18:36:55 +0400 Subject: [PATCH 07/27] Add BeaconChainControllerComponent --- .../init/BeaconChainControllerComponent.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java new file mode 100644 index 00000000000..484c51b2e43 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java @@ -0,0 +1,39 @@ +package tech.pegasys.teku.services.beaconchain.init; + +import dagger.Component; + +import javax.inject.Singleton; + +@Singleton +@Component(modules = { + AsyncRunnerModule.class, + BeaconConfigModule.class, + BeaconModule.class, + BlobModule.class, + ChannelsModule.class, + CryptoModule.class, + DataProviderModule.class, + ExternalDependenciesModule.class, + ForkChoiceModule.class, + LoggingModule.class, + MainModule.class, + MetricsModule.class, + NetworkModule.class, + PoolAndCachesModule.class, + PowModule.class, + ServiceConfigModule.class, + SpecModule.class, + StorageModule.class, + SubnetsModule.class, + SyncModule.class, + ValidatorModule.class, + VerifyModule.class, + WSModule.class +}) +public interface BeaconChainControllerComponent { + + MainModule.ServiceStarter starter(); + + MainModule.ServiceStopper stopper(); + +} From 093862262548a2409a8885bfbeb89ddde5977b14 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Thu, 20 Jun 2024 18:38:16 +0400 Subject: [PATCH 08/27] Resolve missing and duplicate bindings --- .../beaconchain/init/BeaconConfigModule.java | 20 +++++++++++--- .../beaconchain/init/BeaconModule.java | 7 +++++ .../services/beaconchain/init/MainModule.java | 2 +- .../beaconchain/init/NetworkModule.java | 13 ++++++++++ .../init/RecentChainDataStateInitializer.java | 4 +++ .../services/beaconchain/init/WSModule.java | 26 +++++++++---------- 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java index 1617e42263d..dff03633f25 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java @@ -2,7 +2,9 @@ import dagger.Module; import dagger.Provides; +import tech.pegasys.teku.beacon.sync.SyncConfig; import tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig; +import tech.pegasys.teku.infrastructure.metrics.MetricsConfig; import tech.pegasys.teku.networking.eth2.P2PConfig; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; @@ -15,6 +17,11 @@ @Module public interface BeaconConfigModule { + @Provides + static Spec spec(BeaconChainConfiguration config){ + return config.getSpec(); + } + @Provides static Eth2NetworkConfiguration eth2NetworkConfig(BeaconChainConfiguration config){ return config.eth2NetworkConfig(); @@ -41,17 +48,22 @@ static ValidatorConfig validatorConfig(BeaconChainConfiguration config){ } @Provides - static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config){ - return config.beaconRestApiConfig(); + static SyncConfig syncConfig(BeaconChainConfiguration config){ + return config.syncConfig(); } @Provides - static Spec spec(BeaconChainConfiguration config){ - return config.getSpec(); + static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config){ + return config.beaconRestApiConfig(); } @Provides static WeakSubjectivityConfig weakSubjectivityConfig(BeaconChainConfiguration config) { return config.weakSubjectivity(); } + + @Provides + static MetricsConfig metricsConfig(BeaconChainConfiguration config) { + return config.getMetricsConfig(); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java index 80f1731469e..43d5d7e6fe1 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -49,6 +49,7 @@ import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; import tech.pegasys.teku.statetransition.forkchoice.TickProcessingPerformance; +import tech.pegasys.teku.statetransition.forkchoice.TickProcessor; import tech.pegasys.teku.statetransition.util.FutureItems; import tech.pegasys.teku.statetransition.util.PendingPool; import tech.pegasys.teku.statetransition.validation.BlockValidator; @@ -276,4 +277,10 @@ public void update() { } }; } + + @Provides + @Singleton + static TickProcessor tickProcessor(Spec spec, RecentChainData recentChainData) { + return new TickProcessor(spec, recentChainData); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index e0c6785730c..133cbb9cfd6 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -151,7 +151,7 @@ static ServiceStarter serviceStarter( @Provides @Singleton - static ServiceStarter serviceStopper( + static ServiceStopper serviceStopper( Optional beaconRestApi, SyncService syncService, BlockManager blockManager, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java index 578f754d260..b49fecfd405 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java @@ -14,6 +14,7 @@ import tech.pegasys.teku.networking.eth2.P2PConfig; import tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork; import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig; +import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.NetworkAsyncRunner; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; @@ -28,6 +29,7 @@ import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.statetransition.util.P2PDebugDataFileDumper; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @@ -124,4 +126,15 @@ static Eth2P2PNetwork eth2P2PNetwork( return p2pNetwork; } + + @Provides + @Singleton + static P2PDebugDataDumper p2pDebugDataDumper( + P2PConfig p2pConfig, + DataDirLayout dataDirLayout + ) { + return p2pConfig.isP2pDumpsToFileEnabled() + ? new P2PDebugDataFileDumper(dataDirLayout.getDebugDataDirectory()) + : P2PDebugDataDumper.NOOP; + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java index a55bf43c18f..5a31724d367 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java @@ -35,6 +35,10 @@ public class RecentChainDataStateInitializer { @Inject EventLogger eventLogger; @Inject StatusLogger statusLogger; + @Inject + public RecentChainDataStateInitializer() { + } + public void setupInitialState(RecentChainData recentChainData) { final Optional initialAnchor = diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java index 53b88c0c73e..72f4077e56c 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java @@ -25,6 +25,8 @@ @Module public interface WSModule { + record WeakSubjectivityFinalizedConfig(WeakSubjectivityConfig config) {} + interface WeakSubjectivityPeriodValidator { void validate(RecentChainData recentChainData); } @@ -41,31 +43,29 @@ static WeakSubjectivityInitializer weakSubjectivityInitializer() { @Provides @Singleton - static SafeFuture weakSubjectivityConfigFuture( + static SafeFuture weakSubjectivityFinalizedConfigFuture( WeakSubjectivityInitializer weakSubjectivityInitializer, WeakSubjectivityConfig weakSubjectivityConfig, StorageQueryChannel storageQueryChannel, - StorageUpdateChannel storageUpdateChannel - ) { - return weakSubjectivityInitializer.finalizeAndStoreConfig( + StorageUpdateChannel storageUpdateChannel) { + SafeFuture finalizedConfig = weakSubjectivityInitializer.finalizeAndStoreConfig( weakSubjectivityConfig, storageQueryChannel, storageUpdateChannel); + return finalizedConfig.thenApply(WeakSubjectivityFinalizedConfig::new); } @Provides @Singleton // TODO producer ? - static WeakSubjectivityConfig weakSubjectivityConfig( - SafeFuture weakSubjectivityConfigFuture - ) { + static WeakSubjectivityFinalizedConfig weakSubjectivityConfig( + SafeFuture weakSubjectivityConfigFuture) { return weakSubjectivityConfigFuture.join(); } @Provides @Singleton static WeakSubjectivityValidator weakSubjectivityValidator( - WeakSubjectivityConfig weakSubjectivityConfig - ) { - return WeakSubjectivityValidator.moderate(weakSubjectivityConfig); + WeakSubjectivityFinalizedConfig weakSubjectivityConfig) { + return WeakSubjectivityValidator.moderate(weakSubjectivityConfig.config()); } @Provides @@ -77,8 +77,7 @@ static WeakSubjectivityPeriodValidator weakSubjectivityPeriodValidator( WeakSubjectivityInitializer weakSubjectivityInitializer) { return client -> { final AnchorPoint latestFinalizedAnchor = client.getStore().getLatestFinalized(); - final UInt64 currentSlot = - currentSlotProvider.getCurrentSlot(client.getGenesisTime()); + final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(client.getGenesisTime()); final WeakSubjectivityCalculator wsCalculator = WeakSubjectivityCalculator.create(weakSubjectivityConfig); weakSubjectivityInitializer.validateAnchorIsWithinWeakSubjectivityPeriod( @@ -108,7 +107,8 @@ static WeakSubjectivityStoreChainValidator weakSubjectivityStoreChainValidator( .finish( err -> { weakSubjectivityValidator.handleValidationFailure( - "Encountered an error while trying to validate latest finalized checkpoint", err); + "Encountered an error while trying to validate latest finalized checkpoint", + err); throw new RuntimeException(err); }); }; From 64344678f7c9c1b960ad0f8c16d32d418ab7c0a5 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 16:08:53 +0400 Subject: [PATCH 09/27] Resolve circular dependencies --- .../beaconchain/init/BeaconModule.java | 4 ---- .../services/beaconchain/init/MainModule.java | 24 ++++++++++++++++++- .../beaconchain/init/StorageModule.java | 11 ++++----- .../beaconchain/init/ValidatorModule.java | 5 ++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java index 43d5d7e6fe1..d37beb2e7f4 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -140,7 +140,6 @@ static BlockManager blockManager( @InvalidBlockRoots Map invalidBlockRoots, Optional blockImportMetrics, FutureItems futureBlocks, - FailedExecutionPool failedExecutionPool, EventChannelSubscriber slotEventsChannelSubscriber, EventChannelSubscriber blockImportChannelSubscriber, EventChannelSubscriber receivedBlockEventsChannelSubscriber) { @@ -158,9 +157,6 @@ static BlockManager blockManager( eventLogger, blockImportMetrics); - if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { - blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); - } slotEventsChannelSubscriber.subscribe(blockManager); blockImportChannelSubscriber.subscribe(blockManager); receivedBlockEventsChannelSubscriber.subscribe(blockManager); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index 133cbb9cfd6..5fc18030fe0 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -18,12 +18,15 @@ import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; import tech.pegasys.teku.services.powchain.PowchainConfiguration; import tech.pegasys.teku.services.timer.TimerService; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; import tech.pegasys.teku.statetransition.OperationPool; import tech.pegasys.teku.statetransition.OperationsReOrgManager; import tech.pegasys.teku.statetransition.attestation.AttestationManager; import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.block.FailedExecutionPool; import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; import tech.pegasys.teku.statetransition.genesis.GenesisHandler; import tech.pegasys.teku.storage.client.RecentChainData; @@ -107,7 +110,26 @@ static VoidInitializer initRecentBlocksFetcher(RecentBlocksFetcher recentBlocksF @Provides @IntoSet static VoidInitializer initRecentBlobSidecarsFetcher( - RecentBlobSidecarsFetcher recentBlocksFetcher) { + RecentBlobSidecarsFetcher recentBlobSidecarsFetcher) { + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer subscribeFailedPayloadExecution( + Spec spec, BlockManager blockManager, FailedExecutionPool failedExecutionPool) { + if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); + } + return new VoidInitializer(); + } + + @Provides + @IntoSet + static VoidInitializer subscribeOnStoreInitialized( + RecentChainData recentChainData, StorageModule.OnStoreInitializedHandler onStoreInitializedHandler) { + + recentChainData.subscribeStoreInitialized(onStoreInitializedHandler::handle); return new VoidInitializer(); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index eb938ebb7ee..2d1982edebe 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -94,7 +94,7 @@ static SafeFuture recentChainDataFuture( StoreConfig storeConfig, StorageQueryChannel storageQueryChannel, StorageUpdateChannel storageUpdateChannel, - BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + Lazy blockBlobSidecarsTrackersPool, VoteUpdateChannel voteUpdateChannel, FinalizedCheckpointChannel finalizedCheckpointChannel, ChainHeadChannel chainHeadChannel, @@ -105,8 +105,8 @@ static SafeFuture recentChainDataFuture( storeConfig, beaconAsyncRunner, timeProvider, - blockBlobSidecarsTrackersPool::getBlock, - blockBlobSidecarsTrackersPool::getBlobSidecar, + blockRoot -> blockBlobSidecarsTrackersPool.get().getBlock(blockRoot), + (blockRoot, index) -> blockBlobSidecarsTrackersPool.get().getBlobSidecar(blockRoot, index), storageQueryChannel, storageUpdateChannel, voteUpdateChannel, @@ -124,8 +124,7 @@ static RecentChainData recentChainData( SafeFuture recentChainDataFuture, StatusLogger statusLogger, Lazy weakSubjectivityPeriodValidator, - Lazy recentChainDataStateInitializer, - OnStoreInitializedHandler onStoreInitializedHandler) { + Lazy recentChainDataStateInitializer) { RecentChainData recentChainData = recentChainDataFuture.join(); @@ -150,8 +149,6 @@ static RecentChainData recentChainData( } } - recentChainData.subscribeStoreInitialized(onStoreInitializedHandler::handle); - return recentChainData; } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index 5853dd414f2..744fecc2cd5 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -1,5 +1,6 @@ package tech.pegasys.teku.services.beaconchain.init; +import dagger.Lazy; import dagger.Module; import dagger.Provides; import javax.inject.Singleton; @@ -259,8 +260,8 @@ static AttestationManager attestationManager( @Provides @Singleton static ValidatorIsConnectedProvider validatorIsConnectedProvider( - ForkChoiceNotifier forkChoiceNotifier) { - return new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier); + Lazy forkChoiceNotifier) { + return new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier.get()); } @Provides From f5b05a91c2e965552408f47a991be8c06827c8bf Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 17:00:56 +0400 Subject: [PATCH 10/27] New Dagger based BeaconChainController --- .../beaconchain/BeaconChainController.java | 1529 +--------------- .../BeaconChainControllerFactory.java | 10 +- .../beaconchain/BeaconChainControllerOld.java | 1596 +++++++++++++++++ .../init/BeaconChainControllerComponent.java | 58 +- .../services/beaconchain/init/MainModule.java | 38 + .../teku/config/TekuConfigurationTest.java | 46 +- 6 files changed, 1733 insertions(+), 1544 deletions(-) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index 1989071b384..537d04a5e23 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -13,200 +13,23 @@ package tech.pegasys.teku.services.beaconchain; -import static tech.pegasys.teku.infrastructure.exceptions.ExitConstants.FATAL_EXIT_CODE; -import static tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG; -import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; -import static tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory.BEACON; -import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds; -import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; -import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; -import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; -import static tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool.DEFAULT_MAXIMUM_ATTESTATION_COUNT; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Throwables; -import java.io.IOException; -import java.net.BindException; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Comparator; -import java.util.Map; import java.util.Optional; -import java.util.function.Function; -import java.util.function.IntSupplier; +import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.plugin.services.MetricsSystem; -import tech.pegasys.teku.api.ChainDataProvider; -import tech.pegasys.teku.api.DataProvider; -import tech.pegasys.teku.api.ExecutionClientDataProvider; -import tech.pegasys.teku.api.RewardCalculator; -import tech.pegasys.teku.beacon.sync.DefaultSyncServiceFactory; import tech.pegasys.teku.beacon.sync.SyncService; -import tech.pegasys.teku.beacon.sync.SyncServiceFactory; -import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; -import tech.pegasys.teku.beacon.sync.gossip.blobs.RecentBlobSidecarsFetcher; -import tech.pegasys.teku.beacon.sync.gossip.blocks.RecentBlocksFetcher; import tech.pegasys.teku.beaconrestapi.BeaconRestApi; -import tech.pegasys.teku.beaconrestapi.JsonTypeDefinitionBeaconRestApi; -import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; -import tech.pegasys.teku.ethereum.events.SlotEventsChannel; -import tech.pegasys.teku.ethereum.execution.types.Eth1Address; -import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionChannel; -import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionProvider; -import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionAndPublishingPerformanceFactory; -import tech.pegasys.teku.ethereum.pow.api.Eth1EventsChannel; -import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.async.SafeFuture; -import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; -import tech.pegasys.teku.infrastructure.collections.LimitedMap; -import tech.pegasys.teku.infrastructure.events.EventChannels; -import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; -import tech.pegasys.teku.infrastructure.io.PortAvailability; -import tech.pegasys.teku.infrastructure.metrics.SettableGauge; -import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge; -import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; import tech.pegasys.teku.infrastructure.time.TimeProvider; -import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.kzg.KZG; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; -import tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder; -import tech.pegasys.teku.networking.eth2.P2PConfig; -import tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipChannel; -import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; -import tech.pegasys.teku.networking.eth2.gossip.subnets.AllSubnetsSubscriber; -import tech.pegasys.teku.networking.eth2.gossip.subnets.AllSyncCommitteeSubscriptions; -import tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber; -import tech.pegasys.teku.networking.eth2.gossip.subnets.NodeBasedStableSubnetSubscriber; -import tech.pegasys.teku.networking.eth2.gossip.subnets.StableSubnetSubscriber; -import tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager; -import tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork; -import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig; -import tech.pegasys.teku.networks.Eth2NetworkConfiguration; -import tech.pegasys.teku.networks.StateBoostrapConfig; import tech.pegasys.teku.service.serviceutils.Service; -import tech.pegasys.teku.service.serviceutils.ServiceConfig; -import tech.pegasys.teku.services.executionlayer.ExecutionLayerBlockManagerFactory; -import tech.pegasys.teku.services.timer.TimerService; import tech.pegasys.teku.spec.Spec; -import tech.pegasys.teku.spec.SpecMilestone; -import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation; -import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; -import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; -import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; -import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.capella.BeaconBlockBodySchemaCapella; -import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; -import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder; -import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; -import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; -import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; -import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; -import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; -import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; -import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager; -import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; -import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; -import tech.pegasys.teku.spec.logic.common.util.BlockRewardCalculatorUtil; -import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb; -import tech.pegasys.teku.statetransition.EpochCachePrimer; -import tech.pegasys.teku.statetransition.LocalOperationAcceptedFilter; -import tech.pegasys.teku.statetransition.MappedOperationPool; -import tech.pegasys.teku.statetransition.OperationPool; -import tech.pegasys.teku.statetransition.OperationsReOrgManager; -import tech.pegasys.teku.statetransition.SimpleOperationPool; -import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool; -import tech.pegasys.teku.statetransition.attestation.AttestationManager; -import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; -import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager.RemoteOrigin; -import tech.pegasys.teku.statetransition.blobs.BlobSidecarManagerImpl; -import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; -import tech.pegasys.teku.statetransition.block.BlockImportChannel; -import tech.pegasys.teku.statetransition.block.BlockImportChannel.BlockImportAndBroadcastValidationResults; -import tech.pegasys.teku.statetransition.block.BlockImportMetrics; -import tech.pegasys.teku.statetransition.block.BlockImporter; -import tech.pegasys.teku.statetransition.block.BlockManager; -import tech.pegasys.teku.statetransition.block.FailedExecutionPool; -import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceStateProvider; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; -import tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator; -import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; -import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; -import tech.pegasys.teku.statetransition.forkchoice.TickProcessingPerformance; -import tech.pegasys.teku.statetransition.forkchoice.TickProcessor; -import tech.pegasys.teku.statetransition.genesis.GenesisHandler; -import tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator; -import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; -import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; -import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator; -import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils; -import tech.pegasys.teku.statetransition.util.BlockBlobSidecarsTrackersPoolImpl; -import tech.pegasys.teku.statetransition.util.FutureItems; -import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; -import tech.pegasys.teku.statetransition.util.P2PDebugDataFileDumper; -import tech.pegasys.teku.statetransition.util.PendingPool; -import tech.pegasys.teku.statetransition.util.PoolFactory; -import tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator; -import tech.pegasys.teku.statetransition.validation.AttestationValidator; -import tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator; -import tech.pegasys.teku.statetransition.validation.BlobSidecarGossipValidator; -import tech.pegasys.teku.statetransition.validation.BlockGossipValidator; -import tech.pegasys.teku.statetransition.validation.BlockValidator; -import tech.pegasys.teku.statetransition.validation.GossipValidationHelper; -import tech.pegasys.teku.statetransition.validation.InternalValidationResult; -import tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator; -import tech.pegasys.teku.statetransition.validation.SignedBlsToExecutionChangeValidator; -import tech.pegasys.teku.statetransition.validation.VoluntaryExitValidator; -import tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; -import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache; -import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; -import tech.pegasys.teku.storage.api.ChainHeadChannel; -import tech.pegasys.teku.storage.api.CombinedStorageChannel; -import tech.pegasys.teku.storage.api.Eth1DepositStorageChannel; -import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; -import tech.pegasys.teku.storage.api.StorageQueryChannel; -import tech.pegasys.teku.storage.api.StorageUpdateChannel; -import tech.pegasys.teku.storage.api.VoteUpdateChannel; import tech.pegasys.teku.storage.client.CombinedChainDataClient; -import tech.pegasys.teku.storage.client.EarliestAvailableBlockSlot; import tech.pegasys.teku.storage.client.RecentChainData; -import tech.pegasys.teku.storage.client.StorageBackedRecentChainData; -import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider; -import tech.pegasys.teku.storage.store.FileKeyValueStore; -import tech.pegasys.teku.storage.store.KeyValueStore; -import tech.pegasys.teku.storage.store.StoreConfig; -import tech.pegasys.teku.validator.api.InteropConfig; -import tech.pegasys.teku.validator.api.ValidatorApiChannel; -import tech.pegasys.teku.validator.api.ValidatorPerformanceTrackingMode; -import tech.pegasys.teku.validator.api.ValidatorTimingChannel; -import tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker; -import tech.pegasys.teku.validator.coordinator.BlockFactory; -import tech.pegasys.teku.validator.coordinator.BlockOperationSelectorFactory; -import tech.pegasys.teku.validator.coordinator.DepositProvider; -import tech.pegasys.teku.validator.coordinator.DutyMetrics; -import tech.pegasys.teku.validator.coordinator.Eth1DataCache; -import tech.pegasys.teku.validator.coordinator.Eth1DataProvider; -import tech.pegasys.teku.validator.coordinator.Eth1VotingPeriod; -import tech.pegasys.teku.validator.coordinator.GraffitiBuilder; -import tech.pegasys.teku.validator.coordinator.MilestoneBasedBlockFactory; -import tech.pegasys.teku.validator.coordinator.ValidatorApiHandler; -import tech.pegasys.teku.validator.coordinator.ValidatorIndexCacheTracker; -import tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker; -import tech.pegasys.teku.validator.coordinator.performance.NoOpPerformanceTracker; -import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; -import tech.pegasys.teku.validator.coordinator.performance.SyncCommitteePerformanceTracker; -import tech.pegasys.teku.validator.coordinator.performance.ValidatorPerformanceMetrics; -import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; -import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; /** * The central class which assembles together and initializes Beacon Chain components @@ -219,1329 +42,55 @@ public class BeaconChainController extends Service implements BeaconChainControl private static final Logger LOG = LogManager.getLogger(); - protected static final String KEY_VALUE_STORE_SUBDIRECTORY = "kvstore"; + private final Spec spec; + private final TimeProvider timeProvider; + private final AsyncRunnerFactory asyncRunnerFactory; + private final ForkChoice forkChoice; + private final RecentChainData recentChainData; + private final Eth2P2PNetwork p2pNetwork; + private final Optional beaconRestAPI; + private final SyncService syncService; + private final SignatureVerificationService signatureVerificationService; + private final CombinedChainDataClient combinedChainDataClient; - protected volatile BeaconChainConfiguration beaconConfig; - protected volatile Spec spec; - protected volatile Function> beaconBlockSchemaSupplier; - protected volatile EventChannels eventChannels; - protected volatile MetricsSystem metricsSystem; - protected volatile AsyncRunner beaconAsyncRunner; - protected volatile TimeProvider timeProvider; - protected volatile SlotEventsChannel slotEventsChannelPublisher; - protected volatile ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher; - protected volatile AsyncRunner networkAsyncRunner; - protected volatile AsyncRunnerFactory asyncRunnerFactory; - protected volatile AsyncRunner eventAsyncRunner; - protected volatile Path beaconDataDirectory; - protected volatile WeakSubjectivityInitializer wsInitializer = new WeakSubjectivityInitializer(); - protected volatile AsyncRunnerEventThread forkChoiceExecutor; - - private volatile AsyncRunner operationPoolAsyncRunner; - - protected volatile ForkChoice forkChoice; - protected volatile ForkChoiceTrigger forkChoiceTrigger; - protected volatile BlockImporter blockImporter; - - protected volatile DataProvider dataProvider; - protected volatile RecentChainData recentChainData; - protected volatile Eth2P2PNetwork p2pNetwork; - protected volatile Optional beaconRestAPI = Optional.empty(); - protected volatile AggregatingAttestationPool attestationPool; - protected volatile DepositProvider depositProvider; - protected volatile SyncService syncService; - protected volatile AttestationManager attestationManager; - protected volatile SignatureVerificationService signatureVerificationService; - protected volatile CombinedChainDataClient combinedChainDataClient; - protected volatile Eth1DataCache eth1DataCache; - protected volatile SlotProcessor slotProcessor; - protected volatile OperationPool attesterSlashingPool; - protected volatile OperationPool proposerSlashingPool; - protected volatile OperationPool voluntaryExitPool; - protected volatile MappedOperationPool blsToExecutionChangePool; - protected volatile SyncCommitteeContributionPool syncCommitteeContributionPool; - protected volatile SyncCommitteeMessagePool syncCommitteeMessagePool; - protected volatile WeakSubjectivityValidator weakSubjectivityValidator; - protected volatile PerformanceTracker performanceTracker; - protected volatile PendingPool pendingBlocks; - protected volatile BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool; - protected volatile Map invalidBlockRoots; - protected volatile CoalescingChainHeadChannel coalescingChainHeadChannel; - protected volatile ActiveValidatorTracker activeValidatorTracker; - protected volatile AttestationTopicSubscriber attestationTopicSubscriber; - protected volatile ForkChoiceNotifier forkChoiceNotifier; - protected volatile ForkChoiceStateProvider forkChoiceStateProvider; - protected volatile ExecutionLayerChannel executionLayer; - protected volatile GossipValidationHelper gossipValidationHelper; - protected volatile KZG kzg; - protected volatile BlobSidecarManager blobSidecarManager; - protected volatile Optional terminalPowBlockMonitor = Optional.empty(); - protected volatile ProposersDataManager proposersDataManager; - protected volatile KeyValueStore keyValueStore; - protected volatile StorageQueryChannel storageQueryChannel; - protected volatile StorageUpdateChannel storageUpdateChannel; - protected volatile StableSubnetSubscriber stableSubnetSubscriber; - protected volatile ExecutionLayerBlockProductionManager executionLayerBlockProductionManager; - protected volatile RewardCalculator rewardCalculator; - protected UInt64 genesisTimeTracker = ZERO; - protected BlockManager blockManager; - protected TimerService timerService; - protected PoolFactory poolFactory; - protected SettableLabelledGauge futureItemsMetric; - protected IntSupplier rejectedExecutionCountSupplier; - protected P2PDebugDataDumper p2pDebugDataDumper; + private final Supplier> starter; + private final Supplier> stopper; public BeaconChainController( - final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig) { - final Eth2NetworkConfiguration eth2NetworkConfig = beaconConfig.eth2NetworkConfig(); - this.beaconConfig = beaconConfig; - this.spec = beaconConfig.getSpec(); - this.beaconBlockSchemaSupplier = - slot -> spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockBodySchema(); - this.beaconDataDirectory = serviceConfig.getDataDirLayout().getBeaconDataDirectory(); - this.asyncRunnerFactory = serviceConfig.getAsyncRunnerFactory(); - this.beaconAsyncRunner = - serviceConfig.createAsyncRunner( - "beaconchain", - eth2NetworkConfig.getAsyncBeaconChainMaxThreads(), - eth2NetworkConfig.getAsyncBeaconChainMaxQueue()); - this.eventAsyncRunner = serviceConfig.createAsyncRunner("events", 10); - this.networkAsyncRunner = - serviceConfig.createAsyncRunner( - "p2p", - eth2NetworkConfig.getAsyncP2pMaxThreads(), - eth2NetworkConfig.getAsyncP2pMaxQueue()); - this.operationPoolAsyncRunner = serviceConfig.createAsyncRunner("operationPoolUpdater", 1); - this.timeProvider = serviceConfig.getTimeProvider(); - this.eventChannels = serviceConfig.getEventChannels(); - this.metricsSystem = serviceConfig.getMetricsSystem(); - this.poolFactory = new PoolFactory(this.metricsSystem); - this.rejectedExecutionCountSupplier = serviceConfig.getRejectedExecutionsSupplier(); - this.slotEventsChannelPublisher = eventChannels.getPublisher(SlotEventsChannel.class); - this.receivedBlockEventsChannelPublisher = - eventChannels.getPublisher(ReceivedBlockEventsChannel.class); - this.forkChoiceExecutor = new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); - this.p2pDebugDataDumper = - beaconConfig.p2pConfig().isP2pDumpsToFileEnabled() - ? new P2PDebugDataFileDumper(serviceConfig.getDataDirLayout().getDebugDataDirectory()) - : P2PDebugDataDumper.NOOP; - this.futureItemsMetric = - SettableLabelledGauge.create( - metricsSystem, - BEACON, - "future_items_size", - "Current number of items held for future slots, labelled by type", - "type"); + Spec spec, + TimeProvider timeProvider, + AsyncRunnerFactory asyncRunnerFactory, + ForkChoice forkChoice, + RecentChainData recentChainData, + Eth2P2PNetwork p2pNetwork, + Optional beaconRestAPI, + SyncService syncService, + SignatureVerificationService signatureVerificationService, + CombinedChainDataClient combinedChainDataClient, + Supplier> starter, + Supplier> stopper) { + this.spec = spec; + this.timeProvider = timeProvider; + this.asyncRunnerFactory = asyncRunnerFactory; + this.forkChoice = forkChoice; + this.recentChainData = recentChainData; + this.p2pNetwork = p2pNetwork; + this.beaconRestAPI = beaconRestAPI; + this.syncService = syncService; + this.signatureVerificationService = signatureVerificationService; + this.combinedChainDataClient = combinedChainDataClient; + this.starter = starter; + this.stopper = stopper; } @Override protected SafeFuture doStart() { - LOG.debug("Starting {}", this.getClass().getSimpleName()); - forkChoiceExecutor.start(); - return initialize() - .thenCompose( - (__) -> - beaconRestAPI.map(BeaconRestApi::start).orElse(SafeFuture.completedFuture(null))); - } - - protected void startServices() { - final RecentBlocksFetcher recentBlocksFetcher = syncService.getRecentBlocksFetcher(); - recentBlocksFetcher.subscribeBlockFetched( - (block) -> - blockManager - .importBlock( - block, BroadcastValidationLevel.NOT_REQUIRED, Optional.of(RemoteOrigin.RPC)) - .thenCompose(BlockImportAndBroadcastValidationResults::blockImportResult) - .finish(err -> LOG.error("Failed to process recently fetched block.", err))); - eventChannels.subscribe(ReceivedBlockEventsChannel.class, recentBlocksFetcher); - final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher = - syncService.getRecentBlobSidecarsFetcher(); - recentBlobSidecarsFetcher.subscribeBlobSidecarFetched( - (blobSidecar) -> blobSidecarManager.prepareForBlockImport(blobSidecar, RemoteOrigin.RPC)); - blobSidecarManager.subscribeToReceivedBlobSidecar( - blobSidecar -> - recentBlobSidecarsFetcher.cancelRecentBlobSidecarRequest( - new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()))); - SafeFuture.allOfFailFast( - attestationManager.start(), - p2pNetwork.start(), - blockManager.start(), - syncService.start(), - SafeFuture.fromRunnable( - () -> terminalPowBlockMonitor.ifPresent(TerminalPowBlockMonitor::start))) - .finish( - error -> { - Throwable rootCause = Throwables.getRootCause(error); - if (rootCause instanceof BindException) { - final String errorWhilePerformingDescription = - "starting P2P services on port " + this.p2pNetwork.getListenPort() + "."; - STATUS_LOG.fatalError(errorWhilePerformingDescription, rootCause); - System.exit(FATAL_EXIT_CODE); - } else { - Thread.currentThread() - .getUncaughtExceptionHandler() - .uncaughtException(Thread.currentThread(), error); - } - }); + return starter.get(); } @Override protected SafeFuture doStop() { - LOG.debug("Stopping {}", this.getClass().getSimpleName()); - return SafeFuture.allOf( - beaconRestAPI.map(BeaconRestApi::stop).orElse(SafeFuture.completedFuture(null)), - syncService.stop(), - blockManager.stop(), - attestationManager.stop(), - p2pNetwork.stop(), - timerService.stop(), - SafeFuture.fromRunnable( - () -> terminalPowBlockMonitor.ifPresent(TerminalPowBlockMonitor::stop))) - .thenRun(forkChoiceExecutor::stop); - } - - protected SafeFuture initialize() { - - timerService = new TimerService(this::onTick); - - final StoreConfig storeConfig = beaconConfig.storeConfig(); - coalescingChainHeadChannel = - new CoalescingChainHeadChannel( - eventChannels.getPublisher(ChainHeadChannel.class), EVENT_LOG); - - final CombinedStorageChannel combinedStorageChannel = - eventChannels.getPublisher(CombinedStorageChannel.class, beaconAsyncRunner); - storageQueryChannel = combinedStorageChannel; - storageUpdateChannel = combinedStorageChannel; - final VoteUpdateChannel voteUpdateChannel = eventChannels.getPublisher(VoteUpdateChannel.class); - - final ValidatorIsConnectedProvider validatorIsConnectedProvider = - new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier); - // Init other services - return initWeakSubjectivity(storageQueryChannel, storageUpdateChannel) - .thenCompose( - __ -> - StorageBackedRecentChainData.create( - metricsSystem, - storeConfig, - beaconAsyncRunner, - timeProvider, - (blockRoot) -> blockBlobSidecarsTrackersPool.getBlock(blockRoot), - (blockRoot, index) -> - blockBlobSidecarsTrackersPool.getBlobSidecar(blockRoot, index), - storageQueryChannel, - storageUpdateChannel, - voteUpdateChannel, - eventChannels.getPublisher(FinalizedCheckpointChannel.class, beaconAsyncRunner), - coalescingChainHeadChannel, - validatorIsConnectedProvider, - spec)) - .thenCompose( - client -> { - if (isAllowSyncOutsideWeakSubjectivityPeriod()) { - STATUS_LOG.warnIgnoringWeakSubjectivityPeriod(); - } - - // Setup chain storage - this.recentChainData = client; - if (recentChainData.isPreGenesis()) { - setupInitialState(client); - } else { - if (isUsingCustomInitialState()) { - STATUS_LOG.warnInitialStateIgnored(); - } - if (!isAllowSyncOutsideWeakSubjectivityPeriod()) { - validateWeakSubjectivityPeriod(client); - } - } - return SafeFuture.completedFuture(client); - }) - // Init other services - .thenRun(this::initAll) - .thenRun( - () -> { - recentChainData.subscribeStoreInitialized(this::onStoreInitialized); - recentChainData.subscribeBestBlockInitialized(this::startServices); - }) - .thenCompose(__ -> - timerService.start() - ); - } - - private boolean isUsingCustomInitialState() { - return beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().isUsingCustomInitialState(); - } - - private boolean isAllowSyncOutsideWeakSubjectivityPeriod() { - return beaconConfig - .eth2NetworkConfig() - .getNetworkBoostrapConfig() - .isAllowSyncOutsideWeakSubjectivityPeriod(); - } - - private void validateWeakSubjectivityPeriod(final RecentChainData client) { - final AnchorPoint latestFinalizedAnchor = client.getStore().getLatestFinalized(); - final UInt64 currentSlot = getCurrentSlot(client.getGenesisTime()); - final WeakSubjectivityCalculator wsCalculator = - WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity()); - wsInitializer.validateAnchorIsWithinWeakSubjectivityPeriod( - latestFinalizedAnchor, currentSlot, spec, wsCalculator); - } - - public void initAll() { - initKeyValueStore(); - initExecutionLayer(); - initExecutionLayerBlockProductionManager(); - initRewardCalculator(); - initGossipValidationHelper(); - initBlockPoolsAndCaches(); - initKzg(); - initBlockBlobSidecarsTrackersPool(); - initBlobSidecarManager(); - initForkChoiceStateProvider(); - initForkChoiceNotifier(); - initMergeMonitors(); - initForkChoice(); - initBlockImporter(); - initCombinedChainDataClient(); - initSignatureVerificationService(); - initAttestationPool(); - initAttesterSlashingPool(); - initProposerSlashingPool(); - initVoluntaryExitPool(); - initSignedBlsToExecutionChangePool(); - initEth1DataCache(); - initDepositProvider(); - initGenesisHandler(); - initAttestationManager(); - initBlockManager(); - initSyncCommitteePools(); - initP2PNetwork(); - initSyncService(); - initSlotProcessor(); - initMetrics(); - initAttestationTopicSubscriber(); - initActiveValidatorTracker(); - initSubnetSubscriber(); - initSlashingEventsSubscriptions(); - initPerformanceTracker(); - initDataProvider(); - initValidatorApiHandler(); - initRestAPI(); - initOperationsReOrgManager(); - initValidatorIndexCacheTracker(); - } - - private void initKeyValueStore() { - keyValueStore = - new FileKeyValueStore(beaconDataDirectory.resolve(KEY_VALUE_STORE_SUBDIRECTORY)); - } - - protected void initExecutionLayer() { - executionLayer = eventChannels.getPublisher(ExecutionLayerChannel.class, beaconAsyncRunner); - } - - protected void initKzg() { - if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { - kzg = KZG.getInstance(); - final String trustedSetupFile = - beaconConfig - .eth2NetworkConfig() - .getTrustedSetup() - .orElseThrow( - () -> - new InvalidConfigurationException( - "Trusted setup should be configured when Deneb is enabled")); - kzg.loadTrustedSetup(trustedSetupFile); - } else { - kzg = KZG.NOOP; - } - } - - protected void initBlobSidecarManager() { - if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { - final FutureItems futureBlobSidecars = - FutureItems.create(BlobSidecar::getSlot, futureItemsMetric, "blob_sidecars"); - - final Map invalidBlobSidecarRoots = - LimitedMap.createSynchronizedLRU(500); - final MiscHelpersDeneb miscHelpers = - MiscHelpersDeneb.required(spec.forMilestone(SpecMilestone.DENEB).miscHelpers()); - final BlobSidecarGossipValidator blobSidecarValidator = - BlobSidecarGossipValidator.create( - spec, invalidBlockRoots, gossipValidationHelper, miscHelpers, kzg); - final BlobSidecarManagerImpl blobSidecarManagerImpl = - new BlobSidecarManagerImpl( - spec, - beaconAsyncRunner, - recentChainData, - blockBlobSidecarsTrackersPool, - blobSidecarValidator, - kzg, - futureBlobSidecars, - invalidBlobSidecarRoots); - eventChannels.subscribe(SlotEventsChannel.class, blobSidecarManagerImpl); - - blobSidecarManager = blobSidecarManagerImpl; - } else { - blobSidecarManager = BlobSidecarManager.NOOP; - } - } - - protected void initMergeMonitors() { - if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { - terminalPowBlockMonitor = - Optional.of( - new TerminalPowBlockMonitor( - executionLayer, - spec, - recentChainData, - forkChoiceNotifier, - beaconAsyncRunner, - EVENT_LOG, - timeProvider)); - } - } - - protected void initBlockPoolsAndCaches() { - LOG.debug("BeaconChainController.initBlockPoolsAndCaches()"); - pendingBlocks = poolFactory.createPendingPoolForBlocks(spec); - eventChannels.subscribe(FinalizedCheckpointChannel.class, pendingBlocks); - invalidBlockRoots = LimitedMap.createSynchronizedLRU(500); - } - - protected void initBlockBlobSidecarsTrackersPool() { - LOG.debug("BeaconChainController.initBlockBlobSidecarsTrackersPool()"); - if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { - final BlockImportChannel blockImportChannel = - eventChannels.getPublisher(BlockImportChannel.class, beaconAsyncRunner); - final BlockBlobSidecarsTrackersPoolImpl pool = - poolFactory.createPoolForBlockBlobSidecarsTrackers( - blockImportChannel, spec, timeProvider, beaconAsyncRunner, recentChainData); - eventChannels.subscribe(FinalizedCheckpointChannel.class, pool); - blockBlobSidecarsTrackersPool = pool; - - } else { - blockBlobSidecarsTrackersPool = BlockBlobSidecarsTrackersPool.NOOP; - } - } - - protected void initGossipValidationHelper() { - LOG.debug("BeaconChainController.initGossipValidationHelper()"); - gossipValidationHelper = new GossipValidationHelper(spec, recentChainData); - } - - protected void initPerformanceTracker() { - LOG.debug("BeaconChainController.initPerformanceTracker()"); - ValidatorPerformanceTrackingMode mode = - beaconConfig.validatorConfig().getValidatorPerformanceTrackingMode(); - if (mode.isEnabled()) { - final SettableGauge performanceTrackerTimings = - SettableGauge.create( - metricsSystem, - BEACON, - "performance_tracker_timings", - "Tracks how much time (in millis) performance tracker takes to perform calculations"); - performanceTracker = - new DefaultPerformanceTracker( - combinedChainDataClient, - STATUS_LOG, - new ValidatorPerformanceMetrics(metricsSystem), - beaconConfig.validatorConfig().getValidatorPerformanceTrackingMode(), - activeValidatorTracker, - new SyncCommitteePerformanceTracker(spec, combinedChainDataClient), - spec, - performanceTrackerTimings); - eventChannels.subscribe(SlotEventsChannel.class, performanceTracker); - } else { - performanceTracker = new NoOpPerformanceTracker(); - } - } - - protected void initAttesterSlashingPool() { - LOG.debug("BeaconChainController.initAttesterSlashingPool()"); - attesterSlashingPool = - new SimpleOperationPool<>( - "AttesterSlashingPool", - metricsSystem, - beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getAttesterSlashingsSchema), - new AttesterSlashingValidator(recentChainData, spec), - // Prioritise slashings that include more validators at a time - Comparator.comparingInt( - slashing -> slashing.getIntersectingValidatorIndices().size()) - .reversed()); - blockImporter.subscribeToVerifiedBlockAttesterSlashings(attesterSlashingPool::removeAll); - attesterSlashingPool.subscribeOperationAdded(forkChoice::onAttesterSlashing); - } - - protected void initProposerSlashingPool() { - LOG.debug("BeaconChainController.initProposerSlashingPool()"); - ProposerSlashingValidator validator = new ProposerSlashingValidator(spec, recentChainData); - proposerSlashingPool = - new SimpleOperationPool<>( - "ProposerSlashingPool", - metricsSystem, - beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getProposerSlashingsSchema), - validator); - blockImporter.subscribeToVerifiedBlockProposerSlashings(proposerSlashingPool::removeAll); - } - - protected void initSlashingEventsSubscriptions() { - if (beaconConfig.validatorConfig().isShutdownWhenValidatorSlashedEnabled()) { - final ValidatorTimingChannel validatorTimingChannel = - eventChannels.getPublisher(ValidatorTimingChannel.class); - attesterSlashingPool.subscribeOperationAdded( - (operation, validationStatus, fromNetwork) -> - validatorTimingChannel.onAttesterSlashing(operation)); - proposerSlashingPool.subscribeOperationAdded( - (operation, validationStatus, fromNetwork) -> - validatorTimingChannel.onProposerSlashing(operation)); - } - } - - protected void initVoluntaryExitPool() { - LOG.debug("BeaconChainController.initVoluntaryExitPool()"); - VoluntaryExitValidator validator = new VoluntaryExitValidator(spec, recentChainData); - voluntaryExitPool = - new MappedOperationPool<>( - "VoluntaryExitPool", - metricsSystem, - beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getVoluntaryExitsSchema), - validator, - operationPoolAsyncRunner, - timeProvider); - blockImporter.subscribeToVerifiedBlockVoluntaryExits(voluntaryExitPool::removeAll); - } - - protected void initSignedBlsToExecutionChangePool() { - LOG.debug("BeaconChainController.initSignedBlsToExecutionChangePool()"); - final SignedBlsToExecutionChangeValidator validator = - new SignedBlsToExecutionChangeValidator( - spec, timeProvider, recentChainData, signatureVerificationService); - - blsToExecutionChangePool = - new MappedOperationPool<>( - "SignedBlsToExecutionChangePool", - metricsSystem, - beaconBlockSchemaSupplier - .andThen(BeaconBlockBodySchema::toVersionCapella) - .andThen(Optional::orElseThrow) - .andThen(BeaconBlockBodySchemaCapella::getBlsToExecutionChangesSchema), - validator, - operationPoolAsyncRunner, - timeProvider); - blockImporter.subscribeToVerifiedBlockBlsToExecutionChanges( - blsToExecutionChangePool::removeAll); - } - - protected void initDataProvider() { - dataProvider = - DataProvider.builder() - .spec(spec) - .recentChainData(recentChainData) - .combinedChainDataClient(combinedChainDataClient) - .rewardCalculator(rewardCalculator) - .p2pNetwork(p2pNetwork) - .syncService(syncService) - .validatorApiChannel( - eventChannels.getPublisher(ValidatorApiChannel.class, beaconAsyncRunner)) - .attestationPool(attestationPool) - .blockBlobSidecarsTrackersPool(blockBlobSidecarsTrackersPool) - .attestationManager(attestationManager) - .isLivenessTrackingEnabled(getLivenessTrackingEnabled(beaconConfig)) - .activeValidatorChannel( - eventChannels.getPublisher(ActiveValidatorChannel.class, beaconAsyncRunner)) - .attesterSlashingPool(attesterSlashingPool) - .proposerSlashingPool(proposerSlashingPool) - .voluntaryExitPool(voluntaryExitPool) - .blsToExecutionChangePool(blsToExecutionChangePool) - .syncCommitteeContributionPool(syncCommitteeContributionPool) - .proposersDataManager(proposersDataManager) - .forkChoiceNotifier(forkChoiceNotifier) - .rejectedExecutionSupplier(rejectedExecutionCountSupplier) - .build(); - } - - private boolean getLivenessTrackingEnabled(BeaconChainConfiguration beaconConfig) { - return beaconConfig.beaconRestApiConfig().isBeaconLivenessTrackingEnabled() - || beaconConfig.validatorConfig().isDoppelgangerDetectionEnabled(); - } - - protected void initCombinedChainDataClient() { - LOG.debug("BeaconChainController.initCombinedChainDataClient()"); - final EarliestAvailableBlockSlot earliestAvailableBlockSlot = - new EarliestAvailableBlockSlot( - storageQueryChannel, - timeProvider, - beaconConfig.storeConfig().getEarliestAvailableBlockSlotFrequency()); - - combinedChainDataClient = - new CombinedChainDataClient( - recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); - } - - protected SafeFuture initWeakSubjectivity( - final StorageQueryChannel queryChannel, final StorageUpdateChannel updateChannel) { - return wsInitializer - .finalizeAndStoreConfig(beaconConfig.weakSubjectivity(), queryChannel, updateChannel) - .thenAccept( - finalConfig -> - this.weakSubjectivityValidator = WeakSubjectivityValidator.moderate(finalConfig)); - } - - protected void initForkChoice() { - LOG.debug("BeaconChainController.initForkChoice()"); - forkChoice = - new ForkChoice( - spec, - forkChoiceExecutor, - recentChainData, - blobSidecarManager, - forkChoiceNotifier, - forkChoiceStateProvider, - new TickProcessor(spec, recentChainData), - new MergeTransitionBlockValidator(spec, recentChainData, executionLayer), - beaconConfig.eth2NetworkConfig().isForkChoiceLateBlockReorgEnabled(), - p2pDebugDataDumper, - metricsSystem); - forkChoiceTrigger = new ForkChoiceTrigger(forkChoice); - } - - public void initMetrics() { - LOG.debug("BeaconChainController.initMetrics()"); - final SyncCommitteeMetrics syncCommitteeMetrics = - new SyncCommitteeMetrics(spec, recentChainData, metricsSystem); - final BeaconChainMetrics beaconChainMetrics = - new BeaconChainMetrics( - spec, - recentChainData, - slotProcessor.getNodeSlot(), - metricsSystem, - p2pNetwork, - eth1DataCache); - eventChannels - .subscribe(SlotEventsChannel.class, beaconChainMetrics) - .subscribe(SlotEventsChannel.class, syncCommitteeMetrics) - .subscribe(ChainHeadChannel.class, syncCommitteeMetrics); - } - - protected void initEth1DataCache() { - LOG.debug("BeaconChainController.initEth1DataCache"); - eth1DataCache = new Eth1DataCache(spec, metricsSystem, new Eth1VotingPeriod(spec)); - } - - public void initDepositProvider() { - LOG.debug("BeaconChainController.initDepositProvider()"); - depositProvider = - new DepositProvider( - metricsSystem, - recentChainData, - eth1DataCache, - storageUpdateChannel, - eventChannels.getPublisher(Eth1DepositStorageChannel.class, beaconAsyncRunner), - spec, - EVENT_LOG, - beaconConfig.powchainConfig().useMissingDepositEventLogging()); - eventChannels - .subscribe(Eth1EventsChannel.class, depositProvider) - .subscribe(FinalizedCheckpointChannel.class, depositProvider) - .subscribe(SlotEventsChannel.class, depositProvider); - } - - protected void initAttestationTopicSubscriber() { - LOG.debug("BeaconChainController.initAttestationTopicSubscriber"); - final SettableLabelledGauge subnetSubscriptionsGauge = - SettableLabelledGauge.create( - metricsSystem, - TekuMetricCategory.NETWORK, - "subnet_subscriptions", - "Tracks attestations subnet subscriptions", - "type"); - this.attestationTopicSubscriber = - new AttestationTopicSubscriber(spec, p2pNetwork, subnetSubscriptionsGauge); - } - - protected void initActiveValidatorTracker() { - LOG.debug("BeaconChainController.initActiveValidatorTracker"); - this.activeValidatorTracker = new ActiveValidatorTracker(spec); - } - - protected void initSubnetSubscriber() { - LOG.debug("BeaconChainController.initSubnetSubscriber"); - if (beaconConfig.p2pConfig().isSubscribeAllSubnetsEnabled()) { - LOG.info("Subscribing to all attestation subnets"); - this.stableSubnetSubscriber = - AllSubnetsSubscriber.create(attestationTopicSubscriber, spec.getNetworkingConfig()); - } else { - if (p2pNetwork.getDiscoveryNodeId().isPresent()) { - this.stableSubnetSubscriber = - new NodeBasedStableSubnetSubscriber( - attestationTopicSubscriber, spec, p2pNetwork.getDiscoveryNodeId().get()); - } else { - LOG.warn("Discovery nodeId is not defined, disabling stable subnet subscriptions"); - this.stableSubnetSubscriber = StableSubnetSubscriber.NOOP; - } - } - eventChannels.subscribe(SlotEventsChannel.class, stableSubnetSubscriber); - } - - public void initExecutionLayerBlockProductionManager() { - LOG.debug("BeaconChainController.initExecutionLayerBlockProductionManager()"); - this.executionLayerBlockProductionManager = - ExecutionLayerBlockManagerFactory.create( - executionLayer, eventChannels.createSubscriber(SlotEventsChannel.class)); - } - - public void initRewardCalculator() { - LOG.debug("BeaconChainController.initRewardCalculator()"); - rewardCalculator = new RewardCalculator(spec, new BlockRewardCalculatorUtil(spec)); - } - - public void initValidatorApiHandler() { - LOG.debug("BeaconChainController.initValidatorApiHandler()"); - final GraffitiBuilder graffitiBuilder = - new GraffitiBuilder( - beaconConfig.validatorConfig().getClientGraffitiAppendFormat(), - beaconConfig.validatorConfig().getGraffitiProvider().get()); - eventChannels.subscribe(ExecutionClientVersionChannel.class, graffitiBuilder); - final ExecutionClientVersionProvider executionClientVersionProvider = - new ExecutionClientVersionProvider( - executionLayer, - eventChannels.getPublisher(ExecutionClientVersionChannel.class), - graffitiBuilder.getConsensusClientVersion()); - final BlockOperationSelectorFactory operationSelector = - new BlockOperationSelectorFactory( - spec, - attestationPool, - attesterSlashingPool, - proposerSlashingPool, - voluntaryExitPool, - blsToExecutionChangePool, - syncCommitteeContributionPool, - depositProvider, - eth1DataCache, - graffitiBuilder, - forkChoiceNotifier, - executionLayerBlockProductionManager); - final BlockFactory blockFactory = new MilestoneBasedBlockFactory(spec, operationSelector); - SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager = - beaconConfig.p2pConfig().isSubscribeAllSubnetsEnabled() - ? new AllSyncCommitteeSubscriptions(p2pNetwork, spec) - : new SyncCommitteeSubscriptionManager(p2pNetwork); - final BlockImportChannel blockImportChannel = - eventChannels.getPublisher(BlockImportChannel.class, beaconAsyncRunner); - final BlockGossipChannel blockGossipChannel = - eventChannels.getPublisher(BlockGossipChannel.class); - final BlobSidecarGossipChannel blobSidecarGossipChannel; - if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { - blobSidecarGossipChannel = eventChannels.getPublisher(BlobSidecarGossipChannel.class); - } else { - blobSidecarGossipChannel = BlobSidecarGossipChannel.NOOP; - } - - final BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory = - new BlockProductionAndPublishingPerformanceFactory( - timeProvider, - (slot) -> secondsToMillis(recentChainData.computeTimeAtSlot(slot)), - beaconConfig.getMetricsConfig().isBlockProductionAndPublishingPerformanceEnabled(), - beaconConfig.getMetricsConfig().getBlockProductionPerformanceWarningLocalThreshold(), - beaconConfig.getMetricsConfig().getBlockProductionPerformanceWarningBuilderThreshold(), - beaconConfig.getMetricsConfig().getBlockPublishingPerformanceWarningLocalThreshold(), - beaconConfig.getMetricsConfig().getBlockPublishingPerformanceWarningBuilderThreshold()); - - final ValidatorApiHandler validatorApiHandler = - new ValidatorApiHandler( - new ChainDataProvider(spec, recentChainData, combinedChainDataClient, rewardCalculator), - dataProvider.getNodeDataProvider(), - combinedChainDataClient, - syncService, - blockFactory, - blockImportChannel, - blockGossipChannel, - blockBlobSidecarsTrackersPool, - blobSidecarGossipChannel, - attestationPool, - attestationManager, - attestationTopicSubscriber, - activeValidatorTracker, - DutyMetrics.create(metricsSystem, timeProvider, recentChainData, spec), - performanceTracker, - spec, - forkChoiceTrigger, - proposersDataManager, - syncCommitteeMessagePool, - syncCommitteeContributionPool, - syncCommitteeSubscriptionManager, - blockProductionPerformanceFactory); - eventChannels - .subscribe(SlotEventsChannel.class, activeValidatorTracker) - .subscribe(ExecutionClientEventsChannel.class, executionClientVersionProvider) - .subscribeMultithreaded( - ValidatorApiChannel.class, - validatorApiHandler, - beaconConfig.beaconRestApiConfig().getValidatorThreads()); - - // if subscribeAllSubnets is set, the slot events in these handlers are empty, - // so don't subscribe. - if (!beaconConfig.p2pConfig().isSubscribeAllSubnetsEnabled()) { - eventChannels - .subscribe(SlotEventsChannel.class, attestationTopicSubscriber) - .subscribe(SlotEventsChannel.class, syncCommitteeSubscriptionManager); - } - } - - protected void initGenesisHandler() { - if (!recentChainData.isPreGenesis()) { - // We already have a genesis block - no need for a genesis handler - return; - } else if (!beaconConfig.powchainConfig().isEnabled()) { - // We're pre-genesis but no eth1 endpoint is set - throw new IllegalStateException("ETH1 is disabled, but no initial state is set."); - } - STATUS_LOG.loadingGenesisFromEth1Chain(); - eventChannels.subscribe( - Eth1EventsChannel.class, new GenesisHandler(recentChainData, timeProvider, spec)); - } - - protected void initSignatureVerificationService() { - final P2PConfig p2PConfig = beaconConfig.p2pConfig(); - signatureVerificationService = - new AggregatingSignatureVerificationService( - metricsSystem, - asyncRunnerFactory, - beaconAsyncRunner, - p2PConfig.getBatchVerifyMaxThreads(), - p2PConfig.getBatchVerifyQueueCapacity(), - p2PConfig.getBatchVerifyMaxBatchSize(), - p2PConfig.isBatchVerifyStrictThreadLimitEnabled()); - } - - protected void initAttestationManager() { - final PendingPool pendingAttestations = - poolFactory.createPendingPoolForAttestations(spec); - final FutureItems futureAttestations = - FutureItems.create( - ValidatableAttestation::getEarliestSlotForForkChoiceProcessing, - UInt64.valueOf(3), - futureItemsMetric, - "attestations"); - AttestationValidator attestationValidator = - new AttestationValidator( - spec, recentChainData, signatureVerificationService, metricsSystem); - AggregateAttestationValidator aggregateValidator = - new AggregateAttestationValidator(spec, attestationValidator, signatureVerificationService); - blockImporter.subscribeToVerifiedBlockAttestations( - (slot, attestations) -> - attestations.forEach( - attestation -> - aggregateValidator.addSeenAggregate( - ValidatableAttestation.from(spec, attestation)))); - attestationManager = - AttestationManager.create( - pendingAttestations, - futureAttestations, - forkChoice, - attestationPool, - attestationValidator, - aggregateValidator, - signatureVerificationService, - eventChannels.getPublisher(ActiveValidatorChannel.class, beaconAsyncRunner)); - - eventChannels - .subscribe(SlotEventsChannel.class, attestationManager) - .subscribe(FinalizedCheckpointChannel.class, pendingAttestations) - .subscribe(ReceivedBlockEventsChannel.class, attestationManager); - } - - protected void initSyncCommitteePools() { - final SyncCommitteeStateUtils syncCommitteeStateUtils = - new SyncCommitteeStateUtils(spec, recentChainData); - syncCommitteeContributionPool = - new SyncCommitteeContributionPool( - spec, - new SignedContributionAndProofValidator( - spec, - recentChainData, - syncCommitteeStateUtils, - timeProvider, - signatureVerificationService)); - - syncCommitteeMessagePool = - new SyncCommitteeMessagePool( - spec, - new SyncCommitteeMessageValidator( - spec, - recentChainData, - syncCommitteeStateUtils, - signatureVerificationService, - timeProvider)); - eventChannels - .subscribe(SlotEventsChannel.class, syncCommitteeContributionPool) - .subscribe(SlotEventsChannel.class, syncCommitteeMessagePool); - } - - protected void initP2PNetwork() { - LOG.debug("BeaconChainController.initP2PNetwork()"); - if (!beaconConfig.p2pConfig().getNetworkConfig().isEnabled()) { - this.p2pNetwork = new NoOpEth2P2PNetwork(spec); - return; - } - - DiscoveryConfig discoveryConfig = beaconConfig.p2pConfig().getDiscoveryConfig(); - final Optional maybeUdpPort = - discoveryConfig.isDiscoveryEnabled() - ? Optional.of(discoveryConfig.getListenUdpPort()) - : Optional.empty(); - - PortAvailability.checkPortsAvailable( - beaconConfig.p2pConfig().getNetworkConfig().getListenPort(), maybeUdpPort); - - this.p2pNetwork = - createEth2P2PNetworkBuilder() - .config(beaconConfig.p2pConfig()) - .eventChannels(eventChannels) - .combinedChainDataClient(combinedChainDataClient) - .gossipedBlockProcessor(blockManager::validateAndImportBlock) - .gossipedBlobSidecarProcessor(blobSidecarManager::validateAndPrepareForBlockImport) - .gossipedAttestationProcessor(attestationManager::addAttestation) - .gossipedAggregateProcessor(attestationManager::addAggregate) - .gossipedAttesterSlashingProcessor(attesterSlashingPool::addRemote) - .gossipedProposerSlashingProcessor(proposerSlashingPool::addRemote) - .gossipedVoluntaryExitProcessor(voluntaryExitPool::addRemote) - .gossipedSignedContributionAndProofProcessor(syncCommitteeContributionPool::addRemote) - .gossipedSyncCommitteeMessageProcessor(syncCommitteeMessagePool::addRemote) - .gossipedSignedBlsToExecutionChangeProcessor(blsToExecutionChangePool::addRemote) - .processedAttestationSubscriptionProvider( - attestationManager::subscribeToAttestationsToSend) - .metricsSystem(metricsSystem) - .timeProvider(timeProvider) - .asyncRunner(networkAsyncRunner) - .keyValueStore(keyValueStore) - .requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()) - .specProvider(spec) - .kzg(kzg) - .recordMessageArrival(true) - .p2pDebugDataDumper(p2pDebugDataDumper) - .build(); - - syncCommitteeMessagePool.subscribeOperationAdded( - new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeMessage)); - syncCommitteeContributionPool.subscribeOperationAdded( - new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeContribution)); - proposerSlashingPool.subscribeOperationAdded( - new LocalOperationAcceptedFilter<>(p2pNetwork::publishProposerSlashing)); - attesterSlashingPool.subscribeOperationAdded( - new LocalOperationAcceptedFilter<>(p2pNetwork::publishAttesterSlashing)); - voluntaryExitPool.subscribeOperationAdded( - new LocalOperationAcceptedFilter<>(p2pNetwork::publishVoluntaryExit)); - blsToExecutionChangePool.subscribeOperationAdded( - new LocalOperationAcceptedFilter<>(p2pNetwork::publishSignedBlsToExecutionChange)); - } - - protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { - return Eth2P2PNetworkBuilder.create(); - } - - protected void initSlotProcessor() { - slotProcessor = - new SlotProcessor( - spec, - recentChainData, - syncService, - forkChoiceTrigger, - forkChoiceNotifier, - p2pNetwork, - slotEventsChannelPublisher, - new EpochCachePrimer(spec, recentChainData, beaconAsyncRunner)); - } - - public void initAttestationPool() { - LOG.debug("BeaconChainController.initAttestationPool()"); - attestationPool = - new AggregatingAttestationPool( - spec, recentChainData, metricsSystem, DEFAULT_MAXIMUM_ATTESTATION_COUNT); - eventChannels.subscribe(SlotEventsChannel.class, attestationPool); - blockImporter.subscribeToVerifiedBlockAttestations( - attestationPool::onAttestationsIncludedInBlock); - } - - public void initRestAPI() { - LOG.debug("BeaconChainController.initRestAPI()"); - if (!beaconConfig.beaconRestApiConfig().isRestApiEnabled()) { - LOG.info("rest-api-enabled is false, not starting rest api."); - return; - } - final Eth1DataProvider eth1DataProvider = new Eth1DataProvider(eth1DataCache, depositProvider); - - final ExecutionClientDataProvider executionClientDataProvider = - dataProvider.getExecutionClientDataProvider(); - - eventChannels.subscribe(ExecutionClientEventsChannel.class, executionClientDataProvider); - - beaconRestAPI = - Optional.of( - new JsonTypeDefinitionBeaconRestApi( - dataProvider, - eth1DataProvider, - beaconConfig.beaconRestApiConfig(), - eventChannels, - eventAsyncRunner, - timeProvider, - spec)); - - if (getLivenessTrackingEnabled(beaconConfig)) { - final int initialValidatorsCount = - spec.getGenesisSpec().getConfig().getMinGenesisActiveValidatorCount(); - eventChannels.subscribe( - ActiveValidatorChannel.class, new ActiveValidatorCache(spec, initialValidatorsCount)); - } - } - - public void initBlockImporter() { - LOG.debug("BeaconChainController.initBlockImporter()"); - blockImporter = - new BlockImporter( - spec, - receivedBlockEventsChannelPublisher, - recentChainData, - forkChoice, - weakSubjectivityValidator, - executionLayer); - } - - public void initBlockManager() { - LOG.debug("BeaconChainController.initBlockManager()"); - final FutureItems futureBlocks = - FutureItems.create(SignedBeaconBlock::getSlot, futureItemsMetric, "blocks"); - final BlockGossipValidator blockGossipValidator = - new BlockGossipValidator(spec, gossipValidationHelper, receivedBlockEventsChannelPublisher); - final BlockValidator blockValidator = new BlockValidator(blockGossipValidator); - final Optional importMetrics = - beaconConfig.getMetricsConfig().isBlockPerformanceEnabled() - ? Optional.of(BlockImportMetrics.create(metricsSystem)) - : Optional.empty(); - - blockManager = - new BlockManager( - recentChainData, - blockImporter, - blockBlobSidecarsTrackersPool, - pendingBlocks, - futureBlocks, - invalidBlockRoots, - blockValidator, - timeProvider, - EVENT_LOG, - importMetrics); - if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { - final FailedExecutionPool failedExecutionPool = - new FailedExecutionPool(blockManager, beaconAsyncRunner); - blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); - } - eventChannels - .subscribe(SlotEventsChannel.class, blockManager) - .subscribe(BlockImportChannel.class, blockManager) - .subscribe(ReceivedBlockEventsChannel.class, blockManager); - } - - protected SyncServiceFactory createSyncServiceFactory() { - return new DefaultSyncServiceFactory( - beaconConfig.syncConfig(), - beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().getGenesisState(), - metricsSystem, - asyncRunnerFactory, - beaconAsyncRunner, - timeProvider, - recentChainData, - combinedChainDataClient, - storageUpdateChannel, - p2pNetwork, - blockImporter, - blobSidecarManager, - pendingBlocks, - blockBlobSidecarsTrackersPool, - beaconConfig.eth2NetworkConfig().getStartupTargetPeerCount(), - signatureVerificationService, - Duration.ofSeconds(beaconConfig.eth2NetworkConfig().getStartupTimeoutSeconds()), - spec); - } - - public void initSyncService() { - LOG.debug("BeaconChainController.initSyncService()"); - syncService = createSyncServiceFactory().create(eventChannels); - - // chainHeadChannel subscription - syncService.getForwardSync().subscribeToSyncChanges(coalescingChainHeadChannel); - - // forkChoiceNotifier subscription - syncService.subscribeToSyncStateChangesAndUpdate( - syncState -> forkChoiceNotifier.onSyncingStatusChanged(syncState.isInSync())); - - // depositProvider subscription - syncService.subscribeToSyncStateChangesAndUpdate( - syncState -> depositProvider.onSyncingStatusChanged(syncState.isInSync())); - - // forkChoice subscription - forkChoice.subscribeToOptimisticHeadChangesAndUpdate(syncService.getOptimisticSyncSubscriber()); - - // terminalPowBlockMonitor subscription - terminalPowBlockMonitor.ifPresent( - monitor -> - syncService.subscribeToSyncStateChangesAndUpdate( - syncState -> monitor.onNodeSyncStateChanged(syncState.isInSync()))); - - // p2pNetwork subscription so gossip can be enabled and disabled appropriately - syncService.subscribeToSyncStateChangesAndUpdate( - state -> p2pNetwork.onSyncStateChanged(state.isInSync(), state.isOptimistic())); - } - - protected void initOperationsReOrgManager() { - LOG.debug("BeaconChainController.initOperationsReOrgManager()"); - OperationsReOrgManager operationsReOrgManager = - new OperationsReOrgManager( - proposerSlashingPool, - attesterSlashingPool, - voluntaryExitPool, - attestationPool, - attestationManager, - blsToExecutionChangePool, - recentChainData); - eventChannels.subscribe(ChainHeadChannel.class, operationsReOrgManager); - } - - protected void initValidatorIndexCacheTracker() { - LOG.debug("BeaconChainController.initValidatorIndexCacheTracker()"); - final ValidatorIndexCacheTracker validatorIndexCacheTracker = - new ValidatorIndexCacheTracker(recentChainData); - eventChannels.subscribe(FinalizedCheckpointChannel.class, validatorIndexCacheTracker); - } - - protected void initForkChoiceStateProvider() { - LOG.debug("BeaconChainController.initForkChoiceStateProvider()"); - forkChoiceStateProvider = new ForkChoiceStateProvider(forkChoiceExecutor, recentChainData); - } - - protected void initForkChoiceNotifier() { - LOG.debug("BeaconChainController.initForkChoiceNotifier()"); - final AsyncRunnerEventThread eventThread = - new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); - eventThread.start(); - proposersDataManager = - new ProposersDataManager( - eventThread, - spec, - metricsSystem, - executionLayer, - recentChainData, - getProposerDefaultFeeRecipient(), - beaconConfig.eth2NetworkConfig().isForkChoiceUpdatedAlwaysSendPayloadAttributes()); - eventChannels.subscribe(SlotEventsChannel.class, proposersDataManager); - forkChoiceNotifier = - new ForkChoiceNotifierImpl( - forkChoiceStateProvider, - eventThread, - timeProvider, - spec, - executionLayer, - recentChainData, - proposersDataManager); - } - - private Optional getProposerDefaultFeeRecipient() { - if (!spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { - return Optional.of(Eth1Address.ZERO); - } - - final Optional defaultFeeRecipient = - beaconConfig.validatorConfig().getProposerDefaultFeeRecipient(); - - if (defaultFeeRecipient.isEmpty() && beaconConfig.beaconRestApiConfig().isRestApiEnabled()) { - STATUS_LOG.warnMissingProposerDefaultFeeRecipientWithRestAPIEnabled(); - } - - return defaultFeeRecipient; - } - - protected void setupInitialState(final RecentChainData client) { - final Eth2NetworkConfiguration networkConfiguration = beaconConfig.eth2NetworkConfig(); - - final Optional initialAnchor = - tryLoadingAnchorPointFromInitialState(networkConfiguration) - .or( - () -> - attemptToLoadAnchorPoint( - networkConfiguration.getNetworkBoostrapConfig().getGenesisState())); - - /* - If flag to allow sync outside of weak subjectivity period has been set, we pass an instance of - WeakSubjectivityPeriodCalculator to the WeakSubjectivityInitializer. Otherwise, we pass an Optional.empty(). - */ - final Optional maybeWsCalculator; - if (isAllowSyncOutsideWeakSubjectivityPeriod()) { - maybeWsCalculator = Optional.empty(); - } else { - maybeWsCalculator = - Optional.of(WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity())); - } - - // Validate - initialAnchor.ifPresent( - anchor -> { - final UInt64 currentSlot = getCurrentSlot(anchor.getState().getGenesisTime()); - wsInitializer.validateInitialAnchor(anchor, currentSlot, spec, maybeWsCalculator); - }); - - if (initialAnchor.isPresent()) { - final AnchorPoint anchor = initialAnchor.get(); - client.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds()); - if (anchor.isGenesis()) { - EVENT_LOG.genesisEvent( - anchor.getStateRoot(), - recentChainData.getBestBlockRoot().orElseThrow(), - anchor.getState().getGenesisTime()); - } - } else if (beaconConfig.interopConfig().isInteropEnabled()) { - setupInteropState(); - } else if (!beaconConfig.powchainConfig().isEnabled()) { - throw new InvalidConfigurationException( - "ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state" - + "."); - } - } - - private Optional tryLoadingAnchorPointFromInitialState( - final Eth2NetworkConfiguration networkConfiguration) { - Optional initialAnchor = Optional.empty(); - - try { - initialAnchor = - attemptToLoadAnchorPoint( - networkConfiguration.getNetworkBoostrapConfig().getInitialState()); - } catch (final InvalidConfigurationException e) { - final StateBoostrapConfig stateBoostrapConfig = - networkConfiguration.getNetworkBoostrapConfig(); - if (stateBoostrapConfig.isUsingCustomInitialState() - && !stateBoostrapConfig.isUsingCheckpointSync()) { - throw e; - } - STATUS_LOG.warnFailedToLoadInitialState(e.getMessage()); - } - - return initialAnchor; - } - - protected Optional attemptToLoadAnchorPoint(final Optional initialState) { - return wsInitializer.loadInitialAnchorPoint(spec, initialState); - } - - protected void setupInteropState() { - final InteropConfig config = beaconConfig.interopConfig(); - STATUS_LOG.generatingMockStartGenesis( - config.getInteropGenesisTime(), config.getInteropNumberOfValidators()); - - Optional executionPayloadHeader = Optional.empty(); - if (config.getInteropGenesisPayloadHeader().isPresent()) { - try { - executionPayloadHeader = - Optional.of( - spec.deserializeJsonExecutionPayloadHeader( - new ObjectMapper(), - config.getInteropGenesisPayloadHeader().get().toFile(), - GENESIS_SLOT)); - } catch (IOException e) { - throw new RuntimeException( - "Unable to load payload header from " + config.getInteropGenesisPayloadHeader().get(), - e); - } - } - - final BeaconState genesisState = - new GenesisStateBuilder() - .spec(spec) - .genesisTime(config.getInteropGenesisTime()) - .addMockValidators(config.getInteropNumberOfValidators()) - .executionPayloadHeader(executionPayloadHeader) - .build(); - - recentChainData.initializeFromGenesis(genesisState, timeProvider.getTimeInSeconds()); - - EVENT_LOG.genesisEvent( - genesisState.hashTreeRoot(), - recentChainData.getBestBlockRoot().orElseThrow(), - genesisState.getGenesisTime()); - } - - protected void onStoreInitialized() { - UInt64 genesisTime = recentChainData.getGenesisTime(); - UInt64 currentTime = timeProvider.getTimeInSeconds(); - final UInt64 currentSlot = getCurrentSlot(genesisTime, currentTime); - if (currentTime.compareTo(genesisTime) >= 0) { - // Validate that we're running within the weak subjectivity period - validateChain(currentSlot); - } else { - UInt64 timeUntilGenesis = genesisTime.minus(currentTime); - genesisTimeTracker = currentTime; - STATUS_LOG.timeUntilGenesis(timeUntilGenesis.longValue(), p2pNetwork.getPeerCount()); - } - slotProcessor.setCurrentSlot(currentSlot); - performanceTracker.start(currentSlot); - } - - protected UInt64 getCurrentSlot(final UInt64 genesisTime) { - return getCurrentSlot(genesisTime, timeProvider.getTimeInSeconds()); - } - - protected UInt64 getCurrentSlot(final UInt64 genesisTime, final UInt64 currentTime) { - return spec.getCurrentSlot(currentTime, genesisTime); - } - - protected void validateChain(final UInt64 currentSlot) { - weakSubjectivityValidator - .validateChainIsConsistentWithWSCheckpoint(combinedChainDataClient) - .thenCompose( - __ -> - SafeFuture.of( - () -> recentChainData.getStore().retrieveFinalizedCheckpointAndState())) - .thenAccept( - finalizedCheckpointState -> { - final UInt64 slot = currentSlot.max(recentChainData.getCurrentSlot().orElse(ZERO)); - weakSubjectivityValidator.validateLatestFinalizedCheckpoint( - finalizedCheckpointState, slot); - }) - .finish( - err -> { - weakSubjectivityValidator.handleValidationFailure( - "Encountered an error while trying to validate latest finalized checkpoint", err); - throw new RuntimeException(err); - }); - } - - private void onTick() { - if (recentChainData.isPreGenesis()) { - return; - } - - final UInt64 currentTimeMillis = timeProvider.getTimeInMillis(); - final UInt64 currentTimeSeconds = millisToSeconds(currentTimeMillis); - final Optional performanceRecord = - beaconConfig.getMetricsConfig().isTickPerformanceEnabled() - ? Optional.of(new TickProcessingPerformance(timeProvider, currentTimeMillis)) - : Optional.empty(); - - forkChoice.onTick(currentTimeMillis, performanceRecord); - - final UInt64 genesisTime = recentChainData.getGenesisTime(); - if (genesisTime.isGreaterThan(currentTimeSeconds)) { - // notify every 10 minutes - if (genesisTimeTracker.plus(600L).isLessThanOrEqualTo(currentTimeSeconds)) { - genesisTimeTracker = currentTimeSeconds; - STATUS_LOG.timeUntilGenesis( - genesisTime.minus(currentTimeSeconds).longValue(), p2pNetwork.getPeerCount()); - } - } - - slotProcessor.onTick(currentTimeMillis, performanceRecord); - performanceRecord.ifPresent(TickProcessingPerformance::complete); + return stopper.get(); } @Override diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java index 95dc4ba2115..9d41f32b4ed 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java @@ -14,6 +14,8 @@ package tech.pegasys.teku.services.beaconchain; import tech.pegasys.teku.service.serviceutils.ServiceConfig; +import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; +import tech.pegasys.teku.services.beaconchain.init.ExternalDependenciesModule; /** * CAUTION: this API is unstable and primarily intended for debugging and testing purposes this API @@ -21,7 +23,13 @@ */ public interface BeaconChainControllerFactory { - BeaconChainControllerFactory DEFAULT = BeaconChainController::new; + BeaconChainControllerFactory DEFAULT = + (serviceConfig, beaconConfig) -> + DaggerBeaconChainControllerComponent.builder() + .externalDependenciesModule( + new ExternalDependenciesModule(serviceConfig, beaconConfig)) + .build() + .beaconChainController(); BeaconChainController create( final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java new file mode 100644 index 00000000000..20056db6557 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java @@ -0,0 +1,1596 @@ +/* + * Copyright Consensys Software Inc., 2022 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package tech.pegasys.teku.services.beaconchain; + +import static tech.pegasys.teku.infrastructure.exceptions.ExitConstants.FATAL_EXIT_CODE; +import static tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG; +import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; +import static tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory.BEACON; +import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds; +import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; +import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; +import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; +import static tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool.DEFAULT_MAXIMUM_ATTESTATION_COUNT; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Throwables; +import java.io.IOException; +import java.net.BindException; +import java.nio.file.Path; +import java.time.Duration; +import java.util.Comparator; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.IntSupplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.plugin.services.MetricsSystem; +import tech.pegasys.teku.api.ChainDataProvider; +import tech.pegasys.teku.api.DataProvider; +import tech.pegasys.teku.api.ExecutionClientDataProvider; +import tech.pegasys.teku.api.RewardCalculator; +import tech.pegasys.teku.beacon.sync.DefaultSyncServiceFactory; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.beacon.sync.SyncServiceFactory; +import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; +import tech.pegasys.teku.beacon.sync.gossip.blobs.RecentBlobSidecarsFetcher; +import tech.pegasys.teku.beacon.sync.gossip.blocks.RecentBlocksFetcher; +import tech.pegasys.teku.beaconrestapi.BeaconRestApi; +import tech.pegasys.teku.beaconrestapi.JsonTypeDefinitionBeaconRestApi; +import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; +import tech.pegasys.teku.ethereum.events.SlotEventsChannel; +import tech.pegasys.teku.ethereum.execution.types.Eth1Address; +import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionChannel; +import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionProvider; +import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionAndPublishingPerformanceFactory; +import tech.pegasys.teku.ethereum.pow.api.Eth1EventsChannel; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.async.SafeFuture; +import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; +import tech.pegasys.teku.infrastructure.collections.LimitedMap; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; +import tech.pegasys.teku.infrastructure.io.PortAvailability; +import tech.pegasys.teku.infrastructure.metrics.SettableGauge; +import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge; +import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.infrastructure.unsigned.UInt64; +import tech.pegasys.teku.kzg.KZG; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder; +import tech.pegasys.teku.networking.eth2.P2PConfig; +import tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipChannel; +import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AllSubnetsSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AllSyncCommitteeSubscriptions; +import tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.NodeBasedStableSubnetSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.StableSubnetSubscriber; +import tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager; +import tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork; +import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig; +import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.networks.StateBoostrapConfig; +import tech.pegasys.teku.service.serviceutils.Service; +import tech.pegasys.teku.service.serviceutils.ServiceConfig; +import tech.pegasys.teku.services.executionlayer.ExecutionLayerBlockManagerFactory; +import tech.pegasys.teku.services.timer.TimerService; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; +import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation; +import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.capella.BeaconBlockBodySchemaCapella; +import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader; +import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder; +import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.spec.datastructures.state.AnchorPoint; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager; +import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; +import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; +import tech.pegasys.teku.spec.logic.common.util.BlockRewardCalculatorUtil; +import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb; +import tech.pegasys.teku.statetransition.EpochCachePrimer; +import tech.pegasys.teku.statetransition.LocalOperationAcceptedFilter; +import tech.pegasys.teku.statetransition.MappedOperationPool; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.OperationsReOrgManager; +import tech.pegasys.teku.statetransition.SimpleOperationPool; +import tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager.RemoteOrigin; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManagerImpl; +import tech.pegasys.teku.statetransition.blobs.BlockBlobSidecarsTrackersPool; +import tech.pegasys.teku.statetransition.block.BlockImportChannel; +import tech.pegasys.teku.statetransition.block.BlockImportChannel.BlockImportAndBroadcastValidationResults; +import tech.pegasys.teku.statetransition.block.BlockImportMetrics; +import tech.pegasys.teku.statetransition.block.BlockImporter; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.block.FailedExecutionPool; +import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceStateProvider; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger; +import tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator; +import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; +import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; +import tech.pegasys.teku.statetransition.forkchoice.TickProcessingPerformance; +import tech.pegasys.teku.statetransition.forkchoice.TickProcessor; +import tech.pegasys.teku.statetransition.genesis.GenesisHandler; +import tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils; +import tech.pegasys.teku.statetransition.util.BlockBlobSidecarsTrackersPoolImpl; +import tech.pegasys.teku.statetransition.util.FutureItems; +import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.statetransition.util.P2PDebugDataFileDumper; +import tech.pegasys.teku.statetransition.util.PendingPool; +import tech.pegasys.teku.statetransition.util.PoolFactory; +import tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator; +import tech.pegasys.teku.statetransition.validation.AttestationValidator; +import tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator; +import tech.pegasys.teku.statetransition.validation.BlobSidecarGossipValidator; +import tech.pegasys.teku.statetransition.validation.BlockGossipValidator; +import tech.pegasys.teku.statetransition.validation.BlockValidator; +import tech.pegasys.teku.statetransition.validation.GossipValidationHelper; +import tech.pegasys.teku.statetransition.validation.InternalValidationResult; +import tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator; +import tech.pegasys.teku.statetransition.validation.SignedBlsToExecutionChangeValidator; +import tech.pegasys.teku.statetransition.validation.VoluntaryExitValidator; +import tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache; +import tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel; +import tech.pegasys.teku.storage.api.ChainHeadChannel; +import tech.pegasys.teku.storage.api.CombinedStorageChannel; +import tech.pegasys.teku.storage.api.Eth1DepositStorageChannel; +import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; +import tech.pegasys.teku.storage.api.StorageQueryChannel; +import tech.pegasys.teku.storage.api.StorageUpdateChannel; +import tech.pegasys.teku.storage.api.VoteUpdateChannel; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.EarliestAvailableBlockSlot; +import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.storage.client.StorageBackedRecentChainData; +import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider; +import tech.pegasys.teku.storage.store.FileKeyValueStore; +import tech.pegasys.teku.storage.store.KeyValueStore; +import tech.pegasys.teku.storage.store.StoreConfig; +import tech.pegasys.teku.validator.api.InteropConfig; +import tech.pegasys.teku.validator.api.ValidatorApiChannel; +import tech.pegasys.teku.validator.api.ValidatorPerformanceTrackingMode; +import tech.pegasys.teku.validator.api.ValidatorTimingChannel; +import tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker; +import tech.pegasys.teku.validator.coordinator.BlockFactory; +import tech.pegasys.teku.validator.coordinator.BlockOperationSelectorFactory; +import tech.pegasys.teku.validator.coordinator.DepositProvider; +import tech.pegasys.teku.validator.coordinator.DutyMetrics; +import tech.pegasys.teku.validator.coordinator.Eth1DataCache; +import tech.pegasys.teku.validator.coordinator.Eth1DataProvider; +import tech.pegasys.teku.validator.coordinator.Eth1VotingPeriod; +import tech.pegasys.teku.validator.coordinator.GraffitiBuilder; +import tech.pegasys.teku.validator.coordinator.MilestoneBasedBlockFactory; +import tech.pegasys.teku.validator.coordinator.ValidatorApiHandler; +import tech.pegasys.teku.validator.coordinator.ValidatorIndexCacheTracker; +import tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.NoOpPerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.SyncCommitteePerformanceTracker; +import tech.pegasys.teku.validator.coordinator.performance.ValidatorPerformanceMetrics; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; + +/** + * The central class which assembles together and initializes Beacon Chain components + * + *

CAUTION: This class can be overridden by custom implementation to tweak creation and + * initialization behavior (see {@link BeaconChainControllerFactory}} however this class may change + * in a backward incompatible manner and either break compilation or runtime behavior + */ +public class BeaconChainControllerOld extends Service implements BeaconChainControllerFacade { + + private static final Logger LOG = LogManager.getLogger(); + + protected static final String KEY_VALUE_STORE_SUBDIRECTORY = "kvstore"; + + protected volatile BeaconChainConfiguration beaconConfig; + protected volatile Spec spec; + protected volatile Function> beaconBlockSchemaSupplier; + protected volatile EventChannels eventChannels; + protected volatile MetricsSystem metricsSystem; + protected volatile AsyncRunner beaconAsyncRunner; + protected volatile TimeProvider timeProvider; + protected volatile SlotEventsChannel slotEventsChannelPublisher; + protected volatile ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher; + protected volatile AsyncRunner networkAsyncRunner; + protected volatile AsyncRunnerFactory asyncRunnerFactory; + protected volatile AsyncRunner eventAsyncRunner; + protected volatile Path beaconDataDirectory; + protected volatile WeakSubjectivityInitializer wsInitializer = new WeakSubjectivityInitializer(); + protected volatile AsyncRunnerEventThread forkChoiceExecutor; + + private volatile AsyncRunner operationPoolAsyncRunner; + + protected volatile ForkChoice forkChoice; + protected volatile ForkChoiceTrigger forkChoiceTrigger; + protected volatile BlockImporter blockImporter; + + protected volatile DataProvider dataProvider; + protected volatile RecentChainData recentChainData; + protected volatile Eth2P2PNetwork p2pNetwork; + protected volatile Optional beaconRestAPI = Optional.empty(); + protected volatile AggregatingAttestationPool attestationPool; + protected volatile DepositProvider depositProvider; + protected volatile SyncService syncService; + protected volatile AttestationManager attestationManager; + protected volatile SignatureVerificationService signatureVerificationService; + protected volatile CombinedChainDataClient combinedChainDataClient; + protected volatile Eth1DataCache eth1DataCache; + protected volatile SlotProcessor slotProcessor; + protected volatile OperationPool attesterSlashingPool; + protected volatile OperationPool proposerSlashingPool; + protected volatile OperationPool voluntaryExitPool; + protected volatile MappedOperationPool blsToExecutionChangePool; + protected volatile SyncCommitteeContributionPool syncCommitteeContributionPool; + protected volatile SyncCommitteeMessagePool syncCommitteeMessagePool; + protected volatile WeakSubjectivityValidator weakSubjectivityValidator; + protected volatile PerformanceTracker performanceTracker; + protected volatile PendingPool pendingBlocks; + protected volatile BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool; + protected volatile Map invalidBlockRoots; + protected volatile CoalescingChainHeadChannel coalescingChainHeadChannel; + protected volatile ActiveValidatorTracker activeValidatorTracker; + protected volatile AttestationTopicSubscriber attestationTopicSubscriber; + protected volatile ForkChoiceNotifier forkChoiceNotifier; + protected volatile ForkChoiceStateProvider forkChoiceStateProvider; + protected volatile ExecutionLayerChannel executionLayer; + protected volatile GossipValidationHelper gossipValidationHelper; + protected volatile KZG kzg; + protected volatile BlobSidecarManager blobSidecarManager; + protected volatile Optional terminalPowBlockMonitor = Optional.empty(); + protected volatile ProposersDataManager proposersDataManager; + protected volatile KeyValueStore keyValueStore; + protected volatile StorageQueryChannel storageQueryChannel; + protected volatile StorageUpdateChannel storageUpdateChannel; + protected volatile StableSubnetSubscriber stableSubnetSubscriber; + protected volatile ExecutionLayerBlockProductionManager executionLayerBlockProductionManager; + protected volatile RewardCalculator rewardCalculator; + protected UInt64 genesisTimeTracker = ZERO; + protected BlockManager blockManager; + protected TimerService timerService; + protected PoolFactory poolFactory; + protected SettableLabelledGauge futureItemsMetric; + protected IntSupplier rejectedExecutionCountSupplier; + protected P2PDebugDataDumper p2pDebugDataDumper; + + public BeaconChainControllerOld( + final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig) { + final Eth2NetworkConfiguration eth2NetworkConfig = beaconConfig.eth2NetworkConfig(); + this.beaconConfig = beaconConfig; + this.spec = beaconConfig.getSpec(); + this.beaconBlockSchemaSupplier = + slot -> spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockBodySchema(); + this.beaconDataDirectory = serviceConfig.getDataDirLayout().getBeaconDataDirectory(); + this.asyncRunnerFactory = serviceConfig.getAsyncRunnerFactory(); + this.beaconAsyncRunner = + serviceConfig.createAsyncRunner( + "beaconchain", + eth2NetworkConfig.getAsyncBeaconChainMaxThreads(), + eth2NetworkConfig.getAsyncBeaconChainMaxQueue()); + this.eventAsyncRunner = serviceConfig.createAsyncRunner("events", 10); + this.networkAsyncRunner = + serviceConfig.createAsyncRunner( + "p2p", + eth2NetworkConfig.getAsyncP2pMaxThreads(), + eth2NetworkConfig.getAsyncP2pMaxQueue()); + this.operationPoolAsyncRunner = serviceConfig.createAsyncRunner("operationPoolUpdater", 1); + this.timeProvider = serviceConfig.getTimeProvider(); + this.eventChannels = serviceConfig.getEventChannels(); + this.metricsSystem = serviceConfig.getMetricsSystem(); + this.poolFactory = new PoolFactory(this.metricsSystem); + this.rejectedExecutionCountSupplier = serviceConfig.getRejectedExecutionsSupplier(); + this.slotEventsChannelPublisher = eventChannels.getPublisher(SlotEventsChannel.class); + this.receivedBlockEventsChannelPublisher = + eventChannels.getPublisher(ReceivedBlockEventsChannel.class); + this.forkChoiceExecutor = new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); + this.p2pDebugDataDumper = + beaconConfig.p2pConfig().isP2pDumpsToFileEnabled() + ? new P2PDebugDataFileDumper(serviceConfig.getDataDirLayout().getDebugDataDirectory()) + : P2PDebugDataDumper.NOOP; + this.futureItemsMetric = + SettableLabelledGauge.create( + metricsSystem, + BEACON, + "future_items_size", + "Current number of items held for future slots, labelled by type", + "type"); + } + + @Override + protected SafeFuture doStart() { + LOG.debug("Starting {}", this.getClass().getSimpleName()); + forkChoiceExecutor.start(); + return initialize() + .thenCompose( + (__) -> + beaconRestAPI.map(BeaconRestApi::start).orElse(SafeFuture.completedFuture(null))); + } + + protected void startServices() { + final RecentBlocksFetcher recentBlocksFetcher = syncService.getRecentBlocksFetcher(); + recentBlocksFetcher.subscribeBlockFetched( + (block) -> + blockManager + .importBlock( + block, BroadcastValidationLevel.NOT_REQUIRED, Optional.of(RemoteOrigin.RPC)) + .thenCompose(BlockImportAndBroadcastValidationResults::blockImportResult) + .finish(err -> LOG.error("Failed to process recently fetched block.", err))); + eventChannels.subscribe(ReceivedBlockEventsChannel.class, recentBlocksFetcher); + final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher = + syncService.getRecentBlobSidecarsFetcher(); + recentBlobSidecarsFetcher.subscribeBlobSidecarFetched( + (blobSidecar) -> blobSidecarManager.prepareForBlockImport(blobSidecar, RemoteOrigin.RPC)); + blobSidecarManager.subscribeToReceivedBlobSidecar( + blobSidecar -> + recentBlobSidecarsFetcher.cancelRecentBlobSidecarRequest( + new BlobIdentifier(blobSidecar.getBlockRoot(), blobSidecar.getIndex()))); + SafeFuture.allOfFailFast( + attestationManager.start(), + p2pNetwork.start(), + blockManager.start(), + syncService.start(), + SafeFuture.fromRunnable( + () -> terminalPowBlockMonitor.ifPresent(TerminalPowBlockMonitor::start))) + .finish( + error -> { + Throwable rootCause = Throwables.getRootCause(error); + if (rootCause instanceof BindException) { + final String errorWhilePerformingDescription = + "starting P2P services on port " + this.p2pNetwork.getListenPort() + "."; + STATUS_LOG.fatalError(errorWhilePerformingDescription, rootCause); + System.exit(FATAL_EXIT_CODE); + } else { + Thread.currentThread() + .getUncaughtExceptionHandler() + .uncaughtException(Thread.currentThread(), error); + } + }); + } + + @Override + protected SafeFuture doStop() { + LOG.debug("Stopping {}", this.getClass().getSimpleName()); + return SafeFuture.allOf( + beaconRestAPI.map(BeaconRestApi::stop).orElse(SafeFuture.completedFuture(null)), + syncService.stop(), + blockManager.stop(), + attestationManager.stop(), + p2pNetwork.stop(), + timerService.stop(), + SafeFuture.fromRunnable( + () -> terminalPowBlockMonitor.ifPresent(TerminalPowBlockMonitor::stop))) + .thenRun(forkChoiceExecutor::stop); + } + + protected SafeFuture initialize() { + + timerService = new TimerService(this::onTick); + + final StoreConfig storeConfig = beaconConfig.storeConfig(); + coalescingChainHeadChannel = + new CoalescingChainHeadChannel( + eventChannels.getPublisher(ChainHeadChannel.class), EVENT_LOG); + + final CombinedStorageChannel combinedStorageChannel = + eventChannels.getPublisher(CombinedStorageChannel.class, beaconAsyncRunner); + storageQueryChannel = combinedStorageChannel; + storageUpdateChannel = combinedStorageChannel; + final VoteUpdateChannel voteUpdateChannel = eventChannels.getPublisher(VoteUpdateChannel.class); + + final ValidatorIsConnectedProvider validatorIsConnectedProvider = + new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier); + // Init other services + return initWeakSubjectivity(storageQueryChannel, storageUpdateChannel) + .thenCompose( + __ -> + StorageBackedRecentChainData.create( + metricsSystem, + storeConfig, + beaconAsyncRunner, + timeProvider, + (blockRoot) -> blockBlobSidecarsTrackersPool.getBlock(blockRoot), + (blockRoot, index) -> + blockBlobSidecarsTrackersPool.getBlobSidecar(blockRoot, index), + storageQueryChannel, + storageUpdateChannel, + voteUpdateChannel, + eventChannels.getPublisher(FinalizedCheckpointChannel.class, beaconAsyncRunner), + coalescingChainHeadChannel, + validatorIsConnectedProvider, + spec)) + .thenCompose( + client -> { + if (isAllowSyncOutsideWeakSubjectivityPeriod()) { + STATUS_LOG.warnIgnoringWeakSubjectivityPeriod(); + } + + // Setup chain storage + this.recentChainData = client; + if (recentChainData.isPreGenesis()) { + setupInitialState(client); + } else { + if (isUsingCustomInitialState()) { + STATUS_LOG.warnInitialStateIgnored(); + } + if (!isAllowSyncOutsideWeakSubjectivityPeriod()) { + validateWeakSubjectivityPeriod(client); + } + } + return SafeFuture.completedFuture(client); + }) + // Init other services + .thenRun(this::initAll) + .thenRun( + () -> { + recentChainData.subscribeStoreInitialized(this::onStoreInitialized); + recentChainData.subscribeBestBlockInitialized(this::startServices); + }) + .thenCompose(__ -> + timerService.start() + ); + } + + private boolean isUsingCustomInitialState() { + return beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().isUsingCustomInitialState(); + } + + private boolean isAllowSyncOutsideWeakSubjectivityPeriod() { + return beaconConfig + .eth2NetworkConfig() + .getNetworkBoostrapConfig() + .isAllowSyncOutsideWeakSubjectivityPeriod(); + } + + private void validateWeakSubjectivityPeriod(final RecentChainData client) { + final AnchorPoint latestFinalizedAnchor = client.getStore().getLatestFinalized(); + final UInt64 currentSlot = getCurrentSlot(client.getGenesisTime()); + final WeakSubjectivityCalculator wsCalculator = + WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity()); + wsInitializer.validateAnchorIsWithinWeakSubjectivityPeriod( + latestFinalizedAnchor, currentSlot, spec, wsCalculator); + } + + public void initAll() { + initKeyValueStore(); + initExecutionLayer(); + initExecutionLayerBlockProductionManager(); + initRewardCalculator(); + initGossipValidationHelper(); + initBlockPoolsAndCaches(); + initKzg(); + initBlockBlobSidecarsTrackersPool(); + initBlobSidecarManager(); + initForkChoiceStateProvider(); + initForkChoiceNotifier(); + initMergeMonitors(); + initForkChoice(); + initBlockImporter(); + initCombinedChainDataClient(); + initSignatureVerificationService(); + initAttestationPool(); + initAttesterSlashingPool(); + initProposerSlashingPool(); + initVoluntaryExitPool(); + initSignedBlsToExecutionChangePool(); + initEth1DataCache(); + initDepositProvider(); + initGenesisHandler(); + initAttestationManager(); + initBlockManager(); + initSyncCommitteePools(); + initP2PNetwork(); + initSyncService(); + initSlotProcessor(); + initMetrics(); + initAttestationTopicSubscriber(); + initActiveValidatorTracker(); + initSubnetSubscriber(); + initSlashingEventsSubscriptions(); + initPerformanceTracker(); + initDataProvider(); + initValidatorApiHandler(); + initRestAPI(); + initOperationsReOrgManager(); + initValidatorIndexCacheTracker(); + } + + private void initKeyValueStore() { + keyValueStore = + new FileKeyValueStore(beaconDataDirectory.resolve(KEY_VALUE_STORE_SUBDIRECTORY)); + } + + protected void initExecutionLayer() { + executionLayer = eventChannels.getPublisher(ExecutionLayerChannel.class, beaconAsyncRunner); + } + + protected void initKzg() { + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + kzg = KZG.getInstance(); + final String trustedSetupFile = + beaconConfig + .eth2NetworkConfig() + .getTrustedSetup() + .orElseThrow( + () -> + new InvalidConfigurationException( + "Trusted setup should be configured when Deneb is enabled")); + kzg.loadTrustedSetup(trustedSetupFile); + } else { + kzg = KZG.NOOP; + } + } + + protected void initBlobSidecarManager() { + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + final FutureItems futureBlobSidecars = + FutureItems.create(BlobSidecar::getSlot, futureItemsMetric, "blob_sidecars"); + + final Map invalidBlobSidecarRoots = + LimitedMap.createSynchronizedLRU(500); + final MiscHelpersDeneb miscHelpers = + MiscHelpersDeneb.required(spec.forMilestone(SpecMilestone.DENEB).miscHelpers()); + final BlobSidecarGossipValidator blobSidecarValidator = + BlobSidecarGossipValidator.create( + spec, invalidBlockRoots, gossipValidationHelper, miscHelpers, kzg); + final BlobSidecarManagerImpl blobSidecarManagerImpl = + new BlobSidecarManagerImpl( + spec, + beaconAsyncRunner, + recentChainData, + blockBlobSidecarsTrackersPool, + blobSidecarValidator, + kzg, + futureBlobSidecars, + invalidBlobSidecarRoots); + eventChannels.subscribe(SlotEventsChannel.class, blobSidecarManagerImpl); + + blobSidecarManager = blobSidecarManagerImpl; + } else { + blobSidecarManager = BlobSidecarManager.NOOP; + } + } + + protected void initMergeMonitors() { + if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + terminalPowBlockMonitor = + Optional.of( + new TerminalPowBlockMonitor( + executionLayer, + spec, + recentChainData, + forkChoiceNotifier, + beaconAsyncRunner, + EVENT_LOG, + timeProvider)); + } + } + + protected void initBlockPoolsAndCaches() { + LOG.debug("BeaconChainController.initBlockPoolsAndCaches()"); + pendingBlocks = poolFactory.createPendingPoolForBlocks(spec); + eventChannels.subscribe(FinalizedCheckpointChannel.class, pendingBlocks); + invalidBlockRoots = LimitedMap.createSynchronizedLRU(500); + } + + protected void initBlockBlobSidecarsTrackersPool() { + LOG.debug("BeaconChainController.initBlockBlobSidecarsTrackersPool()"); + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + final BlockImportChannel blockImportChannel = + eventChannels.getPublisher(BlockImportChannel.class, beaconAsyncRunner); + final BlockBlobSidecarsTrackersPoolImpl pool = + poolFactory.createPoolForBlockBlobSidecarsTrackers( + blockImportChannel, spec, timeProvider, beaconAsyncRunner, recentChainData); + eventChannels.subscribe(FinalizedCheckpointChannel.class, pool); + blockBlobSidecarsTrackersPool = pool; + + } else { + blockBlobSidecarsTrackersPool = BlockBlobSidecarsTrackersPool.NOOP; + } + } + + protected void initGossipValidationHelper() { + LOG.debug("BeaconChainController.initGossipValidationHelper()"); + gossipValidationHelper = new GossipValidationHelper(spec, recentChainData); + } + + protected void initPerformanceTracker() { + LOG.debug("BeaconChainController.initPerformanceTracker()"); + ValidatorPerformanceTrackingMode mode = + beaconConfig.validatorConfig().getValidatorPerformanceTrackingMode(); + if (mode.isEnabled()) { + final SettableGauge performanceTrackerTimings = + SettableGauge.create( + metricsSystem, + BEACON, + "performance_tracker_timings", + "Tracks how much time (in millis) performance tracker takes to perform calculations"); + performanceTracker = + new DefaultPerformanceTracker( + combinedChainDataClient, + STATUS_LOG, + new ValidatorPerformanceMetrics(metricsSystem), + beaconConfig.validatorConfig().getValidatorPerformanceTrackingMode(), + activeValidatorTracker, + new SyncCommitteePerformanceTracker(spec, combinedChainDataClient), + spec, + performanceTrackerTimings); + eventChannels.subscribe(SlotEventsChannel.class, performanceTracker); + } else { + performanceTracker = new NoOpPerformanceTracker(); + } + } + + protected void initAttesterSlashingPool() { + LOG.debug("BeaconChainController.initAttesterSlashingPool()"); + attesterSlashingPool = + new SimpleOperationPool<>( + "AttesterSlashingPool", + metricsSystem, + beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getAttesterSlashingsSchema), + new AttesterSlashingValidator(recentChainData, spec), + // Prioritise slashings that include more validators at a time + Comparator.comparingInt( + slashing -> slashing.getIntersectingValidatorIndices().size()) + .reversed()); + blockImporter.subscribeToVerifiedBlockAttesterSlashings(attesterSlashingPool::removeAll); + attesterSlashingPool.subscribeOperationAdded(forkChoice::onAttesterSlashing); + } + + protected void initProposerSlashingPool() { + LOG.debug("BeaconChainController.initProposerSlashingPool()"); + ProposerSlashingValidator validator = new ProposerSlashingValidator(spec, recentChainData); + proposerSlashingPool = + new SimpleOperationPool<>( + "ProposerSlashingPool", + metricsSystem, + beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getProposerSlashingsSchema), + validator); + blockImporter.subscribeToVerifiedBlockProposerSlashings(proposerSlashingPool::removeAll); + } + + protected void initSlashingEventsSubscriptions() { + if (beaconConfig.validatorConfig().isShutdownWhenValidatorSlashedEnabled()) { + final ValidatorTimingChannel validatorTimingChannel = + eventChannels.getPublisher(ValidatorTimingChannel.class); + attesterSlashingPool.subscribeOperationAdded( + (operation, validationStatus, fromNetwork) -> + validatorTimingChannel.onAttesterSlashing(operation)); + proposerSlashingPool.subscribeOperationAdded( + (operation, validationStatus, fromNetwork) -> + validatorTimingChannel.onProposerSlashing(operation)); + } + } + + protected void initVoluntaryExitPool() { + LOG.debug("BeaconChainController.initVoluntaryExitPool()"); + VoluntaryExitValidator validator = new VoluntaryExitValidator(spec, recentChainData); + voluntaryExitPool = + new MappedOperationPool<>( + "VoluntaryExitPool", + metricsSystem, + beaconBlockSchemaSupplier.andThen(BeaconBlockBodySchema::getVoluntaryExitsSchema), + validator, + operationPoolAsyncRunner, + timeProvider); + blockImporter.subscribeToVerifiedBlockVoluntaryExits(voluntaryExitPool::removeAll); + } + + protected void initSignedBlsToExecutionChangePool() { + LOG.debug("BeaconChainController.initSignedBlsToExecutionChangePool()"); + final SignedBlsToExecutionChangeValidator validator = + new SignedBlsToExecutionChangeValidator( + spec, timeProvider, recentChainData, signatureVerificationService); + + blsToExecutionChangePool = + new MappedOperationPool<>( + "SignedBlsToExecutionChangePool", + metricsSystem, + beaconBlockSchemaSupplier + .andThen(BeaconBlockBodySchema::toVersionCapella) + .andThen(Optional::orElseThrow) + .andThen(BeaconBlockBodySchemaCapella::getBlsToExecutionChangesSchema), + validator, + operationPoolAsyncRunner, + timeProvider); + blockImporter.subscribeToVerifiedBlockBlsToExecutionChanges( + blsToExecutionChangePool::removeAll); + } + + protected void initDataProvider() { + dataProvider = + DataProvider.builder() + .spec(spec) + .recentChainData(recentChainData) + .combinedChainDataClient(combinedChainDataClient) + .rewardCalculator(rewardCalculator) + .p2pNetwork(p2pNetwork) + .syncService(syncService) + .validatorApiChannel( + eventChannels.getPublisher(ValidatorApiChannel.class, beaconAsyncRunner)) + .attestationPool(attestationPool) + .blockBlobSidecarsTrackersPool(blockBlobSidecarsTrackersPool) + .attestationManager(attestationManager) + .isLivenessTrackingEnabled(getLivenessTrackingEnabled(beaconConfig)) + .activeValidatorChannel( + eventChannels.getPublisher(ActiveValidatorChannel.class, beaconAsyncRunner)) + .attesterSlashingPool(attesterSlashingPool) + .proposerSlashingPool(proposerSlashingPool) + .voluntaryExitPool(voluntaryExitPool) + .blsToExecutionChangePool(blsToExecutionChangePool) + .syncCommitteeContributionPool(syncCommitteeContributionPool) + .proposersDataManager(proposersDataManager) + .forkChoiceNotifier(forkChoiceNotifier) + .rejectedExecutionSupplier(rejectedExecutionCountSupplier) + .build(); + } + + private boolean getLivenessTrackingEnabled(BeaconChainConfiguration beaconConfig) { + return beaconConfig.beaconRestApiConfig().isBeaconLivenessTrackingEnabled() + || beaconConfig.validatorConfig().isDoppelgangerDetectionEnabled(); + } + + protected void initCombinedChainDataClient() { + LOG.debug("BeaconChainController.initCombinedChainDataClient()"); + final EarliestAvailableBlockSlot earliestAvailableBlockSlot = + new EarliestAvailableBlockSlot( + storageQueryChannel, + timeProvider, + beaconConfig.storeConfig().getEarliestAvailableBlockSlotFrequency()); + + combinedChainDataClient = + new CombinedChainDataClient( + recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); + } + + protected SafeFuture initWeakSubjectivity( + final StorageQueryChannel queryChannel, final StorageUpdateChannel updateChannel) { + return wsInitializer + .finalizeAndStoreConfig(beaconConfig.weakSubjectivity(), queryChannel, updateChannel) + .thenAccept( + finalConfig -> + this.weakSubjectivityValidator = WeakSubjectivityValidator.moderate(finalConfig)); + } + + protected void initForkChoice() { + LOG.debug("BeaconChainController.initForkChoice()"); + forkChoice = + new ForkChoice( + spec, + forkChoiceExecutor, + recentChainData, + blobSidecarManager, + forkChoiceNotifier, + forkChoiceStateProvider, + new TickProcessor(spec, recentChainData), + new MergeTransitionBlockValidator(spec, recentChainData, executionLayer), + beaconConfig.eth2NetworkConfig().isForkChoiceLateBlockReorgEnabled(), + p2pDebugDataDumper, + metricsSystem); + forkChoiceTrigger = new ForkChoiceTrigger(forkChoice); + } + + public void initMetrics() { + LOG.debug("BeaconChainController.initMetrics()"); + final SyncCommitteeMetrics syncCommitteeMetrics = + new SyncCommitteeMetrics(spec, recentChainData, metricsSystem); + final BeaconChainMetrics beaconChainMetrics = + new BeaconChainMetrics( + spec, + recentChainData, + slotProcessor.getNodeSlot(), + metricsSystem, + p2pNetwork, + eth1DataCache); + eventChannels + .subscribe(SlotEventsChannel.class, beaconChainMetrics) + .subscribe(SlotEventsChannel.class, syncCommitteeMetrics) + .subscribe(ChainHeadChannel.class, syncCommitteeMetrics); + } + + protected void initEth1DataCache() { + LOG.debug("BeaconChainController.initEth1DataCache"); + eth1DataCache = new Eth1DataCache(spec, metricsSystem, new Eth1VotingPeriod(spec)); + } + + public void initDepositProvider() { + LOG.debug("BeaconChainController.initDepositProvider()"); + depositProvider = + new DepositProvider( + metricsSystem, + recentChainData, + eth1DataCache, + storageUpdateChannel, + eventChannels.getPublisher(Eth1DepositStorageChannel.class, beaconAsyncRunner), + spec, + EVENT_LOG, + beaconConfig.powchainConfig().useMissingDepositEventLogging()); + eventChannels + .subscribe(Eth1EventsChannel.class, depositProvider) + .subscribe(FinalizedCheckpointChannel.class, depositProvider) + .subscribe(SlotEventsChannel.class, depositProvider); + } + + protected void initAttestationTopicSubscriber() { + LOG.debug("BeaconChainController.initAttestationTopicSubscriber"); + final SettableLabelledGauge subnetSubscriptionsGauge = + SettableLabelledGauge.create( + metricsSystem, + TekuMetricCategory.NETWORK, + "subnet_subscriptions", + "Tracks attestations subnet subscriptions", + "type"); + this.attestationTopicSubscriber = + new AttestationTopicSubscriber(spec, p2pNetwork, subnetSubscriptionsGauge); + } + + protected void initActiveValidatorTracker() { + LOG.debug("BeaconChainController.initActiveValidatorTracker"); + this.activeValidatorTracker = new ActiveValidatorTracker(spec); + } + + protected void initSubnetSubscriber() { + LOG.debug("BeaconChainController.initSubnetSubscriber"); + if (beaconConfig.p2pConfig().isSubscribeAllSubnetsEnabled()) { + LOG.info("Subscribing to all attestation subnets"); + this.stableSubnetSubscriber = + AllSubnetsSubscriber.create(attestationTopicSubscriber, spec.getNetworkingConfig()); + } else { + if (p2pNetwork.getDiscoveryNodeId().isPresent()) { + this.stableSubnetSubscriber = + new NodeBasedStableSubnetSubscriber( + attestationTopicSubscriber, spec, p2pNetwork.getDiscoveryNodeId().get()); + } else { + LOG.warn("Discovery nodeId is not defined, disabling stable subnet subscriptions"); + this.stableSubnetSubscriber = StableSubnetSubscriber.NOOP; + } + } + eventChannels.subscribe(SlotEventsChannel.class, stableSubnetSubscriber); + } + + public void initExecutionLayerBlockProductionManager() { + LOG.debug("BeaconChainController.initExecutionLayerBlockProductionManager()"); + this.executionLayerBlockProductionManager = + ExecutionLayerBlockManagerFactory.create( + executionLayer, eventChannels.createSubscriber(SlotEventsChannel.class)); + } + + public void initRewardCalculator() { + LOG.debug("BeaconChainController.initRewardCalculator()"); + rewardCalculator = new RewardCalculator(spec, new BlockRewardCalculatorUtil(spec)); + } + + public void initValidatorApiHandler() { + LOG.debug("BeaconChainController.initValidatorApiHandler()"); + final GraffitiBuilder graffitiBuilder = + new GraffitiBuilder( + beaconConfig.validatorConfig().getClientGraffitiAppendFormat(), + beaconConfig.validatorConfig().getGraffitiProvider().get()); + eventChannels.subscribe(ExecutionClientVersionChannel.class, graffitiBuilder); + final ExecutionClientVersionProvider executionClientVersionProvider = + new ExecutionClientVersionProvider( + executionLayer, + eventChannels.getPublisher(ExecutionClientVersionChannel.class), + graffitiBuilder.getConsensusClientVersion()); + final BlockOperationSelectorFactory operationSelector = + new BlockOperationSelectorFactory( + spec, + attestationPool, + attesterSlashingPool, + proposerSlashingPool, + voluntaryExitPool, + blsToExecutionChangePool, + syncCommitteeContributionPool, + depositProvider, + eth1DataCache, + graffitiBuilder, + forkChoiceNotifier, + executionLayerBlockProductionManager); + final BlockFactory blockFactory = new MilestoneBasedBlockFactory(spec, operationSelector); + SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager = + beaconConfig.p2pConfig().isSubscribeAllSubnetsEnabled() + ? new AllSyncCommitteeSubscriptions(p2pNetwork, spec) + : new SyncCommitteeSubscriptionManager(p2pNetwork); + final BlockImportChannel blockImportChannel = + eventChannels.getPublisher(BlockImportChannel.class, beaconAsyncRunner); + final BlockGossipChannel blockGossipChannel = + eventChannels.getPublisher(BlockGossipChannel.class); + final BlobSidecarGossipChannel blobSidecarGossipChannel; + if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { + blobSidecarGossipChannel = eventChannels.getPublisher(BlobSidecarGossipChannel.class); + } else { + blobSidecarGossipChannel = BlobSidecarGossipChannel.NOOP; + } + + final BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory = + new BlockProductionAndPublishingPerformanceFactory( + timeProvider, + (slot) -> secondsToMillis(recentChainData.computeTimeAtSlot(slot)), + beaconConfig.getMetricsConfig().isBlockProductionAndPublishingPerformanceEnabled(), + beaconConfig.getMetricsConfig().getBlockProductionPerformanceWarningLocalThreshold(), + beaconConfig.getMetricsConfig().getBlockProductionPerformanceWarningBuilderThreshold(), + beaconConfig.getMetricsConfig().getBlockPublishingPerformanceWarningLocalThreshold(), + beaconConfig.getMetricsConfig().getBlockPublishingPerformanceWarningBuilderThreshold()); + + final ValidatorApiHandler validatorApiHandler = + new ValidatorApiHandler( + new ChainDataProvider(spec, recentChainData, combinedChainDataClient, rewardCalculator), + dataProvider.getNodeDataProvider(), + combinedChainDataClient, + syncService, + blockFactory, + blockImportChannel, + blockGossipChannel, + blockBlobSidecarsTrackersPool, + blobSidecarGossipChannel, + attestationPool, + attestationManager, + attestationTopicSubscriber, + activeValidatorTracker, + DutyMetrics.create(metricsSystem, timeProvider, recentChainData, spec), + performanceTracker, + spec, + forkChoiceTrigger, + proposersDataManager, + syncCommitteeMessagePool, + syncCommitteeContributionPool, + syncCommitteeSubscriptionManager, + blockProductionPerformanceFactory); + eventChannels + .subscribe(SlotEventsChannel.class, activeValidatorTracker) + .subscribe(ExecutionClientEventsChannel.class, executionClientVersionProvider) + .subscribeMultithreaded( + ValidatorApiChannel.class, + validatorApiHandler, + beaconConfig.beaconRestApiConfig().getValidatorThreads()); + + // if subscribeAllSubnets is set, the slot events in these handlers are empty, + // so don't subscribe. + if (!beaconConfig.p2pConfig().isSubscribeAllSubnetsEnabled()) { + eventChannels + .subscribe(SlotEventsChannel.class, attestationTopicSubscriber) + .subscribe(SlotEventsChannel.class, syncCommitteeSubscriptionManager); + } + } + + protected void initGenesisHandler() { + if (!recentChainData.isPreGenesis()) { + // We already have a genesis block - no need for a genesis handler + return; + } else if (!beaconConfig.powchainConfig().isEnabled()) { + // We're pre-genesis but no eth1 endpoint is set + throw new IllegalStateException("ETH1 is disabled, but no initial state is set."); + } + STATUS_LOG.loadingGenesisFromEth1Chain(); + eventChannels.subscribe( + Eth1EventsChannel.class, new GenesisHandler(recentChainData, timeProvider, spec)); + } + + protected void initSignatureVerificationService() { + final P2PConfig p2PConfig = beaconConfig.p2pConfig(); + signatureVerificationService = + new AggregatingSignatureVerificationService( + metricsSystem, + asyncRunnerFactory, + beaconAsyncRunner, + p2PConfig.getBatchVerifyMaxThreads(), + p2PConfig.getBatchVerifyQueueCapacity(), + p2PConfig.getBatchVerifyMaxBatchSize(), + p2PConfig.isBatchVerifyStrictThreadLimitEnabled()); + } + + protected void initAttestationManager() { + final PendingPool pendingAttestations = + poolFactory.createPendingPoolForAttestations(spec); + final FutureItems futureAttestations = + FutureItems.create( + ValidatableAttestation::getEarliestSlotForForkChoiceProcessing, + UInt64.valueOf(3), + futureItemsMetric, + "attestations"); + AttestationValidator attestationValidator = + new AttestationValidator( + spec, recentChainData, signatureVerificationService, metricsSystem); + AggregateAttestationValidator aggregateValidator = + new AggregateAttestationValidator(spec, attestationValidator, signatureVerificationService); + blockImporter.subscribeToVerifiedBlockAttestations( + (slot, attestations) -> + attestations.forEach( + attestation -> + aggregateValidator.addSeenAggregate( + ValidatableAttestation.from(spec, attestation)))); + attestationManager = + AttestationManager.create( + pendingAttestations, + futureAttestations, + forkChoice, + attestationPool, + attestationValidator, + aggregateValidator, + signatureVerificationService, + eventChannels.getPublisher(ActiveValidatorChannel.class, beaconAsyncRunner)); + + eventChannels + .subscribe(SlotEventsChannel.class, attestationManager) + .subscribe(FinalizedCheckpointChannel.class, pendingAttestations) + .subscribe(ReceivedBlockEventsChannel.class, attestationManager); + } + + protected void initSyncCommitteePools() { + final SyncCommitteeStateUtils syncCommitteeStateUtils = + new SyncCommitteeStateUtils(spec, recentChainData); + syncCommitteeContributionPool = + new SyncCommitteeContributionPool( + spec, + new SignedContributionAndProofValidator( + spec, + recentChainData, + syncCommitteeStateUtils, + timeProvider, + signatureVerificationService)); + + syncCommitteeMessagePool = + new SyncCommitteeMessagePool( + spec, + new SyncCommitteeMessageValidator( + spec, + recentChainData, + syncCommitteeStateUtils, + signatureVerificationService, + timeProvider)); + eventChannels + .subscribe(SlotEventsChannel.class, syncCommitteeContributionPool) + .subscribe(SlotEventsChannel.class, syncCommitteeMessagePool); + } + + protected void initP2PNetwork() { + LOG.debug("BeaconChainController.initP2PNetwork()"); + if (!beaconConfig.p2pConfig().getNetworkConfig().isEnabled()) { + this.p2pNetwork = new NoOpEth2P2PNetwork(spec); + return; + } + + DiscoveryConfig discoveryConfig = beaconConfig.p2pConfig().getDiscoveryConfig(); + final Optional maybeUdpPort = + discoveryConfig.isDiscoveryEnabled() + ? Optional.of(discoveryConfig.getListenUdpPort()) + : Optional.empty(); + + PortAvailability.checkPortsAvailable( + beaconConfig.p2pConfig().getNetworkConfig().getListenPort(), maybeUdpPort); + + this.p2pNetwork = + createEth2P2PNetworkBuilder() + .config(beaconConfig.p2pConfig()) + .eventChannels(eventChannels) + .combinedChainDataClient(combinedChainDataClient) + .gossipedBlockProcessor(blockManager::validateAndImportBlock) + .gossipedBlobSidecarProcessor(blobSidecarManager::validateAndPrepareForBlockImport) + .gossipedAttestationProcessor(attestationManager::addAttestation) + .gossipedAggregateProcessor(attestationManager::addAggregate) + .gossipedAttesterSlashingProcessor(attesterSlashingPool::addRemote) + .gossipedProposerSlashingProcessor(proposerSlashingPool::addRemote) + .gossipedVoluntaryExitProcessor(voluntaryExitPool::addRemote) + .gossipedSignedContributionAndProofProcessor(syncCommitteeContributionPool::addRemote) + .gossipedSyncCommitteeMessageProcessor(syncCommitteeMessagePool::addRemote) + .gossipedSignedBlsToExecutionChangeProcessor(blsToExecutionChangePool::addRemote) + .processedAttestationSubscriptionProvider( + attestationManager::subscribeToAttestationsToSend) + .metricsSystem(metricsSystem) + .timeProvider(timeProvider) + .asyncRunner(networkAsyncRunner) + .keyValueStore(keyValueStore) + .requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()) + .specProvider(spec) + .kzg(kzg) + .recordMessageArrival(true) + .p2pDebugDataDumper(p2pDebugDataDumper) + .build(); + + syncCommitteeMessagePool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeMessage)); + syncCommitteeContributionPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeContribution)); + proposerSlashingPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishProposerSlashing)); + attesterSlashingPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishAttesterSlashing)); + voluntaryExitPool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishVoluntaryExit)); + blsToExecutionChangePool.subscribeOperationAdded( + new LocalOperationAcceptedFilter<>(p2pNetwork::publishSignedBlsToExecutionChange)); + } + + protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { + return Eth2P2PNetworkBuilder.create(); + } + + protected void initSlotProcessor() { + slotProcessor = + new SlotProcessor( + spec, + recentChainData, + syncService, + forkChoiceTrigger, + forkChoiceNotifier, + p2pNetwork, + slotEventsChannelPublisher, + new EpochCachePrimer(spec, recentChainData, beaconAsyncRunner)); + } + + public void initAttestationPool() { + LOG.debug("BeaconChainController.initAttestationPool()"); + attestationPool = + new AggregatingAttestationPool( + spec, recentChainData, metricsSystem, DEFAULT_MAXIMUM_ATTESTATION_COUNT); + eventChannels.subscribe(SlotEventsChannel.class, attestationPool); + blockImporter.subscribeToVerifiedBlockAttestations( + attestationPool::onAttestationsIncludedInBlock); + } + + public void initRestAPI() { + LOG.debug("BeaconChainController.initRestAPI()"); + if (!beaconConfig.beaconRestApiConfig().isRestApiEnabled()) { + LOG.info("rest-api-enabled is false, not starting rest api."); + return; + } + final Eth1DataProvider eth1DataProvider = new Eth1DataProvider(eth1DataCache, depositProvider); + + final ExecutionClientDataProvider executionClientDataProvider = + dataProvider.getExecutionClientDataProvider(); + + eventChannels.subscribe(ExecutionClientEventsChannel.class, executionClientDataProvider); + + beaconRestAPI = + Optional.of( + new JsonTypeDefinitionBeaconRestApi( + dataProvider, + eth1DataProvider, + beaconConfig.beaconRestApiConfig(), + eventChannels, + eventAsyncRunner, + timeProvider, + spec)); + + if (getLivenessTrackingEnabled(beaconConfig)) { + final int initialValidatorsCount = + spec.getGenesisSpec().getConfig().getMinGenesisActiveValidatorCount(); + eventChannels.subscribe( + ActiveValidatorChannel.class, new ActiveValidatorCache(spec, initialValidatorsCount)); + } + } + + public void initBlockImporter() { + LOG.debug("BeaconChainController.initBlockImporter()"); + blockImporter = + new BlockImporter( + spec, + receivedBlockEventsChannelPublisher, + recentChainData, + forkChoice, + weakSubjectivityValidator, + executionLayer); + } + + public void initBlockManager() { + LOG.debug("BeaconChainController.initBlockManager()"); + final FutureItems futureBlocks = + FutureItems.create(SignedBeaconBlock::getSlot, futureItemsMetric, "blocks"); + final BlockGossipValidator blockGossipValidator = + new BlockGossipValidator(spec, gossipValidationHelper, receivedBlockEventsChannelPublisher); + final BlockValidator blockValidator = new BlockValidator(blockGossipValidator); + final Optional importMetrics = + beaconConfig.getMetricsConfig().isBlockPerformanceEnabled() + ? Optional.of(BlockImportMetrics.create(metricsSystem)) + : Optional.empty(); + + blockManager = + new BlockManager( + recentChainData, + blockImporter, + blockBlobSidecarsTrackersPool, + pendingBlocks, + futureBlocks, + invalidBlockRoots, + blockValidator, + timeProvider, + EVENT_LOG, + importMetrics); + if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + final FailedExecutionPool failedExecutionPool = + new FailedExecutionPool(blockManager, beaconAsyncRunner); + blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); + } + eventChannels + .subscribe(SlotEventsChannel.class, blockManager) + .subscribe(BlockImportChannel.class, blockManager) + .subscribe(ReceivedBlockEventsChannel.class, blockManager); + } + + protected SyncServiceFactory createSyncServiceFactory() { + return new DefaultSyncServiceFactory( + beaconConfig.syncConfig(), + beaconConfig.eth2NetworkConfig().getNetworkBoostrapConfig().getGenesisState(), + metricsSystem, + asyncRunnerFactory, + beaconAsyncRunner, + timeProvider, + recentChainData, + combinedChainDataClient, + storageUpdateChannel, + p2pNetwork, + blockImporter, + blobSidecarManager, + pendingBlocks, + blockBlobSidecarsTrackersPool, + beaconConfig.eth2NetworkConfig().getStartupTargetPeerCount(), + signatureVerificationService, + Duration.ofSeconds(beaconConfig.eth2NetworkConfig().getStartupTimeoutSeconds()), + spec); + } + + public void initSyncService() { + LOG.debug("BeaconChainController.initSyncService()"); + syncService = createSyncServiceFactory().create(eventChannels); + + // chainHeadChannel subscription + syncService.getForwardSync().subscribeToSyncChanges(coalescingChainHeadChannel); + + // forkChoiceNotifier subscription + syncService.subscribeToSyncStateChangesAndUpdate( + syncState -> forkChoiceNotifier.onSyncingStatusChanged(syncState.isInSync())); + + // depositProvider subscription + syncService.subscribeToSyncStateChangesAndUpdate( + syncState -> depositProvider.onSyncingStatusChanged(syncState.isInSync())); + + // forkChoice subscription + forkChoice.subscribeToOptimisticHeadChangesAndUpdate(syncService.getOptimisticSyncSubscriber()); + + // terminalPowBlockMonitor subscription + terminalPowBlockMonitor.ifPresent( + monitor -> + syncService.subscribeToSyncStateChangesAndUpdate( + syncState -> monitor.onNodeSyncStateChanged(syncState.isInSync()))); + + // p2pNetwork subscription so gossip can be enabled and disabled appropriately + syncService.subscribeToSyncStateChangesAndUpdate( + state -> p2pNetwork.onSyncStateChanged(state.isInSync(), state.isOptimistic())); + } + + protected void initOperationsReOrgManager() { + LOG.debug("BeaconChainController.initOperationsReOrgManager()"); + OperationsReOrgManager operationsReOrgManager = + new OperationsReOrgManager( + proposerSlashingPool, + attesterSlashingPool, + voluntaryExitPool, + attestationPool, + attestationManager, + blsToExecutionChangePool, + recentChainData); + eventChannels.subscribe(ChainHeadChannel.class, operationsReOrgManager); + } + + protected void initValidatorIndexCacheTracker() { + LOG.debug("BeaconChainController.initValidatorIndexCacheTracker()"); + final ValidatorIndexCacheTracker validatorIndexCacheTracker = + new ValidatorIndexCacheTracker(recentChainData); + eventChannels.subscribe(FinalizedCheckpointChannel.class, validatorIndexCacheTracker); + } + + protected void initForkChoiceStateProvider() { + LOG.debug("BeaconChainController.initForkChoiceStateProvider()"); + forkChoiceStateProvider = new ForkChoiceStateProvider(forkChoiceExecutor, recentChainData); + } + + protected void initForkChoiceNotifier() { + LOG.debug("BeaconChainController.initForkChoiceNotifier()"); + final AsyncRunnerEventThread eventThread = + new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); + eventThread.start(); + proposersDataManager = + new ProposersDataManager( + eventThread, + spec, + metricsSystem, + executionLayer, + recentChainData, + getProposerDefaultFeeRecipient(), + beaconConfig.eth2NetworkConfig().isForkChoiceUpdatedAlwaysSendPayloadAttributes()); + eventChannels.subscribe(SlotEventsChannel.class, proposersDataManager); + forkChoiceNotifier = + new ForkChoiceNotifierImpl( + forkChoiceStateProvider, + eventThread, + timeProvider, + spec, + executionLayer, + recentChainData, + proposersDataManager); + } + + private Optional getProposerDefaultFeeRecipient() { + if (!spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { + return Optional.of(Eth1Address.ZERO); + } + + final Optional defaultFeeRecipient = + beaconConfig.validatorConfig().getProposerDefaultFeeRecipient(); + + if (defaultFeeRecipient.isEmpty() && beaconConfig.beaconRestApiConfig().isRestApiEnabled()) { + STATUS_LOG.warnMissingProposerDefaultFeeRecipientWithRestAPIEnabled(); + } + + return defaultFeeRecipient; + } + + protected void setupInitialState(final RecentChainData client) { + final Eth2NetworkConfiguration networkConfiguration = beaconConfig.eth2NetworkConfig(); + + final Optional initialAnchor = + tryLoadingAnchorPointFromInitialState(networkConfiguration) + .or( + () -> + attemptToLoadAnchorPoint( + networkConfiguration.getNetworkBoostrapConfig().getGenesisState())); + + /* + If flag to allow sync outside of weak subjectivity period has been set, we pass an instance of + WeakSubjectivityPeriodCalculator to the WeakSubjectivityInitializer. Otherwise, we pass an Optional.empty(). + */ + final Optional maybeWsCalculator; + if (isAllowSyncOutsideWeakSubjectivityPeriod()) { + maybeWsCalculator = Optional.empty(); + } else { + maybeWsCalculator = + Optional.of(WeakSubjectivityCalculator.create(beaconConfig.weakSubjectivity())); + } + + // Validate + initialAnchor.ifPresent( + anchor -> { + final UInt64 currentSlot = getCurrentSlot(anchor.getState().getGenesisTime()); + wsInitializer.validateInitialAnchor(anchor, currentSlot, spec, maybeWsCalculator); + }); + + if (initialAnchor.isPresent()) { + final AnchorPoint anchor = initialAnchor.get(); + client.initializeFromAnchorPoint(anchor, timeProvider.getTimeInSeconds()); + if (anchor.isGenesis()) { + EVENT_LOG.genesisEvent( + anchor.getStateRoot(), + recentChainData.getBestBlockRoot().orElseThrow(), + anchor.getState().getGenesisTime()); + } + } else if (beaconConfig.interopConfig().isInteropEnabled()) { + setupInteropState(); + } else if (!beaconConfig.powchainConfig().isEnabled()) { + throw new InvalidConfigurationException( + "ETH1 is disabled but initial state is unknown. Enable ETH1 or specify an initial state" + + "."); + } + } + + private Optional tryLoadingAnchorPointFromInitialState( + final Eth2NetworkConfiguration networkConfiguration) { + Optional initialAnchor = Optional.empty(); + + try { + initialAnchor = + attemptToLoadAnchorPoint( + networkConfiguration.getNetworkBoostrapConfig().getInitialState()); + } catch (final InvalidConfigurationException e) { + final StateBoostrapConfig stateBoostrapConfig = + networkConfiguration.getNetworkBoostrapConfig(); + if (stateBoostrapConfig.isUsingCustomInitialState() + && !stateBoostrapConfig.isUsingCheckpointSync()) { + throw e; + } + STATUS_LOG.warnFailedToLoadInitialState(e.getMessage()); + } + + return initialAnchor; + } + + protected Optional attemptToLoadAnchorPoint(final Optional initialState) { + return wsInitializer.loadInitialAnchorPoint(spec, initialState); + } + + protected void setupInteropState() { + final InteropConfig config = beaconConfig.interopConfig(); + STATUS_LOG.generatingMockStartGenesis( + config.getInteropGenesisTime(), config.getInteropNumberOfValidators()); + + Optional executionPayloadHeader = Optional.empty(); + if (config.getInteropGenesisPayloadHeader().isPresent()) { + try { + executionPayloadHeader = + Optional.of( + spec.deserializeJsonExecutionPayloadHeader( + new ObjectMapper(), + config.getInteropGenesisPayloadHeader().get().toFile(), + GENESIS_SLOT)); + } catch (IOException e) { + throw new RuntimeException( + "Unable to load payload header from " + config.getInteropGenesisPayloadHeader().get(), + e); + } + } + + final BeaconState genesisState = + new GenesisStateBuilder() + .spec(spec) + .genesisTime(config.getInteropGenesisTime()) + .addMockValidators(config.getInteropNumberOfValidators()) + .executionPayloadHeader(executionPayloadHeader) + .build(); + + recentChainData.initializeFromGenesis(genesisState, timeProvider.getTimeInSeconds()); + + EVENT_LOG.genesisEvent( + genesisState.hashTreeRoot(), + recentChainData.getBestBlockRoot().orElseThrow(), + genesisState.getGenesisTime()); + } + + protected void onStoreInitialized() { + UInt64 genesisTime = recentChainData.getGenesisTime(); + UInt64 currentTime = timeProvider.getTimeInSeconds(); + final UInt64 currentSlot = getCurrentSlot(genesisTime, currentTime); + if (currentTime.compareTo(genesisTime) >= 0) { + // Validate that we're running within the weak subjectivity period + validateChain(currentSlot); + } else { + UInt64 timeUntilGenesis = genesisTime.minus(currentTime); + genesisTimeTracker = currentTime; + STATUS_LOG.timeUntilGenesis(timeUntilGenesis.longValue(), p2pNetwork.getPeerCount()); + } + slotProcessor.setCurrentSlot(currentSlot); + performanceTracker.start(currentSlot); + } + + protected UInt64 getCurrentSlot(final UInt64 genesisTime) { + return getCurrentSlot(genesisTime, timeProvider.getTimeInSeconds()); + } + + protected UInt64 getCurrentSlot(final UInt64 genesisTime, final UInt64 currentTime) { + return spec.getCurrentSlot(currentTime, genesisTime); + } + + protected void validateChain(final UInt64 currentSlot) { + weakSubjectivityValidator + .validateChainIsConsistentWithWSCheckpoint(combinedChainDataClient) + .thenCompose( + __ -> + SafeFuture.of( + () -> recentChainData.getStore().retrieveFinalizedCheckpointAndState())) + .thenAccept( + finalizedCheckpointState -> { + final UInt64 slot = currentSlot.max(recentChainData.getCurrentSlot().orElse(ZERO)); + weakSubjectivityValidator.validateLatestFinalizedCheckpoint( + finalizedCheckpointState, slot); + }) + .finish( + err -> { + weakSubjectivityValidator.handleValidationFailure( + "Encountered an error while trying to validate latest finalized checkpoint", err); + throw new RuntimeException(err); + }); + } + + private void onTick() { + if (recentChainData.isPreGenesis()) { + return; + } + + final UInt64 currentTimeMillis = timeProvider.getTimeInMillis(); + final UInt64 currentTimeSeconds = millisToSeconds(currentTimeMillis); + final Optional performanceRecord = + beaconConfig.getMetricsConfig().isTickPerformanceEnabled() + ? Optional.of(new TickProcessingPerformance(timeProvider, currentTimeMillis)) + : Optional.empty(); + + forkChoice.onTick(currentTimeMillis, performanceRecord); + + final UInt64 genesisTime = recentChainData.getGenesisTime(); + if (genesisTime.isGreaterThan(currentTimeSeconds)) { + // notify every 10 minutes + if (genesisTimeTracker.plus(600L).isLessThanOrEqualTo(currentTimeSeconds)) { + genesisTimeTracker = currentTimeSeconds; + STATUS_LOG.timeUntilGenesis( + genesisTime.minus(currentTimeSeconds).longValue(), p2pNetwork.getPeerCount()); + } + } + + slotProcessor.onTick(currentTimeMillis, performanceRecord); + performanceRecord.ifPresent(TickProcessingPerformance::complete); + } + + @Override + public Spec getSpec() { + return spec; + } + + @Override + public TimeProvider getTimeProvider() { + return timeProvider; + } + + @Override + public AsyncRunnerFactory getAsyncRunnerFactory() { + return asyncRunnerFactory; + } + + @Override + public SignatureVerificationService getSignatureVerificationService() { + return signatureVerificationService; + } + + @Override + public RecentChainData getRecentChainData() { + return recentChainData; + } + + @Override + public CombinedChainDataClient getCombinedChainDataClient() { + return combinedChainDataClient; + } + + @Override + public Eth2P2PNetwork getP2pNetwork() { + return p2pNetwork; + } + + @Override + public Optional getBeaconRestAPI() { + return beaconRestAPI; + } + + @Override + public SyncService getSyncService() { + return syncService; + } + + @Override + public ForkChoice getForkChoice() { + return forkChoice; + } +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java index 484c51b2e43..7304f2f21ea 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java @@ -1,39 +1,37 @@ package tech.pegasys.teku.services.beaconchain.init; import dagger.Component; - import javax.inject.Singleton; +import tech.pegasys.teku.services.beaconchain.BeaconChainController; @Singleton -@Component(modules = { - AsyncRunnerModule.class, - BeaconConfigModule.class, - BeaconModule.class, - BlobModule.class, - ChannelsModule.class, - CryptoModule.class, - DataProviderModule.class, - ExternalDependenciesModule.class, - ForkChoiceModule.class, - LoggingModule.class, - MainModule.class, - MetricsModule.class, - NetworkModule.class, - PoolAndCachesModule.class, - PowModule.class, - ServiceConfigModule.class, - SpecModule.class, - StorageModule.class, - SubnetsModule.class, - SyncModule.class, - ValidatorModule.class, - VerifyModule.class, - WSModule.class -}) +@Component( + modules = { + AsyncRunnerModule.class, + BeaconConfigModule.class, + BeaconModule.class, + BlobModule.class, + ChannelsModule.class, + CryptoModule.class, + DataProviderModule.class, + ExternalDependenciesModule.class, + ForkChoiceModule.class, + LoggingModule.class, + MainModule.class, + MetricsModule.class, + NetworkModule.class, + PoolAndCachesModule.class, + PowModule.class, + ServiceConfigModule.class, + SpecModule.class, + StorageModule.class, + SubnetsModule.class, + SyncModule.class, + ValidatorModule.class, + VerifyModule.class, + WSModule.class + }) public interface BeaconChainControllerComponent { - MainModule.ServiceStarter starter(); - - MainModule.ServiceStopper stopper(); - + BeaconChainController beaconChainController(); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index 5fc18030fe0..94c86b25b59 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -10,10 +10,13 @@ import tech.pegasys.teku.beacon.sync.gossip.blobs.RecentBlobSidecarsFetcher; import tech.pegasys.teku.beacon.sync.gossip.blocks.RecentBlocksFetcher; import tech.pegasys.teku.beaconrestapi.BeaconRestApi; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; import tech.pegasys.teku.infrastructure.logging.StatusLogger; +import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.services.beaconchain.BeaconChainController; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; import tech.pegasys.teku.services.powchain.PowchainConfiguration; @@ -27,8 +30,11 @@ import tech.pegasys.teku.statetransition.attestation.AttestationManager; import tech.pegasys.teku.statetransition.block.BlockManager; import tech.pegasys.teku.statetransition.block.FailedExecutionPool; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; import tech.pegasys.teku.statetransition.genesis.GenesisHandler; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.validator.api.ValidatorConfig; import tech.pegasys.teku.validator.api.ValidatorTimingChannel; @@ -36,6 +42,7 @@ import java.util.Optional; import java.util.Set; +import java.util.function.Supplier; @Module public interface MainModule { @@ -51,6 +58,37 @@ interface ServiceStopper { SafeFuture stop(); } + @Provides + @Singleton + static BeaconChainController beaconChainController( + Spec spec, + TimeProvider timeProvider, + AsyncRunnerFactory asyncRunnerFactory, + ForkChoice forkChoice, + RecentChainData recentChainData, + Eth2P2PNetwork p2pNetwork, + Optional beaconRestAPI, + SyncService syncService, + SignatureVerificationService signatureVerificationService, + CombinedChainDataClient combinedChainDataClient, + ServiceStarter starter, + ServiceStopper stopper) { + + return new BeaconChainController( + spec, + timeProvider, + asyncRunnerFactory, + forkChoice, + recentChainData, + p2pNetwork, + beaconRestAPI, + syncService, + signatureVerificationService, + combinedChainDataClient, + starter::start, + stopper::stop); + } + @Provides @IntoSet static VoidInitializer initSlashingEventsSubscriptions( diff --git a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java index 8f7aebcc234..e94b4dca0d0 100644 --- a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java +++ b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java @@ -93,28 +93,28 @@ protected LibP2PNetworkBuilder createLibP2PNetworkBuilder() { } }; - BeaconChainControllerFactory customControllerFactory = - (serviceConfig, beaconConfig) -> - new BeaconChainController(serviceConfig, beaconConfig) { - @Override - protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { - return customEth2P2PNetworkBuilder; - } - }; - - TekuConfiguration tekuConfiguration = - TekuConfiguration.builder() - .data(b -> b.dataBasePath(tempDir)) - .executionLayer(b -> b.engineEndpoint("unsafe-test-stub")) - .eth2NetworkConfig(b -> b.ignoreWeakSubjectivityPeriodEnabled(true)) - .beaconChainControllerFactory(customControllerFactory) - .build(); - - try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) { - assertThat(beaconNode).isNotNull(); - assertThat(customDiscoveryBuilderMethodCalled).isTrue(); - assertThat(customLibP2PBuilderMethodCalled).isTrue(); - assertThat(customGossipNetworkBuilderCalled).isTrue(); - } +// BeaconChainControllerFactory customControllerFactory = +// (serviceConfig, beaconConfig) -> +// new BeaconChainController(serviceConfig, beaconConfig) { +// @Override +// protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { +// return customEth2P2PNetworkBuilder; +// } +// }; +// +// TekuConfiguration tekuConfiguration = +// TekuConfiguration.builder() +// .data(b -> b.dataBasePath(tempDir)) +// .executionLayer(b -> b.engineEndpoint("unsafe-test-stub")) +// .eth2NetworkConfig(b -> b.ignoreWeakSubjectivityPeriodEnabled(true)) +// .beaconChainControllerFactory(customControllerFactory) +// .build(); +// +// try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) { +// assertThat(beaconNode).isNotNull(); +// assertThat(customDiscoveryBuilderMethodCalled).isTrue(); +// assertThat(customLibP2PBuilderMethodCalled).isTrue(); +// assertThat(customGossipNetworkBuilderCalled).isTrue(); +// } } } From 259935a31a90a1a35971bc6d13e617a3dc046b8e Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 17:54:07 +0400 Subject: [PATCH 11/27] Make old/new BeaconChainController easily interchangeable --- .../beaconchain/AbstractBeaconChainController.java | 7 +++++++ .../teku/services/beaconchain/BeaconChainController.java | 2 +- .../services/beaconchain/BeaconChainControllerOld.java | 2 +- .../teku/services/beaconchain/BeaconChainService.java | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java new file mode 100644 index 00000000000..45cc5f8d670 --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java @@ -0,0 +1,7 @@ +package tech.pegasys.teku.services.beaconchain; + +import tech.pegasys.teku.service.serviceutils.Service; + +public abstract class AbstractBeaconChainController extends Service implements BeaconChainControllerFacade { + +} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index 537d04a5e23..feefe7509b4 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -38,7 +38,7 @@ * initialization behavior (see {@link BeaconChainControllerFactory}} however this class may change * in a backward incompatible manner and either break compilation or runtime behavior */ -public class BeaconChainController extends Service implements BeaconChainControllerFacade { +public class BeaconChainController extends AbstractBeaconChainController { private static final Logger LOG = LogManager.getLogger(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java index 20056db6557..12a69bce715 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java @@ -215,7 +215,7 @@ * initialization behavior (see {@link BeaconChainControllerFactory}} however this class may change * in a backward incompatible manner and either break compilation or runtime behavior */ -public class BeaconChainControllerOld extends Service implements BeaconChainControllerFacade { +public class BeaconChainControllerOld extends AbstractBeaconChainController { private static final Logger LOG = LogManager.getLogger(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java index fd50babc30f..35a68456909 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java @@ -19,7 +19,7 @@ public class BeaconChainService extends Service implements BeaconChainServiceFacade { - private final BeaconChainController controller; + private final AbstractBeaconChainController controller; public BeaconChainService( final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig) { @@ -38,7 +38,7 @@ protected SafeFuture doStop() { } @Override - public BeaconChainController getBeaconChainController() { + public BeaconChainControllerFacade getBeaconChainController() { return controller; } } From 1dd893e34b22ce6e66b225ff7d5a8cf888dd75c5 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 17:55:16 +0400 Subject: [PATCH 12/27] Initialize BeaconChainController Dagger components inside doStart() when other services are started --- .../beaconchain/BeaconChainController.java | 88 ++++++++++--------- .../BeaconChainControllerFactory.java | 10 +-- .../init/BeaconChainControllerComponent.java | 37 +++++++- .../services/beaconchain/init/MainModule.java | 31 ------- 4 files changed, 86 insertions(+), 80 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index feefe7509b4..c76c7e5382a 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -25,6 +25,10 @@ import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.service.serviceutils.Service; +import tech.pegasys.teku.service.serviceutils.ServiceConfig; +import tech.pegasys.teku.services.beaconchain.init.BeaconChainControllerComponent; +import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; +import tech.pegasys.teku.services.beaconchain.init.ExternalDependenciesModule; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; @@ -42,55 +46,57 @@ public class BeaconChainController extends AbstractBeaconChainController { private static final Logger LOG = LogManager.getLogger(); - private final Spec spec; - private final TimeProvider timeProvider; - private final AsyncRunnerFactory asyncRunnerFactory; - private final ForkChoice forkChoice; - private final RecentChainData recentChainData; - private final Eth2P2PNetwork p2pNetwork; - private final Optional beaconRestAPI; - private final SyncService syncService; - private final SignatureVerificationService signatureVerificationService; - private final CombinedChainDataClient combinedChainDataClient; - - private final Supplier> starter; - private final Supplier> stopper; - - public BeaconChainController( - Spec spec, - TimeProvider timeProvider, - AsyncRunnerFactory asyncRunnerFactory, - ForkChoice forkChoice, - RecentChainData recentChainData, - Eth2P2PNetwork p2pNetwork, - Optional beaconRestAPI, - SyncService syncService, - SignatureVerificationService signatureVerificationService, - CombinedChainDataClient combinedChainDataClient, - Supplier> starter, - Supplier> stopper) { - this.spec = spec; - this.timeProvider = timeProvider; - this.asyncRunnerFactory = asyncRunnerFactory; - this.forkChoice = forkChoice; - this.recentChainData = recentChainData; - this.p2pNetwork = p2pNetwork; - this.beaconRestAPI = beaconRestAPI; - this.syncService = syncService; - this.signatureVerificationService = signatureVerificationService; - this.combinedChainDataClient = combinedChainDataClient; - this.starter = starter; - this.stopper = stopper; + private final ServiceConfig serviceConfig; + private final BeaconChainConfiguration beaconConfig; + + private Spec spec; + private TimeProvider timeProvider; + private AsyncRunnerFactory asyncRunnerFactory; + private ForkChoice forkChoice; + private RecentChainData recentChainData; + private Eth2P2PNetwork p2pNetwork; + private Optional beaconRestAPI; + private SyncService syncService; + private SignatureVerificationService signatureVerificationService; + private CombinedChainDataClient combinedChainDataClient; + + private Supplier> starter; + private Supplier> stopper; + + public BeaconChainController(ServiceConfig serviceConfig, BeaconChainConfiguration beaconConfig) { + this.serviceConfig = serviceConfig; + this.beaconConfig = beaconConfig; } @Override protected SafeFuture doStart() { - return starter.get(); + LOG.info("Starting BeaconChainController..."); + BeaconChainControllerComponent component = DaggerBeaconChainControllerComponent.builder() + .externalDependenciesModule(new ExternalDependenciesModule(serviceConfig, beaconConfig)) + .build(); + + this.spec = component.getSpec(); + this.timeProvider = component.getTimeProvider(); + this.asyncRunnerFactory = component.getAsyncRunnerFactory(); + this.forkChoice = component.getForkChoice(); + this.recentChainData = component.getRecentChainData(); + this.p2pNetwork = component.getP2pNetwork(); + this.beaconRestAPI = component.getBeaconRestAPI(); + this.syncService = component.getSyncService(); + this.signatureVerificationService = component.getSignatureVerificationService(); + this.combinedChainDataClient = component.getCombinedChainDataClient(); + this.starter = () -> component.starter().start(); + this.stopper = () -> component.stopper().stop(); + + SafeFuture startFuture = this.starter.get(); + LOG.info("BeaconChainController start complete"); + + return startFuture; } @Override protected SafeFuture doStop() { - return stopper.get(); + return this.stopper.get(); } @Override diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java index 9d41f32b4ed..6898df86d08 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java @@ -24,13 +24,9 @@ public interface BeaconChainControllerFactory { BeaconChainControllerFactory DEFAULT = - (serviceConfig, beaconConfig) -> - DaggerBeaconChainControllerComponent.builder() - .externalDependenciesModule( - new ExternalDependenciesModule(serviceConfig, beaconConfig)) - .build() - .beaconChainController(); +// BeaconChainControllerOld::new; + BeaconChainController::new; - BeaconChainController create( + AbstractBeaconChainController create( final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java index 7304f2f21ea..80bd206ad90 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java @@ -2,7 +2,20 @@ import dagger.Component; import javax.inject.Singleton; + +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.beaconrestapi.BeaconRestApi; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.services.beaconchain.BeaconChainController; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.RecentChainData; + +import java.util.Optional; @Singleton @Component( @@ -33,5 +46,27 @@ }) public interface BeaconChainControllerComponent { - BeaconChainController beaconChainController(); + MainModule.ServiceStarter starter(); + + MainModule.ServiceStopper stopper(); + + Spec getSpec(); + + TimeProvider getTimeProvider(); + + AsyncRunnerFactory getAsyncRunnerFactory(); + + SignatureVerificationService getSignatureVerificationService(); + + RecentChainData getRecentChainData(); + + CombinedChainDataClient getCombinedChainDataClient(); + + Eth2P2PNetwork getP2pNetwork(); + + Optional getBeaconRestAPI(); + + SyncService getSyncService(); + + ForkChoice getForkChoice(); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index 94c86b25b59..d3f03eb606e 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -58,37 +58,6 @@ interface ServiceStopper { SafeFuture stop(); } - @Provides - @Singleton - static BeaconChainController beaconChainController( - Spec spec, - TimeProvider timeProvider, - AsyncRunnerFactory asyncRunnerFactory, - ForkChoice forkChoice, - RecentChainData recentChainData, - Eth2P2PNetwork p2pNetwork, - Optional beaconRestAPI, - SyncService syncService, - SignatureVerificationService signatureVerificationService, - CombinedChainDataClient combinedChainDataClient, - ServiceStarter starter, - ServiceStopper stopper) { - - return new BeaconChainController( - spec, - timeProvider, - asyncRunnerFactory, - forkChoice, - recentChainData, - p2pNetwork, - beaconRestAPI, - syncService, - signatureVerificationService, - combinedChainDataClient, - starter::start, - stopper::stop); - } - @Provides @IntoSet static VoidInitializer initSlashingEventsSubscriptions( From 6f7bd8c0a6f1d5718ead18e6ed78556b09b5aec0 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 18:05:42 +0400 Subject: [PATCH 13/27] Start AsyncRunnerEventThread right after creation --- .../beaconchain/init/AsyncRunnerModule.java | 2 ++ .../teku/services/beaconchain/init/MainModule.java | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java index 1c532b1466b..40d52e47816 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java @@ -71,6 +71,7 @@ static AsyncRunner operationPoolAsyncRunner(AsyncRunnerFactory asyncRunnerFactor static AsyncRunnerEventThread forkChoiceExecutor(AsyncRunnerFactory asyncRunnerFactory) { AsyncRunnerEventThread forkChoiceExecutor = new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); + forkChoiceExecutor.start(); return forkChoiceExecutor; } @@ -80,6 +81,7 @@ static AsyncRunnerEventThread forkChoiceExecutor(AsyncRunnerFactory asyncRunnerF static AsyncRunnerEventThread forkChoiceNotifierExecutor(AsyncRunnerFactory asyncRunnerFactory) { AsyncRunnerEventThread forkChoiceNotifierExecutor = new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); + forkChoiceNotifierExecutor.start(); return forkChoiceNotifierExecutor; } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index d3f03eb606e..f3b3948aecb 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -19,6 +19,7 @@ import tech.pegasys.teku.services.beaconchain.BeaconChainController; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; +import tech.pegasys.teku.services.beaconchain.init.LoggingModule.InitLogger; import tech.pegasys.teku.services.powchain.PowchainConfiguration; import tech.pegasys.teku.services.timer.TimerService; import tech.pegasys.teku.spec.Spec; @@ -151,14 +152,10 @@ static ServiceStarter serviceStarter( Eth2P2PNetwork p2pNetwork, TimerService timerService, Optional terminalPowBlockMonitor, - @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, - @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor) { + InitLogger initLogger) { return () -> SafeFuture.fromRunnable( - () -> { - forkChoiceExecutor.start(); - forkChoiceNotifierExecutor.start(); - }) + () -> initLogger.logger().info("Starting BeaconChain services")) .thenCompose( __ -> SafeFuture.allOf( @@ -175,7 +172,10 @@ static ServiceStarter serviceStarter( beaconRestApi .map(BeaconRestApi::start) .orElse(SafeFuture.completedFuture(null)) - .thenApply(___ -> null)); + .thenApply(___ -> null)) + .thenRun( + () -> initLogger.logger().info("BeaconChain services started") + ); } @Provides From a7eb722c6c4921324140e21d29af669068a63d60 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 18:24:07 +0400 Subject: [PATCH 14/27] Fix the mess with currentTime & genesisTime parameters order for getCurrentSlot() --- .../pegasys/teku/services/beaconchain/init/SpecModule.java | 6 +++--- .../teku/services/beaconchain/init/StorageModule.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index 3041c0582fe..381be9d9cb9 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -52,12 +52,12 @@ static CurrentSlotProvider currentSlotProvider(Spec spec, TimeProvider timeProvi return new CurrentSlotProvider() { @Override public UInt64 getCurrentSlot(UInt64 genesisTime) { - return getCurrentSlot(genesisTime, timeProvider.getTimeInSeconds()); + return getCurrentSlot(timeProvider.getTimeInSeconds(), genesisTime); } @Override - public UInt64 getCurrentSlot(UInt64 genesisTime, UInt64 currentTime) { - return spec.getCurrentSlot(genesisTime, currentTime); + public UInt64 getCurrentSlot(UInt64 currentTime, UInt64 genesisTime) { + return spec.getCurrentSlot(currentTime, genesisTime); } }; } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index 2d1982edebe..c3f44399478 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -166,7 +166,7 @@ static OnStoreInitializedHandler onStoreInitializedHandler( return () -> { UInt64 genesisTime = recentChainData.getGenesisTime(); UInt64 currentTime = timeProvider.getTimeInSeconds(); - final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(genesisTime, currentTime); + final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(currentTime, genesisTime); if (currentTime.compareTo(genesisTime) >= 0) { // Validate that we're running within the weak subjectivity period weakSubjectivityStoreChainValidator.get().validate(currentSlot); From b067905489b85450684d5374b77ce47fa1f8268a Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 21 Jun 2024 18:38:50 +0400 Subject: [PATCH 15/27] WeakSubjectivityFinalizedConfig updates storage prior to RecentChainData initialization so we need to add this dummy dependency --- .../teku/services/beaconchain/init/StorageModule.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index c3f44399478..1e246a479ae 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -4,7 +4,6 @@ import dagger.Lazy; import dagger.Module; import dagger.Provides; - import javax.inject.Singleton; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -19,6 +18,7 @@ import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; import tech.pegasys.teku.services.beaconchain.init.BeaconModule.GenesisTimeTracker; import tech.pegasys.teku.services.beaconchain.init.SpecModule.CurrentSlotProvider; +import tech.pegasys.teku.services.beaconchain.init.WSModule.WeakSubjectivityFinalizedConfig; import tech.pegasys.teku.services.beaconchain.init.WSModule.WeakSubjectivityPeriodValidator; import tech.pegasys.teku.services.beaconchain.init.WSModule.WeakSubjectivityStoreChainValidator; import tech.pegasys.teku.spec.Spec; @@ -38,8 +38,7 @@ import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.storage.store.StoreConfig; import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; - -import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @Module public interface StorageModule { @@ -98,7 +97,9 @@ static SafeFuture recentChainDataFuture( VoteUpdateChannel voteUpdateChannel, FinalizedCheckpointChannel finalizedCheckpointChannel, ChainHeadChannel chainHeadChannel, - ValidatorIsConnectedProvider validatorIsConnectedProvider) { + ValidatorIsConnectedProvider validatorIsConnectedProvider, + // TODO is there a better option for this dependency ? + WeakSubjectivityFinalizedConfig __) { return StorageBackedRecentChainData.create( metricsSystem, From 34059a0f2c72efde3e7642ebb684502aca8c3013 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Mon, 24 Jun 2024 16:43:21 +0400 Subject: [PATCH 16/27] Add missing ValidatorApiChannel subscription --- .../teku/services/beaconchain/init/ChannelsModule.java | 8 ++++++++ .../services/beaconchain/init/ValidatorModule.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java index e9aa36a61ab..30e8936914b 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java @@ -3,6 +3,7 @@ import dagger.Module; import dagger.Provides; import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; +import tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig; import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; import tech.pegasys.teku.ethereum.events.SlotEventsChannel; import tech.pegasys.teku.ethereum.executionclient.ExecutionClientVersionChannel; @@ -168,4 +169,11 @@ static EventChannelSubscriber blockImportChannelSubscriber( EventChannels eventChannels) { return eventChannels.createSubscriber(BlockImportChannel.class); } + + @Provides + static EventChannelSubscriber validatorApiChannelSubscriber( + EventChannels eventChannels, BeaconRestApiConfig beaconRestApiConfig) { + return eventChannels.createSubscriberMultithreaded( + ValidatorApiChannel.class, beaconRestApiConfig.getValidatorThreads()); + } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index 744fecc2cd5..65b7dcaee06 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -53,6 +53,7 @@ import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.storage.client.ValidatorIsConnectedProvider; +import tech.pegasys.teku.validator.api.ValidatorApiChannel; import tech.pegasys.teku.validator.api.ValidatorConfig; import tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker; import tech.pegasys.teku.validator.coordinator.BlockFactory; @@ -190,8 +191,9 @@ static ValidatorApiHandler validatorApiHandler( SyncCommitteeMessagePool syncCommitteeMessagePool, SyncCommitteeContributionPool syncCommitteeContributionPool, SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager, - BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory) { - return new ValidatorApiHandler( + BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory, + EventChannelSubscriber validatorApiChannelSubscriber) { + ValidatorApiHandler validatorApiHandler = new ValidatorApiHandler( chainDataProvider, dataProvider.getNodeDataProvider(), combinedChainDataClient, @@ -214,6 +216,10 @@ static ValidatorApiHandler validatorApiHandler( syncCommitteeContributionPool, syncCommitteeSubscriptionManager, blockProductionPerformanceFactory); + + validatorApiChannelSubscriber.subscribe(validatorApiHandler); + + return validatorApiHandler; } @Provides From 6bd40ffd68386c6383bc401aafea0019be6bf5ba Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Tue, 25 Jun 2024 13:29:53 +0400 Subject: [PATCH 17/27] !!! TO ROLLBACK !!! Temp remove -Werror option --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6e6e73ab69c..19c7e9611c4 100644 --- a/build.gradle +++ b/build.gradle @@ -191,7 +191,7 @@ allprojects { '-Xlint:divzero', '-Xlint:finally', '-Xlint:static', - '-Werror', +// '-Werror', ] options.forkOptions.jvmArgs += [ '--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', From 8d491efe4fc2aa852edb3dad6fca9d8a6c2a143a Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 19:29:55 +0400 Subject: [PATCH 18/27] Fix compiler warnings --- .../pegasys/teku/services/beaconchain/init/BeaconModule.java | 1 - .../teku/services/beaconchain/init/DataProviderModule.java | 1 - .../teku/services/beaconchain/init/LoggingModule.java | 1 + .../pegasys/teku/services/beaconchain/init/MainModule.java | 5 +++++ .../pegasys/teku/services/beaconchain/init/SpecModule.java | 2 +- .../teku/services/beaconchain/init/StorageModule.java | 1 + 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java index d37beb2e7f4..a78c22e1ece 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -129,7 +129,6 @@ static BlockImporter blockImporter( @Provides @Singleton static BlockManager blockManager( - Spec spec, EventLogger eventLogger, TimeProvider timeProvider, RecentChainData recentChainData, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java index 1fa9728c4c2..15a42de6558 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java @@ -107,7 +107,6 @@ static Optional beaconRestApi( @Singleton static DataProvider dataProvider( Spec spec, - BeaconChainConfiguration beaconConfig, RecentChainData recentChainData, CombinedChainDataClient combinedChainDataClient, RewardCalculator rewardCalculator, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java index fa4846bcce6..cfa4e1a7ad3 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java @@ -13,6 +13,7 @@ @Module public interface LoggingModule { + @SuppressWarnings("PrivateStaticFinalLoggers") record InitLogger(Logger logger) {} @Provides diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index f3b3948aecb..6c2ad581f04 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -98,12 +98,14 @@ static VoidInitializer initGenesisHandler( @Provides @IntoSet + @SuppressWarnings("UnusedVariable") static VoidInitializer initOperationsReOrgManager(OperationsReOrgManager operationsReOrgManager) { return new VoidInitializer(); } @Provides @IntoSet + @SuppressWarnings("UnusedVariable") static VoidInitializer initValidatorIndexCacheTracker( ValidatorIndexCacheTracker validatorIndexCacheTracker) { return new VoidInitializer(); @@ -111,12 +113,14 @@ static VoidInitializer initValidatorIndexCacheTracker( @Provides @IntoSet + @SuppressWarnings("UnusedVariable") static VoidInitializer initRecentBlocksFetcher(RecentBlocksFetcher recentBlocksFetcher) { return new VoidInitializer(); } @Provides @IntoSet + @SuppressWarnings("UnusedVariable") static VoidInitializer initRecentBlobSidecarsFetcher( RecentBlobSidecarsFetcher recentBlobSidecarsFetcher) { return new VoidInitializer(); @@ -143,6 +147,7 @@ static VoidInitializer subscribeOnStoreInitialized( @Provides @Singleton + @SuppressWarnings("UnusedVariable") static ServiceStarter serviceStarter( Set allInitializers, Optional beaconRestApi, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index 381be9d9cb9..310c1fc84b0 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -20,7 +20,7 @@ interface CurrentSlotProvider { UInt64 getCurrentSlot(UInt64 genesisTime); - UInt64 getCurrentSlot(UInt64 genesisTime, UInt64 currentTime); + UInt64 getCurrentSlot(UInt64 currentTime, UInt64 genesisTime); } @FunctionalInterface diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index 1e246a479ae..bac96102470 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -85,6 +85,7 @@ static CombinedChainDataClient combinedChainDataClient( @Provides @Singleton + @SuppressWarnings("UnusedVariable") static SafeFuture recentChainDataFuture( @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, TimeProvider timeProvider, From 7277cc5a4fe52ad92fc24b23a91a59a10324acbe Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 19:31:08 +0400 Subject: [PATCH 19/27] Add stricter Dagger compiler options --- services/beaconchain/build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/beaconchain/build.gradle b/services/beaconchain/build.gradle index db629004ecd..f75ae47c03f 100644 --- a/services/beaconchain/build.gradle +++ b/services/beaconchain/build.gradle @@ -46,4 +46,12 @@ dependencies { testImplementation testFixtures(project(':infrastructure:metrics')) implementation 'io.libp2p:jvm-libp2p' +} + +tasks.withType(JavaCompile) { + options.compilerArgs += [ + '-Adagger.formatGeneratedSource=enabled', + '-Adagger.fullBindingGraphValidation=ERROR', + '-Adagger.ignoreProvisionKeyWildcards=ENABLED' + ] } \ No newline at end of file From 8c5ee393d4799151ebf1f0db3a07833452186271 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 19:31:30 +0400 Subject: [PATCH 20/27] Return back -Werror --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 19c7e9611c4..6e6e73ab69c 100644 --- a/build.gradle +++ b/build.gradle @@ -191,7 +191,7 @@ allprojects { '-Xlint:divzero', '-Xlint:finally', '-Xlint:static', -// '-Werror', + '-Werror', ] options.forkOptions.jvmArgs += [ '--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', From b7893a7497f55121283f3c685d4041dbe1a1d966 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 19:31:52 +0400 Subject: [PATCH 21/27] Enable errorprone disableWarningsInGeneratedCode --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6e6e73ab69c..56bea889623 100644 --- a/build.gradle +++ b/build.gradle @@ -201,7 +201,7 @@ allprojects { options.errorprone { enabled = !'true'.equalsIgnoreCase(System.getProperty('avt.disableErrorProne')) - disableWarningsInGeneratedCode + disableWarningsInGeneratedCode = true // Our equals need to be symmetric, this checker doesn't respect that check('EqualsGetClass', net.ltgt.gradle.errorprone.CheckSeverity.OFF) From f56974734ff9c7f1bb97d89f112d3a361a54efe2 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 19:49:46 +0400 Subject: [PATCH 22/27] Spotless --- .../events/EventChannelSubscriber.java | 13 +++ .../infrastructure/events/EventChannels.java | 6 +- .../AbstractBeaconChainController.java | 18 ++++- .../beaconchain/BeaconChainController.java | 9 +-- .../BeaconChainControllerFactory.java | 4 +- .../beaconchain/BeaconChainControllerOld.java | 5 +- .../beaconchain/init/AsyncRunnerModule.java | 18 ++++- .../init/BeaconChainControllerComponent.java | 18 ++++- .../beaconchain/init/BeaconConfigModule.java | 29 +++++-- .../beaconchain/init/BeaconModule.java | 27 ++++--- .../services/beaconchain/init/BlobModule.java | 22 ++++-- .../beaconchain/init/ChannelsModule.java | 15 +++- .../beaconchain/init/CryptoModule.java | 16 +++- .../beaconchain/init/DataProviderModule.java | 16 +++- .../init/ExternalDependenciesModule.java | 16 +++- .../beaconchain/init/ForkChoiceModule.java | 38 +++++---- .../beaconchain/init/LoggingModule.java | 16 +++- .../services/beaconchain/init/MainModule.java | 38 ++++----- .../beaconchain/init/MetricsModule.java | 31 +++++--- .../beaconchain/init/NetworkModule.java | 79 +++++++++++-------- .../beaconchain/init/PoolAndCachesModule.java | 30 ++++--- .../services/beaconchain/init/PowModule.java | 28 ++++--- .../init/RecentChainDataStateInitializer.java | 27 +++++-- .../beaconchain/init/ServiceConfigModule.java | 31 +++++--- .../services/beaconchain/init/SpecModule.java | 18 ++++- .../beaconchain/init/StorageModule.java | 21 +++-- .../beaconchain/init/SubnetsModule.java | 16 +++- .../services/beaconchain/init/SyncModule.java | 33 ++++++-- .../beaconchain/init/ValidatorModule.java | 62 +++++++++------ .../beaconchain/init/VerifyModule.java | 22 ++++-- .../services/beaconchain/init/WSModule.java | 27 +++++-- .../ExecutionLayerBlockManagerFactory.java | 3 +- .../teku/config/TekuConfigurationTest.java | 52 ++++++------ 33 files changed, 542 insertions(+), 262 deletions(-) diff --git a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java index 8e21d8c2d6c..8242c02def2 100644 --- a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java +++ b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannelSubscriber.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.infrastructure.events; public interface EventChannelSubscriber { diff --git a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java index 7d19e7cfec5..5306b9f6842 100644 --- a/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java +++ b/infrastructure/events/src/main/java/tech/pegasys/teku/infrastructure/events/EventChannels.java @@ -84,7 +84,8 @@ public EventChannels subscribe( return subscribeMultithreaded(channelInterface, subscriber, 1); } - public EventChannelSubscriber createSubscriber(final Class channelInterface) { + public EventChannelSubscriber createSubscriber( + final Class channelInterface) { return createSubscriberMultithreaded(channelInterface, 1); } @@ -103,7 +104,7 @@ public EventChannelSubscriber createSubscriber(f */ public EventChannels subscribeMultithreaded( final Class channelInterface, final T subscriber, final int requestedParallelism) { - createSubscriberMultithreaded(channelInterface,requestedParallelism).subscribe(subscriber); + createSubscriberMultithreaded(channelInterface, requestedParallelism).subscribe(subscriber); return this; } @@ -113,7 +114,6 @@ public EventChannelSubscriber createSubscriberMu getChannel(channelInterface).subscribeMultithreaded(listener, requestedParallelism); } - @SuppressWarnings("unchecked") private EventChannel getChannel(final Class channelInterface) { return (EventChannel) channels.computeIfAbsent(channelInterface, eventChannelFactory); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java index 45cc5f8d670..bc390f03cc6 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java @@ -1,7 +1,19 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain; import tech.pegasys.teku.service.serviceutils.Service; -public abstract class AbstractBeaconChainController extends Service implements BeaconChainControllerFacade { - -} +public abstract class AbstractBeaconChainController extends Service + implements BeaconChainControllerFacade {} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index c76c7e5382a..01df2ea98d9 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -13,7 +13,6 @@ package tech.pegasys.teku.services.beaconchain; - import java.util.Optional; import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; @@ -24,7 +23,6 @@ import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; -import tech.pegasys.teku.service.serviceutils.Service; import tech.pegasys.teku.service.serviceutils.ServiceConfig; import tech.pegasys.teku.services.beaconchain.init.BeaconChainControllerComponent; import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; @@ -71,9 +69,10 @@ public BeaconChainController(ServiceConfig serviceConfig, BeaconChainConfigurati @Override protected SafeFuture doStart() { LOG.info("Starting BeaconChainController..."); - BeaconChainControllerComponent component = DaggerBeaconChainControllerComponent.builder() - .externalDependenciesModule(new ExternalDependenciesModule(serviceConfig, beaconConfig)) - .build(); + BeaconChainControllerComponent component = + DaggerBeaconChainControllerComponent.builder() + .externalDependenciesModule(new ExternalDependenciesModule(serviceConfig, beaconConfig)) + .build(); this.spec = component.getSpec(); this.timeProvider = component.getTimeProvider(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java index 6898df86d08..e2b137f159d 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java @@ -14,8 +14,6 @@ package tech.pegasys.teku.services.beaconchain; import tech.pegasys.teku.service.serviceutils.ServiceConfig; -import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; -import tech.pegasys.teku.services.beaconchain.init.ExternalDependenciesModule; /** * CAUTION: this API is unstable and primarily intended for debugging and testing purposes this API @@ -24,7 +22,7 @@ public interface BeaconChainControllerFactory { BeaconChainControllerFactory DEFAULT = -// BeaconChainControllerOld::new; + // BeaconChainControllerOld::new; BeaconChainController::new; AbstractBeaconChainController create( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java index 12a69bce715..c4d62a802d1 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java @@ -87,7 +87,6 @@ import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; import tech.pegasys.teku.networks.StateBoostrapConfig; -import tech.pegasys.teku.service.serviceutils.Service; import tech.pegasys.teku.service.serviceutils.ServiceConfig; import tech.pegasys.teku.services.executionlayer.ExecutionLayerBlockManagerFactory; import tech.pegasys.teku.services.timer.TimerService; @@ -463,9 +462,7 @@ protected SafeFuture initialize() { recentChainData.subscribeStoreInitialized(this::onStoreInitialized); recentChainData.subscribeBestBlockInitialized(this::startServices); }) - .thenCompose(__ -> - timerService.start() - ); + .thenCompose(__ -> timerService.start()); } private boolean isUsingCustomInitialState() { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java index 40d52e47816..75fe70213fe 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java @@ -1,15 +1,27 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import javax.inject.Qualifier; +import javax.inject.Singleton; import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; -import javax.inject.Qualifier; -import javax.inject.Singleton; - @Module public interface AsyncRunnerModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java index 80bd206ad90..99ef1ac0e47 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java @@ -1,22 +1,32 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Component; +import java.util.Optional; import javax.inject.Singleton; - import tech.pegasys.teku.beacon.sync.SyncService; import tech.pegasys.teku.beaconrestapi.BeaconRestApi; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; -import tech.pegasys.teku.services.beaconchain.BeaconChainController; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; -import java.util.Optional; - @Singleton @Component( modules = { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java index dff03633f25..9c126aae934 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; @@ -18,42 +31,42 @@ public interface BeaconConfigModule { @Provides - static Spec spec(BeaconChainConfiguration config){ + static Spec spec(BeaconChainConfiguration config) { return config.getSpec(); } @Provides - static Eth2NetworkConfiguration eth2NetworkConfig(BeaconChainConfiguration config){ + static Eth2NetworkConfiguration eth2NetworkConfig(BeaconChainConfiguration config) { return config.eth2NetworkConfig(); } @Provides - static StoreConfig storeConfig(BeaconChainConfiguration config){ + static StoreConfig storeConfig(BeaconChainConfiguration config) { return config.storeConfig(); } @Provides - static PowchainConfiguration powchainConfig(BeaconChainConfiguration config){ + static PowchainConfiguration powchainConfig(BeaconChainConfiguration config) { return config.powchainConfig(); } @Provides - static P2PConfig p2pConfig(BeaconChainConfiguration config){ + static P2PConfig p2pConfig(BeaconChainConfiguration config) { return config.p2pConfig(); } @Provides - static ValidatorConfig validatorConfig(BeaconChainConfiguration config){ + static ValidatorConfig validatorConfig(BeaconChainConfiguration config) { return config.validatorConfig(); } @Provides - static SyncConfig syncConfig(BeaconChainConfiguration config){ + static SyncConfig syncConfig(BeaconChainConfiguration config) { return config.syncConfig(); } @Provides - static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config){ + static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config) { return config.beaconRestApiConfig(); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java index a78c22e1ece..74adc84a43d 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -1,7 +1,25 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; +import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds; + import dagger.Module; import dagger.Provides; +import java.util.Map; +import java.util.Optional; +import javax.inject.Singleton; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.beacon.sync.SyncService; @@ -24,7 +42,6 @@ import tech.pegasys.teku.services.beaconchain.init.PowModule.ProposerDefaultFeeRecipient; import tech.pegasys.teku.services.timer.TimerService; import tech.pegasys.teku.spec.Spec; -import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; @@ -42,7 +59,6 @@ import tech.pegasys.teku.statetransition.block.BlockImportMetrics; import tech.pegasys.teku.statetransition.block.BlockImporter; import tech.pegasys.teku.statetransition.block.BlockManager; -import tech.pegasys.teku.statetransition.block.FailedExecutionPool; import tech.pegasys.teku.statetransition.block.ReceivedBlockEventsChannel; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier; @@ -57,13 +73,6 @@ import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; -import javax.inject.Singleton; -import java.util.Map; -import java.util.Optional; - -import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; -import static tech.pegasys.teku.infrastructure.time.TimeUtilities.millisToSeconds; - @Module public interface BeaconModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java index 4331295e601..ffda44f5e30 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; @@ -35,15 +48,13 @@ static BlobSidecarGossipValidator blobSidecarGossipValidator( Spec spec, KZG kzg, @InvalidBlockRoots Map invalidBlockRoots, - GossipValidationHelper gossipValidationHelper - ) { + GossipValidationHelper gossipValidationHelper) { final MiscHelpersDeneb miscHelpers = MiscHelpersDeneb.required(spec.forMilestone(SpecMilestone.DENEB).miscHelpers()); return BlobSidecarGossipValidator.create( spec, invalidBlockRoots, gossipValidationHelper, miscHelpers, kzg); } - - + @Provides @Singleton static BlobSidecarManager blobSidecarManager( @@ -55,8 +66,7 @@ static BlobSidecarManager blobSidecarManager( BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, BlobSidecarGossipValidator blobSidecarGossipValidator, @InvalidBlobSidecarRoots Map invalidBlobSidecarRoots, - FutureItems futureBlobSidecars - ) { + FutureItems futureBlobSidecars) { if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { final BlobSidecarManagerImpl blobSidecarManagerImpl = new BlobSidecarManagerImpl( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java index 30e8936914b..d942f188d34 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java @@ -1,8 +1,20 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; -import tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel; import tech.pegasys.teku.beaconrestapi.BeaconRestApiConfig; import tech.pegasys.teku.ethereum.events.ExecutionClientEventsChannel; import tech.pegasys.teku.ethereum.events.SlotEventsChannel; @@ -11,7 +23,6 @@ import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; import tech.pegasys.teku.infrastructure.events.EventChannels; -import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipChannel; import tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.BeaconAsyncRunner; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java index a96f9ec79e0..6df42134fd2 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java @@ -1,7 +1,21 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import javax.inject.Singleton; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.infrastructure.async.AsyncRunner; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; @@ -15,8 +29,6 @@ import tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; -import javax.inject.Singleton; - @Module public interface CryptoModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java index 15a42de6558..08c913721c6 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; @@ -153,8 +166,7 @@ static DataProvider dataProvider( } @Provides - static LivenessTrackingStatus livenessTrackingStatus( - BeaconChainConfiguration beaconConfig) { + static LivenessTrackingStatus livenessTrackingStatus(BeaconChainConfiguration beaconConfig) { return new LivenessTrackingStatus( beaconConfig.beaconRestApiConfig().isBeaconLivenessTrackingEnabled() || beaconConfig.validatorConfig().isDoppelgangerDetectionEnabled()); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java index d50e854eaf0..58cbaece0e9 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; @@ -11,7 +24,8 @@ public class ExternalDependenciesModule { private final ServiceConfig serviceConfig; private final BeaconChainConfiguration beaconConfig; - public ExternalDependenciesModule(ServiceConfig serviceConfig, BeaconChainConfiguration beaconConfig) { + public ExternalDependenciesModule( + ServiceConfig serviceConfig, BeaconChainConfiguration beaconConfig) { this.serviceConfig = serviceConfig; this.beaconConfig = beaconConfig; } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java index 746c32735dd..69a417bf694 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java @@ -1,17 +1,27 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import javax.inject.Singleton; import org.hyperledger.besu.plugin.services.MetricsSystem; -import tech.pegasys.teku.ethereum.events.SlotEventsChannel; -import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; -import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; -import tech.pegasys.teku.services.beaconchain.init.PowModule.ProposerDefaultFeeRecipient; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; @@ -26,9 +36,6 @@ import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; import tech.pegasys.teku.storage.client.RecentChainData; -import javax.inject.Singleton; -import java.util.Optional; - @Module public interface ForkChoiceModule { @@ -85,14 +92,13 @@ static ForkChoiceNotifier forkChoiceNotifier( RecentChainData recentChainData, ForkChoiceStateProvider forkChoiceStateProvider) { - return - new ForkChoiceNotifierImpl( - forkChoiceStateProvider, - forkChoiceNotifierExecutor, - timeProvider, - spec, - executionLayer, - recentChainData, - proposersDataManager); + return new ForkChoiceNotifierImpl( + forkChoiceStateProvider, + forkChoiceNotifierExecutor, + timeProvider, + spec, + executionLayer, + recentChainData, + proposersDataManager); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java index cfa4e1a7ad3..7b7a746663f 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java @@ -1,15 +1,27 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import javax.inject.Singleton; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.infrastructure.logging.StatusLogger; import tech.pegasys.teku.services.beaconchain.BeaconChainController; -import javax.inject.Singleton; - @Module public interface LoggingModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index 6c2ad581f04..9ff9e6aa583 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -1,22 +1,33 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Lazy; import dagger.Module; import dagger.Provides; -import javax.inject.Singleton; - import dagger.multibindings.IntoSet; +import java.util.Optional; +import java.util.Set; +import javax.inject.Singleton; import tech.pegasys.teku.beacon.sync.SyncService; import tech.pegasys.teku.beacon.sync.gossip.blobs.RecentBlobSidecarsFetcher; import tech.pegasys.teku.beacon.sync.gossip.blocks.RecentBlocksFetcher; import tech.pegasys.teku.beaconrestapi.BeaconRestApi; -import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; import tech.pegasys.teku.infrastructure.logging.StatusLogger; -import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; -import tech.pegasys.teku.services.beaconchain.BeaconChainController; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; import tech.pegasys.teku.services.beaconchain.init.LoggingModule.InitLogger; @@ -31,20 +42,13 @@ import tech.pegasys.teku.statetransition.attestation.AttestationManager; import tech.pegasys.teku.statetransition.block.BlockManager; import tech.pegasys.teku.statetransition.block.FailedExecutionPool; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor; import tech.pegasys.teku.statetransition.genesis.GenesisHandler; -import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; -import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; import tech.pegasys.teku.validator.api.ValidatorConfig; import tech.pegasys.teku.validator.api.ValidatorTimingChannel; import tech.pegasys.teku.validator.coordinator.ValidatorIndexCacheTracker; -import java.util.Optional; -import java.util.Set; -import java.util.function.Supplier; - @Module public interface MainModule { @@ -139,7 +143,8 @@ static VoidInitializer subscribeFailedPayloadExecution( @Provides @IntoSet static VoidInitializer subscribeOnStoreInitialized( - RecentChainData recentChainData, StorageModule.OnStoreInitializedHandler onStoreInitializedHandler) { + RecentChainData recentChainData, + StorageModule.OnStoreInitializedHandler onStoreInitializedHandler) { recentChainData.subscribeStoreInitialized(onStoreInitializedHandler::handle); return new VoidInitializer(); @@ -159,8 +164,7 @@ static ServiceStarter serviceStarter( Optional terminalPowBlockMonitor, InitLogger initLogger) { return () -> - SafeFuture.fromRunnable( - () -> initLogger.logger().info("Starting BeaconChain services")) + SafeFuture.fromRunnable(() -> initLogger.logger().info("Starting BeaconChain services")) .thenCompose( __ -> SafeFuture.allOf( @@ -178,9 +182,7 @@ static ServiceStarter serviceStarter( .map(BeaconRestApi::start) .orElse(SafeFuture.completedFuture(null)) .thenApply(___ -> null)) - .thenRun( - () -> initLogger.logger().info("BeaconChain services started") - ); + .thenRun(() -> initLogger.logger().info("BeaconChain services started")); } @Provides diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java index 41be0ffaa6f..e338fbea957 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java @@ -1,7 +1,26 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; +import static tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory.BEACON; +import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; + import dagger.Module; import dagger.Provides; +import java.util.Optional; +import javax.inject.Qualifier; +import javax.inject.Singleton; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.ethereum.events.SlotEventsChannel; import tech.pegasys.teku.ethereum.performance.trackers.BlockProductionAndPublishingPerformanceFactory; @@ -38,15 +57,6 @@ import tech.pegasys.teku.validator.coordinator.performance.SyncCommitteePerformanceTracker; import tech.pegasys.teku.validator.coordinator.performance.ValidatorPerformanceMetrics; -import javax.inject.Qualifier; -import javax.inject.Singleton; - -import java.util.Optional; - -import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; -import static tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory.BEACON; -import static tech.pegasys.teku.infrastructure.time.TimeUtilities.secondsToMillis; - @Module public interface MetricsModule { @@ -108,8 +118,7 @@ static FutureItems futureBlobSidecars( @Provides @Singleton - static ValidatorPerformanceMetrics validatorPerformanceMetrics( - MetricsSystem metricsSystem) { + static ValidatorPerformanceMetrics validatorPerformanceMetrics(MetricsSystem metricsSystem) { return new ValidatorPerformanceMetrics(metricsSystem); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java index b49fecfd405..3017278b16d 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java @@ -1,7 +1,22 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import java.util.Optional; +import javax.inject.Singleton; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.infrastructure.async.AsyncRunner; @@ -34,9 +49,6 @@ import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; -import javax.inject.Singleton; -import java.util.Optional; - @Module public interface NetworkModule { @@ -68,8 +80,7 @@ static Eth2P2PNetwork eth2P2PNetwork( OperationPool blsToExecutionChangePool, KZG kzg, WeakSubjectivityValidator weakSubjectivityValidator, - P2PDebugDataDumper p2pDebugDataDumper - ) { + P2PDebugDataDumper p2pDebugDataDumper) { if (!p2pConfig.getNetworkConfig().isEnabled()) { return new NoOpEth2P2PNetwork(spec); } @@ -84,32 +95,33 @@ static Eth2P2PNetwork eth2P2PNetwork( p2pConfig.getNetworkConfig().getListenPort(), maybeUdpPort); // TODO adopt Dagger instead of eth2P2PNetworkBuilder() - Eth2P2PNetwork p2pNetwork = eth2P2PNetworkBuilder - .config(p2pConfig) - .eventChannels(eventChannels) - .combinedChainDataClient(combinedChainDataClient) - .gossipedBlockProcessor(blockManager::validateAndImportBlock) - .gossipedBlobSidecarProcessor(blobSidecarManager::validateAndPrepareForBlockImport) - .gossipedAttestationProcessor(attestationManager::addAttestation) - .gossipedAggregateProcessor(attestationManager::addAggregate) - .gossipedAttesterSlashingProcessor(attesterSlashingPool::addRemote) - .gossipedProposerSlashingProcessor(proposerSlashingPool::addRemote) - .gossipedVoluntaryExitProcessor(voluntaryExitPool::addRemote) - .gossipedSignedContributionAndProofProcessor(syncCommitteeContributionPool::addRemote) - .gossipedSyncCommitteeMessageProcessor(syncCommitteeMessagePool::addRemote) - .gossipedSignedBlsToExecutionChangeProcessor(blsToExecutionChangePool::addRemote) - .processedAttestationSubscriptionProvider( - attestationManager::subscribeToAttestationsToSend) - .metricsSystem(metricsSystem) - .timeProvider(timeProvider) - .asyncRunner(networkAsyncRunner) - .keyValueStore(keyValueStore) - .requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()) - .specProvider(spec) - .kzg(kzg) - .recordMessageArrival(true) - .p2pDebugDataDumper(p2pDebugDataDumper) - .build(); + Eth2P2PNetwork p2pNetwork = + eth2P2PNetworkBuilder + .config(p2pConfig) + .eventChannels(eventChannels) + .combinedChainDataClient(combinedChainDataClient) + .gossipedBlockProcessor(blockManager::validateAndImportBlock) + .gossipedBlobSidecarProcessor(blobSidecarManager::validateAndPrepareForBlockImport) + .gossipedAttestationProcessor(attestationManager::addAttestation) + .gossipedAggregateProcessor(attestationManager::addAggregate) + .gossipedAttesterSlashingProcessor(attesterSlashingPool::addRemote) + .gossipedProposerSlashingProcessor(proposerSlashingPool::addRemote) + .gossipedVoluntaryExitProcessor(voluntaryExitPool::addRemote) + .gossipedSignedContributionAndProofProcessor(syncCommitteeContributionPool::addRemote) + .gossipedSyncCommitteeMessageProcessor(syncCommitteeMessagePool::addRemote) + .gossipedSignedBlsToExecutionChangeProcessor(blsToExecutionChangePool::addRemote) + .processedAttestationSubscriptionProvider( + attestationManager::subscribeToAttestationsToSend) + .metricsSystem(metricsSystem) + .timeProvider(timeProvider) + .asyncRunner(networkAsyncRunner) + .keyValueStore(keyValueStore) + .requiredCheckpoint(weakSubjectivityValidator.getWSCheckpoint()) + .specProvider(spec) + .kzg(kzg) + .recordMessageArrival(true) + .p2pDebugDataDumper(p2pDebugDataDumper) + .build(); syncCommitteeMessagePool.subscribeOperationAdded( new LocalOperationAcceptedFilter<>(p2pNetwork::publishSyncCommitteeMessage)); @@ -129,10 +141,7 @@ static Eth2P2PNetwork eth2P2PNetwork( @Provides @Singleton - static P2PDebugDataDumper p2pDebugDataDumper( - P2PConfig p2pConfig, - DataDirLayout dataDirLayout - ) { + static P2PDebugDataDumper p2pDebugDataDumper(P2PConfig p2pConfig, DataDirLayout dataDirLayout) { return p2pConfig.isP2pDumpsToFileEnabled() ? new P2PDebugDataFileDumper(dataDirLayout.getDebugDataDirectory()) : P2PDebugDataDumper.NOOP; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java index 702dce541fe..ec9fec5627c 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java @@ -1,7 +1,27 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; +import static tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool.DEFAULT_MAXIMUM_ATTESTATION_COUNT; + import dagger.Module; import dagger.Provides; +import java.util.Comparator; +import java.util.Map; +import java.util.Optional; +import javax.inject.Qualifier; +import javax.inject.Singleton; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.ethereum.events.SlotEventsChannel; @@ -22,7 +42,6 @@ import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; -import tech.pegasys.teku.spec.datastructures.operations.VoluntaryExit; import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult; import tech.pegasys.teku.statetransition.MappedOperationPool; import tech.pegasys.teku.statetransition.OperationPool; @@ -38,7 +57,6 @@ import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator; -import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils; import tech.pegasys.teku.statetransition.util.BlockBlobSidecarsTrackersPoolImpl; import tech.pegasys.teku.statetransition.util.PendingPool; import tech.pegasys.teku.statetransition.util.PoolFactory; @@ -50,14 +68,6 @@ import tech.pegasys.teku.storage.api.FinalizedCheckpointChannel; import tech.pegasys.teku.storage.client.RecentChainData; -import javax.inject.Qualifier; -import javax.inject.Singleton; -import java.util.Comparator; -import java.util.Map; -import java.util.Optional; - -import static tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool.DEFAULT_MAXIMUM_ATTESTATION_COUNT; - @Module public interface PoolAndCachesModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java index b94f4b14d28..7204377b8e0 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; @@ -32,15 +45,11 @@ import tech.pegasys.teku.validator.coordinator.Eth1DataCache; import tech.pegasys.teku.validator.coordinator.Eth1VotingPeriod; -import static tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG; - @Module public interface PowModule { @Qualifier - @interface ProposerDefaultFeeRecipient{ - -} + @interface ProposerDefaultFeeRecipient {} @Provides @Singleton @@ -86,8 +95,7 @@ static DepositProvider depositProvider( EventChannelSubscriber eth1EventsChannelSubscriber, EventChannelSubscriber finalizedCheckpointChannelSubscriber, EventChannelSubscriber slotEventsChannelSubscriber, - EventLogger eventLogger - ) { + EventLogger eventLogger) { DepositProvider depositProvider = new DepositProvider( metricsSystem, @@ -112,8 +120,7 @@ static Optional proposerDefaultFeeRecipient( Spec spec, ValidatorConfig validatorConfig, BeaconRestApiConfig restApiConfig, - StatusLogger statusLogger - ) { + StatusLogger statusLogger) { if (!spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { return Optional.of(Eth1Address.ZERO); } @@ -134,8 +141,7 @@ static GenesisHandler genesisHandler( TimeProvider timeProvider, Spec spec, RecentChainData recentChainData, - EventChannelSubscriber eth1EventsChannelSubscriber - ) { + EventChannelSubscriber eth1EventsChannelSubscriber) { GenesisHandler genesisHandler = new GenesisHandler(recentChainData, timeProvider, spec); eth1EventsChannelSubscriber.subscribe(genesisHandler); return genesisHandler; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java index 5a31724d367..e9d7caef4fc 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java @@ -1,6 +1,24 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; +import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; + import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.Optional; +import javax.inject.Inject; import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException; import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.infrastructure.logging.StatusLogger; @@ -19,12 +37,6 @@ import tech.pegasys.teku.validator.api.InteropConfig; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityCalculator; -import javax.inject.Inject; -import java.io.IOException; -import java.util.Optional; - -import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; - public class RecentChainDataStateInitializer { @Inject TimeProvider timeProvider; @@ -36,8 +48,7 @@ public class RecentChainDataStateInitializer { @Inject StatusLogger statusLogger; @Inject - public RecentChainDataStateInitializer() { - } + public RecentChainDataStateInitializer() {} public void setupInitialState(RecentChainData recentChainData) { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java index f30f895c734..de090799920 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java @@ -1,7 +1,23 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import java.util.function.IntSupplier; +import javax.inject.Qualifier; +import javax.inject.Singleton; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.events.EventChannels; @@ -9,10 +25,6 @@ import tech.pegasys.teku.service.serviceutils.ServiceConfig; import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; -import javax.inject.Qualifier; -import javax.inject.Singleton; -import java.util.function.IntSupplier; - @Module public interface ServiceConfigModule { @@ -20,27 +32,27 @@ public interface ServiceConfigModule { @interface RejectedExecutionCountSupplier {} @Provides - static DataDirLayout dataDirLayout(ServiceConfig config){ + static DataDirLayout dataDirLayout(ServiceConfig config) { return config.getDataDirLayout(); } @Provides - static AsyncRunnerFactory asyncRunnerFactory(ServiceConfig config){ + static AsyncRunnerFactory asyncRunnerFactory(ServiceConfig config) { return config.getAsyncRunnerFactory(); } @Provides - static TimeProvider timeProvider(ServiceConfig config){ + static TimeProvider timeProvider(ServiceConfig config) { return config.getTimeProvider(); } @Provides - static EventChannels eventChannels(ServiceConfig config){ + static EventChannels eventChannels(ServiceConfig config) { return config.getEventChannels(); } @Provides - static MetricsSystem metricsSystem(ServiceConfig config){ + static MetricsSystem metricsSystem(ServiceConfig config) { return config.getMetricsSystem(); } @@ -50,5 +62,4 @@ static MetricsSystem metricsSystem(ServiceConfig config){ static IntSupplier rejectedExecutionCountSupplier(ServiceConfig config) { return config.getRejectedExecutionsSupplier(); } - } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index 310c1fc84b0..cc1ae75b51d 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -1,7 +1,22 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import java.util.function.Function; +import javax.inject.Singleton; import tech.pegasys.teku.api.RewardCalculator; import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema; import tech.pegasys.teku.infrastructure.time.TimeProvider; @@ -10,9 +25,6 @@ import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; import tech.pegasys.teku.spec.logic.common.util.BlockRewardCalculatorUtil; -import javax.inject.Singleton; -import java.util.function.Function; - @Module public interface SpecModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index bac96102470..2da1529a624 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Binds; @@ -38,7 +51,6 @@ import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.storage.store.StoreConfig; import tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker; -import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @Module public interface StorageModule { @@ -65,9 +77,7 @@ static KeyValueStore keyValueStore(DataDirLayout dataDirLayout) { @Provides @Singleton static EarliestAvailableBlockSlot earliestAvailableBlockSlot( - StoreConfig storeConfig, - TimeProvider timeProvider, - StorageQueryChannel storageQueryChannel) { + StoreConfig storeConfig, TimeProvider timeProvider, StorageQueryChannel storageQueryChannel) { return new EarliestAvailableBlockSlot( storageQueryChannel, timeProvider, storeConfig.getEarliestAvailableBlockSlotFrequency()); } @@ -163,8 +173,7 @@ static OnStoreInitializedHandler onStoreInitializedHandler( Lazy weakSubjectivityStoreChainValidator, Lazy genesisTimeTracker, SlotProcessor slotProcessor, - PerformanceTracker performanceTracker - ) { + PerformanceTracker performanceTracker) { return () -> { UInt64 genesisTime = recentChainData.getGenesisTime(); UInt64 currentTime = timeProvider.getTimeInSeconds(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java index 4fe81b7ebc4..c93319b0397 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java @@ -1,7 +1,21 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import javax.inject.Singleton; import tech.pegasys.teku.ethereum.events.SlotEventsChannel; import tech.pegasys.teku.infrastructure.events.EventChannelSubscriber; import tech.pegasys.teku.infrastructure.metrics.SettableLabelledGauge; @@ -15,8 +29,6 @@ import tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager; import tech.pegasys.teku.spec.Spec; -import javax.inject.Singleton; - @Module public interface SubnetsModule { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java index e1273749dbd..26a0219ce84 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java @@ -1,3 +1,16 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; @@ -141,9 +154,16 @@ static RecentBlocksFetcher recentBlocksFetcher( (block) -> blockManager .importBlock( - block, BroadcastValidationLevel.NOT_REQUIRED, Optional.of(BlobSidecarManager.RemoteOrigin.RPC)) - .thenCompose(BlockImportChannel.BlockImportAndBroadcastValidationResults::blockImportResult) - .finish(err -> initLogger.logger().error("Failed to process recently fetched block.", err))); + block, + BroadcastValidationLevel.NOT_REQUIRED, + Optional.of(BlobSidecarManager.RemoteOrigin.RPC)) + .thenCompose( + BlockImportChannel.BlockImportAndBroadcastValidationResults::blockImportResult) + .finish( + err -> + initLogger + .logger() + .error("Failed to process recently fetched block.", err))); receivedBlockEventsChannelSubscriber.subscribe(recentBlocksFetcher); return recentBlocksFetcher; } @@ -151,12 +171,13 @@ static RecentBlocksFetcher recentBlocksFetcher( @Provides @Singleton static RecentBlobSidecarsFetcher recentBlobSidecarsFetcher( - SyncService syncService, - BlobSidecarManager blobSidecarManager) { + SyncService syncService, BlobSidecarManager blobSidecarManager) { final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher = syncService.getRecentBlobSidecarsFetcher(); recentBlobSidecarsFetcher.subscribeBlobSidecarFetched( - (blobSidecar) -> blobSidecarManager.prepareForBlockImport(blobSidecar, BlobSidecarManager.RemoteOrigin.RPC)); + (blobSidecar) -> + blobSidecarManager.prepareForBlockImport( + blobSidecar, BlobSidecarManager.RemoteOrigin.RPC)); blobSidecarManager.subscribeToReceivedBlobSidecar( blobSidecar -> recentBlobSidecarsFetcher.cancelRecentBlobSidecarRequest( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index 65b7dcaee06..fee3073b4b4 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -1,11 +1,22 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Lazy; import dagger.Module; import dagger.Provides; import javax.inject.Singleton; - -import dagger.multibindings.IntoSet; import tech.pegasys.teku.api.ChainDataProvider; import tech.pegasys.teku.api.DataProvider; import tech.pegasys.teku.api.RewardCalculator; @@ -193,29 +204,30 @@ static ValidatorApiHandler validatorApiHandler( SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager, BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory, EventChannelSubscriber validatorApiChannelSubscriber) { - ValidatorApiHandler validatorApiHandler = new ValidatorApiHandler( - chainDataProvider, - dataProvider.getNodeDataProvider(), - combinedChainDataClient, - syncService, - blockFactory, - blockImportChannel, - blockGossipChannel, - blockBlobSidecarsTrackersPool, - blobSidecarGossipChannel, - attestationPool, - attestationManager, - attestationTopicSubscriber, - activeValidatorTracker, - dutyMetrics, - performanceTracker, - spec, - forkChoiceTrigger, - proposersDataManager, - syncCommitteeMessagePool, - syncCommitteeContributionPool, - syncCommitteeSubscriptionManager, - blockProductionPerformanceFactory); + ValidatorApiHandler validatorApiHandler = + new ValidatorApiHandler( + chainDataProvider, + dataProvider.getNodeDataProvider(), + combinedChainDataClient, + syncService, + blockFactory, + blockImportChannel, + blockGossipChannel, + blockBlobSidecarsTrackersPool, + blobSidecarGossipChannel, + attestationPool, + attestationManager, + attestationTopicSubscriber, + activeValidatorTracker, + dutyMetrics, + performanceTracker, + spec, + forkChoiceTrigger, + proposersDataManager, + syncCommitteeMessagePool, + syncCommitteeContributionPool, + syncCommitteeSubscriptionManager, + blockProductionPerformanceFactory); validatorApiChannelSubscriber.subscribe(validatorApiHandler); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java index c2a0073d73e..f534522ebce 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java @@ -1,7 +1,21 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; import dagger.Module; import dagger.Provides; +import javax.inject.Singleton; import org.hyperledger.besu.plugin.services.MetricsSystem; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.spec.Spec; @@ -23,14 +37,11 @@ import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; import tech.pegasys.teku.storage.client.RecentChainData; -import javax.inject.Singleton; - @Module public interface VerifyModule { @Provides @Singleton - static GossipValidationHelper gossipValidationHelper( - Spec spec, RecentChainData recentChainData) { + static GossipValidationHelper gossipValidationHelper(Spec spec, RecentChainData recentChainData) { return new GossipValidationHelper(spec, recentChainData); } @@ -50,8 +61,7 @@ static ProposerSlashingValidator proposerSlashingValidator( @Provides @Singleton - static VoluntaryExitValidator voluntaryExitValidator( - Spec spec, RecentChainData recentChainData) { + static VoluntaryExitValidator voluntaryExitValidator(Spec spec, RecentChainData recentChainData) { return new VoluntaryExitValidator(spec, recentChainData); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java index 72f4077e56c..262d143187c 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java @@ -1,11 +1,25 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package tech.pegasys.teku.services.beaconchain.init; +import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; + import dagger.Module; import dagger.Provides; +import javax.inject.Singleton; import tech.pegasys.teku.infrastructure.async.SafeFuture; -import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.networks.Eth2NetworkConfiguration; import tech.pegasys.teku.services.beaconchain.WeakSubjectivityInitializer; import tech.pegasys.teku.services.beaconchain.init.SpecModule.CurrentSlotProvider; import tech.pegasys.teku.spec.Spec; @@ -18,10 +32,6 @@ import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; import tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig; -import javax.inject.Singleton; - -import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; - @Module public interface WSModule { @@ -48,8 +58,9 @@ static SafeFuture weakSubjectivityFinalizedConf WeakSubjectivityConfig weakSubjectivityConfig, StorageQueryChannel storageQueryChannel, StorageUpdateChannel storageUpdateChannel) { - SafeFuture finalizedConfig = weakSubjectivityInitializer.finalizeAndStoreConfig( - weakSubjectivityConfig, storageQueryChannel, storageUpdateChannel); + SafeFuture finalizedConfig = + weakSubjectivityInitializer.finalizeAndStoreConfig( + weakSubjectivityConfig, storageQueryChannel, storageUpdateChannel); return finalizedConfig.thenApply(WeakSubjectivityFinalizedConfig::new); } diff --git a/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java b/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java index 59feb9e8027..7f110f854d8 100644 --- a/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java +++ b/services/executionlayer/src/main/java/tech/pegasys/teku/services/executionlayer/ExecutionLayerBlockManagerFactory.java @@ -21,7 +21,8 @@ public class ExecutionLayerBlockManagerFactory { public static ExecutionLayerBlockProductionManager create( - final ExecutionLayerChannel executionLayerManager, final EventChannelSubscriber slotEventsChannelSubscriber) { + final ExecutionLayerChannel executionLayerManager, + final EventChannelSubscriber slotEventsChannelSubscriber) { final ExecutionLayerBlockProductionManagerImpl executionLayerBlockProductionManager = new ExecutionLayerBlockProductionManagerImpl(executionLayerManager); slotEventsChannelSubscriber.subscribe(executionLayerBlockProductionManager); diff --git a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java index e94b4dca0d0..2e9d539fa21 100644 --- a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java +++ b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java @@ -13,14 +13,10 @@ package tech.pegasys.teku.config; -import static org.assertj.core.api.Assertions.assertThat; - import java.nio.file.Path; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import tech.pegasys.teku.BeaconNodeFacade; -import tech.pegasys.teku.TekuFacade; import tech.pegasys.teku.cli.TempDirUtils; import tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder; import tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetwork; @@ -30,8 +26,6 @@ import tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder; import tech.pegasys.teku.networking.p2p.network.P2PNetwork; import tech.pegasys.teku.networking.p2p.peer.Peer; -import tech.pegasys.teku.services.beaconchain.BeaconChainController; -import tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory; public class TekuConfigurationTest { @@ -93,28 +87,28 @@ protected LibP2PNetworkBuilder createLibP2PNetworkBuilder() { } }; -// BeaconChainControllerFactory customControllerFactory = -// (serviceConfig, beaconConfig) -> -// new BeaconChainController(serviceConfig, beaconConfig) { -// @Override -// protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { -// return customEth2P2PNetworkBuilder; -// } -// }; -// -// TekuConfiguration tekuConfiguration = -// TekuConfiguration.builder() -// .data(b -> b.dataBasePath(tempDir)) -// .executionLayer(b -> b.engineEndpoint("unsafe-test-stub")) -// .eth2NetworkConfig(b -> b.ignoreWeakSubjectivityPeriodEnabled(true)) -// .beaconChainControllerFactory(customControllerFactory) -// .build(); -// -// try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) { -// assertThat(beaconNode).isNotNull(); -// assertThat(customDiscoveryBuilderMethodCalled).isTrue(); -// assertThat(customLibP2PBuilderMethodCalled).isTrue(); -// assertThat(customGossipNetworkBuilderCalled).isTrue(); -// } + // BeaconChainControllerFactory customControllerFactory = + // (serviceConfig, beaconConfig) -> + // new BeaconChainController(serviceConfig, beaconConfig) { + // @Override + // protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { + // return customEth2P2PNetworkBuilder; + // } + // }; + // + // TekuConfiguration tekuConfiguration = + // TekuConfiguration.builder() + // .data(b -> b.dataBasePath(tempDir)) + // .executionLayer(b -> b.engineEndpoint("unsafe-test-stub")) + // .eth2NetworkConfig(b -> b.ignoreWeakSubjectivityPeriodEnabled(true)) + // .beaconChainControllerFactory(customControllerFactory) + // .build(); + // + // try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) { + // assertThat(beaconNode).isNotNull(); + // assertThat(customDiscoveryBuilderMethodCalled).isTrue(); + // assertThat(customLibP2PBuilderMethodCalled).isTrue(); + // assertThat(customGossipNetworkBuilderCalled).isTrue(); + // } } } From e8c0296bb3cae7ead605d5532b6bdc56ce4483da Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 20:03:08 +0400 Subject: [PATCH 23/27] Remove AbstractBeaconChainController --- .../AbstractBeaconChainController.java | 19 ------------------- .../beaconchain/BeaconChainController.java | 3 ++- .../BeaconChainControllerFacade.java | 3 ++- .../BeaconChainControllerFactory.java | 4 ++-- .../beaconchain/BeaconChainControllerOld.java | 3 ++- .../beaconchain/BeaconChainService.java | 2 +- 6 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java deleted file mode 100644 index bc390f03cc6..00000000000 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/AbstractBeaconChainController.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.services.beaconchain; - -import tech.pegasys.teku.service.serviceutils.Service; - -public abstract class AbstractBeaconChainController extends Service - implements BeaconChainControllerFacade {} diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java index 01df2ea98d9..58370ce6e6f 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java @@ -23,6 +23,7 @@ import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.service.serviceutils.Service; import tech.pegasys.teku.service.serviceutils.ServiceConfig; import tech.pegasys.teku.services.beaconchain.init.BeaconChainControllerComponent; import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; @@ -40,7 +41,7 @@ * initialization behavior (see {@link BeaconChainControllerFactory}} however this class may change * in a backward incompatible manner and either break compilation or runtime behavior */ -public class BeaconChainController extends AbstractBeaconChainController { +public class BeaconChainController extends Service implements BeaconChainControllerFacade { private static final Logger LOG = LogManager.getLogger(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFacade.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFacade.java index 5c2b66d009f..eb261eed17c 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFacade.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFacade.java @@ -19,6 +19,7 @@ import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; import tech.pegasys.teku.infrastructure.time.TimeProvider; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.service.serviceutils.ServiceFacade; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; @@ -29,7 +30,7 @@ * CAUTION: this API is unstable and primarily intended for debugging and testing purposes this API * might be changed in any version in backward incompatible way */ -public interface BeaconChainControllerFacade { +public interface BeaconChainControllerFacade extends ServiceFacade { Spec getSpec(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java index e2b137f159d..60c093b0653 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java @@ -22,9 +22,9 @@ public interface BeaconChainControllerFactory { BeaconChainControllerFactory DEFAULT = - // BeaconChainControllerOld::new; +// BeaconChainControllerOld::new; BeaconChainController::new; - AbstractBeaconChainController create( + BeaconChainControllerFacade create( final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java index c4d62a802d1..f27718abab7 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerOld.java @@ -87,6 +87,7 @@ import tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; import tech.pegasys.teku.networks.StateBoostrapConfig; +import tech.pegasys.teku.service.serviceutils.Service; import tech.pegasys.teku.service.serviceutils.ServiceConfig; import tech.pegasys.teku.services.executionlayer.ExecutionLayerBlockManagerFactory; import tech.pegasys.teku.services.timer.TimerService; @@ -214,7 +215,7 @@ * initialization behavior (see {@link BeaconChainControllerFactory}} however this class may change * in a backward incompatible manner and either break compilation or runtime behavior */ -public class BeaconChainControllerOld extends AbstractBeaconChainController { +public class BeaconChainControllerOld extends Service implements BeaconChainControllerFacade { private static final Logger LOG = LogManager.getLogger(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java index 35a68456909..e8fd3a98da7 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainService.java @@ -19,7 +19,7 @@ public class BeaconChainService extends Service implements BeaconChainServiceFacade { - private final AbstractBeaconChainController controller; + private final BeaconChainControllerFacade controller; public BeaconChainService( final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig) { From a8958fb35e447ae8d4890cc3fdccbe90c1881685 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 21:09:28 +0400 Subject: [PATCH 24/27] Redesign BeaconChainController creation --- .../BeaconChainControllerFactory.java | 13 +- ...ateInitDelegateBeaconChainController.java} | 87 +++++--------- .../init/BeaconChainControllerComponent.java | 36 +----- .../beaconchain/init/LoggingModule.java | 3 +- .../services/beaconchain/init/MainModule.java | 6 + .../init/SimpleBeaconChainController.java | 112 ++++++++++++++++++ 6 files changed, 162 insertions(+), 95 deletions(-) rename services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/{BeaconChainController.java => LateInitDelegateBeaconChainController.java} (50%) create mode 100644 services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SimpleBeaconChainController.java diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java index 60c093b0653..5506f838b7c 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainControllerFactory.java @@ -14,6 +14,8 @@ package tech.pegasys.teku.services.beaconchain; import tech.pegasys.teku.service.serviceutils.ServiceConfig; +import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; +import tech.pegasys.teku.services.beaconchain.init.ExternalDependenciesModule; /** * CAUTION: this API is unstable and primarily intended for debugging and testing purposes this API @@ -22,8 +24,15 @@ public interface BeaconChainControllerFactory { BeaconChainControllerFactory DEFAULT = -// BeaconChainControllerOld::new; - BeaconChainController::new; + LateInitDelegateBeaconChainController.createLateInitFactory( + (serviceConfig, beaconConfig) -> + DaggerBeaconChainControllerComponent.builder() + .externalDependenciesModule( + new ExternalDependenciesModule(serviceConfig, beaconConfig)) + .build() + .beaconChainController()); + + BeaconChainControllerFactory OLD = BeaconChainControllerOld::new; BeaconChainControllerFacade create( final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java similarity index 50% rename from services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java rename to services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java index 58370ce6e6f..67d761df9af 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java @@ -14,7 +14,6 @@ package tech.pegasys.teku.services.beaconchain; import java.util.Optional; -import java.util.function.Supplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import tech.pegasys.teku.beacon.sync.SyncService; @@ -25,70 +24,44 @@ import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.service.serviceutils.Service; import tech.pegasys.teku.service.serviceutils.ServiceConfig; -import tech.pegasys.teku.services.beaconchain.init.BeaconChainControllerComponent; -import tech.pegasys.teku.services.beaconchain.init.DaggerBeaconChainControllerComponent; -import tech.pegasys.teku.services.beaconchain.init.ExternalDependenciesModule; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.client.RecentChainData; -/** - * The central class which assembles together and initializes Beacon Chain components - * - *

CAUTION: This class can be overridden by custom implementation to tweak creation and - * initialization behavior (see {@link BeaconChainControllerFactory}} however this class may change - * in a backward incompatible manner and either break compilation or runtime behavior - */ -public class BeaconChainController extends Service implements BeaconChainControllerFacade { +public class LateInitDelegateBeaconChainController extends Service + implements BeaconChainControllerFacade { + + public static BeaconChainControllerFactory createLateInitFactory( + BeaconChainControllerFactory delegateFactory) { + return (serviceConfig, beaconConfig) -> + new LateInitDelegateBeaconChainController(serviceConfig, beaconConfig, delegateFactory); + } private static final Logger LOG = LogManager.getLogger(); private final ServiceConfig serviceConfig; private final BeaconChainConfiguration beaconConfig; + private final BeaconChainControllerFactory delegateFactory; + + private volatile BeaconChainControllerFacade delegate; - private Spec spec; - private TimeProvider timeProvider; - private AsyncRunnerFactory asyncRunnerFactory; - private ForkChoice forkChoice; - private RecentChainData recentChainData; - private Eth2P2PNetwork p2pNetwork; - private Optional beaconRestAPI; - private SyncService syncService; - private SignatureVerificationService signatureVerificationService; - private CombinedChainDataClient combinedChainDataClient; - - private Supplier> starter; - private Supplier> stopper; - - public BeaconChainController(ServiceConfig serviceConfig, BeaconChainConfiguration beaconConfig) { + public LateInitDelegateBeaconChainController( + ServiceConfig serviceConfig, + BeaconChainConfiguration beaconConfig, + BeaconChainControllerFactory delegateFactory) { this.serviceConfig = serviceConfig; this.beaconConfig = beaconConfig; + this.delegateFactory = delegateFactory; } @Override protected SafeFuture doStart() { LOG.info("Starting BeaconChainController..."); - BeaconChainControllerComponent component = - DaggerBeaconChainControllerComponent.builder() - .externalDependenciesModule(new ExternalDependenciesModule(serviceConfig, beaconConfig)) - .build(); - - this.spec = component.getSpec(); - this.timeProvider = component.getTimeProvider(); - this.asyncRunnerFactory = component.getAsyncRunnerFactory(); - this.forkChoice = component.getForkChoice(); - this.recentChainData = component.getRecentChainData(); - this.p2pNetwork = component.getP2pNetwork(); - this.beaconRestAPI = component.getBeaconRestAPI(); - this.syncService = component.getSyncService(); - this.signatureVerificationService = component.getSignatureVerificationService(); - this.combinedChainDataClient = component.getCombinedChainDataClient(); - this.starter = () -> component.starter().start(); - this.stopper = () -> component.stopper().stop(); - - SafeFuture startFuture = this.starter.get(); + this.delegate = delegateFactory.create(serviceConfig, beaconConfig); + + SafeFuture startFuture = this.delegate.start(); LOG.info("BeaconChainController start complete"); return startFuture; @@ -96,56 +69,56 @@ protected SafeFuture doStart() { @Override protected SafeFuture doStop() { - return this.stopper.get(); + return this.delegate.stop(); } @Override public Spec getSpec() { - return spec; + return delegate.getSpec(); } @Override public TimeProvider getTimeProvider() { - return timeProvider; + return delegate.getTimeProvider(); } @Override public AsyncRunnerFactory getAsyncRunnerFactory() { - return asyncRunnerFactory; + return delegate.getAsyncRunnerFactory(); } @Override public SignatureVerificationService getSignatureVerificationService() { - return signatureVerificationService; + return delegate.getSignatureVerificationService(); } @Override public RecentChainData getRecentChainData() { - return recentChainData; + return delegate.getRecentChainData(); } @Override public CombinedChainDataClient getCombinedChainDataClient() { - return combinedChainDataClient; + return delegate.getCombinedChainDataClient(); } @Override public Eth2P2PNetwork getP2pNetwork() { - return p2pNetwork; + return delegate.getP2pNetwork(); } @Override public Optional getBeaconRestAPI() { - return beaconRestAPI; + return delegate.getBeaconRestAPI(); } @Override public SyncService getSyncService() { - return syncService; + return delegate.getSyncService(); } @Override public ForkChoice getForkChoice() { - return forkChoice; + return delegate.getForkChoice(); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java index 99ef1ac0e47..62cd58d56eb 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconChainControllerComponent.java @@ -14,18 +14,8 @@ package tech.pegasys.teku.services.beaconchain.init; import dagger.Component; -import java.util.Optional; import javax.inject.Singleton; -import tech.pegasys.teku.beacon.sync.SyncService; -import tech.pegasys.teku.beaconrestapi.BeaconRestApi; -import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; -import tech.pegasys.teku.infrastructure.time.TimeProvider; -import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; -import tech.pegasys.teku.spec.Spec; -import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; -import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; -import tech.pegasys.teku.storage.client.CombinedChainDataClient; -import tech.pegasys.teku.storage.client.RecentChainData; +import tech.pegasys.teku.services.beaconchain.BeaconChainControllerFacade; @Singleton @Component( @@ -56,27 +46,5 @@ }) public interface BeaconChainControllerComponent { - MainModule.ServiceStarter starter(); - - MainModule.ServiceStopper stopper(); - - Spec getSpec(); - - TimeProvider getTimeProvider(); - - AsyncRunnerFactory getAsyncRunnerFactory(); - - SignatureVerificationService getSignatureVerificationService(); - - RecentChainData getRecentChainData(); - - CombinedChainDataClient getCombinedChainDataClient(); - - Eth2P2PNetwork getP2pNetwork(); - - Optional getBeaconRestAPI(); - - SyncService getSyncService(); - - ForkChoice getForkChoice(); + BeaconChainControllerFacade beaconChainController(); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java index 7b7a746663f..637a8a02f86 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/LoggingModule.java @@ -20,7 +20,6 @@ import org.apache.logging.log4j.Logger; import tech.pegasys.teku.infrastructure.logging.EventLogger; import tech.pegasys.teku.infrastructure.logging.StatusLogger; -import tech.pegasys.teku.services.beaconchain.BeaconChainController; @Module public interface LoggingModule { @@ -43,6 +42,6 @@ static EventLogger eventLogger() { @Provides @Singleton static InitLogger initLogger() { - return new InitLogger(LogManager.getLogger(BeaconChainController.class)); + return new InitLogger(LogManager.getLogger("BeaconChainController")); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index 9ff9e6aa583..39ac6ed2c84 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -13,6 +13,7 @@ package tech.pegasys.teku.services.beaconchain.init; +import dagger.Binds; import dagger.Lazy; import dagger.Module; import dagger.Provides; @@ -28,6 +29,7 @@ import tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread; import tech.pegasys.teku.infrastructure.logging.StatusLogger; import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.services.beaconchain.BeaconChainControllerFacade; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceExecutor; import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule.ForkChoiceNotifierExecutor; import tech.pegasys.teku.services.beaconchain.init.LoggingModule.InitLogger; @@ -63,6 +65,10 @@ interface ServiceStopper { SafeFuture stop(); } + @Binds + @Singleton + BeaconChainControllerFacade beaconChainController(SimpleBeaconChainController impl); + @Provides @IntoSet static VoidInitializer initSlashingEventsSubscriptions( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SimpleBeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SimpleBeaconChainController.java new file mode 100644 index 00000000000..783a4e5824c --- /dev/null +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SimpleBeaconChainController.java @@ -0,0 +1,112 @@ +/* + * Copyright Consensys Software Inc., 2024 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package tech.pegasys.teku.services.beaconchain.init; + +import java.util.Optional; +import javax.inject.Inject; +import tech.pegasys.teku.beacon.sync.SyncService; +import tech.pegasys.teku.beaconrestapi.BeaconRestApi; +import tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory; +import tech.pegasys.teku.infrastructure.async.SafeFuture; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; +import tech.pegasys.teku.services.beaconchain.BeaconChainControllerFacade; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.statetransition.forkchoice.ForkChoice; +import tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.client.RecentChainData; + +public class SimpleBeaconChainController implements BeaconChainControllerFacade { + @Inject MainModule.ServiceStarter starter; + @Inject MainModule.ServiceStopper stopper; + @Inject Spec spec; + @Inject TimeProvider timeProvider; + @Inject AsyncRunnerFactory asyncRunnerFactory; + @Inject SignatureVerificationService signatureVerificationService; + @Inject RecentChainData recentChainData; + @Inject CombinedChainDataClient combinedChainDataClient; + @Inject Eth2P2PNetwork p2pNetwork; + @Inject Optional beaconRestApi; + @Inject SyncService syncService; + @Inject ForkChoice forkChoice; + + @Inject + public SimpleBeaconChainController() {} + + @Override + public SafeFuture start() { + return starter.start(); + } + + @Override + public SafeFuture stop() { + return stopper.stop(); + } + + @Override + public boolean isRunning() { + throw new UnsupportedOperationException(); + } + + @Override + public Spec getSpec() { + return spec; + } + + @Override + public TimeProvider getTimeProvider() { + return timeProvider; + } + + @Override + public AsyncRunnerFactory getAsyncRunnerFactory() { + return asyncRunnerFactory; + } + + @Override + public SignatureVerificationService getSignatureVerificationService() { + return signatureVerificationService; + } + + @Override + public RecentChainData getRecentChainData() { + return recentChainData; + } + + @Override + public CombinedChainDataClient getCombinedChainDataClient() { + return combinedChainDataClient; + } + + @Override + public Eth2P2PNetwork getP2pNetwork() { + return p2pNetwork; + } + + @Override + public Optional getBeaconRestAPI() { + return beaconRestApi; + } + + @Override + public SyncService getSyncService() { + return syncService; + } + + @Override + public ForkChoice getForkChoice() { + return forkChoice; + } +} From c99e74010a04894dcb43211819c292ff2a17fb64 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Wed, 26 Jun 2024 21:09:58 +0400 Subject: [PATCH 25/27] Adopt TekuConfigurationTest --- teku/build.gradle | 5 + .../teku/config/TekuConfigurationTest.java | 207 ++++++++++++++++-- 2 files changed, 189 insertions(+), 23 deletions(-) diff --git a/teku/build.gradle b/teku/build.gradle index 475d195a664..69a90417d0c 100644 --- a/teku/build.gradle +++ b/teku/build.gradle @@ -71,4 +71,9 @@ dependencies { testImplementation project(':data:provider') testImplementation 'org.awaitility:awaitility' + + testImplementation 'com.google.dagger:dagger:2.51.1' + testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.51.1' + + testImplementation project(':ethereum:performance-trackers') } diff --git a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java index 2e9d539fa21..4e770bfbf17 100644 --- a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java +++ b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java @@ -13,12 +13,28 @@ package tech.pegasys.teku.config; +import static org.assertj.core.api.Assertions.assertThat; + +import dagger.Component; +import dagger.Module; +import dagger.Provides; import java.nio.file.Path; import java.util.concurrent.atomic.AtomicBoolean; +import javax.inject.Singleton; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.plugin.services.MetricsSystem; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.BeaconNodeFacade; +import tech.pegasys.teku.TekuFacade; import tech.pegasys.teku.cli.TempDirUtils; +import tech.pegasys.teku.infrastructure.async.AsyncRunner; +import tech.pegasys.teku.infrastructure.events.EventChannels; +import tech.pegasys.teku.infrastructure.time.TimeProvider; +import tech.pegasys.teku.kzg.KZG; +import tech.pegasys.teku.networking.eth2.Eth2P2PNetwork; import tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder; +import tech.pegasys.teku.networking.eth2.P2PConfig; import tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetwork; import tech.pegasys.teku.networking.p2p.discovery.DiscoveryNetworkBuilder; import tech.pegasys.teku.networking.p2p.libp2p.LibP2PNetworkBuilder; @@ -26,6 +42,48 @@ import tech.pegasys.teku.networking.p2p.libp2p.gossip.LibP2PGossipNetworkBuilder; import tech.pegasys.teku.networking.p2p.network.P2PNetwork; import tech.pegasys.teku.networking.p2p.peer.Peer; +import tech.pegasys.teku.service.serviceutils.layout.DataDirLayout; +import tech.pegasys.teku.services.beaconchain.BeaconChainControllerFacade; +import tech.pegasys.teku.services.beaconchain.BeaconChainControllerFactory; +import tech.pegasys.teku.services.beaconchain.LateInitDelegateBeaconChainController; +import tech.pegasys.teku.services.beaconchain.init.AsyncRunnerModule; +import tech.pegasys.teku.services.beaconchain.init.BeaconConfigModule; +import tech.pegasys.teku.services.beaconchain.init.BeaconModule; +import tech.pegasys.teku.services.beaconchain.init.BlobModule; +import tech.pegasys.teku.services.beaconchain.init.ChannelsModule; +import tech.pegasys.teku.services.beaconchain.init.CryptoModule; +import tech.pegasys.teku.services.beaconchain.init.DataProviderModule; +import tech.pegasys.teku.services.beaconchain.init.ExternalDependenciesModule; +import tech.pegasys.teku.services.beaconchain.init.ForkChoiceModule; +import tech.pegasys.teku.services.beaconchain.init.LoggingModule; +import tech.pegasys.teku.services.beaconchain.init.MainModule; +import tech.pegasys.teku.services.beaconchain.init.MetricsModule; +import tech.pegasys.teku.services.beaconchain.init.NetworkModule; +import tech.pegasys.teku.services.beaconchain.init.PoolAndCachesModule; +import tech.pegasys.teku.services.beaconchain.init.PowModule; +import tech.pegasys.teku.services.beaconchain.init.ServiceConfigModule; +import tech.pegasys.teku.services.beaconchain.init.SpecModule; +import tech.pegasys.teku.services.beaconchain.init.StorageModule; +import tech.pegasys.teku.services.beaconchain.init.SubnetsModule; +import tech.pegasys.teku.services.beaconchain.init.SyncModule; +import tech.pegasys.teku.services.beaconchain.init.ValidatorModule; +import tech.pegasys.teku.services.beaconchain.init.VerifyModule; +import tech.pegasys.teku.services.beaconchain.init.WSModule; +import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; +import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; +import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; +import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; +import tech.pegasys.teku.statetransition.OperationPool; +import tech.pegasys.teku.statetransition.attestation.AttestationManager; +import tech.pegasys.teku.statetransition.blobs.BlobSidecarManager; +import tech.pegasys.teku.statetransition.block.BlockManager; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; +import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; +import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.storage.client.CombinedChainDataClient; +import tech.pegasys.teku.storage.store.KeyValueStore; +import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; public class TekuConfigurationTest { @@ -87,28 +145,131 @@ protected LibP2PNetworkBuilder createLibP2PNetworkBuilder() { } }; - // BeaconChainControllerFactory customControllerFactory = - // (serviceConfig, beaconConfig) -> - // new BeaconChainController(serviceConfig, beaconConfig) { - // @Override - // protected Eth2P2PNetworkBuilder createEth2P2PNetworkBuilder() { - // return customEth2P2PNetworkBuilder; - // } - // }; - // - // TekuConfiguration tekuConfiguration = - // TekuConfiguration.builder() - // .data(b -> b.dataBasePath(tempDir)) - // .executionLayer(b -> b.engineEndpoint("unsafe-test-stub")) - // .eth2NetworkConfig(b -> b.ignoreWeakSubjectivityPeriodEnabled(true)) - // .beaconChainControllerFactory(customControllerFactory) - // .build(); - // - // try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) { - // assertThat(beaconNode).isNotNull(); - // assertThat(customDiscoveryBuilderMethodCalled).isTrue(); - // assertThat(customLibP2PBuilderMethodCalled).isTrue(); - // assertThat(customGossipNetworkBuilderCalled).isTrue(); - // } + BeaconChainControllerFactory customControllerFactory = + LateInitDelegateBeaconChainController.createLateInitFactory( + (serviceConfig, beaconConfig) -> + DaggerTekuConfigurationTest_TestBeaconChainControllerComponent.builder() + .externalDependenciesModule( + new ExternalDependenciesModule(serviceConfig, beaconConfig)) + .testNetworkModule(new TestNetworkModule(customEth2P2PNetworkBuilder)) + .build() + .beaconChainController()); + + TekuConfiguration tekuConfiguration = + TekuConfiguration.builder() + .data(b -> b.dataBasePath(tempDir)) + .executionLayer(b -> b.engineEndpoint("unsafe-test-stub")) + .eth2NetworkConfig(b -> b.ignoreWeakSubjectivityPeriodEnabled(true)) + .beaconChainControllerFactory(customControllerFactory) + .build(); + + try (BeaconNodeFacade beaconNode = TekuFacade.startBeaconNode(tekuConfiguration)) { + assertThat(beaconNode).isNotNull(); + assertThat(customDiscoveryBuilderMethodCalled).isTrue(); + assertThat(customLibP2PBuilderMethodCalled).isTrue(); + assertThat(customGossipNetworkBuilderCalled).isTrue(); + } + } + + @Singleton + @Component( + modules = { + AsyncRunnerModule.class, + BeaconConfigModule.class, + BeaconModule.class, + BlobModule.class, + ChannelsModule.class, + CryptoModule.class, + DataProviderModule.class, + ExternalDependenciesModule.class, + ForkChoiceModule.class, + LoggingModule.class, + MainModule.class, + MetricsModule.class, + // NetworkModule.class, + TestNetworkModule.class, + PoolAndCachesModule.class, + PowModule.class, + ServiceConfigModule.class, + SpecModule.class, + StorageModule.class, + SubnetsModule.class, + SyncModule.class, + ValidatorModule.class, + VerifyModule.class, + WSModule.class + }) + public interface TestBeaconChainControllerComponent { + + BeaconChainControllerFacade beaconChainController(); + } + + @Module + public static class TestNetworkModule { + private final Eth2P2PNetworkBuilder eth2P2PNetworkBuilder; + + public TestNetworkModule(Eth2P2PNetworkBuilder eth2P2PNetworkBuilder) { + this.eth2P2PNetworkBuilder = eth2P2PNetworkBuilder; + } + + @Provides + Eth2P2PNetworkBuilder eth2P2PNetworkBuilder() { + return eth2P2PNetworkBuilder; + } + + @Provides + @Singleton + static Eth2P2PNetwork eth2P2PNetwork( + Spec spec, + P2PConfig p2pConfig, + MetricsSystem metricsSystem, + @AsyncRunnerModule.NetworkAsyncRunner AsyncRunner networkAsyncRunner, + TimeProvider timeProvider, + EventChannels eventChannels, + KeyValueStore keyValueStore, + Eth2P2PNetworkBuilder eth2P2PNetworkBuilder, + CombinedChainDataClient combinedChainDataClient, + BlockManager blockManager, + BlobSidecarManager blobSidecarManager, + AttestationManager attestationManager, + OperationPool attesterSlashingPool, + OperationPool proposerSlashingPool, + OperationPool voluntaryExitPool, + SyncCommitteeContributionPool syncCommitteeContributionPool, + SyncCommitteeMessagePool syncCommitteeMessagePool, + OperationPool blsToExecutionChangePool, + KZG kzg, + WeakSubjectivityValidator weakSubjectivityValidator, + P2PDebugDataDumper p2pDebugDataDumper) { + + return NetworkModule.eth2P2PNetwork( + spec, + p2pConfig, + metricsSystem, + networkAsyncRunner, + timeProvider, + eventChannels, + keyValueStore, + eth2P2PNetworkBuilder, + combinedChainDataClient, + blockManager, + blobSidecarManager, + attestationManager, + attesterSlashingPool, + proposerSlashingPool, + voluntaryExitPool, + syncCommitteeContributionPool, + syncCommitteeMessagePool, + blsToExecutionChangePool, + kzg, + weakSubjectivityValidator, + p2pDebugDataDumper); + } + + @Provides + @Singleton + static P2PDebugDataDumper p2pDebugDataDumper(P2PConfig p2pConfig, DataDirLayout dataDirLayout) { + return NetworkModule.p2pDebugDataDumper(p2pConfig, dataDirLayout); + } } } From 04e8b3b8239bb13d3019ea3c3810f1cf44e357eb Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Mon, 1 Jul 2024 18:03:07 +0400 Subject: [PATCH 26/27] Adopt latest config PRs to master --- .../beaconchain/init/BeaconConfigModule.java | 1 + .../beaconchain/init/ForkChoiceModule.java | 6 +++--- .../services/beaconchain/init/NetworkModule.java | 14 +++++++------- .../services/beaconchain/init/ValidatorModule.java | 3 +-- .../pegasys/teku/config/TekuConfigurationTest.java | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java index 9c126aae934..9301ee44302 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java @@ -20,6 +20,7 @@ import tech.pegasys.teku.infrastructure.metrics.MetricsConfig; import tech.pegasys.teku.networking.eth2.P2PConfig; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; +import tech.pegasys.teku.service.serviceutils.layout.DataConfig; import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; import tech.pegasys.teku.services.powchain.PowchainConfiguration; import tech.pegasys.teku.spec.Spec; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java index 69a417bf694..dc627de3b08 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java @@ -33,7 +33,7 @@ import tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator; import tech.pegasys.teku.statetransition.forkchoice.ProposersDataManager; import tech.pegasys.teku.statetransition.forkchoice.TickProcessor; -import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.statetransition.util.DebugDataDumper; import tech.pegasys.teku.storage.client.RecentChainData; @Module @@ -50,7 +50,7 @@ static ForkChoice forkChoice( BlobSidecarManager blobSidecarManager, ForkChoiceNotifier forkChoiceNotifier, ForkChoiceStateProvider forkChoiceStateProvider, - P2PDebugDataDumper p2pDebugDataDumper, + DebugDataDumper debugDataDumper, TickProcessor tickProcessor, MergeTransitionBlockValidator mergeTransitionBlockValidator) { return new ForkChoice( @@ -63,7 +63,7 @@ static ForkChoice forkChoice( tickProcessor, mergeTransitionBlockValidator, eth2NetworkConfig.isForkChoiceLateBlockReorgEnabled(), - p2pDebugDataDumper, + debugDataDumper, metricsSystem); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java index 3017278b16d..abd4fb5f545 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java @@ -43,8 +43,8 @@ import tech.pegasys.teku.statetransition.block.BlockManager; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; -import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; -import tech.pegasys.teku.statetransition.util.P2PDebugDataFileDumper; +import tech.pegasys.teku.statetransition.util.DebugDataDumper; +import tech.pegasys.teku.statetransition.util.DebugDataFileDumper; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @@ -80,7 +80,7 @@ static Eth2P2PNetwork eth2P2PNetwork( OperationPool blsToExecutionChangePool, KZG kzg, WeakSubjectivityValidator weakSubjectivityValidator, - P2PDebugDataDumper p2pDebugDataDumper) { + DebugDataDumper p2pDebugDataDumper) { if (!p2pConfig.getNetworkConfig().isEnabled()) { return new NoOpEth2P2PNetwork(spec); } @@ -141,9 +141,9 @@ static Eth2P2PNetwork eth2P2PNetwork( @Provides @Singleton - static P2PDebugDataDumper p2pDebugDataDumper(P2PConfig p2pConfig, DataDirLayout dataDirLayout) { - return p2pConfig.isP2pDumpsToFileEnabled() - ? new P2PDebugDataFileDumper(dataDirLayout.getDebugDataDirectory()) - : P2PDebugDataDumper.NOOP; + static DebugDataDumper debugDataDumper(DataDirLayout dataDirLayout) { + return dataDirLayout.isDebugDataDumpingEnabled() + ? new DebugDataFileDumper(dataDirLayout.getDebugDataDirectory()) + : DebugDataDumper.NOOP; } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index fee3073b4b4..5e11cc464b2 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -107,8 +107,7 @@ static GraffitiBuilder graffitiBuilder( executionClientVersionChannelSubscriber) { GraffitiBuilder graffitiBuilder = new GraffitiBuilder( - validatorConfig.getClientGraffitiAppendFormat(), - validatorConfig.getGraffitiProvider().get()); + validatorConfig.getClientGraffitiAppendFormat()); executionClientVersionChannelSubscriber.subscribe(graffitiBuilder); return graffitiBuilder; } diff --git a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java index 4e770bfbf17..63f5b3367b0 100644 --- a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java +++ b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java @@ -80,7 +80,7 @@ import tech.pegasys.teku.statetransition.block.BlockManager; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool; import tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool; -import tech.pegasys.teku.statetransition.util.P2PDebugDataDumper; +import tech.pegasys.teku.statetransition.util.DebugDataDumper; import tech.pegasys.teku.storage.client.CombinedChainDataClient; import tech.pegasys.teku.storage.store.KeyValueStore; import tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator; @@ -240,7 +240,7 @@ static Eth2P2PNetwork eth2P2PNetwork( OperationPool blsToExecutionChangePool, KZG kzg, WeakSubjectivityValidator weakSubjectivityValidator, - P2PDebugDataDumper p2pDebugDataDumper) { + DebugDataDumper p2pDebugDataDumper) { return NetworkModule.eth2P2PNetwork( spec, @@ -268,8 +268,8 @@ static Eth2P2PNetwork eth2P2PNetwork( @Provides @Singleton - static P2PDebugDataDumper p2pDebugDataDumper(P2PConfig p2pConfig, DataDirLayout dataDirLayout) { - return NetworkModule.p2pDebugDataDumper(p2pConfig, dataDirLayout); + static DebugDataDumper p2pDebugDataDumper(DataDirLayout dataDirLayout) { + return NetworkModule.debugDataDumper(dataDirLayout); } } } From 124292ca5d100def3700300e02b8644315275bf7 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Mon, 1 Jul 2024 18:41:35 +0400 Subject: [PATCH 27/27] Made method params final --- ...LateInitDelegateBeaconChainController.java | 8 +- .../beaconchain/init/AsyncRunnerModule.java | 15 +- .../beaconchain/init/BeaconConfigModule.java | 21 ++- .../beaconchain/init/BeaconModule.java | 117 +++++++-------- .../services/beaconchain/init/BlobModule.java | 26 ++-- .../beaconchain/init/ChannelsModule.java | 50 +++---- .../beaconchain/init/CryptoModule.java | 10 +- .../beaconchain/init/DataProviderModule.java | 68 ++++----- .../init/ExternalDependenciesModule.java | 2 +- .../beaconchain/init/ForkChoiceModule.java | 42 +++--- .../services/beaconchain/init/MainModule.java | 69 ++++----- .../beaconchain/init/MetricsModule.java | 71 ++++----- .../beaconchain/init/NetworkModule.java | 44 +++--- .../beaconchain/init/PoolAndCachesModule.java | 96 +++++++------ .../services/beaconchain/init/PowModule.java | 54 +++---- .../init/RecentChainDataStateInitializer.java | 4 +- .../beaconchain/init/ServiceConfigModule.java | 12 +- .../services/beaconchain/init/SpecModule.java | 12 +- .../beaconchain/init/StorageModule.java | 64 +++++---- .../beaconchain/init/SubnetsModule.java | 31 ++-- .../services/beaconchain/init/SyncModule.java | 60 ++++---- .../beaconchain/init/ValidatorModule.java | 135 +++++++++--------- .../beaconchain/init/VerifyModule.java | 66 +++++---- .../services/beaconchain/init/WSModule.java | 26 ++-- .../teku/config/TekuConfigurationTest.java | 46 +++--- 25 files changed, 587 insertions(+), 562 deletions(-) diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java index 67d761df9af..c4c2f3caa24 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/LateInitDelegateBeaconChainController.java @@ -34,7 +34,7 @@ public class LateInitDelegateBeaconChainController extends Service implements BeaconChainControllerFacade { public static BeaconChainControllerFactory createLateInitFactory( - BeaconChainControllerFactory delegateFactory) { + final BeaconChainControllerFactory delegateFactory) { return (serviceConfig, beaconConfig) -> new LateInitDelegateBeaconChainController(serviceConfig, beaconConfig, delegateFactory); } @@ -48,9 +48,9 @@ public static BeaconChainControllerFactory createLateInitFactory( private volatile BeaconChainControllerFacade delegate; public LateInitDelegateBeaconChainController( - ServiceConfig serviceConfig, - BeaconChainConfiguration beaconConfig, - BeaconChainControllerFactory delegateFactory) { + final ServiceConfig serviceConfig, + final BeaconChainConfiguration beaconConfig, + final BeaconChainControllerFactory delegateFactory) { this.serviceConfig = serviceConfig; this.beaconConfig = beaconConfig; this.delegateFactory = delegateFactory; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java index 75fe70213fe..f4836f7f929 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/AsyncRunnerModule.java @@ -47,7 +47,8 @@ public interface AsyncRunnerModule { @Singleton @BeaconAsyncRunner static AsyncRunner beaconAsyncRunner( - AsyncRunnerFactory asyncRunnerFactory, Eth2NetworkConfiguration eth2NetworkConfig) { + final AsyncRunnerFactory asyncRunnerFactory, + final Eth2NetworkConfiguration eth2NetworkConfig) { return asyncRunnerFactory.create( "beaconchain", eth2NetworkConfig.getAsyncBeaconChainMaxThreads(), @@ -58,7 +59,8 @@ static AsyncRunner beaconAsyncRunner( @Singleton @NetworkAsyncRunner static AsyncRunner networkAsyncRunner( - AsyncRunnerFactory asyncRunnerFactory, Eth2NetworkConfiguration eth2NetworkConfig) { + final AsyncRunnerFactory asyncRunnerFactory, + final Eth2NetworkConfiguration eth2NetworkConfig) { return asyncRunnerFactory.create( "p2p", eth2NetworkConfig.getAsyncP2pMaxThreads(), eth2NetworkConfig.getAsyncP2pMaxQueue()); } @@ -66,21 +68,21 @@ static AsyncRunner networkAsyncRunner( @Provides @Singleton @EventAsyncRunner - static AsyncRunner eventAsyncRunner(AsyncRunnerFactory asyncRunnerFactory) { + static AsyncRunner eventAsyncRunner(final AsyncRunnerFactory asyncRunnerFactory) { return asyncRunnerFactory.create("events", 10); } @Provides @Singleton @OperationPoolAsyncRunner - static AsyncRunner operationPoolAsyncRunner(AsyncRunnerFactory asyncRunnerFactory) { + static AsyncRunner operationPoolAsyncRunner(final AsyncRunnerFactory asyncRunnerFactory) { return asyncRunnerFactory.create("operationPoolUpdater", 1); } @Provides @Singleton @ForkChoiceExecutor - static AsyncRunnerEventThread forkChoiceExecutor(AsyncRunnerFactory asyncRunnerFactory) { + static AsyncRunnerEventThread forkChoiceExecutor(final AsyncRunnerFactory asyncRunnerFactory) { AsyncRunnerEventThread forkChoiceExecutor = new AsyncRunnerEventThread("forkchoice", asyncRunnerFactory); forkChoiceExecutor.start(); @@ -90,7 +92,8 @@ static AsyncRunnerEventThread forkChoiceExecutor(AsyncRunnerFactory asyncRunnerF @Provides @Singleton @ForkChoiceNotifierExecutor - static AsyncRunnerEventThread forkChoiceNotifierExecutor(AsyncRunnerFactory asyncRunnerFactory) { + static AsyncRunnerEventThread forkChoiceNotifierExecutor( + final AsyncRunnerFactory asyncRunnerFactory) { AsyncRunnerEventThread forkChoiceNotifierExecutor = new AsyncRunnerEventThread("forkChoiceNotifier", asyncRunnerFactory); forkChoiceNotifierExecutor.start(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java index 9301ee44302..0bab99a3fbc 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconConfigModule.java @@ -20,7 +20,6 @@ import tech.pegasys.teku.infrastructure.metrics.MetricsConfig; import tech.pegasys.teku.networking.eth2.P2PConfig; import tech.pegasys.teku.networks.Eth2NetworkConfiguration; -import tech.pegasys.teku.service.serviceutils.layout.DataConfig; import tech.pegasys.teku.services.beaconchain.BeaconChainConfiguration; import tech.pegasys.teku.services.powchain.PowchainConfiguration; import tech.pegasys.teku.spec.Spec; @@ -32,52 +31,52 @@ public interface BeaconConfigModule { @Provides - static Spec spec(BeaconChainConfiguration config) { + static Spec spec(final BeaconChainConfiguration config) { return config.getSpec(); } @Provides - static Eth2NetworkConfiguration eth2NetworkConfig(BeaconChainConfiguration config) { + static Eth2NetworkConfiguration eth2NetworkConfig(final BeaconChainConfiguration config) { return config.eth2NetworkConfig(); } @Provides - static StoreConfig storeConfig(BeaconChainConfiguration config) { + static StoreConfig storeConfig(final BeaconChainConfiguration config) { return config.storeConfig(); } @Provides - static PowchainConfiguration powchainConfig(BeaconChainConfiguration config) { + static PowchainConfiguration powchainConfig(final BeaconChainConfiguration config) { return config.powchainConfig(); } @Provides - static P2PConfig p2pConfig(BeaconChainConfiguration config) { + static P2PConfig p2pConfig(final BeaconChainConfiguration config) { return config.p2pConfig(); } @Provides - static ValidatorConfig validatorConfig(BeaconChainConfiguration config) { + static ValidatorConfig validatorConfig(final BeaconChainConfiguration config) { return config.validatorConfig(); } @Provides - static SyncConfig syncConfig(BeaconChainConfiguration config) { + static SyncConfig syncConfig(final BeaconChainConfiguration config) { return config.syncConfig(); } @Provides - static BeaconRestApiConfig beaconRestApiConfig(BeaconChainConfiguration config) { + static BeaconRestApiConfig beaconRestApiConfig(final BeaconChainConfiguration config) { return config.beaconRestApiConfig(); } @Provides - static WeakSubjectivityConfig weakSubjectivityConfig(BeaconChainConfiguration config) { + static WeakSubjectivityConfig weakSubjectivityConfig(final BeaconChainConfiguration config) { return config.weakSubjectivity(); } @Provides - static MetricsConfig metricsConfig(BeaconChainConfiguration config) { + static MetricsConfig metricsConfig(final BeaconChainConfiguration config) { return config.getMetricsConfig(); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java index 74adc84a43d..8ff97bb8ebf 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BeaconModule.java @@ -89,23 +89,23 @@ interface GenesisTimeTracker { @Provides @Singleton static EpochCachePrimer epochCachePrimer( - Spec spec, - RecentChainData recentChainData, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + final Spec spec, + final RecentChainData recentChainData, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner) { return new EpochCachePrimer(spec, recentChainData, beaconAsyncRunner); } @Provides @Singleton static SlotProcessor slotProcessor( - Spec spec, - RecentChainData recentChainData, - SyncService syncService, - ForkChoiceTrigger forkChoiceTrigger, - ForkChoiceNotifier forkChoiceNotifier, - Eth2P2PNetwork p2pNetwork, - SlotEventsChannel slotEventsChannelPublisher, - EpochCachePrimer epochCachePrimer) { + final Spec spec, + final RecentChainData recentChainData, + final SyncService syncService, + final ForkChoiceTrigger forkChoiceTrigger, + final ForkChoiceNotifier forkChoiceNotifier, + final Eth2P2PNetwork p2pNetwork, + final SlotEventsChannel slotEventsChannelPublisher, + final EpochCachePrimer epochCachePrimer) { return new SlotProcessor( spec, recentChainData, @@ -120,12 +120,12 @@ static SlotProcessor slotProcessor( @Provides @Singleton static BlockImporter blockImporter( - Spec spec, - RecentChainData recentChainData, - ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher, - ForkChoice forkChoice, - WeakSubjectivityValidator weakSubjectivityValidator, - ExecutionLayerChannel executionLayer) { + final Spec spec, + final RecentChainData recentChainData, + final ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher, + final ForkChoice forkChoice, + final WeakSubjectivityValidator weakSubjectivityValidator, + final ExecutionLayerChannel executionLayer) { return new BlockImporter( spec, receivedBlockEventsChannelPublisher, @@ -138,19 +138,20 @@ static BlockImporter blockImporter( @Provides @Singleton static BlockManager blockManager( - EventLogger eventLogger, - TimeProvider timeProvider, - RecentChainData recentChainData, - BlockValidator blockValidator, - BlockImporter blockImporter, - BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, - PendingPool pendingBlocks, - @InvalidBlockRoots Map invalidBlockRoots, - Optional blockImportMetrics, - FutureItems futureBlocks, - EventChannelSubscriber slotEventsChannelSubscriber, - EventChannelSubscriber blockImportChannelSubscriber, - EventChannelSubscriber receivedBlockEventsChannelSubscriber) { + final EventLogger eventLogger, + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final BlockValidator blockValidator, + final BlockImporter blockImporter, + final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + final PendingPool pendingBlocks, + @InvalidBlockRoots final Map invalidBlockRoots, + final Optional blockImportMetrics, + final FutureItems futureBlocks, + final EventChannelSubscriber slotEventsChannelSubscriber, + final EventChannelSubscriber blockImportChannelSubscriber, + final EventChannelSubscriber + receivedBlockEventsChannelSubscriber) { BlockManager blockManager = new BlockManager( @@ -175,14 +176,14 @@ static BlockManager blockManager( @Provides @Singleton static ProposersDataManager proposersDataManager( - Eth2NetworkConfiguration eth2NetworkConfig, - Spec spec, - MetricsSystem metricsSystem, - @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor, - ExecutionLayerChannel executionLayer, - RecentChainData recentChainData, - EventChannelSubscriber slotEventsChannelSubscriber, - @ProposerDefaultFeeRecipient Optional proposerDefaultFeeRecipient) { + final Eth2NetworkConfiguration eth2NetworkConfig, + final Spec spec, + final MetricsSystem metricsSystem, + @ForkChoiceNotifierExecutor final AsyncRunnerEventThread forkChoiceNotifierExecutor, + final ExecutionLayerChannel executionLayer, + final RecentChainData recentChainData, + final EventChannelSubscriber slotEventsChannelSubscriber, + @ProposerDefaultFeeRecipient final Optional proposerDefaultFeeRecipient) { ProposersDataManager proposersDataManager = new ProposersDataManager( @@ -200,14 +201,14 @@ static ProposersDataManager proposersDataManager( @Provides @Singleton static OperationsReOrgManager operationsReOrgManager( - OperationPool attesterSlashingPool, - OperationPool proposerSlashingPool, - OperationPool voluntaryExitPool, - AggregatingAttestationPool attestationPool, - AttestationManager attestationManager, - OperationPool blsToExecutionChangePool, - RecentChainData recentChainData, - EventChannelSubscriber chainHeadChannelSubscriber) { + final OperationPool attesterSlashingPool, + final OperationPool proposerSlashingPool, + final OperationPool voluntaryExitPool, + final AggregatingAttestationPool attestationPool, + final AttestationManager attestationManager, + final OperationPool blsToExecutionChangePool, + final RecentChainData recentChainData, + final EventChannelSubscriber chainHeadChannelSubscriber) { OperationsReOrgManager operationsReOrgManager = new OperationsReOrgManager( @@ -225,12 +226,12 @@ static OperationsReOrgManager operationsReOrgManager( @Provides @Singleton static TickHandler tickHandler( - TimeProvider timeProvider, - RecentChainData recentChainData, - ForkChoice forkChoice, - SlotProcessor slotProcessor, - TickProcessingPerformanceRecordFactory tickProcessingPerformanceRecordFactory, - GenesisTimeTracker genesisTimeTracker) { + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final ForkChoice forkChoice, + final SlotProcessor slotProcessor, + final TickProcessingPerformanceRecordFactory tickProcessingPerformanceRecordFactory, + final GenesisTimeTracker genesisTimeTracker) { return () -> { if (recentChainData.isPreGenesis()) { return; @@ -251,17 +252,17 @@ static TickHandler tickHandler( @Provides @Singleton - static TimerService timerService(TickHandler tickHandler) { + static TimerService timerService(final TickHandler tickHandler) { return new TimerService(tickHandler::onTick); } @Provides @Singleton static GenesisTimeTracker genesisTimeTracker( - TimeProvider timeProvider, - RecentChainData recentChainData, - Eth2P2PNetwork p2pNetwork, - StatusLogger statusLogger) { + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final Eth2P2PNetwork p2pNetwork, + final StatusLogger statusLogger) { return new GenesisTimeTracker() { private UInt64 lastUpdateTime = UInt64.ZERO; @@ -284,7 +285,7 @@ public void update() { @Provides @Singleton - static TickProcessor tickProcessor(Spec spec, RecentChainData recentChainData) { + static TickProcessor tickProcessor(final Spec spec, final RecentChainData recentChainData) { return new TickProcessor(spec, recentChainData); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java index ffda44f5e30..ba2e2314353 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/BlobModule.java @@ -45,10 +45,10 @@ public interface BlobModule { @Provides @Singleton static BlobSidecarGossipValidator blobSidecarGossipValidator( - Spec spec, - KZG kzg, - @InvalidBlockRoots Map invalidBlockRoots, - GossipValidationHelper gossipValidationHelper) { + final Spec spec, + final KZG kzg, + @InvalidBlockRoots final Map invalidBlockRoots, + final GossipValidationHelper gossipValidationHelper) { final MiscHelpersDeneb miscHelpers = MiscHelpersDeneb.required(spec.forMilestone(SpecMilestone.DENEB).miscHelpers()); return BlobSidecarGossipValidator.create( @@ -58,15 +58,15 @@ static BlobSidecarGossipValidator blobSidecarGossipValidator( @Provides @Singleton static BlobSidecarManager blobSidecarManager( - Spec spec, - KZG kzg, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, - RecentChainData recentChainData, - EventChannelSubscriber slotEventsChannelSubscriber, - BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, - BlobSidecarGossipValidator blobSidecarGossipValidator, - @InvalidBlobSidecarRoots Map invalidBlobSidecarRoots, - FutureItems futureBlobSidecars) { + final Spec spec, + final KZG kzg, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner, + final RecentChainData recentChainData, + final EventChannelSubscriber slotEventsChannelSubscriber, + final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + final BlobSidecarGossipValidator blobSidecarGossipValidator, + @InvalidBlobSidecarRoots final Map invalidBlobSidecarRoots, + final FutureItems futureBlobSidecars) { if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { final BlobSidecarManagerImpl blobSidecarManagerImpl = new BlobSidecarManagerImpl( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java index d942f188d34..22a56557629 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ChannelsModule.java @@ -46,58 +46,60 @@ public interface ChannelsModule { // Publishers @Provides - static SlotEventsChannel slotEventsChannel(EventChannels eventChannels) { + static SlotEventsChannel slotEventsChannel(final EventChannels eventChannels) { return eventChannels.getPublisher(SlotEventsChannel.class); } @Provides static ExecutionLayerChannel executionLayerChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(ExecutionLayerChannel.class, asyncRunner); } @Provides static BlockImportChannel blockImportChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(BlockImportChannel.class, asyncRunner); } @Provides static CombinedStorageChannel combinedStorageChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(CombinedStorageChannel.class, asyncRunner); } @Provides static ValidatorApiChannel validatorApiChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(ValidatorApiChannel.class, asyncRunner); } @Provides static ActiveValidatorChannel activeValidatorChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(ActiveValidatorChannel.class, asyncRunner); } @Provides static Eth1DepositStorageChannel eth1DepositStorageChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(Eth1DepositStorageChannel.class, asyncRunner); } @Provides - static ExecutionClientVersionChannel executionClientVersionChannel(EventChannels eventChannels) { + static ExecutionClientVersionChannel executionClientVersionChannel( + final EventChannels eventChannels) { return eventChannels.getPublisher(ExecutionClientVersionChannel.class); } @Provides - static BlockGossipChannel blockGossipChannel(EventChannels eventChannels) { + static BlockGossipChannel blockGossipChannel(final EventChannels eventChannels) { return eventChannels.getPublisher(BlockGossipChannel.class); } @Provides - static BlobSidecarGossipChannel blobSidecarGossipChannel(EventChannels eventChannels, Spec spec) { + static BlobSidecarGossipChannel blobSidecarGossipChannel( + final EventChannels eventChannels, final Spec spec) { if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { return eventChannels.getPublisher(BlobSidecarGossipChannel.class); } else { @@ -106,28 +108,28 @@ static BlobSidecarGossipChannel blobSidecarGossipChannel(EventChannels eventChan } @Provides - static ReceivedBlockEventsChannel receivedBlockEventsChannel(EventChannels eventChannels) { + static ReceivedBlockEventsChannel receivedBlockEventsChannel(final EventChannels eventChannels) { return eventChannels.getPublisher(ReceivedBlockEventsChannel.class); } @Provides - static ChainHeadChannel chainHeadChannel(EventChannels eventChannels) { + static ChainHeadChannel chainHeadChannel(final EventChannels eventChannels) { return eventChannels.getPublisher(ChainHeadChannel.class); } @Provides - static VoteUpdateChannel voteUpdateChannel(EventChannels eventChannels) { + static VoteUpdateChannel voteUpdateChannel(final EventChannels eventChannels) { return eventChannels.getPublisher(VoteUpdateChannel.class); } @Provides static FinalizedCheckpointChannel finalizedCheckpointChannel( - EventChannels eventChannels, @BeaconAsyncRunner AsyncRunner asyncRunner) { + final EventChannels eventChannels, @BeaconAsyncRunner final AsyncRunner asyncRunner) { return eventChannels.getPublisher(FinalizedCheckpointChannel.class, asyncRunner); } @Provides - static ValidatorTimingChannel validatorTimingChannel(EventChannels eventChannels) { + static ValidatorTimingChannel validatorTimingChannel(final EventChannels eventChannels) { return eventChannels.getPublisher(ValidatorTimingChannel.class); } @@ -135,55 +137,55 @@ static ValidatorTimingChannel validatorTimingChannel(EventChannels eventChannels @Provides static EventChannelSubscriber slotEventsChannelSubscriber( - EventChannels eventChannels) { + final EventChannels eventChannels) { return eventChannels.createSubscriber(SlotEventsChannel.class); } @Provides static EventChannelSubscriber finalizedCheckpointChannelSubscriber( - EventChannels eventChannels) { + final EventChannels eventChannels) { return eventChannels.createSubscriber(FinalizedCheckpointChannel.class); } @Provides static EventChannelSubscriber chainHeadChannelSubscriber( - EventChannels eventChannels) { + final EventChannels eventChannels) { return eventChannels.createSubscriber(ChainHeadChannel.class); } @Provides static EventChannelSubscriber eth1EventsChannelSubscriber( - EventChannels eventChannels) { + final EventChannels eventChannels) { return eventChannels.createSubscriber(Eth1EventsChannel.class); } @Provides static EventChannelSubscriber - executionClientVersionChannelSubscriber(EventChannels eventChannels) { + executionClientVersionChannelSubscriber(final EventChannels eventChannels) { return eventChannels.createSubscriber(ExecutionClientVersionChannel.class); } @Provides static EventChannelSubscriber - executionClientEventsChannelSubscriber(EventChannels eventChannels) { + executionClientEventsChannelSubscriber(final EventChannels eventChannels) { return eventChannels.createSubscriber(ExecutionClientEventsChannel.class); } @Provides static EventChannelSubscriber receivedBlockEventsChannelSubscriber( - EventChannels eventChannels) { + final EventChannels eventChannels) { return eventChannels.createSubscriber(ReceivedBlockEventsChannel.class); } @Provides static EventChannelSubscriber blockImportChannelSubscriber( - EventChannels eventChannels) { + final EventChannels eventChannels) { return eventChannels.createSubscriber(BlockImportChannel.class); } @Provides static EventChannelSubscriber validatorApiChannelSubscriber( - EventChannels eventChannels, BeaconRestApiConfig beaconRestApiConfig) { + final EventChannels eventChannels, final BeaconRestApiConfig beaconRestApiConfig) { return eventChannels.createSubscriberMultithreaded( ValidatorApiChannel.class, beaconRestApiConfig.getValidatorThreads()); } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java index 6df42134fd2..c5b6c379e23 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/CryptoModule.java @@ -35,10 +35,10 @@ public interface CryptoModule { @Provides @Singleton static SignatureVerificationService signatureVerificationService( - P2PConfig p2PConfig, - MetricsSystem metricsSystem, - AsyncRunnerFactory asyncRunnerFactory, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + final P2PConfig p2PConfig, + final MetricsSystem metricsSystem, + final AsyncRunnerFactory asyncRunnerFactory, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner) { return new AggregatingSignatureVerificationService( metricsSystem, asyncRunnerFactory, @@ -51,7 +51,7 @@ static SignatureVerificationService signatureVerificationService( @Provides @Singleton - static KZG kzg(Eth2NetworkConfiguration eth2NetworkConfig, Spec spec) { + static KZG kzg(final Eth2NetworkConfiguration eth2NetworkConfig, final Spec spec) { if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { KZG kzg = KZG.getInstance(); final String trustedSetupFile = diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java index 08c913721c6..a25f14332d2 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/DataProviderModule.java @@ -64,15 +64,16 @@ record LivenessTrackingStatus(boolean enabled) {} @Provides @Singleton static Eth1DataProvider eth1DataProvider( - Eth1DataCache eth1DataCache, DepositProvider depositProvider) { + final Eth1DataCache eth1DataCache, final DepositProvider depositProvider) { return new Eth1DataProvider(eth1DataCache, depositProvider); } @Provides @Singleton static ExecutionClientDataProvider executionClientDataProvider( - DataProvider dataProvider, - EventChannelSubscriber executionClientEventsChannelSubscriber) { + final DataProvider dataProvider, + final EventChannelSubscriber + executionClientEventsChannelSubscriber) { final ExecutionClientDataProvider executionClientDataProvider = dataProvider.getExecutionClientDataProvider(); @@ -83,15 +84,15 @@ static ExecutionClientDataProvider executionClientDataProvider( @Provides @Singleton static Optional beaconRestApi( - InitLogger initLogger, - Spec spec, - BeaconRestApiConfig beaconRestApiConfig, - @EventAsyncRunner AsyncRunner eventAsyncRunner, - TimeProvider timeProvider, - Eth1DataProvider eth1DataProvider, - DataProvider dataProvider, - EventChannels eventChannels, - LivenessTrackingStatus livenessTrackingStatus) { + final InitLogger initLogger, + final Spec spec, + final BeaconRestApiConfig beaconRestApiConfig, + @EventAsyncRunner final AsyncRunner eventAsyncRunner, + final TimeProvider timeProvider, + final Eth1DataProvider eth1DataProvider, + final DataProvider dataProvider, + final EventChannels eventChannels, + final LivenessTrackingStatus livenessTrackingStatus) { if (!beaconRestApiConfig.isRestApiEnabled()) { initLogger.logger().info("rest-api-enabled is false, not starting rest api."); return Optional.empty(); @@ -119,26 +120,26 @@ static Optional beaconRestApi( @Provides @Singleton static DataProvider dataProvider( - Spec spec, - RecentChainData recentChainData, - CombinedChainDataClient combinedChainDataClient, - RewardCalculator rewardCalculator, - Eth2P2PNetwork p2pNetwork, - SyncService syncService, - ValidatorApiChannel validatorApiChannel, - ActiveValidatorChannel activeValidatorChannel, - AggregatingAttestationPool attestationPool, - BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, - AttestationManager attestationManager, - OperationPool attesterSlashingPool, - OperationPool proposerSlashingPool, - OperationPool voluntaryExitPool, - OperationPool blsToExecutionChangePool, - SyncCommitteeContributionPool syncCommitteeContributionPool, - ProposersDataManager proposersDataManager, - ForkChoiceNotifier forkChoiceNotifier, - LivenessTrackingStatus livenessTrackingStatus, - @RejectedExecutionCountSupplier IntSupplier rejectedExecutionCountSupplier) { + final Spec spec, + final RecentChainData recentChainData, + final CombinedChainDataClient combinedChainDataClient, + final RewardCalculator rewardCalculator, + final Eth2P2PNetwork p2pNetwork, + final SyncService syncService, + final ValidatorApiChannel validatorApiChannel, + final ActiveValidatorChannel activeValidatorChannel, + final AggregatingAttestationPool attestationPool, + final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + final AttestationManager attestationManager, + final OperationPool attesterSlashingPool, + final OperationPool proposerSlashingPool, + final OperationPool voluntaryExitPool, + final OperationPool blsToExecutionChangePool, + final SyncCommitteeContributionPool syncCommitteeContributionPool, + final ProposersDataManager proposersDataManager, + final ForkChoiceNotifier forkChoiceNotifier, + final LivenessTrackingStatus livenessTrackingStatus, + @RejectedExecutionCountSupplier final IntSupplier rejectedExecutionCountSupplier) { // TODO adopt Dagger instead of DataProvider.builder() return DataProvider.builder() @@ -166,7 +167,8 @@ static DataProvider dataProvider( } @Provides - static LivenessTrackingStatus livenessTrackingStatus(BeaconChainConfiguration beaconConfig) { + static LivenessTrackingStatus livenessTrackingStatus( + final BeaconChainConfiguration beaconConfig) { return new LivenessTrackingStatus( beaconConfig.beaconRestApiConfig().isBeaconLivenessTrackingEnabled() || beaconConfig.validatorConfig().isDoppelgangerDetectionEnabled()); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java index 58cbaece0e9..f8715a00814 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ExternalDependenciesModule.java @@ -25,7 +25,7 @@ public class ExternalDependenciesModule { private final BeaconChainConfiguration beaconConfig; public ExternalDependenciesModule( - ServiceConfig serviceConfig, BeaconChainConfiguration beaconConfig) { + final ServiceConfig serviceConfig, final BeaconChainConfiguration beaconConfig) { this.serviceConfig = serviceConfig; this.beaconConfig = beaconConfig; } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java index dc627de3b08..2ff5f9d93de 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ForkChoiceModule.java @@ -42,17 +42,17 @@ public interface ForkChoiceModule { @Provides @Singleton static ForkChoice forkChoice( - Spec spec, - Eth2NetworkConfiguration eth2NetworkConfig, - @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, - MetricsSystem metricsSystem, - RecentChainData recentChainData, - BlobSidecarManager blobSidecarManager, - ForkChoiceNotifier forkChoiceNotifier, - ForkChoiceStateProvider forkChoiceStateProvider, - DebugDataDumper debugDataDumper, - TickProcessor tickProcessor, - MergeTransitionBlockValidator mergeTransitionBlockValidator) { + final Spec spec, + final Eth2NetworkConfiguration eth2NetworkConfig, + @ForkChoiceExecutor final AsyncRunnerEventThread forkChoiceExecutor, + final MetricsSystem metricsSystem, + final RecentChainData recentChainData, + final BlobSidecarManager blobSidecarManager, + final ForkChoiceNotifier forkChoiceNotifier, + final ForkChoiceStateProvider forkChoiceStateProvider, + final DebugDataDumper debugDataDumper, + final TickProcessor tickProcessor, + final MergeTransitionBlockValidator mergeTransitionBlockValidator) { return new ForkChoice( spec, forkChoiceExecutor, @@ -69,28 +69,28 @@ static ForkChoice forkChoice( @Provides @Singleton - static ForkChoiceTrigger forkChoiceTrigger(ForkChoice forkChoice) { + static ForkChoiceTrigger forkChoiceTrigger(final ForkChoice forkChoice) { return new ForkChoiceTrigger(forkChoice); } @Provides @Singleton static ForkChoiceStateProvider forkChoiceStateProvider( - @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, - RecentChainData recentChainData) { + @ForkChoiceExecutor final AsyncRunnerEventThread forkChoiceExecutor, + final RecentChainData recentChainData) { return new ForkChoiceStateProvider(forkChoiceExecutor, recentChainData); } @Provides @Singleton static ForkChoiceNotifier forkChoiceNotifier( - Spec spec, - @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor, - TimeProvider timeProvider, - ProposersDataManager proposersDataManager, - ExecutionLayerChannel executionLayer, - RecentChainData recentChainData, - ForkChoiceStateProvider forkChoiceStateProvider) { + final Spec spec, + @ForkChoiceNotifierExecutor final AsyncRunnerEventThread forkChoiceNotifierExecutor, + final TimeProvider timeProvider, + final ProposersDataManager proposersDataManager, + final ExecutionLayerChannel executionLayer, + final RecentChainData recentChainData, + final ForkChoiceStateProvider forkChoiceStateProvider) { return new ForkChoiceNotifierImpl( forkChoiceStateProvider, diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java index 39ac6ed2c84..922a340c269 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MainModule.java @@ -72,10 +72,10 @@ interface ServiceStopper { @Provides @IntoSet static VoidInitializer initSlashingEventsSubscriptions( - ValidatorConfig validatorConfig, - ValidatorTimingChannel validatorTimingChannel, - OperationPool attesterSlashingPool, - OperationPool proposerSlashingPool) { + final ValidatorConfig validatorConfig, + final ValidatorTimingChannel validatorTimingChannel, + final OperationPool attesterSlashingPool, + final OperationPool proposerSlashingPool) { if (validatorConfig.isShutdownWhenValidatorSlashedEnabled()) { attesterSlashingPool.subscribeOperationAdded( (operation, validationStatus, fromNetwork) -> @@ -90,10 +90,10 @@ static VoidInitializer initSlashingEventsSubscriptions( @Provides @IntoSet static VoidInitializer initGenesisHandler( - RecentChainData recentChainData, - Lazy genesisHandler, - PowchainConfiguration powchainConfig, - StatusLogger statusLogger) { + final RecentChainData recentChainData, + final Lazy genesisHandler, + final PowchainConfiguration powchainConfig, + final StatusLogger statusLogger) { if (!recentChainData.isPreGenesis()) { // We already have a genesis block - no need for a genesis handler } else if (!powchainConfig.isEnabled()) { @@ -109,7 +109,8 @@ static VoidInitializer initGenesisHandler( @Provides @IntoSet @SuppressWarnings("UnusedVariable") - static VoidInitializer initOperationsReOrgManager(OperationsReOrgManager operationsReOrgManager) { + static VoidInitializer initOperationsReOrgManager( + final OperationsReOrgManager operationsReOrgManager) { return new VoidInitializer(); } @@ -117,14 +118,14 @@ static VoidInitializer initOperationsReOrgManager(OperationsReOrgManager operati @IntoSet @SuppressWarnings("UnusedVariable") static VoidInitializer initValidatorIndexCacheTracker( - ValidatorIndexCacheTracker validatorIndexCacheTracker) { + final ValidatorIndexCacheTracker validatorIndexCacheTracker) { return new VoidInitializer(); } @Provides @IntoSet @SuppressWarnings("UnusedVariable") - static VoidInitializer initRecentBlocksFetcher(RecentBlocksFetcher recentBlocksFetcher) { + static VoidInitializer initRecentBlocksFetcher(final RecentBlocksFetcher recentBlocksFetcher) { return new VoidInitializer(); } @@ -132,14 +133,16 @@ static VoidInitializer initRecentBlocksFetcher(RecentBlocksFetcher recentBlocksF @IntoSet @SuppressWarnings("UnusedVariable") static VoidInitializer initRecentBlobSidecarsFetcher( - RecentBlobSidecarsFetcher recentBlobSidecarsFetcher) { + final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher) { return new VoidInitializer(); } @Provides @IntoSet static VoidInitializer subscribeFailedPayloadExecution( - Spec spec, BlockManager blockManager, FailedExecutionPool failedExecutionPool) { + final Spec spec, + final BlockManager blockManager, + final FailedExecutionPool failedExecutionPool) { if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { blockManager.subscribeFailedPayloadExecution(failedExecutionPool::addFailedBlock); } @@ -149,8 +152,8 @@ static VoidInitializer subscribeFailedPayloadExecution( @Provides @IntoSet static VoidInitializer subscribeOnStoreInitialized( - RecentChainData recentChainData, - StorageModule.OnStoreInitializedHandler onStoreInitializedHandler) { + final RecentChainData recentChainData, + final StorageModule.OnStoreInitializedHandler onStoreInitializedHandler) { recentChainData.subscribeStoreInitialized(onStoreInitializedHandler::handle); return new VoidInitializer(); @@ -160,15 +163,15 @@ static VoidInitializer subscribeOnStoreInitialized( @Singleton @SuppressWarnings("UnusedVariable") static ServiceStarter serviceStarter( - Set allInitializers, - Optional beaconRestApi, - SyncService syncService, - BlockManager blockManager, - AttestationManager attestationManager, - Eth2P2PNetwork p2pNetwork, - TimerService timerService, - Optional terminalPowBlockMonitor, - InitLogger initLogger) { + final Set allInitializers, + final Optional beaconRestApi, + final SyncService syncService, + final BlockManager blockManager, + final AttestationManager attestationManager, + final Eth2P2PNetwork p2pNetwork, + final TimerService timerService, + final Optional terminalPowBlockMonitor, + final InitLogger initLogger) { return () -> SafeFuture.fromRunnable(() -> initLogger.logger().info("Starting BeaconChain services")) .thenCompose( @@ -194,15 +197,15 @@ static ServiceStarter serviceStarter( @Provides @Singleton static ServiceStopper serviceStopper( - Optional beaconRestApi, - SyncService syncService, - BlockManager blockManager, - AttestationManager attestationManager, - Eth2P2PNetwork p2pNetwork, - TimerService timerService, - Optional terminalPowBlockMonitor, - @ForkChoiceExecutor AsyncRunnerEventThread forkChoiceExecutor, - @ForkChoiceNotifierExecutor AsyncRunnerEventThread forkChoiceNotifierExecutor) { + final Optional beaconRestApi, + final SyncService syncService, + final BlockManager blockManager, + final AttestationManager attestationManager, + final Eth2P2PNetwork p2pNetwork, + final TimerService timerService, + final Optional terminalPowBlockMonitor, + @ForkChoiceExecutor final AsyncRunnerEventThread forkChoiceExecutor, + @ForkChoiceNotifierExecutor final AsyncRunnerEventThread forkChoiceNotifierExecutor) { return () -> SafeFuture.allOf( beaconRestApi.map(BeaconRestApi::stop).orElse(SafeFuture.completedFuture(null)), diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java index e338fbea957..1b478b68cbd 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/MetricsModule.java @@ -77,7 +77,7 @@ interface TickProcessingPerformanceRecordFactory { @Provides @Singleton @FutureItemsMetric - static SettableLabelledGauge futureItemsMetric(MetricsSystem metricsSystem) { + static SettableLabelledGauge futureItemsMetric(final MetricsSystem metricsSystem) { return SettableLabelledGauge.create( metricsSystem, BEACON, @@ -89,7 +89,7 @@ static SettableLabelledGauge futureItemsMetric(MetricsSystem metricsSystem) { @Provides @Singleton @SubnetSubscriptionsMetric - static SettableLabelledGauge subnetSubscriptionsMetric(MetricsSystem metricsSystem) { + static SettableLabelledGauge subnetSubscriptionsMetric(final MetricsSystem metricsSystem) { return SettableLabelledGauge.create( metricsSystem, TekuMetricCategory.NETWORK, @@ -101,7 +101,7 @@ static SettableLabelledGauge subnetSubscriptionsMetric(MetricsSystem metricsSyst @Provides @Singleton @PerformanceTrackerTimings - static SettableGauge performanceTrackerTimings(MetricsSystem metricsSystem) { + static SettableGauge performanceTrackerTimings(final MetricsSystem metricsSystem) { return SettableGauge.create( metricsSystem, BEACON, @@ -112,27 +112,28 @@ static SettableGauge performanceTrackerTimings(MetricsSystem metricsSystem) { @Provides @Singleton static FutureItems futureBlobSidecars( - @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { + @FutureItemsMetric final SettableLabelledGauge futureItemsMetric) { return FutureItems.create(BlobSidecar::getSlot, futureItemsMetric, "blob_sidecars"); } @Provides @Singleton - static ValidatorPerformanceMetrics validatorPerformanceMetrics(MetricsSystem metricsSystem) { + static ValidatorPerformanceMetrics validatorPerformanceMetrics( + final MetricsSystem metricsSystem) { return new ValidatorPerformanceMetrics(metricsSystem); } @Provides @Singleton static PerformanceTracker performanceTracker( - Spec spec, - ValidatorConfig validatorConfig, - CombinedChainDataClient combinedChainDataClient, - @PerformanceTrackerTimings SettableGauge performanceTrackerTimings, - EventChannelSubscriber slotEventsChannelSubscriber, - ValidatorPerformanceMetrics validatorPerformanceMetrics, - ActiveValidatorTracker activeValidatorTracker, - StatusLogger statusLogger) { + final Spec spec, + final ValidatorConfig validatorConfig, + final CombinedChainDataClient combinedChainDataClient, + @PerformanceTrackerTimings final SettableGauge performanceTrackerTimings, + final EventChannelSubscriber slotEventsChannelSubscriber, + final ValidatorPerformanceMetrics validatorPerformanceMetrics, + final ActiveValidatorTracker activeValidatorTracker, + final StatusLogger statusLogger) { ValidatorPerformanceTrackingMode mode = validatorConfig.getValidatorPerformanceTrackingMode(); if (mode.isEnabled()) { DefaultPerformanceTracker performanceTracker = @@ -156,11 +157,11 @@ static PerformanceTracker performanceTracker( @Provides @Singleton static SyncCommitteeMetrics syncCommitteeMetrics( - Spec spec, - RecentChainData recentChainData, - MetricsSystem metricsSystem, - EventChannelSubscriber slotEventsChannelSubscriber, - EventChannelSubscriber chainHeadChannelSubscriber) { + final Spec spec, + final RecentChainData recentChainData, + final MetricsSystem metricsSystem, + final EventChannelSubscriber slotEventsChannelSubscriber, + final EventChannelSubscriber chainHeadChannelSubscriber) { SyncCommitteeMetrics syncCommitteeMetrics = new SyncCommitteeMetrics(spec, recentChainData, metricsSystem); slotEventsChannelSubscriber.subscribe(syncCommitteeMetrics); @@ -172,13 +173,13 @@ static SyncCommitteeMetrics syncCommitteeMetrics( @Provides @Singleton static BeaconChainMetrics beaconChainMetrics( - Spec spec, - MetricsSystem metricsSystem, - RecentChainData recentChainData, - SlotProcessor slotProcessor, - Eth2P2PNetwork p2pNetwork, - Eth1DataCache eth1DataCache, - EventChannelSubscriber slotEventsChannelSubscriber) { + final Spec spec, + final MetricsSystem metricsSystem, + final RecentChainData recentChainData, + final SlotProcessor slotProcessor, + final Eth2P2PNetwork p2pNetwork, + final Eth1DataCache eth1DataCache, + final EventChannelSubscriber slotEventsChannelSubscriber) { final BeaconChainMetrics beaconChainMetrics = new BeaconChainMetrics( @@ -196,7 +197,9 @@ static BeaconChainMetrics beaconChainMetrics( @Singleton static BlockProductionAndPublishingPerformanceFactory blockProductionAndPublishingPerformanceFactory( - TimeProvider timeProvider, RecentChainData recentChainData, MetricsConfig metricsConfig) { + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final MetricsConfig metricsConfig) { return new BlockProductionAndPublishingPerformanceFactory( timeProvider, (slot) -> secondsToMillis(recentChainData.computeTimeAtSlot(slot)), @@ -210,17 +213,17 @@ static BeaconChainMetrics beaconChainMetrics( @Provides @Singleton static DutyMetrics dutyMetrics( - MetricsSystem metricsSystem, - Spec spec, - TimeProvider timeProvider, - RecentChainData recentChainData) { + final MetricsSystem metricsSystem, + final Spec spec, + final TimeProvider timeProvider, + final RecentChainData recentChainData) { return DutyMetrics.create(metricsSystem, timeProvider, recentChainData, spec); } @Provides @Singleton static FutureItems futureAttestations( - @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { + @FutureItemsMetric final SettableLabelledGauge futureItemsMetric) { return FutureItems.create( ValidatableAttestation::getEarliestSlotForForkChoiceProcessing, UInt64.valueOf(3), @@ -231,14 +234,14 @@ static FutureItems futureAttestations( @Provides @Singleton static FutureItems futureBlocks( - @FutureItemsMetric SettableLabelledGauge futureItemsMetric) { + @FutureItemsMetric final SettableLabelledGauge futureItemsMetric) { return FutureItems.create(SignedBeaconBlock::getSlot, futureItemsMetric, "blocks"); } @Provides @Singleton static Optional blockImportMetrics( - MetricsConfig metricsConfig, MetricsSystem metricsSystem) { + final MetricsConfig metricsConfig, final MetricsSystem metricsSystem) { return metricsConfig.isBlockPerformanceEnabled() ? Optional.of(BlockImportMetrics.create(metricsSystem)) : Optional.empty(); @@ -247,7 +250,7 @@ static Optional blockImportMetrics( @Provides @Singleton static TickProcessingPerformanceRecordFactory tickProcessingPerformanceRecordFactory( - TimeProvider timeProvider, MetricsConfig metricsConfig) { + final TimeProvider timeProvider, final MetricsConfig metricsConfig) { return () -> metricsConfig.isTickPerformanceEnabled() ? Optional.of( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java index abd4fb5f545..1b668c2f8e8 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/NetworkModule.java @@ -60,27 +60,27 @@ static Eth2P2PNetworkBuilder eth2P2PNetworkBuilder() { @Provides @Singleton static Eth2P2PNetwork eth2P2PNetwork( - Spec spec, - P2PConfig p2pConfig, - MetricsSystem metricsSystem, - @NetworkAsyncRunner AsyncRunner networkAsyncRunner, - TimeProvider timeProvider, - EventChannels eventChannels, - KeyValueStore keyValueStore, - Eth2P2PNetworkBuilder eth2P2PNetworkBuilder, - CombinedChainDataClient combinedChainDataClient, - BlockManager blockManager, - BlobSidecarManager blobSidecarManager, - AttestationManager attestationManager, - OperationPool attesterSlashingPool, - OperationPool proposerSlashingPool, - OperationPool voluntaryExitPool, - SyncCommitteeContributionPool syncCommitteeContributionPool, - SyncCommitteeMessagePool syncCommitteeMessagePool, - OperationPool blsToExecutionChangePool, - KZG kzg, - WeakSubjectivityValidator weakSubjectivityValidator, - DebugDataDumper p2pDebugDataDumper) { + final Spec spec, + final P2PConfig p2pConfig, + final MetricsSystem metricsSystem, + @NetworkAsyncRunner final AsyncRunner networkAsyncRunner, + final TimeProvider timeProvider, + final EventChannels eventChannels, + final KeyValueStore keyValueStore, + final Eth2P2PNetworkBuilder eth2P2PNetworkBuilder, + final CombinedChainDataClient combinedChainDataClient, + final BlockManager blockManager, + final BlobSidecarManager blobSidecarManager, + final AttestationManager attestationManager, + final OperationPool attesterSlashingPool, + final OperationPool proposerSlashingPool, + final OperationPool voluntaryExitPool, + final SyncCommitteeContributionPool syncCommitteeContributionPool, + final SyncCommitteeMessagePool syncCommitteeMessagePool, + final OperationPool blsToExecutionChangePool, + final KZG kzg, + final WeakSubjectivityValidator weakSubjectivityValidator, + final DebugDataDumper p2pDebugDataDumper) { if (!p2pConfig.getNetworkConfig().isEnabled()) { return new NoOpEth2P2PNetwork(spec); } @@ -141,7 +141,7 @@ static Eth2P2PNetwork eth2P2PNetwork( @Provides @Singleton - static DebugDataDumper debugDataDumper(DataDirLayout dataDirLayout) { + static DebugDataDumper debugDataDumper(final DataDirLayout dataDirLayout) { return dataDirLayout.isDebugDataDumpingEnabled() ? new DebugDataFileDumper(dataDirLayout.getDebugDataDirectory()) : DebugDataDumper.NOOP; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java index ec9fec5627c..8f2d65b7913 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PoolAndCachesModule.java @@ -79,16 +79,16 @@ public interface PoolAndCachesModule { @Provides @Singleton - static PoolFactory poolFactory(MetricsSystem metricsSystem) { + static PoolFactory poolFactory(final MetricsSystem metricsSystem) { return new PoolFactory(metricsSystem); } @Provides @Singleton static PendingPool pendingBlocksPool( - Spec spec, - PoolFactory poolFactory, - EventChannelSubscriber channelSubscriber) { + final Spec spec, + final PoolFactory poolFactory, + final EventChannelSubscriber channelSubscriber) { PendingPool pool = poolFactory.createPendingPoolForBlocks(spec); channelSubscriber.subscribe(pool); return pool; @@ -111,13 +111,14 @@ static Map invalidBlobSidecarRoots() { @Provides @Singleton static BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool( - Spec spec, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, - TimeProvider timeProvider, - RecentChainData recentChainData, - BlockImportChannel blockImportChannel, - PoolFactory poolFactory, - EventChannelSubscriber finalizedCheckpointChannelSubscriber) { + final Spec spec, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner, + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final BlockImportChannel blockImportChannel, + final PoolFactory poolFactory, + final EventChannelSubscriber + finalizedCheckpointChannelSubscriber) { if (spec.isMilestoneSupported(SpecMilestone.DENEB)) { final BlockBlobSidecarsTrackersPoolImpl pool = poolFactory.createPoolForBlockBlobSidecarsTrackers( @@ -132,11 +133,11 @@ static BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool( @Provides @Singleton static OperationPool attesterSlashingPool( - MetricsSystem metricsSystem, - SchemaSupplier> beaconBlockSchemaSupplier, - BlockImporter blockImporter, - AttesterSlashingValidator attesterSlashingValidator, - ForkChoice forkChoice) { + final MetricsSystem metricsSystem, + final SchemaSupplier> beaconBlockSchemaSupplier, + final BlockImporter blockImporter, + final AttesterSlashingValidator attesterSlashingValidator, + final ForkChoice forkChoice) { OperationPool attesterSlashingPool = new SimpleOperationPool<>( "AttesterSlashingPool", @@ -155,10 +156,10 @@ static OperationPool attesterSlashingPool( @Provides @Singleton static OperationPool proposerSlashingPool( - MetricsSystem metricsSystem, - SchemaSupplier> beaconBlockSchemaSupplier, - BlockImporter blockImporter, - ProposerSlashingValidator validator) { + final MetricsSystem metricsSystem, + final SchemaSupplier> beaconBlockSchemaSupplier, + final BlockImporter blockImporter, + final ProposerSlashingValidator validator) { SimpleOperationPool proposerSlashingPool = new SimpleOperationPool<>( "ProposerSlashingPool", @@ -172,12 +173,12 @@ static OperationPool proposerSlashingPool( @Provides @Singleton static OperationPool voluntaryExitPool( - MetricsSystem metricsSystem, - @OperationPoolAsyncRunner AsyncRunner operationPoolAsyncRunner, - TimeProvider timeProvider, - SchemaSupplier> beaconBlockSchemaSupplier, - BlockImporter blockImporter, - VoluntaryExitValidator validator) { + final MetricsSystem metricsSystem, + @OperationPoolAsyncRunner final AsyncRunner operationPoolAsyncRunner, + final TimeProvider timeProvider, + final SchemaSupplier> beaconBlockSchemaSupplier, + final BlockImporter blockImporter, + final VoluntaryExitValidator validator) { MappedOperationPool voluntaryExitPool = new MappedOperationPool<>( "VoluntaryExitPool", @@ -193,12 +194,12 @@ static OperationPool voluntaryExitPool( @Provides @Singleton static OperationPool signedBlsToExecutionChangePool( - MetricsSystem metricsSystem, - @OperationPoolAsyncRunner AsyncRunner operationPoolAsyncRunner, - TimeProvider timeProvider, - SchemaSupplier> beaconBlockSchemaSupplier, - BlockImporter blockImporter, - SignedBlsToExecutionChangeValidator validator) { + final MetricsSystem metricsSystem, + @OperationPoolAsyncRunner final AsyncRunner operationPoolAsyncRunner, + final TimeProvider timeProvider, + final SchemaSupplier> beaconBlockSchemaSupplier, + final BlockImporter blockImporter, + final SignedBlsToExecutionChangeValidator validator) { OperationPool blsToExecutionChangePool = new MappedOperationPool<>( "SignedBlsToExecutionChangePool", @@ -218,9 +219,10 @@ static OperationPool signedBlsToExecutionChangePool( @Provides @Singleton static PendingPool pendingAttestationPool( - Spec spec, - PoolFactory poolFactory, - EventChannelSubscriber finalizedCheckpointChannelSubscriber) { + final Spec spec, + final PoolFactory poolFactory, + final EventChannelSubscriber + finalizedCheckpointChannelSubscriber) { final PendingPool pendingAttestations = poolFactory.createPendingPoolForAttestations(spec); finalizedCheckpointChannelSubscriber.subscribe(pendingAttestations); @@ -230,9 +232,9 @@ static PendingPool pendingAttestationPool( @Provides @Singleton static SyncCommitteeContributionPool syncCommitteeContributionPool( - Spec spec, - SignedContributionAndProofValidator signedContributionAndProofValidator, - EventChannelSubscriber slotEventsChannelSubscriber) { + final Spec spec, + final SignedContributionAndProofValidator signedContributionAndProofValidator, + final EventChannelSubscriber slotEventsChannelSubscriber) { SyncCommitteeContributionPool syncCommitteeContributionPool = new SyncCommitteeContributionPool(spec, signedContributionAndProofValidator); @@ -243,9 +245,9 @@ static SyncCommitteeContributionPool syncCommitteeContributionPool( @Provides @Singleton static SyncCommitteeMessagePool syncCommitteeMessagePool( - Spec spec, - SyncCommitteeMessageValidator syncCommitteeMessageValidator, - EventChannelSubscriber slotEventsChannelSubscriber) { + final Spec spec, + final SyncCommitteeMessageValidator syncCommitteeMessageValidator, + final EventChannelSubscriber slotEventsChannelSubscriber) { SyncCommitteeMessagePool syncCommitteeMessagePool = new SyncCommitteeMessagePool(spec, syncCommitteeMessageValidator); slotEventsChannelSubscriber.subscribe(syncCommitteeMessagePool); @@ -255,11 +257,11 @@ static SyncCommitteeMessagePool syncCommitteeMessagePool( @Provides @Singleton static AggregatingAttestationPool aggregatingAttestationPool( - Spec spec, - RecentChainData recentChainData, - MetricsSystem metricsSystem, - BlockImporter blockImporter, - EventChannelSubscriber slotEventsChannelSubscriber) { + final Spec spec, + final RecentChainData recentChainData, + final MetricsSystem metricsSystem, + final BlockImporter blockImporter, + final EventChannelSubscriber slotEventsChannelSubscriber) { AggregatingAttestationPool attestationPool = new AggregatingAttestationPool( spec, recentChainData, metricsSystem, DEFAULT_MAXIMUM_ATTESTATION_COUNT); @@ -272,7 +274,7 @@ static AggregatingAttestationPool aggregatingAttestationPool( @Provides @Singleton static FailedExecutionPool failedExecutionPool( - BlockManager blockManager, @BeaconAsyncRunner AsyncRunner beaconAsyncRunner) { + final BlockManager blockManager, @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner) { return new FailedExecutionPool(blockManager, beaconAsyncRunner); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java index 7204377b8e0..42ed88b8193 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/PowModule.java @@ -54,13 +54,13 @@ public interface PowModule { @Provides @Singleton static Optional terminalPowBlockMonitor( - Spec spec, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, - TimeProvider timeProvider, - ExecutionLayerChannel executionLayer, - RecentChainData recentChainData, - ForkChoiceNotifier forkChoiceNotifier, - EventLogger eventLogger) { + final Spec spec, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner, + final TimeProvider timeProvider, + final ExecutionLayerChannel executionLayer, + final RecentChainData recentChainData, + final ForkChoiceNotifier forkChoiceNotifier, + final EventLogger eventLogger) { if (spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { return Optional.of( new TerminalPowBlockMonitor( @@ -78,24 +78,24 @@ static Optional terminalPowBlockMonitor( @Provides @Singleton - static Eth1DataCache eth1DataCache(Spec spec, MetricsSystem metricsSystem) { + static Eth1DataCache eth1DataCache(final Spec spec, final MetricsSystem metricsSystem) { return new Eth1DataCache(spec, metricsSystem, new Eth1VotingPeriod(spec)); } @Provides @Singleton static DepositProvider depositProvider( - Spec spec, - PowchainConfiguration powchainConfig, - MetricsSystem metricsSystem, - RecentChainData recentChainData, - Eth1DataCache eth1DataCache, - StorageUpdateChannel storageUpdateChannel, - Eth1DepositStorageChannel eth1DepositStorageChannel, - EventChannelSubscriber eth1EventsChannelSubscriber, - EventChannelSubscriber finalizedCheckpointChannelSubscriber, - EventChannelSubscriber slotEventsChannelSubscriber, - EventLogger eventLogger) { + final Spec spec, + final PowchainConfiguration powchainConfig, + final MetricsSystem metricsSystem, + final RecentChainData recentChainData, + final Eth1DataCache eth1DataCache, + final StorageUpdateChannel storageUpdateChannel, + final Eth1DepositStorageChannel eth1DepositStorageChannel, + final EventChannelSubscriber eth1EventsChannelSubscriber, + final EventChannelSubscriber finalizedCheckpointChannelSubscriber, + final EventChannelSubscriber slotEventsChannelSubscriber, + final EventLogger eventLogger) { DepositProvider depositProvider = new DepositProvider( metricsSystem, @@ -117,10 +117,10 @@ static DepositProvider depositProvider( @Singleton @ProposerDefaultFeeRecipient static Optional proposerDefaultFeeRecipient( - Spec spec, - ValidatorConfig validatorConfig, - BeaconRestApiConfig restApiConfig, - StatusLogger statusLogger) { + final Spec spec, + final ValidatorConfig validatorConfig, + final BeaconRestApiConfig restApiConfig, + final StatusLogger statusLogger) { if (!spec.isMilestoneSupported(SpecMilestone.BELLATRIX)) { return Optional.of(Eth1Address.ZERO); } @@ -138,10 +138,10 @@ static Optional proposerDefaultFeeRecipient( @Provides @Singleton static GenesisHandler genesisHandler( - TimeProvider timeProvider, - Spec spec, - RecentChainData recentChainData, - EventChannelSubscriber eth1EventsChannelSubscriber) { + final TimeProvider timeProvider, + final Spec spec, + final RecentChainData recentChainData, + final EventChannelSubscriber eth1EventsChannelSubscriber) { GenesisHandler genesisHandler = new GenesisHandler(recentChainData, timeProvider, spec); eth1EventsChannelSubscriber.subscribe(genesisHandler); return genesisHandler; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java index e9d7caef4fc..e53382c6c6f 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/RecentChainDataStateInitializer.java @@ -50,7 +50,7 @@ public class RecentChainDataStateInitializer { @Inject public RecentChainDataStateInitializer() {} - public void setupInitialState(RecentChainData recentChainData) { + public void setupInitialState(final RecentChainData recentChainData) { final Optional initialAnchor = tryLoadingAnchorPointFromInitialState(beaconConfig.eth2NetworkConfig()) @@ -132,7 +132,7 @@ protected Optional attemptToLoadAnchorPoint(final Optional return weakSubjectivityInitializer.loadInitialAnchorPoint(spec, initialState); } - protected void setupInteropState(RecentChainData recentChainData) { + protected void setupInteropState(final RecentChainData recentChainData) { final InteropConfig config = beaconConfig.interopConfig(); statusLogger.generatingMockStartGenesis( config.getInteropGenesisTime(), config.getInteropNumberOfValidators()); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java index de090799920..415bc44017a 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ServiceConfigModule.java @@ -32,34 +32,34 @@ public interface ServiceConfigModule { @interface RejectedExecutionCountSupplier {} @Provides - static DataDirLayout dataDirLayout(ServiceConfig config) { + static DataDirLayout dataDirLayout(final ServiceConfig config) { return config.getDataDirLayout(); } @Provides - static AsyncRunnerFactory asyncRunnerFactory(ServiceConfig config) { + static AsyncRunnerFactory asyncRunnerFactory(final ServiceConfig config) { return config.getAsyncRunnerFactory(); } @Provides - static TimeProvider timeProvider(ServiceConfig config) { + static TimeProvider timeProvider(final ServiceConfig config) { return config.getTimeProvider(); } @Provides - static EventChannels eventChannels(ServiceConfig config) { + static EventChannels eventChannels(final ServiceConfig config) { return config.getEventChannels(); } @Provides - static MetricsSystem metricsSystem(ServiceConfig config) { + static MetricsSystem metricsSystem(final ServiceConfig config) { return config.getMetricsSystem(); } @Provides @Singleton @RejectedExecutionCountSupplier - static IntSupplier rejectedExecutionCountSupplier(ServiceConfig config) { + static IntSupplier rejectedExecutionCountSupplier(final ServiceConfig config) { return config.getRejectedExecutionsSupplier(); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java index cc1ae75b51d..a89c555ca73 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SpecModule.java @@ -39,7 +39,7 @@ interface CurrentSlotProvider { interface SchemaSupplier> extends Function { @Override - default T apply(UInt64 slot) { + default T apply(final UInt64 slot) { return getSchemaAtSlot(slot); } @@ -48,27 +48,27 @@ default T apply(UInt64 slot) { @Provides @Singleton - static SchemaSupplier> beaconBlockBodySchemaSupplier(Spec spec) { + static SchemaSupplier> beaconBlockBodySchemaSupplier(final Spec spec) { return slot -> spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockBodySchema(); } @Provides @Singleton - static RewardCalculator rewardCalculator(Spec spec) { + static RewardCalculator rewardCalculator(final Spec spec) { return new RewardCalculator(spec, new BlockRewardCalculatorUtil(spec)); } @Provides @Singleton - static CurrentSlotProvider currentSlotProvider(Spec spec, TimeProvider timeProvider) { + static CurrentSlotProvider currentSlotProvider(final Spec spec, final TimeProvider timeProvider) { return new CurrentSlotProvider() { @Override - public UInt64 getCurrentSlot(UInt64 genesisTime) { + public UInt64 getCurrentSlot(final UInt64 genesisTime) { return getCurrentSlot(timeProvider.getTimeInSeconds(), genesisTime); } @Override - public UInt64 getCurrentSlot(UInt64 currentTime, UInt64 genesisTime) { + public UInt64 getCurrentSlot(final UInt64 currentTime, final UInt64 genesisTime) { return spec.getCurrentSlot(currentTime, genesisTime); } }; diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java index 2da1529a624..7c5dab4348f 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/StorageModule.java @@ -69,7 +69,7 @@ interface OnStoreInitializedHandler { @Provides @Singleton - static KeyValueStore keyValueStore(DataDirLayout dataDirLayout) { + static KeyValueStore keyValueStore(final DataDirLayout dataDirLayout) { return new FileKeyValueStore( dataDirLayout.getBeaconDataDirectory().resolve(KEY_VALUE_STORE_SUBDIRECTORY)); } @@ -77,7 +77,9 @@ static KeyValueStore keyValueStore(DataDirLayout dataDirLayout) { @Provides @Singleton static EarliestAvailableBlockSlot earliestAvailableBlockSlot( - StoreConfig storeConfig, TimeProvider timeProvider, StorageQueryChannel storageQueryChannel) { + final StoreConfig storeConfig, + final TimeProvider timeProvider, + final StorageQueryChannel storageQueryChannel) { return new EarliestAvailableBlockSlot( storageQueryChannel, timeProvider, storeConfig.getEarliestAvailableBlockSlotFrequency()); } @@ -85,10 +87,10 @@ static EarliestAvailableBlockSlot earliestAvailableBlockSlot( @Provides @Singleton static CombinedChainDataClient combinedChainDataClient( - Spec spec, - StorageQueryChannel storageQueryChannel, - RecentChainData recentChainData, - EarliestAvailableBlockSlot earliestAvailableBlockSlot) { + final Spec spec, + final StorageQueryChannel storageQueryChannel, + final RecentChainData recentChainData, + final EarliestAvailableBlockSlot earliestAvailableBlockSlot) { return new CombinedChainDataClient( recentChainData, storageQueryChannel, spec, earliestAvailableBlockSlot); } @@ -97,20 +99,20 @@ static CombinedChainDataClient combinedChainDataClient( @Singleton @SuppressWarnings("UnusedVariable") static SafeFuture recentChainDataFuture( - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, - TimeProvider timeProvider, - MetricsSystem metricsSystem, - Spec spec, - StoreConfig storeConfig, - StorageQueryChannel storageQueryChannel, - StorageUpdateChannel storageUpdateChannel, - Lazy blockBlobSidecarsTrackersPool, - VoteUpdateChannel voteUpdateChannel, - FinalizedCheckpointChannel finalizedCheckpointChannel, - ChainHeadChannel chainHeadChannel, - ValidatorIsConnectedProvider validatorIsConnectedProvider, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner, + final TimeProvider timeProvider, + final MetricsSystem metricsSystem, + final Spec spec, + final StoreConfig storeConfig, + final StorageQueryChannel storageQueryChannel, + final StorageUpdateChannel storageUpdateChannel, + final Lazy blockBlobSidecarsTrackersPool, + final VoteUpdateChannel voteUpdateChannel, + final FinalizedCheckpointChannel finalizedCheckpointChannel, + final ChainHeadChannel chainHeadChannel, + final ValidatorIsConnectedProvider validatorIsConnectedProvider, // TODO is there a better option for this dependency ? - WeakSubjectivityFinalizedConfig __) { + final WeakSubjectivityFinalizedConfig __) { return StorageBackedRecentChainData.create( metricsSystem, @@ -132,11 +134,11 @@ static SafeFuture recentChainDataFuture( @Singleton // TODO producer ? static RecentChainData recentChainData( - Eth2NetworkConfiguration eth2NetworkConfig, - SafeFuture recentChainDataFuture, - StatusLogger statusLogger, - Lazy weakSubjectivityPeriodValidator, - Lazy recentChainDataStateInitializer) { + final Eth2NetworkConfiguration eth2NetworkConfig, + final SafeFuture recentChainDataFuture, + final StatusLogger statusLogger, + final Lazy weakSubjectivityPeriodValidator, + final Lazy recentChainDataStateInitializer) { RecentChainData recentChainData = recentChainDataFuture.join(); @@ -167,13 +169,13 @@ static RecentChainData recentChainData( @Provides @Singleton static OnStoreInitializedHandler onStoreInitializedHandler( - TimeProvider timeProvider, - RecentChainData recentChainData, - CurrentSlotProvider currentSlotProvider, - Lazy weakSubjectivityStoreChainValidator, - Lazy genesisTimeTracker, - SlotProcessor slotProcessor, - PerformanceTracker performanceTracker) { + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final CurrentSlotProvider currentSlotProvider, + final Lazy weakSubjectivityStoreChainValidator, + final Lazy genesisTimeTracker, + final SlotProcessor slotProcessor, + final PerformanceTracker performanceTracker) { return () -> { UInt64 genesisTime = recentChainData.getGenesisTime(); UInt64 currentTime = timeProvider.getTimeInSeconds(); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java index c93319b0397..6fe747fef3f 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SubnetsModule.java @@ -35,11 +35,12 @@ public interface SubnetsModule { @Provides @Singleton static AttestationTopicSubscriber attestationTopicSubscriber( - @MetricsModule.SubnetSubscriptionsMetric SettableLabelledGauge subnetSubscriptionsMetric, - Spec spec, - P2PConfig p2pConfig, - EventChannelSubscriber slotEventsChannelSubscriber, - Eth2P2PNetwork p2pNetwork) { + @MetricsModule.SubnetSubscriptionsMetric + final SettableLabelledGauge subnetSubscriptionsMetric, + final Spec spec, + final P2PConfig p2pConfig, + final EventChannelSubscriber slotEventsChannelSubscriber, + final Eth2P2PNetwork p2pNetwork) { AttestationTopicSubscriber attestationTopicSubscriber = new AttestationTopicSubscriber(spec, p2pNetwork, subnetSubscriptionsMetric); if (p2pConfig.isSubscribeAllSubnetsEnabled()) { @@ -51,12 +52,12 @@ static AttestationTopicSubscriber attestationTopicSubscriber( @Provides @Singleton static StableSubnetSubscriber stableSubnetSubscriber( - Spec spec, - P2PConfig p2pConfig, - Eth2P2PNetwork p2pNetwork, - AttestationTopicSubscriber attestationTopicSubscriber, - EventChannelSubscriber slotEventsChannelSubscriber, - LoggingModule.InitLogger logger) { + final Spec spec, + final P2PConfig p2pConfig, + final Eth2P2PNetwork p2pNetwork, + final AttestationTopicSubscriber attestationTopicSubscriber, + final EventChannelSubscriber slotEventsChannelSubscriber, + final LoggingModule.InitLogger logger) { final StableSubnetSubscriber stableSubnetSubscriber; if (p2pConfig.isSubscribeAllSubnetsEnabled()) { logger.logger().info("Subscribing to all attestation subnets"); @@ -81,10 +82,10 @@ static StableSubnetSubscriber stableSubnetSubscriber( @Provides @Singleton static SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager( - Spec spec, - P2PConfig p2pConfig, - EventChannelSubscriber slotEventsChannelSubscriber, - Eth2P2PNetwork p2pNetwork) { + final Spec spec, + final P2PConfig p2pConfig, + final EventChannelSubscriber slotEventsChannelSubscriber, + final Eth2P2PNetwork p2pNetwork) { final SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager; if (p2pConfig.isSubscribeAllSubnetsEnabled()) { diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java index 26a0219ce84..80e1ad614bd 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/SyncModule.java @@ -62,22 +62,22 @@ public interface SyncModule { @Provides @Singleton static SyncServiceFactory syncServiceFactory( - Spec spec, - SyncConfig syncConfig, - Eth2NetworkConfiguration eth2NetworkConfig, - MetricsSystem metricsSystem, - AsyncRunnerFactory asyncRunnerFactory, - @BeaconAsyncRunner AsyncRunner beaconAsyncRunner, - TimeProvider timeProvider, - RecentChainData recentChainData, - CombinedChainDataClient combinedChainDataClient, - StorageUpdateChannel storageUpdateChannel, - Eth2P2PNetwork p2pNetwork, - BlockImporter blockImporter, - BlobSidecarManager blobSidecarManager, - PendingPool pendingBlocksPool, - BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, - SignatureVerificationService signatureVerificationService) { + final Spec spec, + final SyncConfig syncConfig, + final Eth2NetworkConfiguration eth2NetworkConfig, + final MetricsSystem metricsSystem, + final AsyncRunnerFactory asyncRunnerFactory, + @BeaconAsyncRunner final AsyncRunner beaconAsyncRunner, + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final CombinedChainDataClient combinedChainDataClient, + final StorageUpdateChannel storageUpdateChannel, + final Eth2P2PNetwork p2pNetwork, + final BlockImporter blockImporter, + final BlobSidecarManager blobSidecarManager, + final PendingPool pendingBlocksPool, + final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + final SignatureVerificationService signatureVerificationService) { return new DefaultSyncServiceFactory( syncConfig, eth2NetworkConfig.getNetworkBoostrapConfig().getGenesisState(), @@ -102,15 +102,15 @@ static SyncServiceFactory syncServiceFactory( @Provides @Singleton static SyncService syncService( - SyncServiceFactory syncServiceFactory, - EventChannels eventChannels, - ForkChoice forkChoice, - ForkChoiceNotifier forkChoiceNotifier, - DepositProvider depositProvider, - Optional terminalPowBlockMonitor, - Eth2P2PNetwork p2pNetwork, - ChainHeadChannel chainHeadChannelPublisher, - EventLogger eventLogger) { + final SyncServiceFactory syncServiceFactory, + final EventChannels eventChannels, + final ForkChoice forkChoice, + final ForkChoiceNotifier forkChoiceNotifier, + final DepositProvider depositProvider, + final Optional terminalPowBlockMonitor, + final Eth2P2PNetwork p2pNetwork, + final ChainHeadChannel chainHeadChannelPublisher, + final EventLogger eventLogger) { SyncService syncService = syncServiceFactory.create(eventChannels); // chainHeadChannel subscription @@ -145,10 +145,10 @@ static SyncService syncService( @Provides @Singleton static RecentBlocksFetcher recentBlocksFetcher( - SyncService syncService, - BlockManager blockManager, - EventChannelSubscriber receivedBlockEventsChannelSubscriber, - LoggingModule.InitLogger initLogger) { + final SyncService syncService, + final BlockManager blockManager, + final EventChannelSubscriber receivedBlockEventsChannelSubscriber, + final LoggingModule.InitLogger initLogger) { final RecentBlocksFetcher recentBlocksFetcher = syncService.getRecentBlocksFetcher(); recentBlocksFetcher.subscribeBlockFetched( (block) -> @@ -171,7 +171,7 @@ static RecentBlocksFetcher recentBlocksFetcher( @Provides @Singleton static RecentBlobSidecarsFetcher recentBlobSidecarsFetcher( - SyncService syncService, BlobSidecarManager blobSidecarManager) { + final SyncService syncService, final BlobSidecarManager blobSidecarManager) { final RecentBlobSidecarsFetcher recentBlobSidecarsFetcher = syncService.getRecentBlobSidecarsFetcher(); recentBlobSidecarsFetcher.subscribeBlobSidecarFetched( diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java index 5e11cc464b2..363bae37aaf 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/ValidatorModule.java @@ -84,7 +84,8 @@ public interface ValidatorModule { @Provides @Singleton static ActiveValidatorTracker activeValidatorTracker( - Spec spec, EventChannelSubscriber slotEventsChannelSubscriber) { + final Spec spec, + final EventChannelSubscriber slotEventsChannelSubscriber) { ActiveValidatorTracker activeValidatorTracker = new ActiveValidatorTracker(spec); slotEventsChannelSubscriber.subscribe(activeValidatorTracker); return activeValidatorTracker; @@ -93,8 +94,8 @@ static ActiveValidatorTracker activeValidatorTracker( @Provides @Singleton static ExecutionLayerBlockProductionManager executionLayerBlockProductionManager( - ExecutionLayerChannel executionLayer, - EventChannelSubscriber slotEventsChannelSubscriber) { + final ExecutionLayerChannel executionLayer, + final EventChannelSubscriber slotEventsChannelSubscriber) { return ExecutionLayerBlockManagerFactory.create(executionLayer, slotEventsChannelSubscriber); } @@ -102,12 +103,11 @@ static ExecutionLayerBlockProductionManager executionLayerBlockProductionManager @Provides @Singleton static GraffitiBuilder graffitiBuilder( - ValidatorConfig validatorConfig, - EventChannelSubscriber + final ValidatorConfig validatorConfig, + final EventChannelSubscriber executionClientVersionChannelSubscriber) { GraffitiBuilder graffitiBuilder = - new GraffitiBuilder( - validatorConfig.getClientGraffitiAppendFormat()); + new GraffitiBuilder(validatorConfig.getClientGraffitiAppendFormat()); executionClientVersionChannelSubscriber.subscribe(graffitiBuilder); return graffitiBuilder; } @@ -115,10 +115,11 @@ static GraffitiBuilder graffitiBuilder( @Provides @Singleton static ExecutionClientVersionProvider executionClientVersionProvider( - GraffitiBuilder graffitiBuilder, - ExecutionLayerChannel executionLayer, - ExecutionClientVersionChannel executionClientVersionChannelPublisher, - EventChannelSubscriber executionClientEventsChannelSubscriber) { + final GraffitiBuilder graffitiBuilder, + final ExecutionLayerChannel executionLayer, + final ExecutionClientVersionChannel executionClientVersionChannelPublisher, + final EventChannelSubscriber + executionClientEventsChannelSubscriber) { final ExecutionClientVersionProvider executionClientVersionProvider = new ExecutionClientVersionProvider( @@ -132,18 +133,18 @@ static ExecutionClientVersionProvider executionClientVersionProvider( @Provides @Singleton static BlockOperationSelectorFactory blockOperationSelectorFactory( - Spec spec, - AggregatingAttestationPool attestationPool, - OperationPool attesterSlashingPool, - OperationPool proposerSlashingPool, - OperationPool voluntaryExitPool, - OperationPool blsToExecutionChangePool, - SyncCommitteeContributionPool syncCommitteeContributionPool, - DepositProvider depositProvider, - Eth1DataCache eth1DataCache, - ForkChoiceNotifier forkChoiceNotifier, - ExecutionLayerBlockProductionManager executionLayerBlockProductionManager, - GraffitiBuilder graffitiBuilder) { + final Spec spec, + final AggregatingAttestationPool attestationPool, + final OperationPool attesterSlashingPool, + final OperationPool proposerSlashingPool, + final OperationPool voluntaryExitPool, + final OperationPool blsToExecutionChangePool, + final SyncCommitteeContributionPool syncCommitteeContributionPool, + final DepositProvider depositProvider, + final Eth1DataCache eth1DataCache, + final ForkChoiceNotifier forkChoiceNotifier, + final ExecutionLayerBlockProductionManager executionLayerBlockProductionManager, + final GraffitiBuilder graffitiBuilder) { return new BlockOperationSelectorFactory( spec, @@ -163,46 +164,46 @@ static BlockOperationSelectorFactory blockOperationSelectorFactory( @Provides @Singleton static BlockFactory blockFactory( - Spec spec, BlockOperationSelectorFactory blockOperationSelectorFactory) { + final Spec spec, final BlockOperationSelectorFactory blockOperationSelectorFactory) { return new MilestoneBasedBlockFactory(spec, blockOperationSelectorFactory); } @Provides @Singleton static ChainDataProvider chainDataProvider( - Spec spec, - RecentChainData recentChainData, - CombinedChainDataClient combinedChainDataClient, - RewardCalculator rewardCalculator) { + final Spec spec, + final RecentChainData recentChainData, + final CombinedChainDataClient combinedChainDataClient, + final RewardCalculator rewardCalculator) { return new ChainDataProvider(spec, recentChainData, combinedChainDataClient, rewardCalculator); } @Provides @Singleton static ValidatorApiHandler validatorApiHandler( - Spec spec, - ChainDataProvider chainDataProvider, - DataProvider dataProvider, - CombinedChainDataClient combinedChainDataClient, - SyncService syncService, - BlockFactory blockFactory, - BlockImportChannel blockImportChannel, - BlockGossipChannel blockGossipChannel, - BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, - BlobSidecarGossipChannel blobSidecarGossipChannel, - AggregatingAttestationPool attestationPool, - AttestationManager attestationManager, - AttestationTopicSubscriber attestationTopicSubscriber, - ActiveValidatorTracker activeValidatorTracker, - DutyMetrics dutyMetrics, - PerformanceTracker performanceTracker, - ForkChoiceTrigger forkChoiceTrigger, - ProposersDataManager proposersDataManager, - SyncCommitteeMessagePool syncCommitteeMessagePool, - SyncCommitteeContributionPool syncCommitteeContributionPool, - SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager, - BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory, - EventChannelSubscriber validatorApiChannelSubscriber) { + final Spec spec, + final ChainDataProvider chainDataProvider, + final DataProvider dataProvider, + final CombinedChainDataClient combinedChainDataClient, + final SyncService syncService, + final BlockFactory blockFactory, + final BlockImportChannel blockImportChannel, + final BlockGossipChannel blockGossipChannel, + final BlockBlobSidecarsTrackersPool blockBlobSidecarsTrackersPool, + final BlobSidecarGossipChannel blobSidecarGossipChannel, + final AggregatingAttestationPool attestationPool, + final AttestationManager attestationManager, + final AttestationTopicSubscriber attestationTopicSubscriber, + final ActiveValidatorTracker activeValidatorTracker, + final DutyMetrics dutyMetrics, + final PerformanceTracker performanceTracker, + final ForkChoiceTrigger forkChoiceTrigger, + final ProposersDataManager proposersDataManager, + final SyncCommitteeMessagePool syncCommitteeMessagePool, + final SyncCommitteeContributionPool syncCommitteeContributionPool, + final SyncCommitteeSubscriptionManager syncCommitteeSubscriptionManager, + final BlockProductionAndPublishingPerformanceFactory blockProductionPerformanceFactory, + final EventChannelSubscriber validatorApiChannelSubscriber) { ValidatorApiHandler validatorApiHandler = new ValidatorApiHandler( chainDataProvider, @@ -236,18 +237,19 @@ static ValidatorApiHandler validatorApiHandler( @Provides @Singleton static AttestationManager attestationManager( - Spec spec, - BlockImporter blockImporter, - AggregateAttestationValidator aggregateValidator, - PendingPool pendingAttestations, - FutureItems futureAttestations, - ForkChoice forkChoice, - AggregatingAttestationPool attestationPool, - AttestationValidator attestationValidator, - SignatureVerificationService signatureVerificationService, - ActiveValidatorChannel activeValidatorChannel, - EventChannelSubscriber slotEventsChannelSubscriber, - EventChannelSubscriber receivedBlockEventsChannelSubscriber) { + final Spec spec, + final BlockImporter blockImporter, + final AggregateAttestationValidator aggregateValidator, + final PendingPool pendingAttestations, + final FutureItems futureAttestations, + final ForkChoice forkChoice, + final AggregatingAttestationPool attestationPool, + final AttestationValidator attestationValidator, + final SignatureVerificationService signatureVerificationService, + final ActiveValidatorChannel activeValidatorChannel, + final EventChannelSubscriber slotEventsChannelSubscriber, + final EventChannelSubscriber + receivedBlockEventsChannelSubscriber) { // TODO blockImporter.subscribeToVerifiedBlockAttestations( @@ -277,15 +279,16 @@ static AttestationManager attestationManager( @Provides @Singleton static ValidatorIsConnectedProvider validatorIsConnectedProvider( - Lazy forkChoiceNotifier) { + final Lazy forkChoiceNotifier) { return new ValidatorIsConnectedProviderImpl(() -> forkChoiceNotifier.get()); } @Provides @Singleton static ValidatorIndexCacheTracker validatorIndexCacheTracker( - RecentChainData recentChainData, - EventChannelSubscriber finalizedCheckpointChannelSubscriber) { + final RecentChainData recentChainData, + final EventChannelSubscriber + finalizedCheckpointChannelSubscriber) { final ValidatorIndexCacheTracker validatorIndexCacheTracker = new ValidatorIndexCacheTracker(recentChainData); finalizedCheckpointChannelSubscriber.subscribe(validatorIndexCacheTracker); diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java index f534522ebce..27571c37b9e 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/VerifyModule.java @@ -41,37 +41,39 @@ public interface VerifyModule { @Provides @Singleton - static GossipValidationHelper gossipValidationHelper(Spec spec, RecentChainData recentChainData) { + static GossipValidationHelper gossipValidationHelper( + final Spec spec, final RecentChainData recentChainData) { return new GossipValidationHelper(spec, recentChainData); } @Provides @Singleton static AttesterSlashingValidator attesterSlashingValidator( - Spec spec, RecentChainData recentChainData) { + final Spec spec, final RecentChainData recentChainData) { return new AttesterSlashingValidator(recentChainData, spec); } @Provides @Singleton static ProposerSlashingValidator proposerSlashingValidator( - Spec spec, RecentChainData recentChainData) { + final Spec spec, final RecentChainData recentChainData) { return new ProposerSlashingValidator(spec, recentChainData); } @Provides @Singleton - static VoluntaryExitValidator voluntaryExitValidator(Spec spec, RecentChainData recentChainData) { + static VoluntaryExitValidator voluntaryExitValidator( + final Spec spec, final RecentChainData recentChainData) { return new VoluntaryExitValidator(spec, recentChainData); } @Provides @Singleton static SignedBlsToExecutionChangeValidator signedBlsToExecutionChangeValidator( - Spec spec, - TimeProvider timeProvider, - RecentChainData recentChainData, - SignatureVerificationService signatureVerificationService) { + final Spec spec, + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final SignatureVerificationService signatureVerificationService) { return new SignedBlsToExecutionChangeValidator( spec, timeProvider, recentChainData, signatureVerificationService); } @@ -79,17 +81,19 @@ static SignedBlsToExecutionChangeValidator signedBlsToExecutionChangeValidator( @Provides @Singleton static MergeTransitionBlockValidator mergeTransitionBlockValidator( - Spec spec, RecentChainData recentChainData, ExecutionLayerChannel executionLayer) { + final Spec spec, + final RecentChainData recentChainData, + final ExecutionLayerChannel executionLayer) { return new MergeTransitionBlockValidator(spec, recentChainData, executionLayer); } @Provides @Singleton static AttestationValidator attestationValidator( - Spec spec, - RecentChainData recentChainData, - SignatureVerificationService signatureVerificationService, - MetricsSystem metricsSystem) { + final Spec spec, + final RecentChainData recentChainData, + final SignatureVerificationService signatureVerificationService, + final MetricsSystem metricsSystem) { return new AttestationValidator( spec, recentChainData, signatureVerificationService, metricsSystem); } @@ -97,9 +101,9 @@ static AttestationValidator attestationValidator( @Provides @Singleton static AggregateAttestationValidator aggregateAttestationValidator( - Spec spec, - AttestationValidator attestationValidator, - SignatureVerificationService signatureVerificationService) { + final Spec spec, + final AttestationValidator attestationValidator, + final SignatureVerificationService signatureVerificationService) { return new AggregateAttestationValidator( spec, attestationValidator, signatureVerificationService); } @@ -107,18 +111,18 @@ static AggregateAttestationValidator aggregateAttestationValidator( @Provides @Singleton static SyncCommitteeStateUtils syncCommitteeStateUtils( - Spec spec, RecentChainData recentChainData) { + final Spec spec, final RecentChainData recentChainData) { return new SyncCommitteeStateUtils(spec, recentChainData); } @Provides @Singleton static SignedContributionAndProofValidator signedContributionAndProofValidator( - Spec spec, - TimeProvider timeProvider, - RecentChainData recentChainData, - SyncCommitteeStateUtils syncCommitteeStateUtils, - SignatureVerificationService signatureVerificationService) { + final Spec spec, + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final SyncCommitteeStateUtils syncCommitteeStateUtils, + final SignatureVerificationService signatureVerificationService) { return new SignedContributionAndProofValidator( spec, recentChainData, syncCommitteeStateUtils, timeProvider, signatureVerificationService); } @@ -126,11 +130,11 @@ static SignedContributionAndProofValidator signedContributionAndProofValidator( @Provides @Singleton static SyncCommitteeMessageValidator syncCommitteeMessageValidator( - Spec spec, - TimeProvider timeProvider, - RecentChainData recentChainData, - SyncCommitteeStateUtils syncCommitteeStateUtils, - SignatureVerificationService signatureVerificationService) { + final Spec spec, + final TimeProvider timeProvider, + final RecentChainData recentChainData, + final SyncCommitteeStateUtils syncCommitteeStateUtils, + final SignatureVerificationService signatureVerificationService) { return new SyncCommitteeMessageValidator( spec, recentChainData, syncCommitteeStateUtils, signatureVerificationService, timeProvider); } @@ -138,16 +142,16 @@ static SyncCommitteeMessageValidator syncCommitteeMessageValidator( @Provides @Singleton static BlockGossipValidator blockGossipValidator( - Spec spec, - GossipValidationHelper gossipValidationHelper, - ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher) { + final Spec spec, + final GossipValidationHelper gossipValidationHelper, + final ReceivedBlockEventsChannel receivedBlockEventsChannelPublisher) { return new BlockGossipValidator( spec, gossipValidationHelper, receivedBlockEventsChannelPublisher); } @Provides @Singleton - static BlockValidator blockValidator(BlockGossipValidator blockGossipValidator) { + static BlockValidator blockValidator(final BlockGossipValidator blockGossipValidator) { return new BlockValidator(blockGossipValidator); } } diff --git a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java index 262d143187c..56de99d304e 100644 --- a/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java +++ b/services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/init/WSModule.java @@ -54,10 +54,10 @@ static WeakSubjectivityInitializer weakSubjectivityInitializer() { @Provides @Singleton static SafeFuture weakSubjectivityFinalizedConfigFuture( - WeakSubjectivityInitializer weakSubjectivityInitializer, - WeakSubjectivityConfig weakSubjectivityConfig, - StorageQueryChannel storageQueryChannel, - StorageUpdateChannel storageUpdateChannel) { + final WeakSubjectivityInitializer weakSubjectivityInitializer, + final WeakSubjectivityConfig weakSubjectivityConfig, + final StorageQueryChannel storageQueryChannel, + final StorageUpdateChannel storageUpdateChannel) { SafeFuture finalizedConfig = weakSubjectivityInitializer.finalizeAndStoreConfig( weakSubjectivityConfig, storageQueryChannel, storageUpdateChannel); @@ -68,24 +68,24 @@ static SafeFuture weakSubjectivityFinalizedConf @Singleton // TODO producer ? static WeakSubjectivityFinalizedConfig weakSubjectivityConfig( - SafeFuture weakSubjectivityConfigFuture) { + final SafeFuture weakSubjectivityConfigFuture) { return weakSubjectivityConfigFuture.join(); } @Provides @Singleton static WeakSubjectivityValidator weakSubjectivityValidator( - WeakSubjectivityFinalizedConfig weakSubjectivityConfig) { + final WeakSubjectivityFinalizedConfig weakSubjectivityConfig) { return WeakSubjectivityValidator.moderate(weakSubjectivityConfig.config()); } @Provides @Singleton static WeakSubjectivityPeriodValidator weakSubjectivityPeriodValidator( - Spec spec, - CurrentSlotProvider currentSlotProvider, - WeakSubjectivityConfig weakSubjectivityConfig, - WeakSubjectivityInitializer weakSubjectivityInitializer) { + final Spec spec, + final CurrentSlotProvider currentSlotProvider, + final WeakSubjectivityConfig weakSubjectivityConfig, + final WeakSubjectivityInitializer weakSubjectivityInitializer) { return client -> { final AnchorPoint latestFinalizedAnchor = client.getStore().getLatestFinalized(); final UInt64 currentSlot = currentSlotProvider.getCurrentSlot(client.getGenesisTime()); @@ -99,9 +99,9 @@ static WeakSubjectivityPeriodValidator weakSubjectivityPeriodValidator( @Provides @Singleton static WeakSubjectivityStoreChainValidator weakSubjectivityStoreChainValidator( - WeakSubjectivityValidator weakSubjectivityValidator, - CombinedChainDataClient combinedChainDataClient, - RecentChainData recentChainData) { + final WeakSubjectivityValidator weakSubjectivityValidator, + final CombinedChainDataClient combinedChainDataClient, + final RecentChainData recentChainData) { return currentSlot -> { weakSubjectivityValidator .validateChainIsConsistentWithWSCheckpoint(combinedChainDataClient) diff --git a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java index 63f5b3367b0..69a4a6a683a 100644 --- a/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java +++ b/teku/src/test/java/tech/pegasys/teku/config/TekuConfigurationTest.java @@ -208,7 +208,7 @@ public interface TestBeaconChainControllerComponent { public static class TestNetworkModule { private final Eth2P2PNetworkBuilder eth2P2PNetworkBuilder; - public TestNetworkModule(Eth2P2PNetworkBuilder eth2P2PNetworkBuilder) { + public TestNetworkModule(final Eth2P2PNetworkBuilder eth2P2PNetworkBuilder) { this.eth2P2PNetworkBuilder = eth2P2PNetworkBuilder; } @@ -220,27 +220,27 @@ Eth2P2PNetworkBuilder eth2P2PNetworkBuilder() { @Provides @Singleton static Eth2P2PNetwork eth2P2PNetwork( - Spec spec, - P2PConfig p2pConfig, - MetricsSystem metricsSystem, - @AsyncRunnerModule.NetworkAsyncRunner AsyncRunner networkAsyncRunner, - TimeProvider timeProvider, - EventChannels eventChannels, - KeyValueStore keyValueStore, - Eth2P2PNetworkBuilder eth2P2PNetworkBuilder, - CombinedChainDataClient combinedChainDataClient, - BlockManager blockManager, - BlobSidecarManager blobSidecarManager, - AttestationManager attestationManager, - OperationPool attesterSlashingPool, - OperationPool proposerSlashingPool, - OperationPool voluntaryExitPool, - SyncCommitteeContributionPool syncCommitteeContributionPool, - SyncCommitteeMessagePool syncCommitteeMessagePool, - OperationPool blsToExecutionChangePool, - KZG kzg, - WeakSubjectivityValidator weakSubjectivityValidator, - DebugDataDumper p2pDebugDataDumper) { + final Spec spec, + final P2PConfig p2pConfig, + final MetricsSystem metricsSystem, + @AsyncRunnerModule.NetworkAsyncRunner final AsyncRunner networkAsyncRunner, + final TimeProvider timeProvider, + final EventChannels eventChannels, + final KeyValueStore keyValueStore, + final Eth2P2PNetworkBuilder eth2P2PNetworkBuilder, + final CombinedChainDataClient combinedChainDataClient, + final BlockManager blockManager, + final BlobSidecarManager blobSidecarManager, + final AttestationManager attestationManager, + final OperationPool attesterSlashingPool, + final OperationPool proposerSlashingPool, + final OperationPool voluntaryExitPool, + final SyncCommitteeContributionPool syncCommitteeContributionPool, + final SyncCommitteeMessagePool syncCommitteeMessagePool, + final OperationPool blsToExecutionChangePool, + final KZG kzg, + final WeakSubjectivityValidator weakSubjectivityValidator, + final DebugDataDumper p2pDebugDataDumper) { return NetworkModule.eth2P2PNetwork( spec, @@ -268,7 +268,7 @@ static Eth2P2PNetwork eth2P2PNetwork( @Provides @Singleton - static DebugDataDumper p2pDebugDataDumper(DataDirLayout dataDirLayout) { + static DebugDataDumper p2pDebugDataDumper(final DataDirLayout dataDirLayout) { return NetworkModule.debugDataDumper(dataDirLayout); } }