db

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: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenCrossDerivationDB added in v1.11.0

func OpenCrossDerivationDB(logger log.Logger, chainID eth.ChainID, dataDir string, m fromda.ChainMetrics) (*fromda.DB, error)

func OpenLocalDerivationDB added in v1.11.0

func OpenLocalDerivationDB(logger log.Logger, chainID eth.ChainID, dataDir string, m fromda.ChainMetrics) (*fromda.DB, error)

func OpenLogDB added in v1.9.5

func OpenLogDB(logger log.Logger, chainID eth.ChainID, dataDir string, m logs.Metrics) (*logs.DB, error)

func PrepDataDir added in v1.9.5

func PrepDataDir(datadir string) error

Types

type ChainsDB

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

ChainsDB is a database that stores logs and derived-from data for multiple chains. it implements the LogStorage interface, as well as several DB interfaces needed by the cross package.

func NewChainsDB

func NewChainsDB(l log.Logger, depSet depset.DependencySet, m Metrics) *ChainsDB

func (*ChainsDB) AcceptedBlock added in v1.11.0

func (db *ChainsDB) AcceptedBlock(chainID eth.ChainID, id eth.BlockID) error

func (*ChainsDB) AcquireHandle added in v1.13.4

func (db *ChainsDB) AcquireHandle() reads.Handle

func (*ChainsDB) AddCrossDerivationDB added in v1.11.0

func (db *ChainsDB) AddCrossDerivationDB(chainID eth.ChainID, dfDB DerivationStorage)

func (*ChainsDB) AddCrossUnsafeTracker added in v1.9.5

func (db *ChainsDB) AddCrossUnsafeTracker(chainID eth.ChainID)

func (*ChainsDB) AddLocalDerivationDB added in v1.11.0

func (db *ChainsDB) AddLocalDerivationDB(chainID eth.ChainID, dfDB DerivationStorage)

func (*ChainsDB) AddLog

func (db *ChainsDB) AddLog(
	chain eth.ChainID,
	logHash common.Hash,
	parentBlock eth.BlockID,
	logIdx uint32,
	execMsg *types.ExecutingMessage,
) error

func (*ChainsDB) AddLogDB added in v1.9.3

func (db *ChainsDB) AddLogDB(chainID eth.ChainID, logDB LogStorage)

func (*ChainsDB) AnchorPoint added in v1.13.3

func (db *ChainsDB) AnchorPoint(chainID eth.ChainID) (types.DerivedBlockSealPair, error)

AnchorPoint returns the first cross-safe block as anchor-point for interop.

func (*ChainsDB) AttachEmitter added in v1.11.0

func (db *ChainsDB) AttachEmitter(em event.Emitter)

func (*ChainsDB) CandidateCrossSafe added in v1.9.5

func (db *ChainsDB) CandidateCrossSafe(chain eth.ChainID) (result types.DerivedBlockRefPair, err error)

CandidateCrossSafe returns the candidate local-safe block that may become cross-safe, and what L1 block it may potentially be cross-safe derived from.

This returns ErrFuture if no block is known yet.

Or ErrConflict if there is an inconsistency between the local-safe and cross-safe DB.

Or ErrOutOfScope, with non-zero sourceScope, if additional L1 data is needed to cross-verify the candidate L2 block.

func (*ChainsDB) Close

func (db *ChainsDB) Close() error

func (*ChainsDB) Contains added in v1.11.0

func (db *ChainsDB) Contains(chain eth.ChainID, q types.ContainsQuery) (includedIn types.BlockSeal, err error)

Contains calls the underlying logDB to determine if the given log entry exists at the given location. If the block-seal of the block that includes the log is known, it is returned. It is fully zeroed otherwise, if the block is in-progress.

func (*ChainsDB) CrossDerivedToSource added in v1.11.0

func (db *ChainsDB) CrossDerivedToSource(chain eth.ChainID, derived eth.BlockID) (source types.BlockSeal, err error)

CrossDerivedToSource returns the block that the given block was derived from, if it exists in the cross derived-from storage. it routes the request to the appropriate crossDB.

func (*ChainsDB) CrossDerivedToSourceRef added in v1.11.0

