history

package
v0.2103.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package history implements the runtime block history and pruning policy.

Index

Constants

View Source
const (
	// PrunerStrategyNone is the name of the none pruner strategy.
	PrunerStrategyNone = "none"
	// PrunerStrategyKeepLast is the name of the keep last pruner strategy.
	PrunerStrategyKeepLast = "keep_last"
)
View Source
const DbFilename = "history.db"

DbFilename is the filename of the history database.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Pruner configures the pruner to use.
	Pruner PrunerFactory

	// PruneInterval configures the pruning interval.
	PruneInterval time.Duration
}

Config is runtime history keeper configuration.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns the default runtime history keeper config.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB is the history database.

type History

type History interface {
	roothash.BlockHistory

	// Pruner returns the history pruner.
	Pruner() Pruner

	// Close closes the history keeper.
	Close()
}

History is the runtime history interface.

func New

func New(dataDir string, runtimeID common.Namespace, cfg *Config) (History, error)

New creates a new runtime history keeper.

func NewNop

func NewNop(runtimeID common.Namespace) History

NewNop creates a new no-op runtime history keeper.

type PruneHandler

type PruneHandler interface {
	// Prune is called before the specified rounds are pruned.
	//
	// If an error is returned, pruning is aborted and the rounds are
	// not pruned from history.
	//
	// Note that this can be called for the same round multiple
	// times (e.g., if one of the handlers fails but others succeed
	// and pruning is later retried).
	Prune(ctx context.Context, rounds []uint64) error
}

PruneHandler is a handler that is called when rounds are pruned from history.

type Pruner

type Pruner interface {
	// Prune purges unneeded history, given the latest round.
	Prune(ctx context.Context, latestRound uint64) error

	// RegisterHandler registers a prune handler.
	RegisterHandler(handler PruneHandler)
}

Pruner is the runtime history pruner interface.

type PrunerFactory

type PrunerFactory func(db *DB) (Pruner, error)

PrunerFactory is the runtime history pruner factory interface.

func NewKeepLastPruner

func NewKeepLastPruner(numKept uint64) PrunerFactory

NewKeepLastPruner creates a pruner that keeps the last configured number of rounds.

func NewNonePruner

func NewNonePruner() PrunerFactory

NewNonePruner creates a new pruner that never prunes anything.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL