cosmos-sdk/store/types/pruning.go

80 lines
2.3 KiB
Go
Raw Normal View History

2019-02-01 17:03:09 -08:00
package types
2020-06-22 13:31:33 -07:00
import "fmt"
// Pruning option string constants
const (
PruningOptionDefault = "default"
PruningOptionEverything = "everything"
PruningOptionNothing = "nothing"
PruningOptionCustom = "custom"
)
var (
refactor: update default pruning strategy (#9859) The `default` pruning strategy, specifically the total number of recent blocks to keep (currently 100), was decided on completely arbitrary. I propose we change it to be enough blocks given that the typical block time is 5s and typical unbonding period is 21 days: (3600*(24/5)) * 21 = 362880. I propose this because anyone wishing to run an IBC relayer, which will be most chains, will have to be required to use `custom` to set it to this value anyway. So why not just make it the default and make it easier for operators. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-08-06 07:23:13 -07:00
// PruneDefault defines a pruning strategy where the last 362880 heights are
// kept in addition to every 100th and where to-be pruned heights are pruned
// at every 10th height. The last 362880 heights are kept assuming the typical
// block time is 5s and typical unbonding period is 21 days. If these values
// do not match the applications' requirements, use the "custom" option.
PruneDefault = NewPruningOptions(362880, 100, 10)
2020-06-22 13:31:33 -07:00
// PruneEverything defines a pruning strategy where all committed heights are
// deleted, storing only the current height and where to-be pruned heights are
// pruned at every 10th height.
PruneEverything = NewPruningOptions(0, 0, 10)
2020-06-22 13:31:33 -07:00
// PruneNothing defines a pruning strategy where all heights are kept on disk.
PruneNothing = NewPruningOptions(0, 1, 0)
)
2020-06-22 13:31:33 -07:00
// PruningOptions defines the pruning strategy used when determining which
// heights are removed from disk when committing state.
2019-02-01 17:03:09 -08:00
type PruningOptions struct {
2020-06-22 13:31:33 -07:00
// KeepRecent defines how many recent heights to keep on disk.
KeepRecent uint64
// KeepEvery defines how many offset heights are kept on disk past KeepRecent.
KeepEvery uint64
// Interval defines when the pruned heights are removed from disk.
Interval uint64
2019-02-01 17:03:09 -08:00
}
2020-06-22 13:31:33 -07:00
func NewPruningOptions(keepRecent, keepEvery, interval uint64) PruningOptions {
return PruningOptions{
KeepRecent: keepRecent,
KeepEvery: keepEvery,
Interval: interval,
}
2020-06-22 13:31:33 -07:00
}
2020-06-22 13:31:33 -07:00
func (po PruningOptions) Validate() error {
if po.KeepEvery == 0 && po.Interval == 0 {
2020-06-22 13:31:33 -07:00
return fmt.Errorf("invalid 'Interval' when pruning everything: %d", po.Interval)
}
if po.KeepEvery == 1 && po.Interval != 0 { // prune nothing
2020-06-22 13:31:33 -07:00
return fmt.Errorf("invalid 'Interval' when pruning nothing: %d", po.Interval)
2019-02-01 17:03:09 -08:00
}
if po.KeepEvery > 1 && po.Interval == 0 {
return fmt.Errorf("invalid 'Interval' when pruning: %d", po.Interval)
}
2019-02-01 17:03:09 -08:00
2020-06-22 13:31:33 -07:00
return nil
2019-02-01 17:03:09 -08:00
}
2020-06-22 13:31:33 -07:00
func NewPruningOptionsFromString(strategy string) PruningOptions {
switch strategy {
case PruningOptionEverything:
return PruneEverything
2019-02-01 17:03:09 -08:00
2020-06-22 13:31:33 -07:00
case PruningOptionNothing:
return PruneNothing
case PruningOptionDefault:
return PruneDefault
default:
return PruneDefault
}
}