syncing

package
v1.0.1-hotfix Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeouts = Timeouts{
	SyncHighestDecided: 12 * time.Second,
	SyncDecidedByRange: 30 * time.Minute,
}

Functions

This section is empty.

Types

type ConcurrentSyncer

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

ConcurrentSyncer is a Syncer that runs the given Syncer's methods concurrently.

func NewConcurrent

func NewConcurrent(
	ctx context.Context,
	syncer Syncer,
	concurrency int,
	timeouts Timeouts,
	errors chan<- Error,
) *ConcurrentSyncer

NewConcurrent returns a new Syncer that runs the given Syncer's methods concurrently. Unlike the standard syncer, syncing methods are non-blocking and return immediately without error. concurrency is the number of worker goroutines to spawn. errors is a channel to which any errors are sent. Pass nil to discard errors.

func (*ConcurrentSyncer) Capacity

func (s *ConcurrentSyncer) Capacity() int

Capacity returns the maximum number of jobs that can be queued. When Queued() == Capacity(), then the next call will block until a job is finished.

func (*ConcurrentSyncer) Queued

func (s *ConcurrentSyncer) Queued() int

Queued returns the number of jobs that are queued but not yet started.

func (*ConcurrentSyncer) Run

func (s *ConcurrentSyncer) Run(logger *zap.Logger)

Run starts the worker goroutines and blocks until the context is done and any remaining jobs are finished.

func (*ConcurrentSyncer) SyncDecidedByRange

func (s *ConcurrentSyncer) SyncDecidedByRange(
	ctx context.Context,
	logger *zap.Logger,
	id spectypes.MessageID,
	from, to specqbft.Height,
	handler MessageHandler,
) error

func (*ConcurrentSyncer) SyncHighestDecided

func (s *ConcurrentSyncer) SyncHighestDecided(
	ctx context.Context,
	logger *zap.Logger,
	id spectypes.MessageID,
	handler MessageHandler,
) error

type Error

type Error struct {
	Operation Operation
	Err       error
}

Error describes an error that occurred during a syncing operation.

func (Error) Error

func (e Error) Error() string

type MessageHandler

type MessageHandler func(msg spectypes.SSVMessage)

MessageHandler reacts to a message received from Syncer.

type Network

type Network interface {
	LastDecided(logger *zap.Logger, id spectypes.MessageID) ([]protocolp2p.SyncResult, error)
	GetHistory(
		logger *zap.Logger,
		id spectypes.MessageID,
		from, to specqbft.Height,
		targets ...string,
	) ([]protocolp2p.SyncResult, specqbft.Height, error)
}

Network is a subset of protocolp2p.Syncer, required by Syncer to retrieve messages from peers.

type Operation

type Operation interface {
	// contains filtered or unexported methods
}

Operation is a syncing operation that has been queued for execution.

type OperationSyncDecidedByRange

type OperationSyncDecidedByRange struct {
	ID      spectypes.MessageID
	From    specqbft.Height
	To      specqbft.Height
	Handler MessageHandler
}

func (OperationSyncDecidedByRange) String

type OperationSyncHighestDecided

type OperationSyncHighestDecided struct {
	ID      spectypes.MessageID
	Handler MessageHandler
}

func (OperationSyncHighestDecided) String

type Syncer

type Syncer interface {
	SyncHighestDecided(ctx context.Context, logger *zap.Logger, id spectypes.MessageID, handler MessageHandler) error
	SyncDecidedByRange(
		ctx context.Context,
		logger *zap.Logger,
		id spectypes.MessageID,
		from, to specqbft.Height,
		handler MessageHandler,
	) error
}

Syncer handles the syncing of decided messages.

func New

func New(network Network) Syncer

New returns a standard implementation of Syncer.

type Timeouts

type Timeouts struct {
	// SyncHighestDecided is the timeout for SyncHighestDecided.
	// Leave zero to not timeout.
	SyncHighestDecided time.Duration

	// SyncDecidedByRange is the timeout for SyncDecidedByRange.
	// Leave zero to not timeout.
	SyncDecidedByRange time.Duration
}

Timeouts is a set of timeouts for each syncing operation.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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