Skip to content

Commit

Permalink
add lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Feb 25, 2022
1 parent 7cf083d commit f688557
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions node/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
logging "github.com/ipfs/go-log/v2"
"go.uber.org/fx"

"go.uber.org/fx"

nodecore "github.com/celestiaorg/celestia-node/node/core"
"github.com/celestiaorg/celestia-node/node/fxutil"
"github.com/celestiaorg/celestia-node/node/p2p"
Expand All @@ -26,9 +28,17 @@ func lightComponents(cfg *Config, store Store) fxutil.Option {
fxutil.Provide(services.HeaderExchangeP2P(cfg.Services)),
// state components
fxutil.ProvideIf(cfg.Core.Remote, state.NewService),
fxutil.ProvideIf(cfg.Core.Remote, func() (state.Accessor, error) {
// TODO @renaynay: add hooks for CA lifecycle
return statecomponents.CoreAccessor(cfg.Services.KeyConf, store.Path(), cfg.Core.RemoteConfig.RemoteAddr)
fxutil.ProvideIf(cfg.Core.Remote, func(lc fx.Lifecycle) (state.Accessor, error) {
ca, err := statecomponents.CoreAccessor(cfg.Services.KeyConf, store.Path(),
cfg.Core.RemoteConfig.RemoteAddr)
if err != nil {
return nil, err
}
lc.Append(fx.Hook{
OnStart: ca.Start,
OnStop: ca.Stop,
})
return ca, nil
}),
)
}
Expand Down
4 changes: 4 additions & 0 deletions service/state/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import "context"
// query for state-related information and submit transactions/
// messages to the Celestia network.
type Accessor interface {
// Start starts the state Accessor.
Start(context.Context) error
// Stop stops the state Accessor.
Stop(context.Context) error
// Balance retrieves the Celestia coin balance
// for the node's account/signer.
Balance(ctx context.Context) (*Balance, error)
Expand Down

0 comments on commit f688557

Please sign in to comment.