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

chore(node-core): depinject validator service & cleanup #1424

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
26 changes: 0 additions & 26 deletions mod/node-core/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ import (
"github.com/berachain/beacon-kit/mod/beacon/blockchain"
cmdlib "github.com/berachain/beacon-kit/mod/cli/pkg/commands"
consensustypes "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
"github.com/berachain/beacon-kit/mod/da/pkg/kzg/noop"
dastore "github.com/berachain/beacon-kit/mod/da/pkg/store"
datypes "github.com/berachain/beacon-kit/mod/da/pkg/types"
engineclient "github.com/berachain/beacon-kit/mod/execution/pkg/client"
"github.com/berachain/beacon-kit/mod/execution/pkg/deposit"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/signer"
"github.com/berachain/beacon-kit/mod/node-core/pkg/node"
"github.com/berachain/beacon-kit/mod/node-core/pkg/types"
"github.com/berachain/beacon-kit/mod/primitives"
Expand All @@ -46,7 +41,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/types/module"
gokzg4844 "github.com/crate-crypto/go-kzg-4844"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -108,17 +102,6 @@ func (nb *NodeBuilder[NodeT]) buildRootCmd() (*cobra.Command, error) {
log.NewLogger(os.Stdout),
viper.GetViper(),
nb.chainSpec,
&depositdb.KVStore[*consensustypes.Deposit]{},
&engineclient.EngineClient[*consensustypes.ExecutionPayload]{},
&gokzg4844.JSONTrustedSetup{},
&noop.Verifier{},
&dastore.Store[*consensustypes.BeaconBlockBody]{},
&signer.BLSSigner{},
&metrics.TelemetrySink{},
&deposit.WrappedBeaconDepositContract[
*consensustypes.Deposit,
consensustypes.WithdrawalCredentials,
]{},
&runtime.BeaconKitRuntime[
*dastore.Store[*consensustypes.BeaconBlockBody],
*consensustypes.BeaconBlock,
Expand All @@ -141,15 +124,6 @@ func (nb *NodeBuilder[NodeT]) buildRootCmd() (*cobra.Command, error) {
components.ProvideClientContext,
components.ProvideKeyring,
components.ProvideConfig,
components.ProvideLocalBuilder,
components.ProvideStateProcessor,
components.ProvideExecutionEngine[*consensustypes.ExecutionPayload],
components.ProvideBlockFeed[*consensustypes.BeaconBlock],
components.ProvideDepositPruner,
components.ProvideAvailabilityPruner,
components.ProvideBlobProcessor[*consensustypes.BeaconBlockBody],
components.ProvideDBManager,
components.ProvideDepositService,
),
),
&autoCliOpts,
Expand Down
6 changes: 3 additions & 3 deletions mod/node-core/pkg/components/availability_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func ProvideAvailibilityStore[
// function for the depinject framework.
type AvailabilityPrunerInput struct {
depinject.In
Logger log.Logger
ChainSpec primitives.ChainSpec
BlockFeed *event.FeedOf[*feed.Event[*types.BeaconBlock]]
AvailabilityStore *dastore.Store[*types.BeaconBlockBody]
BlockFeed *event.FeedOf[*feed.Event[*types.BeaconBlock]]
ChainSpec primitives.ChainSpec
Logger log.Logger
}

// ProvideAvailabilityPruner provides a availability pruner for the depinject
Expand Down
2 changes: 1 addition & 1 deletion mod/node-core/pkg/components/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func ProvideBlobProofVerifier(
type BlobProcessorIn struct {
depinject.In

Logger log.Logger
BlobProofVerifier kzg.BlobProofVerifier
ChainSpec primitives.ChainSpec
Logger log.Logger
TelemetrySink *metrics.TelemetrySink
}

Expand Down
4 changes: 2 additions & 2 deletions mod/node-core/pkg/components/db_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
// DBManagerInput is the input for the dep inject framework.
type DBManagerInput struct {
depinject.In
Logger log.Logger
DepositPruner pruner.Pruner[*dastore.KVStore[*types.Deposit]]
AvailabilityPruner pruner.Pruner[*filedb.RangeDB]
DepositPruner pruner.Pruner[*dastore.KVStore[*types.Deposit]]
Logger log.Logger
}

// ProvideDBManager provides a DBManager for the depinject framework.
Expand Down
29 changes: 15 additions & 14 deletions mod/node-core/pkg/components/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,31 @@ import (

func DefaultComponentsWithStandardTypes() []any {
return []any{
ProvideAvailabilityPruner,
ProvideAvailibilityStore[*types.BeaconBlockBody],
ProvideBlsSigner,
ProvideTrustedSetup,
ProvideDepositStore[*types.Deposit],
ProvideConfig,
ProvideEngineClient[*types.ExecutionPayload],
ProvideJWTSecret,
ProvideBlobProofVerifier,
ProvideBlockFeed[*types.BeaconBlock],
ProvideBlobProcessor[*types.BeaconBlockBody],
ProvideTelemetrySink,
ProvideExecutionEngine[*types.ExecutionPayload],
ProvideBlobProofVerifier,
ProvideConfig,
ProvideDBManager,
ProvideDepositPruner,
ProvideDepositService,
ProvideDepositStore[*types.Deposit],
ProvideBeaconDepositContract[
*types.Deposit,
*types.ExecutionPayload,
*engineprimitives.Withdrawal,
types.WithdrawalCredentials,
],
ProvideEngineClient[*types.ExecutionPayload],
ProvideExecutionEngine[*types.ExecutionPayload],
ProvideJWTSecret,
ProvideLocalBuilder,
ProvideStateProcessor,
ProvideBlockFeed[*types.BeaconBlock],
ProvideDepositPruner,
ProvideAvailabilityPruner,
ProvideDBManager,
ProvideDepositService,
ProvideRuntime,
ProvideStateProcessor,
ProvideTelemetrySink,
ProvideTrustedSetup,
ProvideValidatorService,
}
}
13 changes: 6 additions & 7 deletions mod/node-core/pkg/components/deposit_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ import (
// DepositServiceIn is the input for the deposit service.
type DepositServiceIn struct {
depinject.In

Logger log.Logger
ChainSpec primitives.ChainSpec
EngineClient *engineclient.EngineClient[*types.ExecutionPayload]
TelemetrySink *metrics.TelemetrySink
DepositStore *depositdb.KVStore[*types.Deposit]
BeaconDepositContract *deposit.WrappedBeaconDepositContract[
*types.Deposit, types.WithdrawalCredentials,
]
BlockFeed *event.FeedOf[*feed.Event[*types.BeaconBlock]]
BlockFeed *event.FeedOf[*feed.Event[*types.BeaconBlock]]
ChainSpec primitives.ChainSpec
DepositStore *depositdb.KVStore[*types.Deposit]
EngineClient *engineclient.EngineClient[*types.ExecutionPayload]
Logger log.Logger
TelemetrySink *metrics.TelemetrySink
}

// ProvideDepositService provides the deposit service to the depinject
Expand Down
4 changes: 2 additions & 2 deletions mod/node-core/pkg/components/deposit_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func ProvideDepositStore[
// DepositPrunerInput is the input for the deposit pruner.
type DepositPrunerInput struct {
depinject.In
Logger log.Logger
ChainSpec primitives.ChainSpec
BlockFeed *event.FeedOf[*feed.Event[*types.BeaconBlock]]
ChainSpec primitives.ChainSpec
DepositStore *depositstore.KVStore[*types.Deposit]
Logger log.Logger
}

// ProvideDepositPruner provides a deposit pruner for the depinject framework.
Expand Down
15 changes: 4 additions & 11 deletions mod/node-core/pkg/components/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,11 @@ import (
// EngineClientInputs is the input for the EngineClient.
type EngineClientInputs struct {
depinject.In
// ChainSpec is the chain spec.
ChainSpec primitives.ChainSpec
// Config is the BeaconKit configuration.
Config *config.Config
// Logger is the logger.
Logger log.Logger
// TelemetrySink is the telemetry sink.
ChainSpec primitives.ChainSpec
Config *config.Config
JWTSecret *jwt.Secret `optional:"true"`
Logger log.Logger
TelemetrySink *metrics.TelemetrySink
// JWTSecret is the jwt secret. It is optional, since
// it is not required when connecting to the execution client
// over IPC.
JWTSecret *jwt.Secret `optional:"true"`
}

// ProvideEngineClient creates a new EngineClient.
Expand Down
78 changes: 8 additions & 70 deletions mod/node-core/pkg/components/module/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,99 +24,37 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
dastore "github.com/berachain/beacon-kit/mod/da/pkg/store"
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components"
modulev1alpha1 "github.com/berachain/beacon-kit/mod/node-core/pkg/components/module/api/module/v1alpha1"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/storage"
"github.com/berachain/beacon-kit/mod/node-core/pkg/config"
"github.com/berachain/beacon-kit/mod/primitives"
"github.com/berachain/beacon-kit/mod/state-transition/pkg/core"
"github.com/berachain/beacon-kit/mod/storage/pkg/beacondb"
"github.com/berachain/beacon-kit/mod/storage/pkg/beacondb/encoding"
depositdb "github.com/berachain/beacon-kit/mod/storage/pkg/deposit"
)

// TODO: we don't allow generics here? Why? Is it fixable?
//
//nolint:gochecknoinits // required by sdk.
func init() {
appconfig.RegisterModule(&modulev1alpha1.Module{},
// TODO: make storage backend its own module and remove the
// coupling between construction of runtime and module
appconfig.Provide(
ProvideStorageBackend,
components.ProvideStorageBackend,
ProvideModule,
),
)
}

// DepInjectInput is the input for the dep inject framework.
type DepInjectInput struct {
// ModuleInput is the input for the dep inject framework.
type ModuleInput struct {
depinject.In
BeaconConfig *config.Config
Runtime *components.BeaconKitRuntime
Runtime *components.BeaconKitRuntime
}

// DepInjectOutput is the output for the dep inject framework.
type DepInjectOutput struct {
// ModuleOutput is the output for the dep inject framework.
type ModuleOutput struct {
depinject.Out
Module appmodule.AppModule
}

// ProvideModule is a function that provides the module to the application.
func ProvideModule(in DepInjectInput) (DepInjectOutput, error) {
return DepInjectOutput{
func ProvideModule(in ModuleInput) (ModuleOutput, error) {
return ModuleOutput{
Module: NewAppModule(in.Runtime),
}, nil
}

// StorageBackendInput is the input for the ProvideStorageBackend function.
type StorageBackendInput struct {
depinject.In
ChainSpec primitives.ChainSpec
AvailabilityStore *dastore.Store[*types.BeaconBlockBody]
Environment appmodule.Environment
DepositStore *depositdb.KVStore[*types.Deposit]
}

// ProvideStorageBackend is the depinject provider that returns a beacon storage
// backend.
func ProvideStorageBackend(
in StorageBackendInput,
) *storage.Backend[
*dastore.Store[*types.BeaconBlockBody],
*types.BeaconBlock,
*types.BeaconBlockBody,
core.BeaconState[
*types.BeaconBlockHeader, *types.Eth1Data,
*types.ExecutionPayloadHeader, *types.Fork,
*types.Validator, *engineprimitives.Withdrawal,
],
*depositdb.KVStore[*types.Deposit],
] {
payloadCodec := &encoding.
SSZInterfaceCodec[*types.ExecutionPayloadHeader]{}
return storage.NewBackend[
*dastore.Store[*types.BeaconBlockBody],
*types.BeaconBlock,
*types.BeaconBlockBody,
core.BeaconState[
*types.BeaconBlockHeader, *types.Eth1Data,
*types.ExecutionPayloadHeader, *types.Fork,
*types.Validator, *engineprimitives.Withdrawal,
],
](
in.ChainSpec,
in.AvailabilityStore,
beacondb.New[
*types.Fork,
*types.BeaconBlockHeader,
*types.ExecutionPayloadHeader,
*types.Eth1Data,
*types.Validator,
](in.Environment.KVStoreService, payloadCodec),
in.DepositStore,
)
}
2 changes: 1 addition & 1 deletion mod/node-core/pkg/components/payload_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type LocalBuilderInput struct {
depinject.In
Cfg *config.Config
ChainSpec primitives.ChainSpec
Logger log.Logger
ExecutionEngine *execution.Engine[*types.ExecutionPayload]
Logger log.Logger
}

func ProvideLocalBuilder(
Expand Down
Loading
Loading