Documentation ¶
Overview ¶
Package fetch implements block replication for participant Chain Cores.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadBlocks ¶
func DownloadBlocks(ctx context.Context, peer *rpc.Client, height uint64) (chan *legacy.Block, chan error)
DownloadBlocks starts a goroutine to download blocks from the given peer, starting at the given height and incrementing from there. It will re-attempt downloads for the next block in the network until it is available. It returns two channels, one for reading blocks and the other for reading errors. Progress will halt unless callers are reading from both. DownloadBlocks will continue even if it encounters errors, until its context is done.
Types ¶
type Replicator ¶
type Replicator struct {
// contains filtered or unexported fields
}
Replicator implements block replication.
func New ¶
func New(peer *rpc.Client) *Replicator
New initializes a new Replicator to replicate blocks from the Chain Core specified by peer. It immediately begins polling for the peer's blockchain height, and will stop only when ctx is cancelled. To begin replicating blocks, the caller must call Fetch.
func (*Replicator) Fetch ¶
Fetch runs in a loop, fetching blocks from the configured peer (e.g. the generator) and applying them to the local Chain.
It returns when its context is canceled. After each attempt to fetch and apply a block, it calls health to report either an error or nil to indicate success.
func (*Replicator) PeerHeight ¶
func (rep *Replicator) PeerHeight() (uint64, time.Time)
PeerHeight returns the height of the peer Chain Core and the timestamp of the moment when that height was observed.
func (*Replicator) PollRemoteHeight ¶
func (rep *Replicator) PollRemoteHeight(ctx context.Context)
PollRemoteHeight periodically polls the configured peer for its blockchain height. It blocks until the ctx is canceled.
type SnapshotProgress ¶
type SnapshotProgress struct {
// contains filtered or unexported fields
}
SnapshotProgress describes a snapshot being downloaded from a peer Core.
func BootstrapSnapshot ¶
func BootstrapSnapshot(ctx context.Context, c *protocol.Chain, store protocol.Store, peer *rpc.Client, health func(error)) *SnapshotProgress
BootstrapSnapshot downloads and stores the most recent snapshot from the provided peer. It's run when bootstrapping a new Core to an existing network. It should be run before invoking Chain.Recover.
func (*SnapshotProgress) Attempt ¶
func (s *SnapshotProgress) Attempt() int
Attempt returns the how many times Core has attempted to download a bootstrap snapshot. If a download request times out or encounters any kind of validation error, it'll re-attempt the snapshot download a few times.
func (*SnapshotProgress) Height ¶
func (s *SnapshotProgress) Height() uint64
Height returns the blockchain height of the snapshot being downloaded.
func (*SnapshotProgress) Progress ¶
func (s *SnapshotProgress) Progress() (downloaded, total uint64)
Progress returns the number of bytes download and the total number of the bytes of the snapshot.
func (*SnapshotProgress) Wait ¶
func (s *SnapshotProgress) Wait()
Wait blocks until the snapshot is either successfully downloaded and stored or the Core has given up on bootstrapping through a snapshot.