fromda

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const EntrySize = 100

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainMetrics

type ChainMetrics interface {
	RecordDBEntryCount(kind string, count int64)
}

type DB

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

DB implements an append only database for log data and cross-chain dependencies. Each entry is fixed size, and denotes an increment in L1 (derived-from) and/or L2 (derived) block. Data is an append-only log, that can be binary searched for any necessary derivation-link data.

func NewFromEntryStore

func NewFromEntryStore(logger log.Logger, m Metrics, store EntryStore) (*DB, error)

func NewFromFile

func NewFromFile(logger log.Logger, m Metrics, path string) (*DB, error)

func (*DB) AddDerived

func (db *DB) AddDerived(derivedFrom eth.BlockRef, derived eth.BlockRef) error

func (*DB) Close

func (db *DB) Close() error

func (*DB) ContainsDerived added in v1.11.0

func (db *DB) ContainsDerived(derived eth.BlockID) error

ContainsDerived checks if the given block is canonical for the given chain. This returns an ErrFuture if the block is not known yet. An ErrConflict if there is a different block. Or an ErrAwaitReplacementBlock if it was invalidated.

func (*DB) DerivedToFirstSource added in v1.11.0

func (db *DB) DerivedToFirstSource(derived eth.BlockID) (types.BlockSeal, error)

DerivedToFirstSource determines where a L2 block was first derived from. (a L2 block may repeat if the following L1 blocks are empty and don't produce additional L2 blocks)

func (*DB) First

func (db *DB) First() (pair types.DerivedBlockSealPair, err error)

First returns the first known values, alike to Latest.

func (*DB) Invalidated added in v1.11.0

func (db *DB) Invalidated() (pair types.DerivedBlockSealPair, err error)

func (*DB) Last added in v1.11.0

func (db *DB) Last() (pair types.DerivedBlockSealPair, err error)

Latest returns the last known values: derivedFrom: the L1 block that the L2 block is safe for (not necessarily the first, multiple L2 blocks may be derived from the same L1 block). derived: the L2 block that was derived (not necessarily the first, the L1 block may have been empty and repeated the last safe L2 block). If the last entry is invalidated, this returns a types.ErrAwaitReplacementBlock error.

func (*DB) Next added in v1.11.0

Next returns the next Derived Block Pair after the given pair. This may return types.ErrAwaitReplacementBlock if the entry was invalidated and needs replacement.

func (*DB) NextDerived

func (db *DB) NextDerived(derived eth.BlockID) (pair types.DerivedBlockSealPair, err error)

NextDerived finds the next L2 block after derived, and what it was derived from. This may return types.ErrAwaitReplacementBlock if the entry was invalidated and needs replacement.

func (*DB) NextSource added in v1.11.0

func (db *DB) NextSource(source eth.BlockID) (types.BlockSeal, error)

NextSource finds the next source after the given source

func (*DB) PreviousDerived

func (db *DB) PreviousDerived(derived eth.BlockID) (prevDerived types.BlockSeal, err error)

func (*DB) PreviousSource added in v1.11.0

func (db *DB) PreviousSource(source eth.BlockID) (types.BlockSeal, error)

func (*DB) ReplaceInvalidatedBlock added in v1.11.0

func (db *DB) ReplaceInvalidatedBlock(replacementDerived eth.BlockRef, invalidated common.Hash) (types.DerivedBlockSealPair, error)

ReplaceInvalidatedBlock replaces the current Invalidated block with the given replacement. The to-be invalidated hash must be provided for consistency checks.

func (*DB) Rewind

func (db *DB) Rewind(target types.DerivedBlockSealPair, including bool) error

Rewind rolls back the database to the target, including the target if the including flag is set. it locks the DB and calls rewindLocked.

func (*DB) RewindAndInvalidate added in v1.11.0

func (db *DB) RewindAndInvalidate(invalidated types.DerivedBlockRefPair) error

RewindAndInvalidate rolls back the database to just before the invalidated block, and then marks the block as invalidated, so that no new data can be added to the DB until a Rewind or ReplaceInvalidatedBlock.

func (*DB) RewindToFirstDerived added in v1.11.0

func (db *DB) RewindToFirstDerived(v eth.BlockID) error

RewindToFirstDerived rewinds to the first time when v was derived (inclusive, v is retained in DB).

func (*DB) RewindToScope added in v1.11.0

func (db *DB) RewindToScope(scope eth.BlockID) error

RewindToScope rewinds the DB to the last entry with a derivedFrom value matching the given scope (inclusive, scope is retained in DB). Note that this drop L1 blocks that resulted in a previously invalidated local-safe block. This returns ErrFuture if the block is newer than the last known block. This returns ErrConflict if a different block at the given height is known. TODO: rename this "RewindToSource" to match the idea of Source

func (*DB) SourceToLastDerived added in v1.11.0

func (db *DB) SourceToLastDerived(source eth.BlockID) (derived types.BlockSeal, err error)

LastDerivedAt returns the last L2 block derived from the given L1 block. This may return types.ErrAwaitReplacementBlock if the entry was invalidated and needs replacement.

type Entry

type Entry [EntrySize]byte

func (Entry) Type

func (e Entry) Type() EntryType

type EntryBinary

type EntryBinary struct{}

func (EntryBinary) Append

func (EntryBinary) Append(dest []byte, e *Entry) []byte

func (EntryBinary) EntrySize

func (EntryBinary) EntrySize() int

func (EntryBinary) ReadAt

func (EntryBinary) ReadAt(dest *Entry, r io.ReaderAt, at int64) (n int, err error)

type EntryStore

type EntryStore interface {
	Size() int64
	LastEntryIdx() entrydb.EntryIdx
	Read(idx entrydb.EntryIdx) (Entry, error)
	Append(entries ...Entry) error
	Truncate(idx entrydb.EntryIdx) error
	Close() error
}

type EntryType

type EntryType uint8
const (
	SourceV0          EntryType = 0
	InvalidatedFromV0 EntryType = 1
)

func (EntryType) String

func (s EntryType) String() string

type LinkEntry

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

LinkEntry is a DerivedFromV0 or a InvalidatedFromV0 kind

func (LinkEntry) String

func (d LinkEntry) String() string

type Metrics

type Metrics interface {
	RecordDBDerivedEntryCount(count int64)
}

func AdaptMetrics

func AdaptMetrics(chainMetrics ChainMetrics, kind string) Metrics

Jump to

Keyboard shortcuts

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