downloader

package
v0.13.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package downloader contains the manual full chain synchronisation.

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxBlockFetch     = 128  // Amount of blocks to be fetched per retrieval request
	MaxHeaderFetch    = 192  // Amount of block headers to be fetched per retrieval request
	MaxSkeletonWindow = 1024 // Amount of blocks to be fetched for a skeleton assembly.
	MaxSkeletonSize   = 1024 // Number of header fetches to need for a skeleton assembly
	MaxStateFetch     = 384  // Amount of node state values to allow fetching per request

	PrimeSkeletonDist = 8
	PrimeFetchDepth   = 1000
	RegionFetchDepth  = 7000
	ZoneFetchDepth    = 21000
)

Functions

This section is empty.

Types

type Core

type Core interface {
	// HasBlock verifies a block's presence in the local chain.
	HasBlock(common.Hash, uint64) bool

	// GetBlockByHash retrieves a block from the local chain.
	GetBlockByHash(common.Hash) *types.Block

	// CurrentHeader retrieves the head of local chain.
	CurrentHeader() *types.Header

	// CurrentLogEntropy returns the logarithm of the total entropy reduction since genesis for our current head block
	CurrentLogEntropy() *big.Int

	// TotalLogS() returns the total entropy reduction if the chain since genesis to the given header
	TotalLogS(header *types.Header) *big.Int

	// AddPendingEtxs adds the pendingEtxs to the database.
	AddPendingEtxs(pendingEtxs types.PendingEtxs) error

	// Snapshots returns the core snapshot tree to paused it during sync.
	Snapshots() *snapshot.Tree

	// Engine
	Engine() consensus.Engine

	// Write block to the database
	WriteBlock(block *types.Block)

	// GetTerminiByHash returns the termini of a given block
	GetTerminiByHash(hash common.Hash) *types.Termini

	// BadHashExistsInChain returns true if any of the specified bad hashes exists on chain
	BadHashExistsInChain() bool

	// IsBlockHashABadHash returns true if block hash exists in the bad hashes list
	IsBlockHashABadHash(hash common.Hash) bool
}

Core encapsulates functions required to sync a full core.

type DoneEvent

type DoneEvent struct {
	Latest *types.Header
}

type Downloader

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

func New

func New(mux *event.TypeMux, core Core, dropPeer peerDropFn) *Downloader

New creates a new downloader to fetch hashes and blocks from remote peers.

func (*Downloader) Cancel

func (d *Downloader) Cancel()

Cancel aborts all of the operations and waits for all download goroutines to finish before returning.

func (*Downloader) DeliverBodies

func (d *Downloader) DeliverBodies(id string, transactions [][]*types.Transaction, uncles [][]*types.Header, extTransactions [][]*types.Transaction, manifests []types.BlockManifest) error

DeliverBodies injects a new batch of block bodies received from a remote node.

func (*Downloader) DeliverHeaders

func (d *Downloader) DeliverHeaders(id string, headers []*types.Header) error

DeliverHeaders injects a new batch of block headers received from a remote node into the download schedule.

func (*Downloader) HeadEntropy

func (d *Downloader) HeadEntropy() *big.Int

HeadEntropy returns the downloader head entropy

func (*Downloader) PeerSet

func (d *Downloader) PeerSet() *peerSet

PeerSet retrieves the current peer set of the downloader.

func (*Downloader) Progress

func (d *Downloader) Progress() quai.SyncProgress

Progress retrieves the synchronisation boundaries, specifically the origin block where synchronisation started at (may have failed/suspended); the block or header sync is currently at; and the latest known block which the sync targets.

In addition, during the state download phase of fast synchronisation the number of processed and the total number of known states are also returned. Otherwise these are zero.

func (*Downloader) RegisterPeer

func (d *Downloader) RegisterPeer(id string, version uint, peer Peer) error

RegisterPeer injects a new download peer into the set of block source to be used for fetching hashes and blocks from.

func (*Downloader) Synchronise

func (d *Downloader) Synchronise(id string, head common.Hash, entropy *big.Int, mode SyncMode) error

Synchronise tries to sync up our local block chain with a remote peer, both adding various sanity checks as well as wrapping it with various log entries.

func (*Downloader) Synchronising

func (d *Downloader) Synchronising() bool

Synchronising returns whether the downloader is currently retrieving blocks.

func (*Downloader) Terminate

func (d *Downloader) Terminate()

Terminate interrupts the downloader, canceling all pending operations. The downloader cannot be reused after calling Terminate.

func (*Downloader) UnregisterPeer

func (d *Downloader) UnregisterPeer(id string) error

UnregisterPeer remove a peer from the known list, preventing any action from the specified peer. An effort is also made to return any pending fetches into the queue.

type FailedEvent

type FailedEvent struct{ Err error }

type LightPeer

type LightPeer interface {
	Head() (common.Hash, *big.Int, *big.Int, time.Time)
	RequestHeadersByHash(common.Hash, int, uint64, bool, bool) error
	RequestHeadersByNumber(uint64, int, uint64, uint64, bool, bool) error
}

LightPeer encapsulates the methods required to synchronise with a remote light peer.

type Peer

type Peer interface {
	LightPeer
	RequestBodies([]common.Hash) error
}

Peer encapsulates the methods required to synchronise with a remote full peer.

type PublicDownloaderAPI

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

PublicDownloaderAPI provides an API which gives information about the current synchronisation status. It offers only methods that operates on data that can be available to anyone without security risks.

func NewPublicDownloaderAPI

func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI

NewPublicDownloaderAPI create a new PublicDownloaderAPI. The API has an internal event loop that listens for events from the downloader through the global event mux. In case it receives one of these events it broadcasts it to all syncing subscriptions that are installed through the installSyncSubscription channel.

func (*PublicDownloaderAPI) SubscribeSyncStatus

func (api *PublicDownloaderAPI) SubscribeSyncStatus(status chan interface{}) *SyncStatusSubscription

SubscribeSyncStatus creates a subscription that will broadcast new synchronisation updates. The given channel must receive interface values, the result can either

func (*PublicDownloaderAPI) Syncing

func (api *PublicDownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error)

Syncing provides information when this nodes starts synchronising with the Quai network and when it's finished.

type StartEvent

type StartEvent struct{}

type SyncMode

type SyncMode uint32

SyncMode represents the synchronisation mode of the downloader. It is a uint32 as it is used with atomic operations.

const (
	FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks
)

func (SyncMode) IsValid

func (mode SyncMode) IsValid() bool

func (SyncMode) MarshalText

func (mode SyncMode) MarshalText() ([]byte, error)

func (SyncMode) String

func (mode SyncMode) String() string

String implements the stringer interface.

func (*SyncMode) UnmarshalText

func (mode *SyncMode) UnmarshalText(text []byte) error

type SyncStatusSubscription

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

SyncStatusSubscription represents a syncing subscription.

func (*SyncStatusSubscription) Unsubscribe

func (s *SyncStatusSubscription) Unsubscribe()

Unsubscribe uninstalls the subscription from the DownloadAPI event loop. The status channel that was passed to subscribeSyncStatus isn't used anymore after this method returns.

type SyncingResult

type SyncingResult struct {
	Syncing bool                    `json:"syncing"`
	Status  interfaces.SyncProgress `json:"status"`
}

SyncingResult provides information about the current synchronisation status for this node.

Jump to

Keyboard shortcuts

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