store

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: Apache-2.0 Imports: 26 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindHeader added in v0.7.0

func FindHeader[H header.Header[H]](
	ctx context.Context,
	store *Store[H],
	startFrom uint64,
) (hdr H, err error)

FindHeader forward iterates over the store starting from the given height until it finds any stored header or the context is canceled.

func UnsafeResetHead added in v0.7.0

func UnsafeResetHead[H header.Header[H]](
	ctx context.Context,
	store *Store[H],
	height uint64,
) error

ResetHead resets the head of the store to be at the given height. The new head must be present in the store. WARNING: Only use this function if you know what you are doing.

func UnsafeResetTail added in v0.7.0

func UnsafeResetTail[H header.Header[H]](
	ctx context.Context,
	store *Store[H],
	height uint64,
) error

ResetTail resets the tail of the store to be at the given height. The new tail must be present in the store. WARNING: Only use this function if you know what you are doing.

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

func WithIndexCacheSize(size int) Option

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(params Parameters) Option

WithParams is a functional option that overrides Parameters.

func WithStoreCacheSize

func WithStoreCacheSize(size int) Option

WithStoreCacheSize is a functional option that configures the `StoreCacheSize` parameter.

func WithStorePrefix added in v0.2.9

func WithStorePrefix(prefix string) Option

WithStorePrefix is a functional option that configures the storePrefix parameter

func WithWriteBatchSize

func WithWriteBatchSize(size int) Option

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

func NewStore[H header.Header[H]](ds datastore.Batching, opts ...Option) (*Store[H], error)

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 NewTestStore

func NewTestStore(tb testing.TB, ctx context.Context,
	ds datastore.Batching, head *headertest.DummyHeader, opts ...Option,
) *Store[*headertest.DummyHeader]

NewTestStore creates initialized and started in memory header Store which is useful for testing.

func (*Store[H]) Append

func (s *Store[H]) Append(ctx context.Context, headers ...H) error

func (*Store[H]) DeleteTo added in v0.7.0

func (s *Store[H]) DeleteTo(ctx context.Context, to uint64) error

DeleteTo implements header.Store interface.

func (*Store[H]) Get

func (s *Store[H]) Get(ctx context.Context, hash header.Hash) (H, error)

func (*Store[H]) GetByHeight

func (s *Store[H]) GetByHeight(ctx context.Context, height uint64) (H, error)

func (*Store[H]) GetRange added in v0.4.0

func (s *Store[H]) GetRange(ctx context.Context, from, to uint64) ([]H, error)

func (*Store[H]) GetRangeByHeight

func (s *Store[H]) GetRangeByHeight(
	ctx context.Context,
	from H,
	to uint64,
) ([]H, error)

func (*Store[H]) Has

func (s *Store[H]) Has(ctx context.Context, hash header.Hash) (bool, error)

func (*Store[H]) HasAt added in v0.1.1

func (s *Store[H]) HasAt(ctx context.Context, height uint64) bool

func (*Store[H]) Head

func (s *Store[H]) Head(_ context.Context, _ ...header.HeadOption[H]) (H, error)

func (*Store[H]) Height

func (s *Store[H]) Height() uint64

func (*Store[H]) OnDelete added in v0.7.0

func (s *Store[H]) OnDelete(fn func(context.Context, uint64) error)

OnDelete implements header.Store interface.

func (*Store[H]) Start

func (s *Store[H]) Start(ctx context.Context) error

func (*Store[H]) Stop

func (s *Store[H]) Stop(ctx context.Context) error

func (*Store[H]) Sync added in v0.7.0

func (s *Store[H]) Sync(ctx context.Context) error

Sync ensures all pending writes are synchronized. It blocks until the operation completes or fails.

func (*Store[H]) Tail added in v0.7.0

func (s *Store[H]) Tail(_ context.Context) (H, error)

Tail implements header.Store interface.

Jump to

Keyboard shortcuts

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