Skip to content

Commit

Permalink
Feat/force compact flag (#16)
Browse files Browse the repository at this point in the history
* fix: wait after pruning.

* feat: force-compact flag; default disabled.

* chore: apply linter suggestions.
  • Loading branch information
christopherbrumm authored Feb 2, 2024
1 parent ef1d7ca commit 3ef15ed
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := v0.3.5
VERSION := v0.3.6

ldflags := $(LDFLAGS)
ldflags += -X main.version=$(VERSION)
Expand Down
4 changes: 3 additions & 1 deletion cmd/supervysor/commands/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func init() {

pruneCmd.Flags().BoolVar(&statePruning, "state-pruning", true, "enable state pruning")

pruneCmd.Flags().BoolVar(&forceCompact, "force-compact", false, "prune with ForceCompact enabled")

pruneCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
}

Expand All @@ -31,7 +33,7 @@ var pruneCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
utils.TrackPruneEvent(optOut)

if err := store.Prune(home, untilHeight, statePruning, logger); err != nil {
if err := store.Prune(home, untilHeight, statePruning, forceCompact, logger); err != nil {
logger.Error(err.Error())
}
},
Expand Down
1 change: 1 addition & 0 deletions cmd/supervysor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
cfgFlag string
chainId string
config string
forceCompact bool
home string
metrics bool
metricsPort int
Expand Down
10 changes: 8 additions & 2 deletions cmd/supervysor/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func init() {

startCmd.Flags().BoolVar(&statePruning, "state-pruning", true, "enable state pruning")

startCmd.Flags().BoolVar(&forceCompact, "force-compact", false, "prune with ForceCompact enabled")

startCmd.Flags().StringVar(&binaryFlags, "flags", "", "flags for the underlying binary (e.g. '--address, ')")

startCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
Expand Down Expand Up @@ -51,6 +53,10 @@ var startCmd = &cobra.Command{
return err
}

if !statePruning {
supervysorConfig.StatePruning = false
}

utils.TrackStartEvent(supervysorConfig.ChainId, optOut)

metrics := supervysorConfig.Metrics
Expand Down Expand Up @@ -132,7 +138,7 @@ var startCmd = &cobra.Command{
}
logger.Info("pruning after node shutdown", "until-height", pruneHeight)

err = e.PruneData(supervysorConfig.HomePath, pruneHeight-1, supervysorConfig.StatePruning, binaryFlags)
err = e.PruneData(supervysorConfig.HomePath, pruneHeight-1, supervysorConfig.StatePruning, forceCompact, binaryFlags)
if err != nil {
logger.Error("could not prune", "err", err)
return err
Expand All @@ -141,7 +147,7 @@ var startCmd = &cobra.Command{
if nodeHeight < poolHeight {
logger.Info("pruning after node shutdown", "until-height", nodeHeight)

err = e.PruneData(supervysorConfig.HomePath, nodeHeight-1, supervysorConfig.StatePruning, binaryFlags)
err = e.PruneData(supervysorConfig.HomePath, nodeHeight-1, supervysorConfig.StatePruning, forceCompact, binaryFlags)
if err != nil {
logger.Error("could not prune", "err", err)
return err
Expand Down
6 changes: 3 additions & 3 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ func (e *Executor) EnableNormalMode(flags string) error {
return nil
}

func (e *Executor) PruneData(homePath string, pruneHeight int, statePruning bool, flags string) error {
func (e *Executor) PruneData(homePath string, pruneHeight int, statePruning, forceCompact bool, flags string) error {
if err := e.Shutdown(); err != nil {
e.Logger.Error("could not shutdown node process", "err", err)
return err
}
err := store.Prune(homePath, int64(pruneHeight)-1, statePruning, e.Logger)
err := store.Prune(homePath, int64(pruneHeight)-1, statePruning, forceCompact, e.Logger)
if err != nil {
e.Logger.Error("could not prune, exiting")
return err
}

time.Sleep(time.Second * time.Duration(10))
time.Sleep(time.Second * time.Duration(30))

if e.Process.GhostMode {
process, err := node.StartGhostNode(e.Cfg, e.Logger, &e.Process, true, flags)
Expand Down
7 changes: 6 additions & 1 deletion store/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import (
"cosmossdk.io/log"
)

func Prune(home string, untilHeight int64, statePruning bool, logger log.Logger) error {
func Prune(home string, untilHeight int64, statePruning, forceCompact bool, logger log.Logger) error {
config, err := utils.LoadConfig(home)
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}

if !forceCompact {
logger.Info("prune without ForceCompact")
return PruneAnyDB(home, untilHeight, statePruning, logger)
}

if strings.ToLower(config.DBBackend) == "goleveldb" {
logger.Info("GoLevelDB detected, using ForceCompact")
return PruneGoLevelDB(home, untilHeight, statePruning, logger)
Expand Down

0 comments on commit 3ef15ed

Please sign in to comment.