Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions sei-cosmos/server/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,35 @@ import (
// PruningOptions. If a pruning strategy is provided, that will be parsed and
// returned, otherwise, it is assumed custom pruning options are provided.
func GetPruningOptionsFromFlags(appOpts types.AppOptions) (storetypes.PruningOptions, error) {
strategy := strings.ToLower(cast.ToString(appOpts.Get(FlagPruning)))
// New format (iavl.*) takes priority, fallback to legacy top-level keys for backward compatibility
strategy := cast.ToString(appOpts.Get(FlagIAVLPruning))
if strategy == "" {
strategy = cast.ToString(appOpts.Get(FlagPruning))
}
Comment on lines +19 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve CLI pruning overrides when iavl config exists

With the generated config template, iavl.pruning is always present (defaulted to a non-empty value), so this logic will always take that value and never consult the legacy --pruning flag. That means running seid start --pruning=everything (or custom --pruning-keep-* flags) won’t override the config anymore once a node has an app.toml with the [iavl] section, even though those flags are still registered. This is a regression in CLI behavior; consider checking whether the legacy flag was explicitly set (or binding new iavl.* flags) before unconditionally preferring iavl.pruning.

Useful? React with 👍 / 👎.

strategy = strings.ToLower(strategy)

switch strategy {
case storetypes.PruningOptionDefault, storetypes.PruningOptionNothing, storetypes.PruningOptionEverything:
return storetypes.NewPruningOptionsFromString(strategy), nil

case storetypes.PruningOptionCustom:
keepRecent := appOpts.Get(FlagIAVLPruningKeepRecent)
if keepRecent == nil {
keepRecent = appOpts.Get(FlagPruningKeepRecent)
}
keepEvery := appOpts.Get(FlagIAVLPruningKeepEvery)
if keepEvery == nil {
keepEvery = appOpts.Get(FlagPruningKeepEvery)
}
interval := appOpts.Get(FlagIAVLPruningInterval)
if interval == nil {
interval = appOpts.Get(FlagPruningInterval)
}

opts := storetypes.NewPruningOptions(
cast.ToUint64(appOpts.Get(FlagPruningKeepRecent)),
cast.ToUint64(appOpts.Get(FlagPruningKeepEvery)),
cast.ToUint64(appOpts.Get(FlagPruningInterval)),
cast.ToUint64(keepRecent),
cast.ToUint64(keepEvery),
cast.ToUint64(interval),
)

if err := opts.Validate(); err != nil {
Expand Down
37 changes: 37 additions & 0 deletions sei-cosmos/server/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ func TestGetPruningOptionsFromFlags(t *testing.T) {
},
expectedOptions: types.PruneNothing,
},
{
name: FlagIAVLPruning,
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagIAVLPruning, types.PruningOptionNothing)
return v
},
expectedOptions: types.PruneNothing,
},
{
name: "custom pruning options",
initParams: func() *viper.Viper {
Expand All @@ -42,6 +51,23 @@ func TestGetPruningOptionsFromFlags(t *testing.T) {
Interval: 10,
},
},
{
name: "custom pruning options iavl",
initParams: func() *viper.Viper {
v := viper.New()
v.Set(FlagIAVLPruning, types.PruningOptionCustom)
v.Set(FlagIAVLPruningKeepRecent, 1234)
v.Set(FlagIAVLPruningKeepEvery, 4321)
v.Set(FlagIAVLPruningInterval, 10)

return v
},
expectedOptions: types.PruningOptions{
KeepRecent: 1234,
KeepEvery: 4321,
Interval: 10,
},
},
{
name: types.PruningOptionDefault,
initParams: func() *viper.Viper {
Expand All @@ -51,6 +77,17 @@ func TestGetPruningOptionsFromFlags(t *testing.T) {
},
expectedOptions: types.PruneDefault,
},
{
name: "new format takes priority over legacy",
initParams: func() *viper.Viper {
v := viper.New()
// Both old and new format present - new format should win
v.Set(FlagPruning, types.PruningOptionNothing)
v.Set(FlagIAVLPruning, types.PruningOptionEverything)
return v
},
expectedOptions: types.PruneEverything,
},
}

for _, tt := range tests {
Expand Down
17 changes: 13 additions & 4 deletions sei-cosmos/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ const (
FlagProfile = "profile"
FlagInvCheckPeriod = "inv-check-period"

FlagPruning = "pruning"
FlagPruningKeepRecent = "pruning-keep-recent"
FlagPruningKeepEvery = "pruning-keep-every"
FlagPruningInterval = "pruning-interval"
// Legacy pruning flags (kept for backward compatibility)
FlagPruning = "pruning"
FlagPruningKeepRecent = "pruning-keep-recent"
FlagPruningKeepEvery = "pruning-keep-every"
FlagPruningInterval = "pruning-interval"

// New pruning config keys under [iavl] section (v6.3.0+)
// TODO: Remove legacy fallback once all nodes have migrated to v6.3.0+
FlagIAVLPruning = "iavl.pruning"
FlagIAVLPruningKeepRecent = "iavl.pruning-keep-recent"
FlagIAVLPruningKeepEvery = "iavl.pruning-keep-every"
FlagIAVLPruningInterval = "iavl.pruning-interval"

FlagIndexEvents = "index-events"
FlagMinRetainBlocks = "min-retain-blocks"
FlagIAVLCacheSize = "iavl-cache-size"
Expand Down
Loading