statefulsyncer

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultPruneSleepTime is how long we sleep between
	// pruning attempts.
	DefaultPruneSleepTime = 10 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	AddBlockStream(context.Context, *types.Block) error
	RemoveBlockStream(context.Context, *types.BlockIdentifier) error
}

Logger is used by the statefulsyncer to log the addition and removal of blocks.

type Option added in v0.6.2

type Option func(s *StatefulSyncer)

Option is used to overwrite default values in StatefulSyncer construction. Any Option not provided falls back to the default value.

func WithAdjustmentWindow added in v0.6.2

func WithAdjustmentWindow(adjustmentWindow int64) Option

WithAdjustmentWindow overrides the default adjustment window.

func WithCacheSize added in v0.6.2

func WithCacheSize(cacheSize int) Option

WithCacheSize overrides the default cache size.

func WithMaxConcurrency added in v0.6.2

func WithMaxConcurrency(concurrency int64) Option

WithMaxConcurrency overrides the default max concurrency.

func WithMetaData added in v0.8.3

func WithMetaData(metaData string) Option

add a metaData map to fetcher

func WithPastBlockLimit added in v0.6.2

func WithPastBlockLimit(blocks int) Option

WithPastBlockLimit overrides the default past block limit

func WithPruneSleepTime added in v0.6.2

func WithPruneSleepTime(sleepTime int) Option

WithPruneSleepTime overrides the default prune sleep time.

func WithSeenConcurrency added in v0.6.5

func WithSeenConcurrency(concurrency int64) Option

WithSeenConcurrency overrides the number of concurrent invocations of BlockSeen we will handle. We default to the value of runtime.NumCPU().

type PruneHelper added in v0.5.4

type PruneHelper interface {
	// PruneableIndex is the largest block
	// index that is considered safe to prune.
	PruneableIndex(ctx context.Context, headIndex int64) (int64, error)
}

PruneHelper is used by the stateful syncer to determine the safe pruneable index. This is a helper instead of a static argument because the pruneable index is often a function of the state of some number of structs.

type StatefulSyncer

type StatefulSyncer struct {
	// contains filtered or unexported fields
}

StatefulSyncer is an abstraction layer over the stateless syncer package. This layer handles sync restarts and provides fully populated blocks during reorgs (not provided by stateless syncer).

func New

func New(
	ctx context.Context,
	network *types.NetworkIdentifier,
	fetcher *fetcher.Fetcher,
	blockStorage *modules.BlockStorage,
	counterStorage *modules.CounterStorage,
	logger Logger,
	cancel context.CancelFunc,
	workers []modules.BlockWorker,
	options ...Option,
) *StatefulSyncer

New returns a new *StatefulSyncer.

func (*StatefulSyncer) Block

Block is called by the syncer to fetch a block.

func (*StatefulSyncer) BlockAdded

func (s *StatefulSyncer) BlockAdded(ctx context.Context, block *types.Block) error

BlockAdded is called by the syncer when a block is added.

func (*StatefulSyncer) BlockRemoved

func (s *StatefulSyncer) BlockRemoved(
	ctx context.Context,
	blockIdentifier *types.BlockIdentifier,
) error

BlockRemoved is called by the syncer when a block is removed.

func (*StatefulSyncer) BlockSeen added in v0.6.5

func (s *StatefulSyncer) BlockSeen(ctx context.Context, block *types.Block) error

BlockSeen is called by the syncer when a block is seen.

func (*StatefulSyncer) NetworkStatus

func (s *StatefulSyncer) NetworkStatus(
	ctx context.Context,
	network *types.NetworkIdentifier,
) (*types.NetworkStatusResponse, error)

NetworkStatus is called by the syncer to get the current network status.

func (*StatefulSyncer) Prune added in v0.4.5

func (s *StatefulSyncer) Prune(ctx context.Context, helper PruneHelper) error

Prune will repeatedly attempt to prune BlockStorage until the context is canceled or an error is encountered.

PruneHelper is provided as an argument here instead of in the initializer because the caller may wish to change pruning strategies during syncing.

func (*StatefulSyncer) Sync

func (s *StatefulSyncer) Sync(ctx context.Context, startIndex int64, endIndex int64) error

Sync starts a new sync run after properly initializing blockStorage.

Jump to

Keyboard shortcuts

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