headerdb

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package headerdb provides a header db/cache implementation.

Index

Constants

This section is empty.

Variables

View Source
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 New

func New(db db.DB) (*DB, error)

New returns a new headerdb backed by the given db.

func (*DB) AddAndReorg

func (db *DB) AddAndReorg(ctx context.Context, known *types.Header, fetch fetchFunc) (int, error)

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

func (*DB) ByHash

func (db *DB) ByHash(ctx context.Context, hash common.Hash) (*types.Header, bool, error)

ByHash returns the header with the given hash or false if not found.

func (*DB) ByHeight

func (db *DB) ByHeight(ctx context.Context, height uint64) (*types.Header, bool, error)

ByHeight returns the header at the given height or false if not found.

func (*DB) MaybePrune

func (db *DB) MaybePrune(ctx context.Context, limit int) (int, error)

MaybePrune deletes headers ensuring max limit header with highest height.

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) Descriptor() ([]byte, []int)

Deprecated: Use Header.ProtoReflect.Descriptor instead.

func (*Header) GetHash

func (x *Header) GetHash() []byte

func (*Header) GetHeaderJson

func (x *Header) GetHeaderJson() []byte

func (*Header) GetHeight

func (x *Header) GetHeight() uint64

func (*Header) GetId

func (x *Header) GetId() uint64

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) ProtoReflect

func (x *Header) ProtoReflect() protoreflect.Message

func (*Header) Reset

func (x *Header) Reset()

func (*Header) String

func (x *Header) String() string

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

type HeaderIterator struct {
	ormtable.Iterator
}

func (HeaderIterator) Value

func (i HeaderIterator) Value() (*Header, error)

type HeaderPrimaryKey

type HeaderPrimaryKey = HeaderIdIndexKey

primary key starting index..

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)

Jump to

Keyboard shortcuts

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