fromda

package
v1.13.7 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const EntrySize = 128

EntrySize is the size of the DB entry. 1+3+(8+8)+8+(8+8)+32+32=108

View Source
const FirstRevision = types.Revision(0)

FirstRevision is the revision that is used when the first entry is added to the DB.

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 (source) and/or L2 (derived) block.

Data is an append-only log, that can be binary searched for any necessary derivation-link data.

The DB only rewinds when the L1 (source) entries are invalidated. If the L2 (derived) entries are no longer valid (due to cross-chain dependency invalidation), then we register the new L2 entries with a higher revision number (matching the block-number of the block where it first invalidated and replaced).

The key-space of the DB is thus as following, in order: - source block number -> incremental, there may be adjacent repeat entries (for multiple L2 blocks derived from same L1 block) - revision number -> incremental, repeats until the chain invalidates something - derived block number -> NOT incremental, but incremental within the scope of a single revision.

This key-space allows for fast binary-search over the source blocks to find any derived blocks, but also the reverse: if the revision is known, the derived blocks can be searched, to find the relevant source 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(source eth.BlockRef, derived eth.BlockRef, revision types.Revision) error

func (*DB) Candidate added in v1.13.0

func (db *DB) Candidate(maxSource eth.BlockID, afterDerived eth.BlockID, revision types.Revision) (pair types.DerivedBlockRefPair, err error)

Candidate returns the candidate block for cross-safe promotion after the given (maxSource, afterDerived) pair (the cross-safe block). It may return types.ErrOutOfScope with a pair value, to request the source to increase.

func (*DB) Clear added in v1.13.5

func (db *DB) Clear(inv reads.Invalidator) error

Clear clears the DB such that there is no data left. An invalidator is required as argument, to force users to invalidate any current open reads.

func (*DB) Close

func (db *DB) Close() error

func (*DB) ContainsDerived added in v1.11.0

func (db *DB) ContainsDerived(derived eth.BlockID, revision types.Revision) 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, revision types.Revision) (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
  • A L2 block may reoccur later (with a gap) attached to a newer L1 block, if the prior information was invalidated with new L1 information.

func (*DB) DerivedToRevision added in v1.13.0

func (db *DB) DerivedToRevision(derived eth.BlockID) (types.Revision, error)

DerivedToRevision retrieves the revision of the latest occurrence of the given block. This may be open-ended (read: match not-yet cross-safe blocks) if the block is not known yet. WARNING: this is only safe to use on the cross-safe DB.

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) IsEmpty added in v1.13.4

func (db *DB) IsEmpty() bool

func (*DB) Last added in v1.11.0

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

Last returns the last known values: source: 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) LastRevision added in v1.13.0

func (db *DB) LastRevision() (revision types.Revision, err 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, revision types.Revision) (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. This will prioritize the last time the input L2 block number was seen, and consistency-checks it against the hash. Older occurrences of the same number with different hash cannot be iterated from, and are non-canonical.

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, revision types.Revision) (prevDerived types.BlockSeal, err error)

PreviousDerived returns the previous derived block. Warning: only safe to use on cross-DB. This will prioritize the last time the input L2 block number was seen, and consistency-checks it against the hash.

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(inv reads.Invalidator, replacementDerived eth.BlockRef, invalidated common.Hash) (
	out types.DerivedBlockRefPair, err 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(inv reads.Invalidator, 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(inv reads.Invalidator, 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(inv reads.Invalidator, v eth.BlockID, revision types.Revision) error

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

func (*DB) RewindToSource added in v1.13.5

func (db *DB) RewindToSource(inv reads.Invalidator, source eth.BlockID) error

RewindToSource rewinds the DB to the last entry with a source value matching the given scope (excluded from the rewind, included after in DB). If the source is before the start of the DB, the DB will be emptied. 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.

func (*DB) SourceToLastDerived added in v1.11.0

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

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

func (*DB) SourceToRevision added in v1.13.0

func (db *DB) SourceToRevision(source eth.BlockID) (types.Revision, error)

SourceToRevision lookups a specific source entry, and returns the corresponding revision. This ignores invalidation status of the given pair. It is used in those cases also, to determine the revision to use for a cross-safe DB, based on the invalidated entry in the local-safe DB.

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 SourceV0 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