db

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenCrossDerivedFromDB added in v1.9.5

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

func OpenLocalDerivedFromDB added in v1.9.5

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

func OpenLogDB added in v1.9.5

func OpenLogDB(logger log.Logger, chainID types.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) *ChainsDB

func (*ChainsDB) AddCrossDerivedFromDB added in v1.9.5

func (db *ChainsDB) AddCrossDerivedFromDB(chainID types.ChainID, dfDB CrossDerivedFromStorage)

func (*ChainsDB) AddCrossUnsafeTracker added in v1.9.5

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

func (*ChainsDB) AddLocalDerivedFromDB added in v1.9.5

func (db *ChainsDB) AddLocalDerivedFromDB(chainID types.ChainID, dfDB LocalDerivedFromStorage)

func (*ChainsDB) AddLog

func (db *ChainsDB) AddLog(
	chain types.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 types.ChainID, logDB LogStorage)

func (*ChainsDB) CandidateCrossSafe added in v1.9.5

func (db *ChainsDB) CandidateCrossSafe(chain types.ChainID) (derivedFromScope, crossSafe eth.BlockRef, err error)

CandidateCrossSafe returns the candidate local-safe block that may become cross-safe.

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 derivedFromScope, if additional L1 data is needed to cross-verify the candidate L2 block.

func (*ChainsDB) Check added in v1.9.1

func (db *ChainsDB) Check(chain types.ChainID, blockNum uint64, logIdx uint32, logHash common.Hash) (includedIn types.BlockSeal, err error)

Check 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) Close

func (db *ChainsDB) Close() error

func (*ChainsDB) CrossDerivedFrom added in v1.9.5

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

CrossDerivedFrom 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) CrossDerivedFromBlockRef added in v1.9.5

func (db *ChainsDB) CrossDerivedFromBlockRef(chainID types.ChainID, derived eth.BlockID) (derivedFrom eth.BlockRef, err error)

CrossDerivedFromBlockRef returns the block that the given block was derived from, if it exists in the cross derived-from storage. This includes the parent-block lookup. Use CrossDerivedFrom if no parent-block info is needed.

func (*ChainsDB) CrossSafe added in v1.9.5

func (db *ChainsDB) CrossSafe(chainID types.ChainID) (derivedFrom types.BlockSeal, derived types.BlockSeal, err error)

func (*ChainsDB) CrossUnsafe added in v1.9.5

func (db *ChainsDB) CrossUnsafe(chainID types.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 types.ChainID) (types.BlockSeal, error)

func (*ChainsDB) FindSealedBlock added in v1.9.3

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

func (*ChainsDB) IsCrossUnsafe added in v1.9.5

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

func (*ChainsDB) IsLocalUnsafe added in v1.9.5

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

func (*ChainsDB) IteratorStartingAt added in v1.9.4

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

func (*ChainsDB) LastDerivedFrom added in v1.9.5

func (db *ChainsDB) LastDerivedFrom(chainID types.ChainID, derivedFrom eth.BlockID) (derived types.BlockSeal, err error)

func (*ChainsDB) LatestBlockNum

func (db *ChainsDB) LatestBlockNum(chain types.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) LocalDerivedFrom added in v1.9.5

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

LocalDerivedFrom 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 types.ChainID) (derivedFrom types.BlockSeal, derived types.BlockSeal, err error)

func (*ChainsDB) LocalUnsafe added in v1.9.5

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

func (*ChainsDB) NextDerivedFrom added in v1.9.5

func (db *ChainsDB) NextDerivedFrom(chain types.ChainID, derivedFrom eth.BlockID) (after eth.BlockRef, err error)

func (*ChainsDB) OpenBlock added in v1.9.5

func (db *ChainsDB) OpenBlock(chainID types.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) ParentBlock added in v1.9.5

func (db *ChainsDB) ParentBlock(chainID types.ChainID, parentOf eth.BlockID) (parent eth.BlockID, err error)

func (*ChainsDB) PreviousDerived added in v1.9.5

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

func (*ChainsDB) PreviousDerivedFrom added in v1.9.5

func (db *ChainsDB) PreviousDerivedFrom(chain types.ChainID, derivedFrom eth.BlockID) (prevDerivedFrom types.BlockSeal, err 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 types.ChainID, headBlockNum uint64) error

func (*ChainsDB) Safest added in v1.9.4

func (db *ChainsDB) Safest(chainID types.ChainID, blockNum uint64, index uint32) (safest types.SafetyLevel, err error)

Safest returns the strongest safety level that can be guaranteed for the given log entry. it assumes the log entry has already been checked and is valid, this function only checks safety levels. Safety levels are assumed to graduate from LocalUnsafe to LocalSafe to CrossUnsafe to CrossSafe, with Finalized as the strongest.

func (*ChainsDB) SealBlock added in v1.9.3

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

func (*ChainsDB) UpdateCrossSafe added in v1.9.5

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

func (*ChainsDB) UpdateCrossUnsafe added in v1.9.5

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

func (*ChainsDB) UpdateFinalizedL1 added in v1.9.5

func (db *ChainsDB) UpdateFinalizedL1(finalized eth.BlockRef) error

func (*ChainsDB) UpdateLocalSafe added in v1.9.5

func (db *ChainsDB) UpdateLocalSafe(chain types.ChainID, derivedFrom eth.BlockRef, lastDerived eth.BlockRef) error

type CrossDerivedFromStorage added in v1.9.5

type CrossDerivedFromStorage interface {
	LocalDerivedFromStorage
}

type LocalDerivedFromStorage added in v1.9.5

type LocalDerivedFromStorage interface {
	First() (derivedFrom types.BlockSeal, derived types.BlockSeal, err error)
	Latest() (derivedFrom types.BlockSeal, derived types.BlockSeal, err error)
	AddDerived(derivedFrom eth.BlockRef, derived eth.BlockRef) error
	LastDerivedAt(derivedFrom eth.BlockID) (derived types.BlockSeal, err error)
	DerivedFrom(derived eth.BlockID) (derivedFrom types.BlockSeal, err error)
	FirstAfter(derivedFrom, derived eth.BlockID) (nextDerivedFrom, nextDerived types.BlockSeal, err error)
	NextDerivedFrom(derivedFrom eth.BlockID) (nextDerivedFrom types.BlockSeal, err error)
	NextDerived(derived eth.BlockID) (derivedFrom types.BlockSeal, nextDerived types.BlockSeal, err error)
	PreviousDerivedFrom(derivedFrom eth.BlockID) (prevDerivedFrom types.BlockSeal, err error)
	PreviousDerived(derived eth.BlockID) (prevDerived types.BlockSeal, err error)
}

type LogStorage

type LogStorage interface {
	io.Closer

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

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

	Rewind(newHeadBlockNum uint64) error

	LatestSealedBlockNum() (n uint64, 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)

	IteratorStartingAt(sealedNum uint64, logsSince uint32) (logs.Iterator, 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(blockNum uint64, logIdx uint32, logHash common.Hash) (includedIn types.BlockSeal, err 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)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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