db

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 12 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

This section is empty.

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, l log.Logger) *ChainsDB

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(chain types.ChainID, logDB LogStorage)

func (*ChainsDB) Check added in v1.9.1

func (db *ChainsDB) Check(chain types.ChainID, blockNum uint64, logIdx uint32, logHash common.Hash) (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) FindSealedBlock added in v1.9.3

func (db *ChainsDB) FindSealedBlock(chain types.ChainID, block eth.BlockID) (nextEntry entrydb.EntryIdx, 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) RequestMaintenance added in v1.9.3

func (db *ChainsDB) RequestMaintenance()

RequestMaintenance requests that the maintenance loop update the cross-heads it does not block if maintenance is already scheduled

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) SealBlock added in v1.9.3

func (db *ChainsDB) SealBlock(chain types.ChainID, parentHash common.Hash, block eth.BlockID, timestamp 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.

type HeadsStorage

type HeadsStorage interface {
	Current() *heads.Heads
	Apply(op heads.Operation) 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, to check if it exists,
	// returning the next index after it where things continue from.
	// returns ErrFuture if the block is too new to be able to tell
	// returns ErrDifferent if the known block does not match
	FindSealedBlock(block eth.BlockID) (nextEntry entrydb.EntryIdx, err error)

	IteratorStartingAt(i entrydb.EntryIdx) (logs.Iterator, error)

	// returns ErrConflict if the log does not match the canonical chain.
	// returns ErrFuture if the log is out of reach.
	// returns nil if the log is known and matches the canonical chain.
	Contains(blockNum uint64, logIdx uint32, logHash common.Hash) (nextIndex entrydb.EntryIdx, err 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 common.Hash) 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