Documentation
¶
Index ¶
- Variables
- type DB
- func (db *DB) AddLog(logHash types.TruncatedHash, block eth.BlockID, timestamp uint64, ...) error
- func (db *DB) Close() error
- func (db *DB) ClosestBlockInfo(blockNum uint64) (uint64, types.TruncatedHash, error)
- func (db *DB) Contains(blockNum uint64, logIdx uint32, logHash types.TruncatedHash) (bool, error)
- func (db *DB) Executes(blockNum uint64, logIdx uint32) (types.ExecutingMessage, error)
- func (db *DB) LatestBlockNum() uint64
- func (db *DB) Rewind(headBlockNum uint64) error
- type EntryStore
- type Metrics
Constants ¶
This section is empty.
Variables ¶
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 (*DB) AddLog ¶
func (db *DB) AddLog(logHash types.TruncatedHash, block eth.BlockID, timestamp uint64, logIdx uint32, execMsg *types.ExecutingMessage) error
func (*DB) ClosestBlockInfo ¶
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) Contains ¶
Contains return true iff the specified logHash is recorded in the specified blockNum and logIdx. logIdx is the index of the log in the array of all logs the block. This can be used to check the validity of cross-chain interop events.
func (*DB) Executes ¶
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 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.