Skip to content

Commit

Permalink
chore(config): improve StateConfig (#2778)
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Sep 14, 2022
1 parent 1adecf8 commit 20b01bc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
13 changes: 9 additions & 4 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ func createDotConfig(ctx *cli.Context) (*dot.Config, error) {
setDotNetworkConfig(ctx, tomlCfg.Network, &cfg.Network)
setDotRPCConfig(ctx, tomlCfg.RPC, &cfg.RPC)
setDotPprofConfig(ctx, tomlCfg.Pprof, &cfg.Pprof)

if rewind := ctx.GlobalUint(RewindFlag.Name); rewind != 0 {
cfg.State.Rewind = rewind
}
setStateConfig(ctx, tomlCfg.State, &cfg.State)

// set system info
setSystemInfoConfig(ctx, cfg)
Expand Down Expand Up @@ -930,3 +927,11 @@ func setDotPprofConfig(ctx *cli.Context, tomlCfg ctoml.PprofConfig, cfg *dot.Ppr

logger.Debug("pprof configuration: " + cfg.String())
}

func setStateConfig(ctx *cli.Context, tomlCfg ctoml.StateConfig, cfg *dot.StateConfig) {
if ctx.GlobalIsSet(RewindFlag.Name) {
cfg.Rewind = ctx.GlobalUint(RewindFlag.Name)
} else if tomlCfg.Rewind > 0 {
cfg.Rewind = tomlCfg.Rewind
}
}
2 changes: 1 addition & 1 deletion cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
Usage: "Roles of the gossamer node",
}
// RewindFlag rewinds the head of the chain to the given block number. Useful for development
RewindFlag = cli.IntFlag{
RewindFlag = cli.UintFlag{
Name: "rewind",
Usage: "Rewind head of chain to the given block number",
}
Expand Down
4 changes: 4 additions & 0 deletions dot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ type StateConfig struct {
Rewind uint
}

func (s *StateConfig) String() string {
return "rewind " + fmt.Sprint(s.Rewind)
}

// networkServiceEnabled returns true if the network service is enabled
func networkServiceEnabled(cfg *Config) bool {
return cfg.Core.Roles != common.NoNetworkRole
Expand Down
6 changes: 6 additions & 0 deletions dot/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
Account AccountConfig `toml:"account,omitempty"`
Core CoreConfig `toml:"core,omitempty"`
Network NetworkConfig `toml:"network,omitempty"`
State StateConfig `toml:"state,omitempty"`
RPC RPCConfig `toml:"rpc,omitempty"`
Pprof PprofConfig `toml:"pprof,omitempty"`
}
Expand Down Expand Up @@ -77,6 +78,11 @@ type CoreConfig struct {
BABELead bool `toml:"babe-lead,omitempty"`
}

// StateConfig contains the configuration for the state.
type StateConfig struct {
Rewind uint `toml:"rewind,omitempty"`
}

// RPCConfig is to marshal/unmarshal toml RPC config vars
type RPCConfig struct {
Enabled bool `toml:"enabled,omitempty"`
Expand Down

0 comments on commit 20b01bc

Please sign in to comment.