Skip to content

Commit

Permalink
refactor: cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Aug 21, 2023
1 parent 1b24356 commit 2d64795
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions nodebuilder/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func DefaultConfig() Config {

// Validate performs basic validation of the config.
func (cfg *Config) Validate() error {
if !cfg.EndpointConfigured() {
if !cfg.IsEndpointConfigured() {
return nil
}

Expand All @@ -46,8 +46,8 @@ func (cfg *Config) Validate() error {
return nil
}

// EndpointConfigured returns whether a core endpoint has been set
// IsEndpointConfigured returns whether a core endpoint has been set
// on the config (true if set).
func (cfg *Config) EndpointConfigured() bool {
func (cfg *Config) IsEndpointConfigured() bool {
return cfg.IP != ""
}
2 changes: 1 addition & 1 deletion nodebuilder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ConstructModule(tp node.Type, network p2p.Network, cfg *Config, store Store
fx.Supply(signer),
// modules provided by the node
p2p.ConstructModule(tp, &cfg.P2P),
state.ConstructModule(tp, &cfg.State),
state.ConstructModule(tp, &cfg.State, &cfg.Core),
header.ConstructModule(tp, &cfg.Header),
share.ConstructModule(tp, &cfg.Share),
rpc.ConstructModule(tp, &cfg.RPC),
Expand Down
5 changes: 0 additions & 5 deletions nodebuilder/state/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ func coreAccessor(
sync *sync.Syncer[*header.ExtendedHeader],
fraudServ libfraud.Service,
) (*state.CoreAccessor, Module, *modfraud.ServiceBreaker[*state.CoreAccessor]) {
if !corecfg.EndpointConfigured() {
log.Info("No core endpoint provided, running node without state access")
return nil, &stubbedStateModule{}, nil
}

ca := state.NewCoreAccessor(signer, sync, corecfg.IP, corecfg.RPCPort, corecfg.GRPCPort)

return ca, ca, &modfraud.ServiceBreaker[*state.CoreAccessor]{
Expand Down
9 changes: 7 additions & 2 deletions nodebuilder/state/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
logging "github.com/ipfs/go-log/v2"
"go.uber.org/fx"

"github.com/celestiaorg/celestia-node/libs/fxutil"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/state"
Expand All @@ -15,14 +17,14 @@ var log = logging.Logger("module/state")

// ConstructModule provides all components necessary to construct the
// state service.
func ConstructModule(tp node.Type, cfg *Config) fx.Option {
func ConstructModule(tp node.Type, cfg *Config, coreCfg *core.Config) fx.Option {
// sanitize config values before constructing module
cfgErr := cfg.Validate()

baseComponents := fx.Options(
fx.Supply(*cfg),
fx.Error(cfgErr),
fx.Provide(fx.Annotate(
fxutil.ProvideIf(coreCfg.IsEndpointConfigured(), fx.Annotate(
coreAccessor,
fx.OnStart(func(ctx context.Context, breaker *modfraud.ServiceBreaker[*state.CoreAccessor]) error {
return breaker.Start(ctx)
Expand All @@ -31,6 +33,9 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
return breaker.Stop(ctx)
}),
)),
fxutil.ProvideIf(!coreCfg.IsEndpointConfigured(), func() (*state.CoreAccessor, Module) {
return nil, &stubbedStateModule{}
}),
)

switch tp {
Expand Down

0 comments on commit 2d64795

Please sign in to comment.