state

package
v1.11.12-rc.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: BSD-3-Clause Imports: 13 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingParentState = errors.New("missing parent state")
)

Functions

This section is empty.

Types

type Chain

type Chain interface {
	ReadOnlyChain
	avax.UTXOAdder
	avax.UTXODeleter

	AddTx(tx *txs.Tx)
	AddBlock(block block.Block)
	SetLastAccepted(blkID ids.ID)
	SetTimestamp(t time.Time)
}

type Diff

type Diff interface {
	Chain

	Apply(Chain)
}

func NewDiff

func NewDiff(
	parentID ids.ID,
	stateVersions Versions,
) (Diff, error)

func NewDiffOn added in v1.10.18

func NewDiffOn(parentState Chain) (Diff, error)

type ReadOnlyChain

type ReadOnlyChain interface {
	avax.UTXOGetter

	GetTx(txID ids.ID) (*txs.Tx, error)
	GetBlockIDAtHeight(height uint64) (ids.ID, error)
	GetBlock(blkID ids.ID) (block.Block, error)
	GetLastAccepted() ids.ID
	GetTimestamp() time.Time
}

type State

type State interface {
	Chain
	avax.UTXOReader

	IsInitialized() (bool, error)
	SetInitialized() error

	// InitializeChainState is called after the VM has been linearized. Calling
	// [GetLastAccepted] or [GetTimestamp] before calling this function will
	// return uninitialized data.
	//
	// Invariant: After the chain is linearized, this function is expected to be
	// called during startup.
	InitializeChainState(stopVertexID ids.ID, genesisTimestamp time.Time) error

	// Discard uncommitted changes to the database.
	Abort()

	// Commit changes to the base database.
	Commit() error

	// Returns a batch of unwritten changes that, when written, will commit all
	// pending changes to the base database.
	CommitBatch() (database.Batch, error)

	// Checksums returns the current TxChecksum and UTXOChecksum.
	Checksums() (txChecksum ids.ID, utxoChecksum ids.ID)

	Close() error
}

State persistently maintains a set of UTXOs, transaction, statuses, and singletons.

func New

func New(
	db *versiondb.Database,
	parser block.Parser,
	metrics prometheus.Registerer,
	trackChecksums bool,
) (State, error)

type Versions

type Versions interface {
	// GetState returns the state of the chain after [blkID] has been accepted.
	// If the state is not known, `false` will be returned.
	GetState(blkID ids.ID) (Chain, bool)
}

Directories

Path Synopsis
Package statemock is a generated GoMock package.
Package statemock is a generated GoMock package.

Jump to

Keyboard shortcuts

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