Skip to content

Commit

Permalink
cleanup service
Browse files Browse the repository at this point in the history
  • Loading branch information
calbera committed Dec 19, 2024
1 parent 6eccb1e commit b905604
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 92 deletions.
2 changes: 1 addition & 1 deletion beacon/blockchain/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *Service[
)
}

if err = s.depositStore.EnqueueDeposits(deposits); err != nil {
if err = s.storageBackend.DepositStore().EnqueueDeposits(deposits); err != nil {
s.logger.Error("Failed to store deposits", "error", err)
s.failedBlocksMu.Lock()
s.failedBlocks[blockNum] = struct{}{}
Expand Down
2 changes: 1 addition & 1 deletion beacon/blockchain/finalize_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *Service[

// store the finalized block in the KVStore.
slot := blk.GetSlot()
if err = s.blockStore.Set(blk); err != nil {
if err = s.storageBackend.BlockStore().Set(blk); err != nil {
s.logger.Error(
"failed to store block", "slot", slot, "error", err,
)
Expand Down
5 changes: 1 addition & 4 deletions beacon/blockchain/init_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import (
// state.
func (s *Service[
_, _, _, _, _, _, GenesisT, _, _,
]) ProcessGenesisData(
ctx context.Context,
bytes []byte,
) (transition.ValidatorUpdates, error) {
]) ProcessGenesisData(ctx context.Context, bytes []byte) (transition.ValidatorUpdates, error) {
genesisData := *new(GenesisT)
if err := json.Unmarshal(bytes, &genesisData); err != nil {
s.logger.Error("Failed to unmarshal genesis data", "error", err)
Expand Down
62 changes: 12 additions & 50 deletions beacon/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,10 @@ type Service[
] struct {
// homeDir is the directory for config and data"
homeDir string
// storageBackend represents the backend storage for beacon states and
// associated sidecars.
storageBackend StorageBackend[
AvailabilityStoreT,
BeaconStateT,
DepositStoreT,
]
blobProcessor da.BlobProcessor[
AvailabilityStoreT,
ConsensusSidecarsT,
BlobSidecarsT,
]
// store is the block store for the service.
// TODO: Remove this and use the block store from the storage backend.
blockStore BlockStoreT
// depositStore is the deposit store that stores deposits.
depositStore deposit.Store
// storageBackend represents the backend storage for not state-enforced data.
storageBackend StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT]
// blobProcessor is used for processing sidecars.
blobProcessor da.BlobProcessor[AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT]
// depositContract is the contract interface for interacting with the
// deposit contract.
depositContract deposit.Contract
Expand All @@ -86,11 +73,7 @@ type Service[
// localBuilder is a local builder for constructing new beacon states.
localBuilder LocalBuilder[BeaconStateT]
// stateProcessor is the state processor for beacon blocks and states.
stateProcessor StateProcessor[
BeaconBlockT,
BeaconStateT,
*transition.Context,
]
stateProcessor StateProcessor[BeaconBlockT, BeaconStateT, *transition.Context]
// metrics is the metrics for the service.
metrics *chainMetrics
// optimisticPayloadBuilds is a flag used when the optimistic payload
Expand All @@ -113,49 +96,28 @@ func NewService[
BlobSidecarsT BlobSidecars[BlobSidecarsT],
](
homeDir string,
storageBackend StorageBackend[
AvailabilityStoreT,
BeaconStateT,
DepositStoreT,
],
blobProcessor da.BlobProcessor[
AvailabilityStoreT,
ConsensusSidecarsT,
BlobSidecarsT,
],
blockStore BlockStoreT,
depositStore deposit.Store,
storageBackend StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT],
blobProcessor da.BlobProcessor[AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT],
depositContract deposit.Contract,
eth1FollowDistance math.U64,
logger log.Logger,
chainSpec chain.ChainSpec,
executionEngine ExecutionEngine,
localBuilder LocalBuilder[BeaconStateT],
stateProcessor StateProcessor[
BeaconBlockT,
BeaconStateT,
*transition.Context,
],
stateProcessor StateProcessor[BeaconBlockT, BeaconStateT, *transition.Context],
telemetrySink TelemetrySink,
optimisticPayloadBuilds bool,
) *Service[
AvailabilityStoreT, DepositStoreT,
ConsensusBlockT, BeaconBlockT,
BeaconStateT, BlockStoreT,
GenesisT,
ConsensusSidecarsT, BlobSidecarsT,
AvailabilityStoreT, DepositStoreT, ConsensusBlockT, BeaconBlockT, BeaconStateT,
BlockStoreT, GenesisT, ConsensusSidecarsT, BlobSidecarsT,
] {
return &Service[
AvailabilityStoreT, DepositStoreT,
ConsensusBlockT, BeaconBlockT,
BeaconStateT, BlockStoreT,
GenesisT, ConsensusSidecarsT, BlobSidecarsT,
AvailabilityStoreT, DepositStoreT, ConsensusBlockT, BeaconBlockT,
BeaconStateT, BlockStoreT, GenesisT, ConsensusSidecarsT, BlobSidecarsT,
]{
homeDir: homeDir,
storageBackend: storageBackend,
blobProcessor: blobProcessor,
blockStore: blockStore,
depositStore: depositStore,
depositContract: depositContract,
eth1FollowDistance: eth1FollowDistance,
failedBlocks: make(map[math.Slot]struct{}),
Expand Down
3 changes: 3 additions & 0 deletions beacon/blockchain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ type StateProcessor[
type StorageBackend[
AvailabilityStoreT any,
BeaconStateT any,
BlockStoreT any,
DepositStoreT any,
] interface {
// AvailabilityStore returns the availability store for the given context.
Expand All @@ -210,6 +211,8 @@ type StorageBackend[
StateFromContext(context.Context) BeaconStateT
// DepositStore retrieves the deposit store.
DepositStore() DepositStoreT
// BlockStore retrieves the block store.
BlockStore() BlockStoreT
}

// TelemetrySink is an interface for sending metrics to a telemetry backend.
Expand Down
2 changes: 1 addition & 1 deletion cmd/beacond/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func DefaultComponents() []any {
*AvailabilityStore,
*ConsensusBlock, *BeaconBlock,
*BeaconState, *BeaconStateMarshallable,
*BlobSidecar, *BlobSidecars, *ConsensusSidecars, *BlockStore,
*BlobSidecar, *BlobSidecars, *ConsensusSidecars,
*DepositStore, *DepositContract,
*Genesis,
*KVStore, *Logger, *StorageBackend, *BlockStore,
Expand Down
54 changes: 19 additions & 35 deletions node-core/components/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ChainServiceInput[
BeaconStateT any,
StorageBackendT any,
LoggerT any,
BeaconBlockStoreT BlockStore[BeaconBlockT],
BlockStoreT BlockStore[BeaconBlockT],
DepositStoreT any,
DepositContractT any,
AvailabilityStoreT any,
Expand All @@ -52,24 +52,18 @@ type ChainServiceInput[
] struct {
depinject.In

AppOpts config.AppOptions
ChainSpec chain.ChainSpec
Cfg *config.Config
EngineClient *client.EngineClient
ExecutionEngine *engine.Engine[PayloadID]
LocalBuilder LocalBuilder[BeaconStateT]
Logger LoggerT
Signer crypto.BLSSigner
StateProcessor StateProcessor[
BeaconBlockT, BeaconStateT, *Context,
]
StorageBackend StorageBackendT
BlobProcessor BlobProcessor[
AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT,
]
AppOpts config.AppOptions
ChainSpec chain.ChainSpec
Cfg *config.Config
EngineClient *client.EngineClient
ExecutionEngine *engine.Engine[PayloadID]
LocalBuilder LocalBuilder[BeaconStateT]
Logger LoggerT
Signer crypto.BLSSigner
StateProcessor StateProcessor[BeaconBlockT, BeaconStateT, *Context]
StorageBackend StorageBackendT
BlobProcessor BlobProcessor[AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT]
TelemetrySink *metrics.TelemetrySink
BlockStore BeaconBlockStoreT
DepositStore DepositStoreT
BeaconDepositContract DepositContractT
}

Expand All @@ -83,44 +77,34 @@ func ProvideChainService[
BlobSidecarT BlobSidecar,
BlobSidecarsT BlobSidecars[BlobSidecarsT, BlobSidecarT],
ConsensusSidecarsT da.ConsensusSidecars[BlobSidecarsT],
BlockStoreT any,
DepositStoreT DepositStore,
DepositContractT deposit.Contract,
GenesisT Genesis,
KVStoreT any,
LoggerT log.AdvancedLogger[LoggerT],
StorageBackendT StorageBackend[
AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT,
],
BeaconBlockStoreT BlockStore[BeaconBlockT],
StorageBackendT StorageBackend[AvailabilityStoreT, BeaconStateT, BlockStoreT, DepositStoreT],
BlockStoreT BlockStore[BeaconBlockT],
](
in ChainServiceInput[
BeaconBlockT, BeaconStateT,
StorageBackendT, LoggerT,
BeaconBlockStoreT, DepositStoreT, DepositContractT,
AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT,
BeaconBlockT, BeaconStateT, StorageBackendT, LoggerT, BlockStoreT, DepositStoreT,
DepositContractT, AvailabilityStoreT, ConsensusSidecarsT, BlobSidecarsT,
],
) *blockchain.Service[
AvailabilityStoreT, DepositStoreT,
ConsensusBlockT, BeaconBlockT,
BeaconStateT, BeaconBlockStoreT,
GenesisT,
ConsensusSidecarsT, BlobSidecarsT,
AvailabilityStoreT, DepositStoreT, ConsensusBlockT, BeaconBlockT, BeaconStateT,
BlockStoreT, GenesisT, ConsensusSidecarsT, BlobSidecarsT,
] {
return blockchain.NewService[
AvailabilityStoreT,
DepositStoreT,
ConsensusBlockT,
BeaconBlockT,
BeaconStateT,
BeaconBlockStoreT,
BlockStoreT,
GenesisT,
](
cast.ToString(in.AppOpts.Get(flags.FlagHome)),
in.StorageBackend,
in.BlobProcessor,
in.BlockStore,
in.DepositStore,
in.BeaconDepositContract,
math.U64(in.ChainSpec.Eth1FollowDistance()),
in.Logger.With("service", "blockchain"),
Expand Down

0 comments on commit b905604

Please sign in to comment.