Documentation ¶
Overview ¶
Package downloader contains the manual full chain synchronisation.
Index ¶
- Constants
- Variables
- func ErrWasRequested(e error) bool
- type BlockChain
- type DoneEvent
- type Downloader
- func (d *Downloader) Cancel()
- func (d *Downloader) DeliverBodies(id string, transactions [][]*types.Transaction, uncles [][]*types.Header) (err error)
- func (d *Downloader) DeliverHeaders(id string, headers []*types.Header) (err error)
- func (d *Downloader) DeliverNodeData(id string, data [][]byte) (err error)
- func (d *Downloader) DeliverReceipts(id string, receipts [][]*types.Receipt) (err error)
- func (d *Downloader) GetMode() SyncMode
- func (d *Downloader) GetPeers() *peerSet
- func (d *Downloader) Progress() (uint64, uint64, uint64, uint64, uint64)
- func (d *Downloader) Qos() (rtt time.Duration, ttl time.Duration, conf float64)
- func (d *Downloader) RegisterPeer(id string, version int, name string, currentHead currentHeadRetrievalFn, ...) error
- func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode SyncMode) error
- func (d *Downloader) Synchronising() bool
- func (d *Downloader) Terminate()
- func (d *Downloader) UnregisterPeer(id string) error
- type FailedEvent
- type InsertChainEvent
- type InsertHeaderChainEvent
- type InsertReceiptChainEvent
- type LightChain
- type Progress
- type PublicDownloaderAPI
- type StartEvent
- type SyncMode
- type SyncingResult
Constants ¶
const (
EpochDuration = 30000 // Duration between proof-of-work epochs
)
Variables ¶
var ( MaxHashFetch = 512 // Amount of hashes to be fetched per retrieval request MaxBlockFetch = 128 // Amount of blocks to be fetched per retrieval request MaxHeaderFetch = 192 // Amount of block headers to be fetched per retrieval request MaxSkeletonSize = 128 // Number of header fetches to need for a skeleton assembly MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request MaxStateFetch = 384 // Amount of node state values to allow fetching per request MaxForkAncestry uint64 = 3 * EpochDuration // Maximum chain reorganisation )
Functions ¶
func ErrWasRequested ¶
Types ¶
type BlockChain ¶
type BlockChain interface { LightChain // HasBlock verifies block presence in the local chain. // NOTE(whilei): https://github.com/ethereum/go-ethereum/pull/16061 HasBlock(common.Hash) bool // HasBlock verifies block and associate state presence in the local chain. HasBlockAndState(common.Hash) bool // GetBlockByHash retrieves a block from the local chain. GetBlockByHash(common.Hash) *types.Block // CurrentBlock retrieves the head block from the local chain. CurrentBlock() *types.Block // CurrentFastBlock retrieves the head fast block from the local chain. CurrentFastBlock() *types.Block // FastSyncCommitHead directly commits the head block to a certain entity. FastSyncCommitHead(common.Hash) error // InsertChain inserts a batch of blocks into the local chain. InsertChain(types.Blocks) *core.ChainInsertResult // InsertReceiptChain inserts a batch of receipts into the local chain. InsertReceiptChain(types.Blocks, []types.Receipts) *core.ReceiptChainInsertResult }
BlockChain encapsulates functions required to sync a (full or fast) blockchain.
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
func New ¶
func New(mode SyncMode, stateDb ethdb.Database, mux *event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer peerDropFn) *Downloader
New creates a new downloader to fetch hashes and blocks from remote peers.
func (*Downloader) Cancel ¶ added in v0.9.20
func (d *Downloader) Cancel()
Cancel aborts all of the operations and waits for all download goroutines to finish before returning.
func (*Downloader) DeliverBodies ¶ added in v1.2.2
func (d *Downloader) DeliverBodies(id string, transactions [][]*types.Transaction, uncles [][]*types.Header) (err error)
DeliverBodies injects a new batch of block bodies received from a remote node.
func (*Downloader) DeliverHeaders ¶ added in v1.2.2
func (d *Downloader) DeliverHeaders(id string, headers []*types.Header) (err error)
DeliverHeaders injects a new batch of block headers received from a remote node into the download schedule.
func (*Downloader) DeliverNodeData ¶ added in v1.3.1
func (d *Downloader) DeliverNodeData(id string, data [][]byte) (err error)
DeliverNodeData injects a new batch of node state data received from a remote node.
func (*Downloader) DeliverReceipts ¶ added in v1.3.1
func (d *Downloader) DeliverReceipts(id string, receipts [][]*types.Receipt) (err error)
DeliverReceipts injects a new batch of receipts received from a remote node.
func (*Downloader) GetMode ¶
func (d *Downloader) GetMode() SyncMode
func (*Downloader) GetPeers ¶
func (d *Downloader) GetPeers() *peerSet
func (*Downloader) Progress ¶ added in v1.3.1
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 int, name string, currentHead currentHeadRetrievalFn, getRelHeaders relativeHeaderFetcherFn, getAbsHeaders absoluteHeaderFetcherFn, getBlockBodies blockBodyFetcherFn, getReceipts receiptFetcherFn, getNodeData stateFetcherFn) 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 ¶
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 ¶ added in v0.9.21
func (d *Downloader) Synchronising() bool
Synchronising returns whether the downloader is currently retrieving blocks.
func (*Downloader) Terminate ¶ added in v0.9.32
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 ¶ added in v0.9.21
type FailedEvent struct { Peer *peer Err error }
type InsertChainEvent ¶
type InsertChainEvent struct {
core.ChainInsertEvent
}
type InsertHeaderChainEvent ¶
type InsertHeaderChainEvent struct {
core.HeaderChainInsertEvent
}
type InsertReceiptChainEvent ¶
type InsertReceiptChainEvent struct { core.ReceiptChainInsertEvent Pivot bool }
type LightChain ¶
type LightChain interface { // HasHeader verifies a header's presence in the local chain. HasHeader(common.Hash) bool // GetHeaderByHash retrieves a header from the local chain. GetHeaderByHash(common.Hash) *types.Header // CurrentHeader retrieves the head header from the local chain. CurrentHeader() *types.Header // GetTd returns the total difficulty of a local block. GetTd(common.Hash) *big.Int // InsertHeaderChain inserts a batch of headers into the local chain. InsertHeaderChain([]*types.Header, int) *core.HeaderChainInsertResult // Rollback removes a few recently added elements from the local chain. Rollback([]common.Hash) }
LightChain encapsulates functions required to synchronise a light chain.
type Progress ¶ added in v1.4.0
type Progress struct { Origin uint64 `json:"startingBlock"` Current uint64 `json:"currentBlock"` Height uint64 `json:"highestBlock"` Pulled uint64 `json:"pulledStates"` Known uint64 `json:"knownStates"` }
Progress gives progress indications when the node is synchronising with the Ethereum network.
type PublicDownloaderAPI ¶ added in v1.4.0
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 ¶ added in v1.4.0
func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI
NewPublicDownloaderAPI create a new PublicDownloaderAPI.
func (*PublicDownloaderAPI) Syncing ¶ added in v1.4.0
func (api *PublicDownloaderAPI) Syncing(ctx context.Context) (rpc.Subscription, error)
Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.
type StartEvent ¶ added in v0.9.21
type SyncMode ¶ added in v1.3.1
type SyncMode int
SyncMode represents the synchronisation mode of the downloader.
type SyncingResult ¶ added in v1.4.0
SyncingResult provides information about the current synchronisation status for this node.