func (db *ChainsDB) CrossDerivedToSourceRef(chainID eth.ChainID, derived eth.BlockID) (source eth.BlockRef, err error)

CrossDerivedToSourceRef returns the block that the given block was derived from, if it exists in the cross derived-from storage. This call requires the block to have a parent to be turned into a Ref. Use CrossDerivedToSource if the parent is not needed.

func (*ChainsDB) CrossSafe added in v1.9.5

func (db *ChainsDB) CrossSafe(chainID eth.ChainID) (pair types.DerivedBlockSealPair, err error)

func (*ChainsDB) CrossUnsafe added in v1.9.5

func (db *ChainsDB) CrossUnsafe(chainID eth.ChainID) (types.BlockSeal, error)

func (*ChainsDB) DependencySet added in v1.9.5

func (db *ChainsDB) DependencySet() depset.DependencySet

func (*ChainsDB) Finalized added in v1.9.5

func (db *ChainsDB) Finalized(chainID eth.ChainID) (types.BlockSeal, error)

func (*ChainsDB) FinalizedL1 added in v1.11.0

func (db *ChainsDB) FinalizedL1() eth.BlockRef

func (*ChainsDB) FindBlockID added in v1.12.1

func (db *ChainsDB) FindBlockID(chain eth.ChainID, number uint64) (id eth.BlockID, err error)

func (*ChainsDB) FindSealedBlock added in v1.9.3

func (db *ChainsDB) FindSealedBlock(chain eth.ChainID, number uint64) (seal types.BlockSeal, err error)

func (*ChainsDB) ForceInitialized added in v1.11.2

func (db *ChainsDB) ForceInitialized(id eth.ChainID)

ForceInitialized marks the chain database as initialized, even if it is not. This function is for testing purposes only and should not be used in production code.

func (*ChainsDB) InvalidateLocalSafe added in v1.11.0

func (db *ChainsDB) InvalidateLocalSafe(chainID eth.ChainID, candidate types.DerivedBlockRefPair) error

func (*ChainsDB) IsCrossSafe added in v1.12.0

func (db *ChainsDB) IsCrossSafe(chainID eth.ChainID, block eth.BlockID) error

func (*ChainsDB) IsCrossUnsafe added in v1.9.5

func (db *ChainsDB) IsCrossUnsafe(chainID eth.ChainID, block eth.BlockID) error

IsCrossUnsafe checks if the given block is less than the cross-unsafe block number. It does not check if the block is actually cross-unsafe (ie, known in the database).

func (*ChainsDB) IsFinalized added in v1.12.2

func (db *ChainsDB) IsFinalized(chainID eth.ChainID, block eth.BlockID) error

func (*ChainsDB) IsLocalSafe added in v1.12.0

func (db *ChainsDB) IsLocalSafe(chainID eth.ChainID, block eth.BlockID) error

func (*ChainsDB) IsLocalUnsafe added in v1.9.5

func (db *ChainsDB) IsLocalUnsafe(chainID eth.ChainID, block eth.BlockID) error

func (*ChainsDB) IteratorStartingAt added in v1.9.4

func (db *ChainsDB) IteratorStartingAt(chain eth.ChainID, sealedNum uint64, logIndex uint32) (logs.Iterator, error)

func (*ChainsDB) LatestBlockNum

func (db *ChainsDB) LatestBlockNum(chain eth.ChainID) (num uint64, ok bool)

LatestBlockNum returns the latest fully-sealed block number that has been recorded to the logs db for the given chain. It does not contain safety guarantees. The block number might not be available (empty database, or non-existent chain).

func (*ChainsDB) LocalDerivedToSource added in v1.11.0

func (db *ChainsDB) LocalDerivedToSource(chain eth.ChainID, derived eth.BlockID) (source types.BlockSeal, err error)

LocalDerivedToSource returns the block that the given block was derived from, if it exists in the local derived-from storage. it routes the request to the appropriate localDB.

func (*ChainsDB) LocalSafe added in v1.9.5

func (db *ChainsDB) LocalSafe(chainID eth.ChainID) (pair types.DerivedBlockSealPair, err error)

