Skip to content

Commit

Permalink
Self review.
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed May 27, 2021
1 parent 2325f98 commit 238222d
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 91 deletions.
5 changes: 3 additions & 2 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@ func setDotGlobalConfigFromToml(tomlCfg *ctoml.Config, cfg *dot.GlobalConfig) {
}

cfg.MetricsPort = tomlCfg.Global.MetricsPort

cfg.RetainBlocks = tomlCfg.Global.RetainBlocks
cfg.GCMode = tomlCfg.Global.GCMode
}
}

Expand Down Expand Up @@ -473,9 +475,8 @@ func setDotGlobalConfigFromFlags(ctx *cli.Context, cfg *dot.GlobalConfig) {
cfg.MetricsPort = uint32(metricsPort)
}

// check --retain-blocks flag
cfg.RetainBlocks = ctx.GlobalInt64(RetainBlockNumberFlag.Name)

cfg.GCMode = ctx.GlobalString(GCModeFlag.Name)
cfg.NoTelemetry = ctx.Bool("no-telemetry")
}

Expand Down
1 change: 1 addition & 0 deletions cmd/gossamer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
LogLvl: dcfg.Global.LogLvl.String(),
MetricsPort: dcfg.Global.MetricsPort,
RetainBlocks: dcfg.Global.RetainBlocks,
GCMode: dcfg.Global.GCMode,
}

cfg.Log = ctoml.LogConfig{
Expand Down
8 changes: 8 additions & 0 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ var (
Usage: "Retain number of block from latest block while pruning",
Value: 256,
}

// GCModeFlag sets the blockchain GC mode. It's either full or archive.
GCModeFlag = cli.StringFlag{
Name: "gcmode",
Usage: `Blockchain garbage collection mode ("full", "archive")`,
Value: "full",
}
)

// flag sets that are shared by multiple commands
Expand All @@ -302,6 +309,7 @@ var (
DBPathFlag,
BloomFilterSizeFlag,
RetainBlockNumberFlag,
GCModeFlag,
}

// StartupFlags are flags that are valid for use with the root command and the export subcommand
Expand Down
8 changes: 6 additions & 2 deletions cmd/gossamer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,12 @@ func gossamerAction(ctx *cli.Context) error {
return err
}

if cfg.Global.RetainBlocks < 256 {
return fmt.Errorf("retain blocks cannot be less than 256")
if cfg.Global.RetainBlocks < 10 {
return fmt.Errorf("--%s cannot be less than 256", RetainBlockNumberFlag.Name)
}

if cfg.Global.GCMode != "full" && cfg.Global.GCMode != "archive" {
return fmt.Errorf("--%s must be either 'full' or 'archive'", GCModeFlag.Name)
}

cfg.Global.LogLvl = lvl
Expand Down
1 change: 1 addition & 0 deletions dot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type GlobalConfig struct {
MetricsPort uint32
NoTelemetry bool
RetainBlocks int64
GCMode string
}

// LogConfig represents the log levels for individual packages
Expand Down
1 change: 1 addition & 0 deletions dot/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type GlobalConfig struct {
LogLvl string `toml:"log,omitempty"`
MetricsPort uint32 `toml:"metrics-port,omitempty"`
RetainBlocks int64 `toml:"retain-blocks,omitempty"`
GCMode string `toml:"gc-mode,omitempty"`
}

// LogConfig represents the log levels for individual packages
Expand Down
11 changes: 8 additions & 3 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,14 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node,
// Network Service
var networkSrvc *network.Service

pruner, err := state.CreatePruner(stateSrvc.DB(), cfg.Global.RetainBlocks)
if err != nil {
logger.Error("failed to create pruner:", err)
var pruner state.Pruner
if cfg.Global.GCMode == "full" {
pruner, err = state.CreatePruner(stateSrvc.DB(), cfg.Global.RetainBlocks)
if err != nil {
return nil, err
}
} else {
pruner = &state.ArchivalNodePruner{}
}

// check if network service is enabled
Expand Down
4 changes: 2 additions & 2 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func createRuntime(cfg *Config, st *state.Service, ks *keystore.GlobalKeystore,
return rt, nil
}

func createBABEService(cfg *Config, rt runtime.Instance, st *state.Service, ks keystore.Keystore, pruner *state.Pruner) (*babe.Service, error) {
func createBABEService(cfg *Config, rt runtime.Instance, st *state.Service, ks keystore.Keystore, pruner state.Pruner) (*babe.Service, error) {
logger.Info(
"creating BABE service...",
"authority", cfg.Core.BabeAuthority,
Expand Down Expand Up @@ -377,7 +377,7 @@ func createBlockVerifier(st *state.Service) (*babe.VerificationManager, error) {
return ver, nil
}

func createSyncService(cfg *Config, st *state.Service, bp sync.BlockProducer, fg sync.FinalityGadget, dh *core.DigestHandler, verifier *babe.VerificationManager, rt runtime.Instance, pruner *state.Pruner) (*sync.Service, error) {
func createSyncService(cfg *Config, st *state.Service, bp sync.BlockProducer, fg sync.FinalityGadget, dh *core.DigestHandler, verifier *babe.VerificationManager, rt runtime.Instance, pruner state.Pruner) (*sync.Service, error) {
syncCfg := &sync.Config{
LogLvl: cfg.Log.SyncLvl,
BlockState: st.Block,
Expand Down
5 changes: 3 additions & 2 deletions dot/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/utils"
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestCreateSyncService(t *testing.T) {
ver, err := createBlockVerifier(stateSrvc)
require.NoError(t, err)

_, err = createSyncService(cfg, stateSrvc, nil, nil, nil, ver, rt, nil)
_, err = createSyncService(cfg, stateSrvc, nil, nil, nil, ver, rt, &state.ArchivalNodePruner{})
require.NoError(t, err)
}

Expand Down Expand Up @@ -233,7 +234,7 @@ func TestCreateBABEService(t *testing.T) {
rt, err := createRuntime(cfg, stateSrvc, ks, &network.Service{})
require.NoError(t, err)

bs, err := createBABEService(cfg, rt, stateSrvc, ks.Babe, nil)
bs, err := createBABEService(cfg, rt, stateSrvc, ks.Babe, &state.ArchivalNodePruner{})
require.NoError(t, err)
require.NotNil(t, bs)
}
Expand Down
Loading

0 comments on commit 238222d

Please sign in to comment.