Skip to content

Commit

Permalink
rework options
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Apr 16, 2024
1 parent 88c9531 commit 9f5f453
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
6 changes: 5 additions & 1 deletion cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,13 @@ func PersistentPreRunEnv(cmd *cobra.Command, nodeType node.Type, _ []string) err
return err
}

err = state.ParseFlags(cmd, &cfg.State)
if err != nil {
return err
}

rpc_cfg.ParseFlags(cmd, &cfg.RPC)
gateway.ParseFlags(cmd, &cfg.Gateway)
state.ParseFlags(cmd, &cfg.State)

switch nodeType {
case node.Light:
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/state/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func coreAccessor(
signer *apptypes.KeyringSigner,
sync *sync.Syncer[*header.ExtendedHeader],
fraudServ libfraud.Service[*header.ExtendedHeader],
opts ...state.Option,
opts []state.Option,
) (*state.CoreAccessor, Module, *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]) {
ca := state.NewCoreAccessor(signer, sync, corecfg.IP, corecfg.RPCPort, corecfg.GRPCPort, opts...)
sBreaker := &modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]{
Expand Down
14 changes: 7 additions & 7 deletions nodebuilder/state/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Flags() *flag.FlagSet {
}

// ParseFlags parses State flags from the given cmd and saves them to the passed config.
func ParseFlags(cmd *cobra.Command, cfg *Config) {
func ParseFlags(cmd *cobra.Command, cfg *Config) error {
keyringAccName := cmd.Flag(keyringAccNameFlag).Value.String()
if keyringAccName != "" {
cfg.KeyringAccName = keyringAccName
Expand All @@ -38,11 +38,11 @@ func ParseFlags(cmd *cobra.Command, cfg *Config) {
cfg.KeyringBackend = cmd.Flag(keyringBackendFlag).Value.String()

addr := cmd.Flag(granterAddressFlag).Value.String()
if addr != "" {
sdkAddress, err := sdktypes.AccAddressFromBech32(addr)
if err != nil {
panic(err)
}
cfg.GranterAddress = sdkAddress
if addr == "" {
return nil
}

sdkAddress, err := sdktypes.AccAddressFromBech32(addr)
cfg.GranterAddress = sdkAddress
return err
}
19 changes: 6 additions & 13 deletions nodebuilder/state/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
logging "github.com/ipfs/go-log/v2"
"go.uber.org/fx"

apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
libfraud "github.com/celestiaorg/go-fraud"
"github.com/celestiaorg/go-header/sync"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/libs/fxutil"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
Expand All @@ -25,19 +21,16 @@ var log = logging.Logger("module/state")
func ConstructModule(tp node.Type, cfg *Config, coreCfg *core.Config) fx.Option {
// sanitize config values before constructing module
cfgErr := cfg.Validate()

opts := make([]state.Option, 0)
if !cfg.GranterAddress.Empty() {
opts = append(opts, state.WithGranter(cfg.GranterAddress))
}
baseComponents := fx.Options(
fx.Supply(*cfg),
fx.Supply(cfg.GranterAddress),
fx.Error(cfgErr),
fx.Supply(opts),
fxutil.ProvideIf(coreCfg.IsEndpointConfigured(), fx.Annotate(
func(
signer *apptypes.KeyringSigner,
sync *sync.Syncer[*header.ExtendedHeader],
fraudServ libfraud.Service[*header.ExtendedHeader],
) (*state.CoreAccessor, Module, *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]) {
return coreAccessor(*coreCfg, signer, sync, fraudServ, state.WithGranter(cfg.GranterAddress))
},
coreAccessor,
fx.OnStart(func(ctx context.Context,
breaker *modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]) error {
return breaker.Start(ctx)
Expand Down

0 comments on commit 9f5f453

Please sign in to comment.