Documentation
¶
Index ¶
- Constants
- type ChainMetrics
- type DB
- func (db *DB) AddDerived(source eth.BlockRef, derived eth.BlockRef, revision types.Revision) error
- func (db *DB) Candidate(maxSource eth.BlockID, afterDerived eth.BlockID, revision types.Revision) (pair types.DerivedBlockRefPair, err error)
- func (db *DB) Clear(inv reads.Invalidator) error
- func (db *DB) Close() error
- func (db *DB) ContainsDerived(derived eth.BlockID, revision types.Revision) error
- func (db *DB) DerivedToFirstSource(derived eth.BlockID, revision types.Revision) (types.BlockSeal, error)
- func (db *DB) DerivedToRevision(derived eth.BlockID) (types.Revision, error)
- func (db *DB) First() (pair types.DerivedBlockSealPair, err error)
- func (db *DB) Invalidated() (pair types.DerivedBlockSealPair, err error)
- func (db *DB) IsEmpty() bool
- func (db *DB) Last() (pair types.DerivedBlockSealPair, err error)
- func (db *DB) LastRevision() (revision types.Revision, err error)
- func (db *DB) Next(pair types.DerivedIDPair) (types.DerivedBlockSealPair, error)
- func (db *DB) NextDerived(derived eth.BlockID, revision types.Revision) (pair types.DerivedBlockSealPair, err error)
- func (db *DB) NextSource(source eth.BlockID) (types.BlockSeal, error)
- func (db *DB) PreviousDerived(derived eth.BlockID, revision types.Revision) (prevDerived types.BlockSeal, err error)
- func (db *DB) PreviousSource(source eth.BlockID) (types.BlockSeal, error)
- func (db *DB) ReplaceInvalidatedBlock(inv reads.Invalidator, replacementDerived eth.BlockRef, ...) (out types.DerivedBlockRefPair, err error)
- func (db *DB) Rewind(inv reads.Invalidator, target types.DerivedBlockSealPair, including bool) error
- func (db *DB) RewindAndInvalidate(inv reads.Invalidator, invalidated types.DerivedBlockRefPair) error
- func (db *DB) RewindToFirstDerived(inv reads.Invalidator, v eth.BlockID, revision types.Revision) error
- func (db *DB) RewindToSource(inv reads.Invalidator, source eth.BlockID) error
- func (db *DB) SourceToLastDerived(source eth.BlockID) (derived types.BlockSeal, err error)
- func (db *DB) SourceToRevision(source eth.BlockID) (types.Revision, error)
- type Entry
- type EntryBinary
- type EntryStore
- type EntryType
- type LinkEntry
- type Metrics
Constants ¶
const EntrySize = 128
EntrySize is the size of the DB entry. 1+3+(8+8)+8+(8+8)+32+32=108
const FirstRevision = types.Revision(0)
FirstRevision is the revision that is used when the first entry is added to the DB.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChainMetrics ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB implements an append only database for log data and cross-chain dependencies. Each entry is fixed size, and denotes an increment in L1 (source) and/or L2 (derived) block.
Data is an append-only log, that can be binary searched for any necessary derivation-link data.
The DB only rewinds when the L1 (source) entries are invalidated. If the L2 (derived) entries are no longer valid (due to cross-chain dependency invalidation), then we register the new L2 entries with a higher revision number (matching the block-number of the block where it first invalidated and replaced).
The key-space of the DB is thus as following, in order: - source block number -> incremental, there may be adjacent repeat entries (for multiple L2 blocks derived from same L1 block) - revision number -> incremental, repeats until the chain invalidates something - derived block number -> NOT incremental, but incremental within the scope of a single revision.
This key-space allows for fast binary-search over the source blocks to find any derived blocks, but also the reverse: if the revision is known, the derived blocks can be searched, to find the relevant source data.
func NewFromEntryStore ¶
func (*DB) AddDerived ¶
func (*DB) Candidate ¶ added in v1.13.0
func (db *DB) Candidate(maxSource eth.BlockID, afterDerived eth.BlockID, revision types.Revision) (pair types.DerivedBlockRefPair, err error)
Candidate returns the candidate block for cross-safe promotion after the given (maxSource, afterDerived) pair (the cross-safe block). It may return types.ErrOutOfScope with a pair value, to request the source to increase.
func (*DB) Clear ¶ added in v1.13.5
func (db *DB) Clear(inv reads.Invalidator) error
Clear clears the DB such that there is no data left. An invalidator is required as argument, to force users to invalidate any current open reads.
func (*DB) ContainsDerived ¶ added in v1.11.0
ContainsDerived checks if the given block is canonical for the given chain. This returns an ErrFuture if the block is not known yet. An ErrConflict if there is a different block. Or an ErrAwaitReplacementBlock if it was invalidated.
func (*DB) DerivedToFirstSource ¶ added in v1.11.0
func (db *DB) DerivedToFirstSource(derived eth.BlockID, revision types.Revision) (types.BlockSeal, error)
DerivedToFirstSource determines where a L2 block was first derived from.
- A L2 block may repeat if the following L1 blocks are empty and don't produce additional L2 blocks
- A L2 block may reoccur later (with a gap) attached to a newer L1 block, if the prior information was invalidated with new L1 information.
func (*DB) DerivedToRevision ¶ added in v1.13.0
DerivedToRevision retrieves the revision of the latest occurrence of the given block. This may be open-ended (read: match not-yet cross-safe blocks) if the block is not known yet. WARNING: this is only safe to use on the cross-safe DB.
func (*DB) First ¶
func (db *DB) First() (pair types.DerivedBlockSealPair, err error)
First returns the first known values, alike to Latest.
func (*DB) Invalidated ¶ added in v1.11.0
func (db *DB) Invalidated() (pair types.DerivedBlockSealPair, err error)
func (*DB) Last ¶ added in v1.11.0
func (db *DB) Last() (pair types.DerivedBlockSealPair, err error)
Last returns the last known values: source: the L1 block that the L2 block is safe for (not necessarily the first, multiple L2 blocks may be derived from the same L1 block). derived: the L2 block that was derived (not necessarily the first, the L1 block may have been empty and repeated the last safe L2 block). If the last entry is invalidated, this returns a types.ErrAwaitReplacementBlock error.
func (*DB) LastRevision ¶ added in v1.13.0
func (*DB) Next ¶ added in v1.11.0
func (db *DB) Next(pair types.DerivedIDPair) (types.DerivedBlockSealPair, error)
Next returns the next Derived Block Pair after the given pair. This may return types.ErrAwaitReplacementBlock if the entry was invalidated and needs replacement.
func (*DB) NextDerived ¶
func (db *DB) NextDerived(derived eth.BlockID, revision types.Revision) (pair types.DerivedBlockSealPair, err error)
NextDerived finds the next L2 block after derived, and what it was derived from. This may return types.ErrAwaitReplacementBlock if the entry was invalidated and needs replacement. This will prioritize the last time the input L2 block number was seen, and consistency-checks it against the hash. Older occurrences of the same number with different hash cannot be iterated from, and are non-canonical.
func (*DB) NextSource ¶ added in v1.11.0
NextSource finds the next source after the given source
func (*DB) PreviousDerived ¶
func (db *DB) PreviousDerived(derived eth.BlockID, revision types.Revision) (prevDerived types.BlockSeal, err error)
PreviousDerived returns the previous derived block. Warning: only safe to use on cross-DB. This will prioritize the last time the input L2 block number was seen, and consistency-checks it against the hash.
func (*DB) PreviousSource ¶ added in v1.11.0
func (*DB) ReplaceInvalidatedBlock ¶ added in v1.11.0
func (db *DB) ReplaceInvalidatedBlock(inv reads.Invalidator, replacementDerived eth.BlockRef, invalidated common.Hash) ( out types.DerivedBlockRefPair, err error, )
ReplaceInvalidatedBlock replaces the current Invalidated block with the given replacement. The to-be invalidated hash must be provided for consistency checks.
func (*DB) Rewind ¶
func (db *DB) Rewind(inv reads.Invalidator, target types.DerivedBlockSealPair, including bool) error
Rewind rolls back the database to the target, including the target if the including flag is set. it locks the DB and calls rewindLocked.
func (*DB) RewindAndInvalidate ¶ added in v1.11.0
func (db *DB) RewindAndInvalidate(inv reads.Invalidator, invalidated types.DerivedBlockRefPair) error
RewindAndInvalidate rolls back the database to just before the invalidated block, and then marks the block as invalidated, so that no new data can be added to the DB until a Rewind or ReplaceInvalidatedBlock.
func (*DB) RewindToFirstDerived ¶ added in v1.11.0
func (db *DB) RewindToFirstDerived(inv reads.Invalidator, v eth.BlockID, revision types.Revision) error
RewindToFirstDerived rewinds to the first time when v was derived (inclusive, v is retained in DB).
func (*DB) RewindToSource ¶ added in v1.13.5
RewindToSource rewinds the DB to the last entry with a source value matching the given scope (excluded from the rewind, included after in DB). If the source is before the start of the DB, the DB will be emptied. Note that this drop L1 blocks that resulted in a previously invalidated local-safe block. This returns ErrFuture if the block is newer than the last known block. This returns ErrConflict if a different block at the given height is known.
func (*DB) SourceToLastDerived ¶ added in v1.11.0
SourceToLastDerived returns the last L2 block derived from the given L1 block. This may return types.ErrAwaitReplacementBlock if the entry was invalidated and needs replacement.
func (*DB) SourceToRevision ¶ added in v1.13.0
SourceToRevision lookups a specific source entry, and returns the corresponding revision. This ignores invalidation status of the given pair. It is used in those cases also, to determine the revision to use for a cross-safe DB, based on the invalidated entry in the local-safe DB.
type EntryBinary ¶
type EntryBinary struct{}
func (EntryBinary) EntrySize ¶
func (EntryBinary) EntrySize() int
type EntryStore ¶
type LinkEntry ¶
type LinkEntry struct {
// contains filtered or unexported fields
}
LinkEntry is a SourceV0 or a InvalidatedFromV0 kind
type Metrics ¶
type Metrics interface {
RecordDBDerivedEntryCount(count int64)
}
func AdaptMetrics ¶
func AdaptMetrics(chainMetrics ChainMetrics, kind string) Metrics