Documentation
¶
Overview ¶
Package headerdb provides a header db/cache implementation.
Index ¶
- Variables
- type DB
- func (db *DB) AddAndReorg(ctx context.Context, known *types.Header, fetch fetchFunc) (int, error)
- func (db *DB) ByHash(ctx context.Context, hash common.Hash) (*types.Header, bool, error)
- func (db *DB) ByHeight(ctx context.Context, height uint64) (*types.Header, bool, error)
- func (db *DB) MaybePrune(ctx context.Context, limit int) (int, error)
- type Header
- func (*Header) Descriptor() ([]byte, []int)deprecated
- func (x *Header) GetHash() []byte
- func (x *Header) GetHeaderJson() []byte
- func (x *Header) GetHeight() uint64
- func (x *Header) GetId() uint64
- func (*Header) ProtoMessage()
- func (x *Header) ProtoReflect() protoreflect.Message
- func (x *Header) Reset()
- func (x *Header) String() string
- type HeaderHashIndexKey
- type HeaderHeightIndexKey
- type HeaderIdIndexKey
- type HeaderIndexKey
- type HeaderIterator
- type HeaderPrimaryKey
- type HeaderTable
- type HeaderdbStore
Constants ¶
This section is empty.
Variables ¶
var File_lib_ethclient_headerdb_headerdb_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB implements a header db/cache. It is reorg aware, via AddAndReorg, so safe to use for both HeaderByHash and HeaderByHeight. Without reorg detection, HeaderByHeight could return invalid headers. It doesn't preemptively fill gaps, this allows multiple workers to populate the DB. When a reorg is however detected, it replaces/fixes any existing invalid headers. Fetching valid parent headers (via fetchFunc) is required to identify all reorged-out-headers.
func (*DB) AddAndReorg ¶
AddAndReorg adds the known header to the chain, and deletes any existing headers not part of known header's chain. It replaces all invalid parents of the known head (using fetchfunc). It returns the number of headers deleted (reorg depth).
type Header ¶
type Header struct {
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // Auto-incremented ID, insert order
Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` // Height of the source-chain block
Hash []byte `protobuf:"bytes,3,opt,name=hash,proto3" json:"hash,omitempty"` // Hash of the source-chain block
HeaderJson []byte `protobuf:"bytes,4,opt,name=header_json,json=headerJson,proto3" json:"header_json,omitempty"` // *types.Header JSON
// contains filtered or unexported fields
}
func (*Header) Descriptor
deprecated
func (*Header) GetHeaderJson ¶
func (*Header) ProtoMessage ¶
func (*Header) ProtoMessage()
func (*Header) ProtoReflect ¶
func (x *Header) ProtoReflect() protoreflect.Message
type HeaderHashIndexKey ¶
type HeaderHashIndexKey struct {
// contains filtered or unexported fields
}
func (HeaderHashIndexKey) WithHash ¶
func (this HeaderHashIndexKey) WithHash(hash []byte) HeaderHashIndexKey
type HeaderHeightIndexKey ¶
type HeaderHeightIndexKey struct {
// contains filtered or unexported fields
}
func (HeaderHeightIndexKey) WithHeight ¶
func (this HeaderHeightIndexKey) WithHeight(height uint64) HeaderHeightIndexKey
type HeaderIdIndexKey ¶
type HeaderIdIndexKey struct {
// contains filtered or unexported fields
}
func (HeaderIdIndexKey) WithId ¶
func (this HeaderIdIndexKey) WithId(id uint64) HeaderIdIndexKey
type HeaderIndexKey ¶
type HeaderIndexKey interface {
// contains filtered or unexported methods
}
type HeaderIterator ¶
func (HeaderIterator) Value ¶
func (i HeaderIterator) Value() (*Header, error)
type HeaderTable ¶
type HeaderTable interface {
Insert(ctx context.Context, header *Header) error
InsertReturningId(ctx context.Context, header *Header) (uint64, error)
LastInsertedSequence(ctx context.Context) (uint64, error)
Update(ctx context.Context, header *Header) error
Save(ctx context.Context, header *Header) error
Delete(ctx context.Context, header *Header) error
Has(ctx context.Context, id uint64) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id uint64) (*Header, error)
HasByHeight(ctx context.Context, height uint64) (found bool, err error)
// GetByHeight returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetByHeight(ctx context.Context, height uint64) (*Header, error)
HasByHash(ctx context.Context, hash []byte) (found bool, err error)
// GetByHash returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
GetByHash(ctx context.Context, hash []byte) (*Header, error)
List(ctx context.Context, prefixKey HeaderIndexKey, opts ...ormlist.Option) (HeaderIterator, error)
ListRange(ctx context.Context, from, to HeaderIndexKey, opts ...ormlist.Option) (HeaderIterator, error)
DeleteBy(ctx context.Context, prefixKey HeaderIndexKey) error
DeleteRange(ctx context.Context, from, to HeaderIndexKey) error
// contains filtered or unexported methods
}
func NewHeaderTable ¶
func NewHeaderTable(db ormtable.Schema) (HeaderTable, error)
type HeaderdbStore ¶
type HeaderdbStore interface {
HeaderTable() HeaderTable
// contains filtered or unexported methods
}
func NewHeaderdbStore ¶
func NewHeaderdbStore(db ormtable.Schema) (HeaderdbStore, error)