Documentation ¶
Index ¶
- func Init[H header.Header[H]](ctx context.Context, store header.Store[H], ex header.Exchange[H], ...) error
- func NewTestStore(ctx context.Context, t *testing.T, head *headertest.DummyHeader) header.Store[*headertest.DummyHeader]
- type Option
- type Parameters
- type Store
- func (s *Store[H]) Append(ctx context.Context, headers ...H) error
- func (s *Store[H]) Get(ctx context.Context, hash header.Hash) (H, error)
- func (s *Store[H]) GetByHeight(ctx context.Context, height uint64) (H, error)
- func (s *Store[H]) GetRange(ctx context.Context, from, to uint64) ([]H, error)
- func (s *Store[H]) GetRangeByHeight(ctx context.Context, from H, to uint64) ([]H, error)
- func (s *Store[H]) Has(ctx context.Context, hash header.Hash) (bool, error)
- func (s *Store[H]) HasAt(_ context.Context, height uint64) bool
- func (s *Store[H]) Head(ctx context.Context, _ ...header.HeadOption[H]) (H, error)
- func (s *Store[H]) Height() uint64
- func (s *Store[H]) Init(ctx context.Context, initial H) error
- func (s *Store[H]) Start(context.Context) error
- func (s *Store[H]) Stop(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init[H header.Header[H]](ctx context.Context, store header.Store[H], ex header.Exchange[H], hash header.Hash) error
Init ensures a Store is initialized. If it is not already initialized, it initializes the Store by requesting the header with the given hash.
func NewTestStore ¶
func NewTestStore(ctx context.Context, t *testing.T, head *headertest.DummyHeader) header.Store[*headertest.DummyHeader]
NewTestStore creates initialized and started in memory header Store which is useful for testing.
Types ¶
type Option ¶
type Option func(*Parameters)
Option is the functional option that is applied to the store instance to configure store parameters.
func WithIndexCacheSize ¶
WithIndexCacheSize is a functional option that configures the `IndexCacheSize` parameter.
func WithMetrics ¶ added in v0.5.0
func WithMetrics() Option
WithMetrics enables metrics on the Store.
func WithParams ¶ added in v0.2.6
func WithParams(new Parameters) Option
WithParams is a functional option that overrides Parameters.
func WithStoreCacheSize ¶
WithStoreCacheSize is a functional option that configures the `StoreCacheSize` parameter.
func WithStorePrefix ¶ added in v0.2.9
WithStorePrefix is a functional option that configures the storePrefix parameter
func WithWriteBatchSize ¶
WithWriteBatchSize is a functional option that configures the `WriteBatchSize` parameter.
type Parameters ¶
type Parameters struct { // StoreCacheSize defines the maximum amount of entries in the Header Store cache. StoreCacheSize int // IndexCacheSize defines the maximum amount of entries in the Height to Hash index cache. IndexCacheSize int // WriteBatchSize defines the size of the batched header flush. // Headers are written in batches not to thrash the underlying Datastore with writes. WriteBatchSize int // contains filtered or unexported fields }
Parameters is the set of parameters that must be configured for the store.
func DefaultParameters ¶
func DefaultParameters() Parameters
DefaultParameters returns the default params to configure the store.
func (*Parameters) Validate ¶
func (p *Parameters) Validate() error
type Store ¶
type Store[H header.Header[H]] struct { Params Parameters // contains filtered or unexported fields }
Store implements the Store interface for Headers over Datastore.
func NewStore ¶
NewStore constructs a Store over datastore. The datastore must have a head there otherwise Start will error. For first initialization of Store use NewStoreWithHead.
func NewStoreWithHead ¶
func NewStoreWithHead[H header.Header[H]]( ctx context.Context, ds datastore.Batching, head H, opts ...Option, ) (*Store[H], error)
NewStoreWithHead initiates a new Store and forcefully sets a given trusted header as head.