sync

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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     tmbytes.HexBytes
	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 struct {
	// contains filtered or unexported fields
}

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

  • Performs syncing from the subjective header up to the network head
  • Syncs by requesting missing headers from Exchange or
  • By accessing cache of pending network headers received from PubSub

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

  • Once received, tries to append it to the store
  • Or, if not adjacent to head of the store,
  • verifies against the latest known subjective header
  • adds the header to pending cache, thereby making it the latest known subjective header
  • and triggers syncing loop to catch up to that point.

func NewSyncer

func NewSyncer(exchange header.Exchange, store header.Store, sub header.Subscriber, blockTime time.Duration) *Syncer

NewSyncer creates a new instance of Syncer.

func (*Syncer) Start

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

Start starts the syncing routine.

func (*Syncer) State

func (s *Syncer) 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) Stop

func (s *Syncer) Stop(ctx context.Context) error

Stop stops Syncer.

func (*Syncer) WaitSync

func (s *Syncer) 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