diff --git a/.changelog/5466.cfg.md b/.changelog/5466.cfg.md new file mode 100644 index 00000000000..0d15c870df8 --- /dev/null +++ b/.changelog/5466.cfg.md @@ -0,0 +1,4 @@ +Add `num_light_blocks_kept` configuration option + +Located under `consensus.prune`, it allows configuring the number of light +blocks that are kept in the local trusted store (defaulting to 10000). diff --git a/go/consensus/cometbft/abci/prune.go b/go/consensus/cometbft/abci/prune.go index 307b9a4146b..16351a50829 100644 --- a/go/consensus/cometbft/abci/prune.go +++ b/go/consensus/cometbft/abci/prune.go @@ -9,16 +9,11 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/logging" "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api" + "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/config" nodedb "github.com/oasisprotocol/oasis-core/go/storage/mkvs/db/api" ) const ( - // PruneDefault is the default PruneStrategy. - PruneDefault = pruneNone - - pruneNone = "none" - pruneKeepN = "keep_n" - // LogEventABCIPruneDelete is a log event value that signals an ABCI pruning // delete event. LogEventABCIPruneDelete = "cometbft/abci/prune" @@ -38,9 +33,9 @@ const ( func (s PruneStrategy) String() string { switch s { case PruneNone: - return pruneNone + return config.PruneStrategyNone case PruneKeepN: - return pruneKeepN + return config.PruneStrategyKeepN default: return "[unknown]" } @@ -48,9 +43,9 @@ func (s PruneStrategy) String() string { func (s *PruneStrategy) FromString(str string) error { switch strings.ToLower(str) { - case pruneNone: + case config.PruneStrategyNone: *s = PruneNone - case pruneKeepN: + case config.PruneStrategyKeepN: *s = PruneKeepN default: return fmt.Errorf("abci/pruner: unknown pruning strategy: '%v'", str) diff --git a/go/consensus/cometbft/config/config.go b/go/consensus/cometbft/config/config.go index 6f5251cd10f..bffbf2356ce 100644 --- a/go/consensus/cometbft/config/config.go +++ b/go/consensus/cometbft/config/config.go @@ -87,6 +87,13 @@ type SubmissionConfig struct { MaxFee uint64 `yaml:"max_fee"` } +const ( + // PruneStrategyNone is the identifier of the strategy that disables pruning. + PruneStrategyNone = "none" + // PruneStrategyKeepN is the identifier of the strategy that keeps the last N versions. + PruneStrategyKeepN = "keep_n" +) + // PruneConfig is the CometBFT ABCI state pruning configuration structure. type PruneConfig struct { // ABCI state pruning strategy. @@ -95,6 +102,8 @@ type PruneConfig struct { NumKept uint64 `yaml:"num_kept"` // ABCI state pruning interval. Interval time.Duration `yaml:"interval"` + // Light blocks kept in trusted store. + NumLightBlocksKept uint16 `yaml:"num_light_blocks_kept"` } // CheckpointerConfig is the CometBFT ABCI state pruning configuration structure. @@ -200,9 +209,10 @@ func DefaultConfig() Config { HaltHeight: 0, UpgradeStopDelay: 60 * time.Second, Prune: PruneConfig{ - Strategy: "none", - NumKept: 3600, - Interval: 2 * time.Minute, + Strategy: PruneStrategyNone, + NumKept: 3600, + Interval: 2 * time.Minute, + NumLightBlocksKept: 10000, }, Checkpointer: CheckpointerConfig{ Disabled: false, diff --git a/go/consensus/cometbft/light/service.go b/go/consensus/cometbft/light/service.go index 4c12ab13073..b3578b803f3 100644 --- a/go/consensus/cometbft/light/service.go +++ b/go/consensus/cometbft/light/service.go @@ -21,8 +21,8 @@ import ( "github.com/oasisprotocol/oasis-core/go/config" consensus "github.com/oasisprotocol/oasis-core/go/consensus/api" cmtAPI "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api" - tmapi "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api" "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/common" + cmtConfig "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/config" "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/db" "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/light/api" p2pLight "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/light/p2p" @@ -151,7 +151,7 @@ func (c *client) worker() { c.logger.Error("failed to obtain chain context", "err", err) return } - tmChainID := tmapi.CometBFTChainID(chainCtx) + tmChainID := cmtAPI.CometBFTChainID(chainCtx) // Loads the local block at the provided height and adds it to the trust store. trustLocalBlock := func(ctx context.Context, height int64) error { @@ -208,15 +208,26 @@ func (c *client) worker() { providers = append(providers, p) c.providers = append(c.providers, p) } + + opts := []cmtlight.Option{ + cmtlight.MaxRetryAttempts(lcMaxRetryAttempts), + cmtlight.Logger(common.NewLogAdapter(!config.GlobalConfig.Consensus.LogDebug)), + cmtlight.DisableProviderRemoval(), + } + switch config.GlobalConfig.Consensus.Prune.Strategy { + case cmtConfig.PruneStrategyNone: + opts = append(opts, cmtlight.PruningSize(0)) // Disable pruning the light store. + default: + opts = append(opts, cmtlight.PruningSize(config.GlobalConfig.Consensus.Prune.NumLightBlocksKept)) + } + tmc, err := cmtlight.NewClientFromTrustedStore( tmChainID, config.GlobalConfig.Consensus.StateSync.TrustPeriod, providers[0], // Primary provider. providers[1:], // Witnesses. c.store, - cmtlight.MaxRetryAttempts(lcMaxRetryAttempts), - cmtlight.Logger(common.NewLogAdapter(!config.GlobalConfig.Consensus.LogDebug)), - cmtlight.DisableProviderRemoval(), + opts..., ) if err != nil { c.logger.Error("failed to initialize cometbft light client", "err", err)