history

package
v0.2601.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package history implements the runtime block history and pruning policy.

Index

Constants

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 BlockIndexer added in v0.2501.0

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

BlockIndexer is responsible for indexing and committing finalized runtime blocks from the consensus into the runtime history.

func NewBlockIndexer added in v0.2501.0

func NewBlockIndexer(consensus consensus.Service, history History, batchSize uint16) *BlockIndexer

NewBlockIndexer creates a new block indexer.

func (*BlockIndexer) Start added in v0.2501.0

func (bi *BlockIndexer) Start()

Start starts the indexer.

func (*BlockIndexer) Status added in v0.2501.0

func (bi *BlockIndexer) Status() *IndexerStatus

Status returns runtime block history indexer status.

func (*BlockIndexer) Stop added in v0.2501.0

func (bi *BlockIndexer) Stop()

Stop halts the indexer.

type DB

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

DB is the history database.

type Factory added in v0.2500.0

type Factory func(runtimeID common.Namespace, dataDir string) (History, error)

Factory is the runtime history factory interface.

func NewFactory added in v0.2500.0

func NewFactory(prunerFactory PrunerFactory, honorStorageSync bool) Factory

NewFactory creates a new runtime history keeper factory.

type History

type History interface {
	roothash.BlockHistory
	consensus.StatePruneHandler

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

	// PruneBefore prunes runtime history before the given round.
	PruneBefore(round uint64) (uint64, error)

	// Compact triggers compaction of the History underlying storage engine.
	Compact() error

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

History is the runtime history interface.

func New

func New(runtimeID common.Namespace, dataDir string, prunerFactory PrunerFactory, honorStorageSync bool) (History, error)

New creates a new runtime history keeper.

If honorStorageSync is true, synced block notifications and block lookups honor the last storage round which was synced to runtime storage (see [History.StorageSyncCheckpoint]).

type IndexerStatus added in v0.2501.0

type IndexerStatus struct {
	// Status is the concise status of runtime history indexer state.
	Status string `json:"status"`

	// LastRound is the last runtime round that was indexed.
	LastRound uint64 `json:"last_round"`

	// ReindexStatus is history reindex status.
	//
	// It is nil unless during history reindex.
	ReindexStatus *ReindexStatus `json:"reindex_status,omitempty"`
}

IndexerStatus is the status of runtime history indexer.

type PruneHandler

type PruneHandler interface {
	// CanPruneRuntime is called before to check if the specified round can be pruned.
	//
	// 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).
	CanPruneRuntime(rounds []uint64) error
}

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

type Pruner

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

	// PruneInterval specifies how often pruning should occur.
	PruneInterval() time.Duration

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

Pruner is the runtime history pruner interface.

func NewKeepLastPruner

func NewKeepLastPruner(runtimeID common.Namespace, numKept uint64, pruneInterval time.Duration, db *DB) (Pruner, error)

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

func NewNonePruner

func NewNonePruner() Pruner

NewNonePruner creates a new pruner that never prunes anything.

type PrunerFactory

type PrunerFactory func(runtimeID common.Namespace, db *DB) (Pruner, error)

PrunerFactory is the runtime history pruner factory interface.

func NewKeepLastPrunerFactory added in v0.2500.0

func NewKeepLastPrunerFactory(numKept uint64, pruneInterval time.Duration) PrunerFactory

NewKeepLastPrunerFactory creates a new pruner factory for pruners that keep the last configured number of rounds.

func NewNonePrunerFactory added in v0.2500.0

func NewNonePrunerFactory() PrunerFactory

NewNonePrunerFactory creates a new pruner factory for pruners that never prune anything.

type ReindexStatus added in v0.2501.0

type ReindexStatus struct {
	// BatchSize is the number of blocks to reindex in a single batch.
	BatchSize uint16 `json:"batch_size"`
	// LastHeight is the last consensus height that was indexed.
	LastHeight int64 `json:"last_height"`
	// StartHeight is the first height of history reindex interval.
	StartHeight int64 `json:"start_height"`
	// EndHeight is the last height of history reindex interval.
	EndHeight int64 `json:"end_height"`
	// ETA is expected time of history reindex completition.
	ETA time.Time `json:"eta"`
}

Jump to

Keyboard shortcuts

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