db

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unsafe    = "unsafe"
	Safe      = "safe"
	Finalized = "finalized"
)

Variables

View Source
var (
	ErrUnknownChain = errors.New("unknown chain")
)

Functions

func Resume

func Resume(logDB LogStorage) error

Resume prepares the given LogStore to resume recording events. It returns the block number of the last block that is guaranteed to have been fully recorded to the database and rewinds the database to ensure it can resume recording from the first log of the next block.

Types

type ChainsDB

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

ChainsDB is a database that stores logs and heads for multiple chains. it implements the ChainsStorage interface.

func NewChainsDB

func NewChainsDB(logDBs map[types.ChainID]LogStorage, heads HeadsStorage) *ChainsDB

func (*ChainsDB) AddLog

func (db *ChainsDB) AddLog(chain types.ChainID, logHash backendTypes.TruncatedHash, block eth.BlockID, timestamp uint64, logIdx uint32, execMsg *backendTypes.ExecutingMessage) error

func (*ChainsDB) Check added in v1.9.1

func (db *ChainsDB) Check(chain types.ChainID, blockNum uint64, logIdx uint32, logHash backendTypes.TruncatedHash) (bool, entrydb.EntryIdx, error)

Check calls the underlying logDB to determine if the given log entry is safe with respect to the checker's criteria.

func (*ChainsDB) Close

func (db *ChainsDB) Close() error

func (*ChainsDB) LastLogInBlock added in v1.9.1

func (db *ChainsDB) LastLogInBlock(chain types.ChainID, blockNum uint64) (entrydb.EntryIdx, error)

LastLogInBlock scans through the logs of the given chain starting from the given block number, and returns the index of the last log entry in that block.

func (*ChainsDB) LatestBlockNum

func (db *ChainsDB) LatestBlockNum(chain types.ChainID) uint64

LatestBlockNum returns the latest block number that has been recorded to the logs db for the given chain. It does not contain safety guarantees.

func (*ChainsDB) Resume

func (db *ChainsDB) Resume() error

Resume 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) StartCrossHeadMaintenance added in v1.9.1

func (db *ChainsDB) StartCrossHeadMaintenance(ctx context.Context)

StartCrossHeadMaintenance starts a background process that maintains the cross-heads of the chains for now it does not prevent multiple instances of this process from running

func (*ChainsDB) UpdateCrossHeads added in v1.9.1

func (db *ChainsDB) UpdateCrossHeads(checker SafetyChecker) error

UpdateCrossHeads updates the cross-heads of all chains based on the provided SafetyChecker. The SafetyChecker is used to determine the safety of each log entry in the database, and the cross-head associated with it.

func (*ChainsDB) UpdateCrossHeadsForChain added in v1.9.1

func (db *ChainsDB) UpdateCrossHeadsForChain(chainID types.ChainID, checker SafetyChecker) error

UpdateCrossHeadsForChain updates the cross-head for a single chain. the provided checker controls which heads are considered. TODO: we should invert control and have the underlying logDB call their own update for now, monolithic control is fine. There may be a stronger reason to refactor if the API needs it.

func (*ChainsDB) UpdateCrossSafeHeads added in v1.9.1

func (db *ChainsDB) UpdateCrossSafeHeads() error

UpdateCrossSafeHeads updates the cross-heads of all chains this is an example of how to use the SafetyChecker to update the cross-heads

type HeadsStorage

type HeadsStorage interface {
	Current() *heads.Heads
	Apply(op heads.Operation) error
}

type LogStorage

type LogStorage interface {
	io.Closer
	AddLog(logHash backendTypes.TruncatedHash, block eth.BlockID, timestamp uint64, logIdx uint32, execMsg *backendTypes.ExecutingMessage) error
	Rewind(newHeadBlockNum uint64) error
	LatestBlockNum() uint64
	ClosestBlockInfo(blockNum uint64) (uint64, backendTypes.TruncatedHash, error)
	ClosestBlockIterator(blockNum uint64) (logs.Iterator, error)
	Contains(blockNum uint64, logIdx uint32, loghash backendTypes.TruncatedHash) (bool, entrydb.EntryIdx, error)
	LastCheckpointBehind(entrydb.EntryIdx) (logs.Iterator, error)
	NextExecutingMessage(logs.Iterator) (backendTypes.ExecutingMessage, error)
}

type SafetyChecker added in v1.9.1

type SafetyChecker interface {
	LocalHeadForChain(chainID types.ChainID) entrydb.EntryIdx
	CrossHeadForChain(chainID types.ChainID) entrydb.EntryIdx
	Check(chain types.ChainID, blockNum uint64, logIdx uint32, logHash backendTypes.TruncatedHash) bool
	Update(chain types.ChainID, index entrydb.EntryIdx) heads.OperationFn
	Name() string
	SafetyLevel() types.SafetyLevel
}

SafetyChecker is an interface for checking the safety of a log entry and updating the local head for a chain.

func NewSafetyChecker added in v1.9.1

func NewSafetyChecker(t types.SafetyLevel, chainsDB *ChainsDB) SafetyChecker

NewSafetyChecker creates a new SafetyChecker of the given type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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