Skip to content

Commit

Permalink
chore(node-core): remove chain service from middleware + cleanup (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocnc2 authored Aug 3, 2024
1 parent 2a8aaf9 commit 6657880
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 58 deletions.
12 changes: 10 additions & 2 deletions mod/node-core/pkg/components/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func ProvideNodeAPIEngine() *NodeAPIEngine {
type NodeAPIBackendInput struct {
depinject.In

StorageBackend *StorageBackend
ChainSpec common.ChainSpec
StateProcessor *StateProcessor
StorageBackend *StorageBackend
}

func ProvideNodeAPIBackend(in NodeAPIBackendInput) *NodeAPIBackend {
Expand Down Expand Up @@ -82,8 +82,8 @@ type NodeAPIServerInput struct {

Engine *NodeAPIEngine
Config *config.Config
Logger log.AdvancedLogger[any, sdklog.Logger]
Handlers []handlers.Handlers[NodeAPIContext]
Logger log.AdvancedLogger[any, sdklog.Logger]
}

func ProvideNodeAPIServer(in NodeAPIServerInput) *NodeAPIServer {
Expand All @@ -99,3 +99,11 @@ func ProvideNodeAPIServer(in NodeAPIServerInput) *NodeAPIServer {
in.Handlers...,
)
}

func DefaultNodeAPIComponents() []any {
return []any{
ProvideNodeAPIServer,
ProvideNodeAPIEngine,
ProvideNodeAPIBackend,
}
}
13 changes: 13 additions & 0 deletions mod/node-core/pkg/components/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,16 @@ func ProvideNodeAPINodeHandler() *NodeAPIHandler {
func ProvideNodeAPIProofHandler(b *NodeAPIBackend) *ProofAPIHandler {
return proofapi.NewHandler[NodeAPIContext](b)
}

func DefaultNodeAPIHandlers() []any {
return []any{
ProvideNodeAPIHandlers,
ProvideNodeAPIBeaconHandler,
ProvideNodeAPIBuilderHandler,
ProvideNodeAPIConfigHandler,
ProvideNodeAPIDebugHandler,
ProvideNodeAPIEventsHandler,
ProvideNodeAPINodeHandler,
ProvideNodeAPIProofHandler,
}
}
19 changes: 13 additions & 6 deletions mod/node-core/pkg/components/attributes_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,32 @@
package components

import (
"cosmossdk.io/depinject"
"github.com/berachain/beacon-kit/mod/config"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/payload/pkg/attributes"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
)

type AttributesFactoryInput struct {
depinject.In

ChainSpec common.ChainSpec
Config *config.Config
Logger log.Logger[any]
}

// ProvideAttributesFactory provides an AttributesFactory for the client.
func ProvideAttributesFactory(
chainSpec common.ChainSpec,
logger log.Logger[any],
cfg *config.Config,
in AttributesFactoryInput,
) (*AttributesFactory, error) {
return attributes.NewAttributesFactory[
*BeaconState,
*PayloadAttributes,
*Withdrawal,
](
chainSpec,
logger,
cfg.PayloadBuilder.SuggestedFeeRecipient,
in.ChainSpec,
in.Logger,
in.Config.PayloadBuilder.SuggestedFeeRecipient,
), nil
}
2 changes: 1 addition & 1 deletion mod/node-core/pkg/components/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (
type StorageBackendInput struct {
depinject.In
AvailabilityStore *AvailabilityStore
BlockStore *BlockStore
ChainSpec common.ChainSpec
DepositStore *DepositStore
KVStore *KVStore
BlockStore *BlockStore
}

// ProvideStorageBackend is the depinject provider that returns a beacon storage
Expand Down
2 changes: 1 addition & 1 deletion mod/node-core/pkg/components/block_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func ProvideBlockStore(
type BlockPrunerInput struct {
depinject.In

Config *config.Config
BlockBroker *BlockBroker
BlockStore *BlockStore
Config *config.Config
Logger log.Logger
}

Expand Down
4 changes: 2 additions & 2 deletions mod/node-core/pkg/components/block_store_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
type BlockServiceInput struct {
depinject.In

Config *config.Config
Logger log.Logger[any]
BlockBroker *BlockBroker
BlockStore *BlockStore
Config *config.Config
Logger log.Logger[any]
}

// ProvideBlockStoreService provides the block service.
Expand Down
20 changes: 16 additions & 4 deletions mod/node-core/pkg/components/brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"github.com/berachain/beacon-kit/mod/async/pkg/broker"
)

// ProvideBlobFeed provides a blob feed for the depinject framework.
func ProvideBlobFeed() *SidecarsBroker {
// ProvideBlobBroker provides a blob feed for the depinject framework.
func ProvideBlobBroker() *SidecarsBroker {
return broker.New[*SidecarEvent](
"blob-broker",
)
}

// ProvideBlockFeed provides a block feed for the depinject framework.
func ProvideBlockFeed() *BlockBroker {
// ProvideBlockBroker provides a block feed for the depinject framework.
func ProvideBlockBroker() *BlockBroker {
return broker.New[*BlockEvent](
"blk-broker",
)
Expand Down Expand Up @@ -65,3 +65,15 @@ func ProvideValidatorUpdateBroker() *ValidatorUpdateBroker {
"validator-updates-broker",
)
}

// DefaultBrokerProviders returns a slice of the default broker providers.
func DefaultBrokerProviders() []interface{} {
return []interface{}{
ProvideBlobBroker,
ProvideBlockBroker,
ProvideGenesisBroker,
ProvideSlotBroker,
ProvideStatusBroker,
ProvideValidatorUpdateBroker,
}
}
1 change: 1 addition & 0 deletions mod/node-core/pkg/components/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
// ChainServiceInput is the input for the chain service provider.
type ChainServiceInput struct {
depinject.In

BlockBroker *BlockBroker
ChainSpec common.ChainSpec
Cfg *config.Config
Expand Down
2 changes: 1 addition & 1 deletion mod/node-core/pkg/components/db_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
type DBManagerInput struct {
depinject.In
AvailabilityPruner DAPruner
DepositPruner DepositPruner
BlockPruner BlockPruner
DepositPruner DepositPruner
Logger log.Logger
}

Expand Down
32 changes: 10 additions & 22 deletions mod/node-core/pkg/components/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
package components

func DefaultComponentsWithStandardTypes() []any {
return []any{
components := []any{
ProvideABCIMiddleware,
ProvideAttributesFactory,
ProvideAvailabilityPruner,
ProvideAvailibilityStore,
ProvideBeaconDepositContract,
ProvideBlockPruner,
ProvideBlockStore,
ProvideBlockStoreService,
ProvideBlsSigner,
ProvideBlobFeed,
ProvideBlockFeed,
ProvideBlobProcessor,
ProvideBlobProofVerifier,
ProvideBlobVerifier,
ProvideBlockStoreService,
ProvideBlockPruner,
ProvideBlockStore,
ProvideChainService,
ProvideChainSpec,
ProvideConfig,
Expand All @@ -44,32 +43,21 @@ func DefaultComponentsWithStandardTypes() []any {
ProvideDepositPruner,
ProvideDepositService,
ProvideDepositStore,
ProvideBeaconDepositContract,
ProvideEngineClient,
ProvideExecutionEngine,
ProvideGenesisBroker,
ProvideJWTSecret,
ProvideLocalBuilder,
ProvideNodeAPIBackend,
ProvideNodeAPIEngine,
ProvideNodeAPIHandlers,
ProvideNodeAPIBeaconHandler,
ProvideNodeAPIBuilderHandler,
ProvideNodeAPIConfigHandler,
ProvideNodeAPIDebugHandler,
ProvideNodeAPIEventsHandler,
ProvideNodeAPINodeHandler,
ProvideNodeAPIProofHandler,
ProvideNodeAPIServer,
ProvideReportingService,
ProvideServiceRegistry,
ProvideSidecarFactory,
ProvideStateProcessor,
ProvideSlotBroker,
ProvideStatusBroker,
ProvideStorageBackend,
ProvideTelemetrySink,
ProvideTrustedSetup,
ProvideValidatorService,
ProvideValidatorUpdateBroker,
}
components = append(components, DefaultNodeAPIComponents()...)
components = append(components, DefaultNodeAPIHandlers()...)
components = append(components, DefaultBrokerProviders()...)
return components
}
2 changes: 0 additions & 2 deletions mod/node-core/pkg/components/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
type ABCIMiddlewareInput struct {
depinject.In
BeaconBlockFeed *BlockBroker
ChainService *ChainService
ChainSpec common.ChainSpec
GenesisBroker *GenesisBroker
Logger log.Logger[any]
Expand All @@ -56,7 +55,6 @@ func ProvideABCIMiddleware(
*Deposit, *ExecutionPayload, *Genesis, *SlotData,
](
in.ChainSpec,
in.ChainService,
in.Logger,
in.TelemetrySink,
in.GenesisBroker,
Expand Down
44 changes: 44 additions & 0 deletions mod/node-core/pkg/components/reporting_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package components

import (
"cosmossdk.io/depinject"
sdklog "cosmossdk.io/log"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics"
"github.com/berachain/beacon-kit/mod/node-core/pkg/services/version"
sdkversion "github.com/cosmos/cosmos-sdk/version"
)

type ReportingServiceInput struct {
depinject.In
Logger log.AdvancedLogger[any, sdklog.Logger]
TelemetrySink *metrics.TelemetrySink
}

func ProvideReportingService(in ReportingServiceInput) *ReportingService {
return version.NewReportingService(
in.Logger.With("service", "reporting"),
in.TelemetrySink,
sdkversion.Version,
)
}
11 changes: 3 additions & 8 deletions mod/node-core/pkg/components/service_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"cosmossdk.io/depinject"
"cosmossdk.io/log"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/metrics"
"github.com/berachain/beacon-kit/mod/node-core/pkg/services/version"
"github.com/berachain/beacon-kit/mod/runtime/pkg/service"
sdkversion "github.com/cosmos/cosmos-sdk/version"
)

// ServiceRegistryInput is the input for the service registry provider.
Expand All @@ -36,13 +34,14 @@ type ServiceRegistryInput struct {
BlockBroker *BlockBroker
BlockStoreService *BlockStoreService
ChainService *ChainService
DBManager *DBManager
DAService *DAService
DBManager *DBManager
DepositService *DepositService
EngineClient *EngineClient
GenesisBroker *GenesisBroker
Logger log.Logger
NodeAPIServer *NodeAPIServer
ReportingService *ReportingService
SidecarsBroker *SidecarsBroker
SlotBroker *SlotBroker
TelemetrySink *metrics.TelemetrySink
Expand All @@ -63,11 +62,7 @@ func ProvideServiceRegistry(
service.WithService(in.DepositService),
service.WithService(in.ABCIService),
service.WithService(in.NodeAPIServer),
service.WithService(version.NewReportingService(
in.Logger.With("service", "reporting"),
in.TelemetrySink,
sdkversion.Version,
)),
service.WithService(in.ReportingService),
service.WithService(in.DBManager),
service.WithService(in.GenesisBroker),
service.WithService(in.BlockBroker),
Expand Down
4 changes: 4 additions & 0 deletions mod/node-core/pkg/components/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/berachain/beacon-kit/mod/node-api/server"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/signer"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components/storage"
"github.com/berachain/beacon-kit/mod/node-core/pkg/services/version"
nodetypes "github.com/berachain/beacon-kit/mod/node-core/pkg/types"
"github.com/berachain/beacon-kit/mod/payload/pkg/attributes"
payloadbuilder "github.com/berachain/beacon-kit/mod/payload/pkg/builder"
Expand Down Expand Up @@ -321,6 +322,9 @@ type (
// PayloadID is a type alias for the payload ID.
PayloadID = engineprimitives.PayloadID

// ReportingService is a type alias for the reporting service.
ReportingService = version.ReportingService

// SidecarFactory is a type alias for the sidecar factory.
SidecarFactory = dablob.SidecarFactory[
*BeaconBlock,
Expand Down
10 changes: 1 addition & 9 deletions mod/runtime/pkg/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ type ABCIMiddleware[
] struct {
// chainSpec is the chain specification.
chainSpec common.ChainSpec
// chainService represents the blockchain service.
chainService BlockchainService[
BeaconBlockT, BlobSidecarsT, DepositT, GenesisT,
]
// TODO: we will eventually gossip the blobs separately from
// CometBFT, but for now, these are no-op gossipers.
blobGossiper p2p.PublisherReceiver[
Expand Down Expand Up @@ -115,9 +111,6 @@ func NewABCIMiddleware[
SlotDataT any,
](
chainSpec common.ChainSpec,
chainService BlockchainService[
BeaconBlockT, BlobSidecarsT, DepositT, GenesisT,
],
logger log.Logger[any],
telemetrySink TelemetrySink,
genesisBroker *broker.Broker[*asynctypes.Event[GenesisT]],
Expand All @@ -133,8 +126,7 @@ func NewABCIMiddleware[
AvailabilityStoreT, BeaconBlockT, BlobSidecarsT, DepositT,
ExecutionPayloadT, GenesisT, SlotDataT,
]{
chainSpec: chainSpec,
chainService: chainService,
chainSpec: chainSpec,
blobGossiper: rp2p.NewNoopBlobHandler[
BlobSidecarsT, encoding.ABCIRequest,
](),
Expand Down

0 comments on commit 6657880

Please sign in to comment.