2019-02-01 17:03:09 -08:00
|
|
|
package types
|
|
|
|
|
2020-02-06 12:58:32 -08:00
|
|
|
var (
|
|
|
|
// PruneEverything defines a pruning strategy where all committed states will
|
|
|
|
// be deleted, persisting only the current state.
|
|
|
|
PruneEverything = PruningOptions{
|
|
|
|
KeepEvery: 1,
|
|
|
|
SnapshotEvery: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
// PruneNothing defines a pruning strategy where all committed states will be
|
|
|
|
// kept on disk, i.e. no states will be pruned.
|
|
|
|
PruneNothing = PruningOptions{
|
|
|
|
KeepEvery: 1,
|
|
|
|
SnapshotEvery: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
// PruneSyncable defines a pruning strategy where only those states not needed
|
|
|
|
// for state syncing will be pruned. It flushes every 100th state to disk and
|
|
|
|
// keeps every 10000th.
|
|
|
|
PruneSyncable = PruningOptions{
|
|
|
|
KeepEvery: 100,
|
|
|
|
SnapshotEvery: 10000,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// PruningOptions defines the specific pruning strategy every store in a multi-store
|
|
|
|
// will use when committing state, where keepEvery determines which committed
|
|
|
|
// heights are flushed to disk and snapshotEvery determines which of these heights
|
|
|
|
// are kept after pruning.
|
2019-02-01 17:03:09 -08:00
|
|
|
type PruningOptions struct {
|
2020-02-06 12:58:32 -08:00
|
|
|
KeepEvery int64
|
|
|
|
SnapshotEvery int64
|
2019-02-01 17:03:09 -08:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:58:32 -08:00
|
|
|
// IsValid verifies if the pruning options are valid. It returns false if invalid
|
|
|
|
// and true otherwise. Pruning options are considered valid iff:
|
|
|
|
//
|
|
|
|
// - KeepEvery > 0
|
|
|
|
// - SnapshotEvery >= 0
|
|
|
|
// - SnapshotEvery % KeepEvery = 0
|
|
|
|
func (po PruningOptions) IsValid() bool {
|
|
|
|
// must flush at positive block interval
|
|
|
|
if po.KeepEvery <= 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// cannot snapshot negative intervals
|
|
|
|
if po.SnapshotEvery < 0 {
|
|
|
|
return false
|
2019-02-01 17:03:09 -08:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:58:32 -08:00
|
|
|
return po.SnapshotEvery%po.KeepEvery == 0
|
2019-02-01 17:03:09 -08:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:58:32 -08:00
|
|
|
// FlushVersion returns a boolean signaling if the provided version/height should
|
|
|
|
// be flushed to disk.
|
|
|
|
func (po PruningOptions) FlushVersion(ver int64) bool {
|
|
|
|
return po.KeepEvery != 0 && ver%po.KeepEvery == 0
|
2019-02-01 17:03:09 -08:00
|
|
|
}
|
|
|
|
|
2020-02-06 12:58:32 -08:00
|
|
|
// SnapshotVersion returns a boolean signaling if the provided version/height
|
|
|
|
// should be snapshotted (kept on disk).
|
|
|
|
func (po PruningOptions) SnapshotVersion(ver int64) bool {
|
|
|
|
return po.SnapshotEvery != 0 && ver%po.SnapshotEvery == 0
|
|
|
|
}
|