func (*ChainsDB) LocalSafeDerivedAt added in v1.13.3

func (db *ChainsDB) LocalSafeDerivedAt(chainID eth.ChainID, source eth.BlockID) (types.BlockSeal, error)

func (*ChainsDB) LocalUnsafe added in v1.9.5

func (db *ChainsDB) LocalUnsafe(chainID eth.ChainID) (types.BlockSeal, error)

func (*ChainsDB) NextSource added in v1.11.0

func (db *ChainsDB) NextSource(chain eth.ChainID, source eth.BlockID) (after eth.BlockRef, err error)

func (*ChainsDB) OnEvent added in v1.11.0

func (db *ChainsDB) OnEvent(ctx context.Context, ev event.Event) bool

func (*ChainsDB) OpenBlock added in v1.9.5

func (db *ChainsDB) OpenBlock(chainID eth.ChainID, blockNum uint64) (seal eth.BlockRef, logCount uint32, execMsgs map[uint32]*types.ExecutingMessage, err error)

OpenBlock returns the Executing Messages for the block at the given number on the given chain. it routes the request to the appropriate logDB.

func (*ChainsDB) PreviousCrossDerived added in v1.13.0

func (db *ChainsDB) PreviousCrossDerived(chain eth.ChainID, derived eth.BlockID) (prevDerived types.BlockSeal, err error)

func (*ChainsDB) PreviousSource added in v1.11.0

func (db *ChainsDB) PreviousSource(chain eth.ChainID, source eth.BlockID) (prevSource types.BlockSeal, err error)

func (*ChainsDB) ResetCrossUnsafeIfNewerThan added in v1.11.0

func (db *ChainsDB) ResetCrossUnsafeIfNewerThan(chainID eth.ChainID, number uint64) error

func (*ChainsDB) ResumeFromLastSealedBlock added in v1.9.3

func (db *ChainsDB) ResumeFromLastSealedBlock() error

ResumeFromLastSealedBlock prepares the chains db to resume recording events after a restart. It rewinds the database to the last block that is guaranteed to have been fully recorded to the database, to ensure it can resume recording from the first log of the next block.

func (*ChainsDB) Rewind

func (db *ChainsDB) Rewind(chain eth.ChainID, headBlock eth.BlockID) error

func (*ChainsDB) RewindCrossSafeSource added in v1.13.5

func (db *ChainsDB) RewindCrossSafeSource(chainID eth.ChainID, source eth.BlockID) error

RewindCrossSafeSource removes all cross-safe blocks after the given new derived-from source. If the source is before the start of the DB, the DB will be emptied. 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 (*ChainsDB) RewindLocalSafeSource added in v1.13.5

func (db *ChainsDB) RewindLocalSafeSource(chainID eth.ChainID, source eth.BlockID) error

RewindLocalSafeSource removes all local-safe blocks after the given new derived-from source. 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 (*ChainsDB) RewindLogs added in v1.11.0

func (db *ChainsDB) RewindLogs(chainID eth.ChainID, newHead types.BlockSeal) error

func (*ChainsDB) SealBlock added in v1.9.3

func (db *ChainsDB) SealBlock(chain eth.ChainID, block eth.BlockRef) error

SealBlock seals the block in the logDB. The database needs to be initialized.

func (*ChainsDB) UpdateCrossSafe added in v1.9.5

func (db *ChainsDB) UpdateCrossSafe(chain eth.ChainID, l1View eth.BlockRef, lastCrossDerived eth.BlockRef) error

func (*ChainsDB) UpdateCrossUnsafe added in v1.9.5

func (db *ChainsDB) UpdateCrossUnsafe(chain eth.ChainID, crossUnsafe types.BlockSeal) error

func (*ChainsDB) UpdateLocalSafe added in v1.9.5

func (db *ChainsDB) UpdateLocalSafe(chain eth.ChainID, source eth.BlockRef, lastDerived eth.BlockRef, nodeId string)

UpdateLocalSafe updates the local-safe database with the given source and lastDerived blocks. It wraps an inner function, blocking the call if the database is not initialized.

type DerivationStorage added in v1.11.0

