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 ¶
WithBlockTime is a functional option that configures the `blockTime` parameter.
func WithTrustingPeriod ¶
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 // 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.
type Syncer ¶
type Syncer[H header.Header] struct { Params *Parameters // contains filtered or unexported fields }
Syncer implements efficient synchronization for headers.
Subjective Head - the latest known local valid header and a sync target. Network Head - the latest valid network-wide header. Becomes subjective once applied locally.
There are two main processes running in Syncer: - Main syncing loop(s.syncLoop)
- Performs syncing from the latest stored header up to the latest known Subjective Head
- Syncs by requesting missing headers from Exchange or
- By accessing cache of pending headers
- Receives every new Network Head from PubSub gossip subnetwork (s.incomingNetworkHead)
- Validates against the latest known Subjective Head, is so
- Sets as the new Subjective Head, which
- if there is a gap between the previous and the new Subjective Head
- Triggers s.syncLoop and saves the Subjective Head in the pending so s.syncLoop can access it
func NewSyncer ¶
func NewSyncer[H header.Header]( getter header.Getter[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 ¶
Head returns the Network Head.
Known subjective head is considered network head if it is recent enough(now-timestamp<=blocktime) Otherwise, head is requested from a trusted peer and set as the new subjective head, assuming that trusted peer is always fully synced.