Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO MERGE] PoC Dagger DI as a system builder #8411

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a73606c
Add EventChannelSubscriber
Nashatyrev Jun 5, 2024
330b4cd
Narrow down parameter from EventChannels to EventChannelSubscriber
Nashatyrev Jun 7, 2024
e73895d
Initial version of Dagger modules (no Dagger compile check)
Nashatyrev Jun 7, 2024
a7639ae
Add RecentChainData async creation and initialization. Add WSModule
Nashatyrev Jun 19, 2024
40acba3
Complete BeaconChainController Dagger draft
Nashatyrev Jun 20, 2024
4815f66
Fix compile errors
Nashatyrev Jun 20, 2024
b100903
Add BeaconChainControllerComponent
Nashatyrev Jun 20, 2024
0938622
Resolve missing and duplicate bindings
Nashatyrev Jun 20, 2024
6434467
Resolve circular dependencies
Nashatyrev Jun 21, 2024
f5b05a9
New Dagger based BeaconChainController
Nashatyrev Jun 21, 2024
259935a
Make old/new BeaconChainController easily interchangeable
Nashatyrev Jun 21, 2024
1dd893e
Initialize BeaconChainController Dagger components inside doStart() w…
Nashatyrev Jun 21, 2024
6f7bd8c
Start AsyncRunnerEventThread right after creation
Nashatyrev Jun 21, 2024
a7eb722
Fix the mess with currentTime & genesisTime parameters order for getC…
Nashatyrev Jun 21, 2024
b067905
WeakSubjectivityFinalizedConfig updates storage prior to RecentChainD…
Nashatyrev Jun 21, 2024
34059a0
Add missing ValidatorApiChannel subscription
Nashatyrev Jun 24, 2024
6bd40ff
!!! TO ROLLBACK !!! Temp remove -Werror option
Nashatyrev Jun 25, 2024
8d491ef
Fix compiler warnings
Nashatyrev Jun 26, 2024
7277cc5
Add stricter Dagger compiler options
Nashatyrev Jun 26, 2024
8c5ee39
Return back -Werror
Nashatyrev Jun 26, 2024
b7893a7
Enable errorprone disableWarningsInGeneratedCode
Nashatyrev Jun 26, 2024
f569747
Spotless
Nashatyrev Jun 26, 2024
e8c0296
Remove AbstractBeaconChainController
Nashatyrev Jun 26, 2024
a8958fb
Redesign BeaconChainController creation
Nashatyrev Jun 26, 2024
c99e740
Adopt TekuConfigurationTest
Nashatyrev Jun 26, 2024
8ed7f5d
Merge branch 'refs/heads/master' into experiment/dagger-beacon-chain
Nashatyrev Jun 27, 2024
04e8b3b
Adopt latest config PRs to master
Nashatyrev Jul 1, 2024
124292c
Made method params final
Nashatyrev Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Spotless
Nashatyrev committed Jun 26, 2024
commit f56974734ff9c7f1bb97d89f112d3a361a54efe2
Original file line number Diff line number Diff line change
@@ -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<T extends ChannelInterface> {
Original file line number Diff line number Diff line change
@@ -84,7 +84,8 @@ public <T extends ChannelInterface> EventChannels subscribe(
return subscribeMultithreaded(channelInterface, subscriber, 1);
}

public <T extends ChannelInterface> EventChannelSubscriber<T> createSubscriber(final Class<T> channelInterface) {
public <T extends ChannelInterface> EventChannelSubscriber<T> createSubscriber(
final Class<T> channelInterface) {
return createSubscriberMultithreaded(channelInterface, 1);
}

@@ -103,7 +104,7 @@ public <T extends ChannelInterface> EventChannelSubscriber<T> createSubscriber(f
*/
public <T extends ChannelInterface> EventChannels subscribeMultithreaded(
final Class<T> channelInterface, final T subscriber, final int requestedParallelism) {
createSubscriberMultithreaded(channelInterface,requestedParallelism).subscribe(subscriber);
createSubscriberMultithreaded(channelInterface, requestedParallelism).subscribe(subscriber);
return this;
}

@@ -113,7 +114,6 @@ public <T extends ChannelInterface> EventChannelSubscriber<T> createSubscriberMu
getChannel(channelInterface).subscribeMultithreaded(listener, requestedParallelism);
}


@SuppressWarnings("unchecked")
private <T extends ChannelInterface> EventChannel<T> getChannel(final Class<T> channelInterface) {
return (EventChannel<T>) channels.computeIfAbsent(channelInterface, eventChannelFactory);
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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(
Original file line number Diff line number Diff line change
@@ -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() {
Original file line number Diff line number Diff line change
@@ -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 {

Original file line number Diff line number Diff line change
@@ -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 = {
Original file line number Diff line number Diff line change
@@ -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();
}

Original file line number Diff line number Diff line change
@@ -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 {

Original file line number Diff line number Diff line change
@@ -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<Bytes32, BlockImportResult> 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<Bytes32, InternalValidationResult> invalidBlobSidecarRoots,
FutureItems<BlobSidecar> futureBlobSidecars
) {
FutureItems<BlobSidecar> futureBlobSidecars) {
if (spec.isMilestoneSupported(SpecMilestone.DENEB)) {
final BlobSidecarManagerImpl blobSidecarManagerImpl =
new BlobSidecarManagerImpl(
Loading