type DerivationStorage interface {
	// basic info
	First() (pair types.DerivedBlockSealPair, err error)
	Last() (pair types.DerivedBlockSealPair, err error)

	// mapping from source<>derived
	DerivedToFirstSource(derived eth.BlockID, revision types.Revision) (source types.BlockSeal, err error)
	SourceToLastDerived(source eth.BlockID) (derived types.BlockSeal, err error)

	// traversal
	NextSource(source eth.BlockID) (nextSource types.BlockSeal, err error)

	Candidate(afterSource eth.BlockID, afterDerived eth.BlockID, revision types.Revision) (pair types.DerivedBlockRefPair, err error)

	PreviousSource(source eth.BlockID) (prevSource types.BlockSeal, err error)

	// Warning: only safe to use on cross-DB
	PreviousDerived(derived eth.BlockID, revision types.Revision) (prevDerived types.BlockSeal, err error)

	// type-specific
	Invalidated() (pair types.DerivedBlockSealPair, err error)
	ContainsDerived(derived eth.BlockID, revision types.Revision) error

	// DerivedToRevision is only safe to use on the cross-safe DB.
	DerivedToRevision(derived eth.BlockID) (types.Revision, error)

	LastRevision() (revision types.Revision, err error)
	SourceToRevision(source eth.BlockID) (types.Revision, error)

	// AddDerived adds a derived block to the database. The first entry to be added may
	// have zero parent hashes.
	AddDerived(source eth.BlockRef, derived eth.BlockRef, revision types.Revision) error
	ReplaceInvalidatedBlock(inv reads.Invalidator, replacementDerived eth.BlockRef, invalidated common.Hash) (out types.DerivedBlockRefPair, err error)

	// rewinding
	RewindAndInvalidate(inv reads.Invalidator, invalidated types.DerivedBlockRefPair) error
	RewindToSource(inv reads.Invalidator, scope eth.BlockID) error
	RewindToFirstDerived(inv reads.Invalidator, v eth.BlockID, revision types.Revision) error
}

type LogStorage

type LogStorage interface {
	io.Closer

	IsEmpty() bool

	AddLog(logHash common.Hash, parentBlock eth.BlockID,
		logIdx uint32, execMsg *types.ExecutingMessage) error

	SealBlock(parentHash common.Hash, block eth.BlockID, timestamp uint64) error

	Rewind(inv reads.Invalidator, newHead eth.BlockID) error

	// FirstSealedBlock() (block types.BlockSeal, err error)
	LatestSealedBlock() (id eth.BlockID, ok bool)

	// FindSealedBlock finds the requested block by number, to check if it exists,
	// returning the block seal if it was found.
	// returns ErrFuture if the block is too new to be able to tell.
	FindSealedBlock(number uint64) (block types.BlockSeal, err error)

	// Contains returns no error iff the specified logHash is recorded in the specified blockNum and logIdx.
	// If the log is out of reach, then ErrFuture is returned.
	// If the log is determined to conflict with the canonical chain, then ErrConflict is returned.
	// logIdx is the index of the log in the array of all logs in the block.
	// This can be used to check the validity of cross-chain interop events.
	// The block-seal of the blockNum block, that the log was included in, is returned.
	// This seal may be fully zeroed, without error, if the block isn't fully known yet.
	Contains(query types.ContainsQuery) (includedIn types.BlockSeal, err error)

	IteratorStartingAt(sealedNum uint64, logsSince uint32) (logs.Iterator, error)

	// OpenBlock accumulates the ExecutingMessage events for a block and returns them
	OpenBlock(blockNum uint64) (ref eth.BlockRef, logCount uint32, execMsgs map[uint32]*types.ExecutingMessage, err error)
}

type Metrics added in v1.11.0

type Metrics interface {
	RecordCrossUnsafe(chainID eth.ChainID, seal types.BlockSeal)
	RecordCrossSafe(chainID eth.ChainID, seal types.BlockSeal)
	RecordLocalSafe(chainID eth.ChainID, seal types.BlockSeal)
	RecordLocalUnsafe(chainID eth.ChainID, seal types.BlockSeal)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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