logs

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLogOutOfOrder  = errors.New("log out of order")
	ErrDataCorruption = errors.New("data corruption")
	ErrNotFound       = errors.New("not found")
)

Functions

This section is empty.

Types

type DB

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

DB implements an append only database for log data and cross-chain dependencies.

To keep the append-only format, reduce data size, and support reorg detection and registering of executing-messages:

Use a fixed 24 bytes per entry.

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

Rules: if entry_index % 256 == 0: must be type 0. For easy binary search. type 1 always adjacent to type 0 type 2 "diff" values are offsets from type 0 values (always within 256 entries range) type 3 always after type 2 type 4 always after type 3

Types (<type> = 1 byte): type 0: "search checkpoint" <type><uint64 block number: 8 bytes><uint32 event index offset: 4 bytes><uint64 timestamp: 8 bytes> = 20 bytes type 1: "canonical hash" <type><parent blockhash truncated: 20 bytes> = 21 bytes type 2: "initiating event" <type><blocknum diff: 1 byte><event flags: 1 byte><event-hash: 20 bytes> = 23 bytes type 3: "executing link" <type><chain: 4 bytes><blocknum: 8 bytes><event index: 3 bytes><uint64 timestamp: 8 bytes> = 24 bytes type 4: "executing check" <type><event-hash: 20 bytes> = 21 bytes other types: future compat. E.g. for linking to L1, registering block-headers as a kind of initiating-event, tracking safe-head progression, etc.

Right-pad each entry that is not 24 bytes.

event-flags: each bit represents a boolean value, currently only two are defined * event-flags & 0x01 - true if the log index should increment. Should only be false when the event is immediately after a search checkpoint and canonical hash * event-flags & 0x02 - true if the initiating event has an executing link that should follow. Allows detecting when the executing link failed to write. event-hash: H(origin, timestamp, payloadhash); enough to check identifier matches & payload matches.

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) AddLog

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

func (*DB) Close

func (db *DB) Close() error

func (*DB) ClosestBlockInfo

func (db *DB) ClosestBlockInfo(blockNum uint64) (uint64, types.TruncatedHash, error)

ClosestBlockInfo returns the block number and hash of the highest recorded block at or before blockNum. Since block data is only recorded in search checkpoints, this may return an earlier block even if log data is recorded for the requested block.

func (*DB) ClosestBlockIterator added in v1.9.1

func (db *DB) ClosestBlockIterator(blockNum uint64) (Iterator, error)

ClosestBlockIterator returns an iterator for the block closest to the specified blockNum. The iterator will start at the search checkpoint for the block, or the first checkpoint before it.

func (*DB) Contains

func (db *DB) Contains(blockNum uint64, logIdx uint32, logHash types.TruncatedHash) (bool, entrydb.EntryIdx, error)

Contains return true iff the specified logHash is recorded in the specified blockNum and logIdx. If the log is found, the entry index of the log is returned, too. 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.

func (*DB) Executes

func (db *DB) Executes(blockNum uint64, logIdx uint32) (types.ExecutingMessage, error)

Executes checks if the log identified by the specific block number and log index, has an ExecutingMessage associated with it that needs to be checked as part of interop validation. logIdx is the index of the log in the array of all logs in the block. Returns the ExecutingMessage if it exists, or ExecutingMessage{} if the log is found but has no ExecutingMessage. Returns ErrNotFound if the specified log does not exist in the database.

func (*DB) Get added in v1.9.1

func (db *DB) Get(blockNum uint64, logiIdx uint32) (types.TruncatedHash, error)

Get returns the truncated hash of the log at the specified blockNum and logIdx, or an error if the log is not found.

func (*DB) LastCheckpointBehind added in v1.9.1

func (db *DB) LastCheckpointBehind(entryIdx entrydb.EntryIdx) (Iterator, error)

LastCheckpointBehind returns an iterator for the last checkpoint behind the specified entry index. If the entry index is a search checkpoint, the iterator will start at that checkpoint. After searching back long enough (the searchCheckpointFrequency), an error is returned, as checkpoints are expected to be found within the frequency.

func (*DB) LatestBlockNum

func (db *DB) LatestBlockNum() uint64

func (*DB) NextExecutingMessage added in v1.9.1

func (db *DB) NextExecutingMessage(iter Iterator) (types.ExecutingMessage, error)

NextExecutingMessage returns the next executing message in the log database. it skips over any non-executing messages, and will return an error if encountered. the iterator is modified in the process.

func (*DB) Rewind

func (db *DB) Rewind(headBlockNum uint64) error

Rewind the database to remove any blocks after headBlockNum The block at headBlockNum itself is not removed.

type EntryStore

type EntryStore interface {
	Size() int64
	LastEntryIdx() entrydb.EntryIdx
	Read(idx entrydb.EntryIdx) (entrydb.Entry, error)
	Append(entries ...entrydb.Entry) error
	Truncate(idx entrydb.EntryIdx) error
	Close() error
}

type Iterator added in v1.9.1

type Iterator interface {
	NextLog() (blockNum uint64, logIdx uint32, evtHash types.TruncatedHash, outErr error)
	Index() entrydb.EntryIdx
	ExecMessage() (types.ExecutingMessage, error)
}

type Metrics

type Metrics interface {
	RecordDBEntryCount(count int64)
	RecordDBSearchEntriesRead(count int64)
}

Jump to

Keyboard shortcuts

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