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

node: start and stop block service by notification from lifecycle #158

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion node/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
nodecore "github.com/celestiaorg/celestia-node/node/core"
"github.com/celestiaorg/celestia-node/node/fxutil"
"github.com/celestiaorg/celestia-node/node/rpc"
"github.com/celestiaorg/celestia-node/node/services"
"github.com/celestiaorg/celestia-node/service/block"
)

Expand All @@ -20,6 +21,6 @@ func fullComponents(cfg *Config, repo Repository) fx.Option {
return core.NewBlockFetcher(client)
}),
fx.Provide(rpc.NewServer),
fx.Provide(block.NewBlockService),
services.Components(),
)
}
17 changes: 0 additions & 17 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ func (n *Node) Start(ctx context.Context) error {
return err
}
}
// start block service if not Light node
if n.Type != Light {
err = n.BlockServ.Start(ctx)
if err != nil {
log.Errorw("starting block service", "err", err)
return fmt.Errorf("node: failed to start block service: %w", err)
}
}

// TODO(@Wondertan): Print useful information about the node:
// * API address
Expand Down Expand Up @@ -155,15 +147,6 @@ func (n *Node) Stop(ctx context.Context) error {
return err
}

// stop block service if not Light node
if n.Type != Light {
err = n.BlockServ.Stop(ctx)
if err != nil {
log.Errorw("stopping block service", "err", err)
return fmt.Errorf("node: failed to stop block service: %w", err)
}
}

log.Infof("stopped %s Node", n.Type)
return nil
}
Expand Down
22 changes: 22 additions & 0 deletions node/services/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package services

import (
"github.com/celestiaorg/celestia-node/service/block"

ipld "github.com/ipfs/go-ipld-format"
"go.uber.org/fx"
)

// Components wraps services creation
func Components() fx.Option {
return fx.Options(
fx.Provide(func(lc fx.Lifecycle, fetcher block.Fetcher, store ipld.DAGService) *block.Service {
service := block.NewBlockService(fetcher, store)
lc.Append(fx.Hook{
OnStart: service.Start,
OnStop: service.Stop,
})
return service
}),
)
}