sync

package
v0.7.0-rc6 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options func(*Parameters)

func WithBlockTime

func WithBlockTime(duration time.Duration) Options

WithBlockTime is a functional option that configures the `blockTime` parameter.

func WithMaxRequestSize

func WithMaxRequestSize(amount uint64) Options

WithMaxRequestSize is a functional option that configures the `MaxRequestSize` parameter.

func WithTrustingPeriod

func WithTrustingPeriod(duration time.Duration) Options

WithTrustingPeriod is a functional option that configures the `TrustingPeriod` parameter.

type Parameters

type Parameters struct {
	// TrustingPeriod is period through which we can trust a header's validators set.
	//
	// Should be significantly less than the unbonding period (e.g. unbonding
	// period = 3 weeks, trusting period = 2 weeks).
	//
	// More specifically, trusting period + time needed to check headers + time
	// needed to report and punish misbehavior should be less than the unbonding
	// period.
	TrustingPeriod time.Duration
	// MaxRequestSizeNumber of headers that can be requested at once.
	MaxRequestSize uint64
	// contains filtered or unexported fields
}

Parameters is the set of parameters that must be configured for the syncer.

func DefaultParameters

func DefaultParameters() Parameters

DefaultParameters returns the default params to configure the syncer.

func (*Parameters) Validate

func (p *Parameters) Validate() error

type State

type State struct {
	ID                   uint64 // incrementing ID of a sync
	Height               uint64 // height at the moment when State is requested for a sync
	FromHeight, ToHeight uint64 // the starting and the ending point of a sync
	FromHash, ToHash     header.Hash
	Start, End           time.Time
	Error                error // the error that might happen within a sync
}

State collects all the information about a sync.

func (State) Duration

func (s State) Duration() time.Duration

Duration returns the duration of the sync.

func (State) Finished

func (s State) Finished() bool

Finished returns true if sync is done, false otherwise.

type Syncer

type Syncer[H header.Header] struct {
	Params *Parameters
	// contains filtered or unexported fields
}

Syncer implements efficient synchronization for headers.

Subjective header - the latest known header that is not expired (within trusting period) Network header - the latest header received from the network

There are two main processes running in Syncer: 1. Main syncing loop(s.syncLoop)

  • Performs syncing from the subjective(local chain view) header up to the latest known trusted header
  • Syncs by requesting missing headers from Exchange or
  • By accessing cache of pending and verified headers

2. Receives new headers from PubSub subnetwork (s.processIncoming)

  • Usually, a new header is adjacent to the trusted head and if so, it is simply appended to the local store, incrementing the subjective height and making it the new latest known trusted header.
  • Or, if it receives a header further in the future, verifies against the latest known trusted header adds the header to pending cache(making it the latest known trusted header) and triggers syncing loop to catch up to that point.

func NewSyncer

func NewSyncer[H header.Header](
	exchange header.Exchange[H],
	store header.Store[H],
	sub header.Subscriber[H],
	opts ...Options,
) (*Syncer[H], error)

NewSyncer creates a new instance of Syncer.

func (*Syncer[H]) Head

func (s *Syncer[H]) Head(ctx context.Context) (H, error)

Head returns the Syncer's latest known header. It calls 'networkHead' in order to either return or eagerly fetch the most recent header.

func (*Syncer[H]) InitMetrics added in v0.7.0

func (s *Syncer[H]) InitMetrics() error

func (*Syncer[H]) Start

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

Start starts the syncing routine.

func (*Syncer[H]) State

func (s *Syncer[H]) State() State

State reports state of the current (if in progress), or last sync (if finished). Note that throughout the whole Syncer lifetime there might an initial sync and multiple catch-ups. All of them are treated as different syncs with different state IDs and other information.

func (*Syncer[H]) Stop

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

Stop stops Syncer.

func (*Syncer[H]) WaitSync

func (s *Syncer[H]) WaitSync(ctx context.Context) error

WaitSync blocks until ongoing sync is done.

Jump to

Keyboard shortcuts

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