Documentation ¶
Index ¶
- Constants
- Variables
- func ToString(mode SyncMode) string
- type BlockChain
- type DoneEvent
- type Downloader
- func (d *Downloader) Cancel()
- func (d *Downloader) DeliverBodies(id string, transactions [][]*types.Transaction) (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) FetchVldTrie(root common.Hash) error
- func (d *Downloader) Progress() SyncProgress
- func (d *Downloader) RegisterPeer(id string, peer Peer) error
- func (d *Downloader) Synchronise(id string, peerNumber *big.Int, mode SyncMode) error
- func (d *Downloader) Synchronising() bool
- func (d *Downloader) Terminate()
- func (d *Downloader) UnregisterPeer(id string) error
- type FailedEvent
- type LightChain
- type Peer
- type PeerSet
- func (ps *PeerSet) AllPeers() []*peerConnection
- func (ps *PeerSet) BodyIdlePeers() ([]*peerConnection, int)
- func (ps *PeerSet) HeaderIdlePeers() ([]*peerConnection, int)
- func (ps *PeerSet) Len() int
- func (ps *PeerSet) NodeDataIdlePeers() ([]*peerConnection, int)
- func (ps *PeerSet) Peer(id string) *peerConnection
- func (ps *PeerSet) ReceiptIdlePeers() ([]*peerConnection, int)
- func (ps *PeerSet) Register(p *peerConnection) error
- func (ps *PeerSet) Reset()
- func (ps *PeerSet) SubscribeNewPeers(ch chan<- *peerConnection) event.Subscription
- func (ps *PeerSet) SubscribePeerDrops(ch chan<- *peerConnection) event.Subscription
- func (ps *PeerSet) Unregister(id string) error
- type PublicDownloaderAPI
- type SkeletonHeader
- type StartEvent
- type StartFetchBlockEvent
- type SyncFinishedEvent
- type SyncMode
- type SyncProgress
- type SyncStatusSubscription
- type SyncingResult
Constants ¶
const ( FastLightDone uint8 = iota FastUndone LightUndone )
Variables ¶
var ( MaxBlockFetch = 128 // Amount of blocks to be fetched per retrieval request MaxHeaderFetch = 192 // Amount of block headers to be fetched per retrieval request MaxSkeletonSize = uint64(128) // Number of header fetches to need for a skeleton assembly MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request MaxTrieNodeFetch = 384 // Amount of trie node values to allow fetching per request )
Functions ¶
Types ¶
type BlockChain ¶
type BlockChain interface { LightChain // HasBlock verifies a block's presence in the local chain. HasBlock(common.Hash, uint64) bool // CurrentBlock retrieves the head block from the local chain. CurrentBlock() *types.Block // InsertChain inserts a batch of blocks into the local chain. InsertChain(types.Blocks) error // InsertReceiptChain inserts a batch of receipts into the local chain. // the bool parameter indicates where to post the ChainHeadEvent or not InsertReceiptChain(types.Blocks, []types.Receipts, bool) (int, error) }
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(chain BlockChain, lightChain LightChain, chainDb youdb.Database, dropPeer peerDropFn, mux *event.TypeMux) *Downloader
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) (err 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) (err error)
DeliverHeaders injects a new batch of block headers received from a remote node into the download schedule.
func (*Downloader) DeliverNodeData ¶
func (d *Downloader) DeliverNodeData(id string, data [][]byte) (err error)
func (*Downloader) DeliverReceipts ¶
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) FetchVldTrie ¶
func (d *Downloader) FetchVldTrie(root common.Hash) error
func (*Downloader) Progress ¶
func (d *Downloader) Progress() 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 nodes are also returned. Otherwise these are zero.
func (*Downloader) RegisterPeer ¶
func (d *Downloader) RegisterPeer(id string, 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 ¶
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
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
type FailedEvent ¶
type FailedEvent struct {
Err error
}
type LightChain ¶
type LightChain interface { // CurrentHeader retrieves the head header from the local chain. CurrentHeader() *types.Header // GetHeaderByNumber retrieves a header by number from the local chain GetHeaderByNumber(number uint64) *types.Header // GetHeaderByHash retrieves a header from the local chain. GetHeaderByHash(common.Hash) *types.Header // GetLightStartHeader retrieves the start header of a light-client GetLightStartHeader() *types.Header // IsUcon returns whether the consensus is Ucon IsUcon() bool UconLookBackParams() (seedLookBack, stakeLookBack uint64) // TrieBackingDb returns the backing database of the specific kind of trie TrieBackingDb(kind types.TrieKind) youdb.Database // VerifyAcHeader verifies the header using CHT certificates, mainly for fast or light sync VerifyAcHeader(header *types.Header, verifiedAcParents []*types.Header) error // UpdateTrustedCht update the CHT indexer when the trie which is represented by acHeader.ChtRoot is fetched. UpdateTrustedCht(acHeader *types.Header) error // UpdateTrustedBlt update the BLT indexer when the trie which is represented by acHeader.BltRoot is fetched. UpdateTrustedBlt(acHeader *types.Header) error // GetHashFromCht gets the header hash from CHT. GetHashFromCht(headerNum uint64) (common.Hash, error) // InsertGuaranteedHeaderChain attempts to insert the given header chain into the local // chain, the header chain here MUST be already guaranteed by cht or other verification. InsertGuaranteedHeaderChain(chain []*types.Header) (int, error) // InsertHeaderChain attempts to insert the given (unverified) header chain into the local chain. InsertHeaderChain(chain []*types.Header) (int, error) }
LightChain encapsulates functions required to synchronise a light chain.
type Peer ¶
type Peer interface { Head() (common.Hash, *big.Int) Origin() *big.Int RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse, light bool) error RequestHeadersByNumber(origin uint64, amount int, skip int, reverse, light bool) error RequestBodies([]common.Hash) error RequestReceipts([]common.Hash) error RequestNodeData(kind types.TrieKind, blockHashes []common.Hash) error }
type PeerSet ¶
type PeerSet struct {
// contains filtered or unexported fields
}
PeerSet represents the collection of active peer participating in the chain download procedure.
func (*PeerSet) AllPeers ¶
func (ps *PeerSet) AllPeers() []*peerConnection
AllPeers retrieves a flat list of all the peers within the set.
func (*PeerSet) BodyIdlePeers ¶
BodyIdlePeers retrieves a flat list of all the currently body-idle peers within the active peer set, ordered by their reputation.
func (*PeerSet) HeaderIdlePeers ¶
HeaderIdlePeers retrieves a flat list of all the currently header-idle peers within the active peer set, ordered by their reputation.
func (*PeerSet) NodeDataIdlePeers ¶
NodeDataIdlePeers retrieves a flat list of all the currently node-data-idle peers within the active peer set, ordered by their reputation.
func (*PeerSet) ReceiptIdlePeers ¶
ReceiptIdlePeers retrieves a flat list of all the currently receipt-idle peers within the active peer set, ordered by their reputation.
func (*PeerSet) Register ¶
Register injects a new peer into the working set, or returns an error if the peer is already known.
The method also sets the starting throughput values of the new peer to the average of all existing peers, to give it a realistic chance of being used for data retrievals.
func (*PeerSet) Reset ¶
func (ps *PeerSet) Reset()
Reset iterates over the current peer set, and resets each of the known peers to prepare for a next batch of block retrieval.
func (*PeerSet) SubscribeNewPeers ¶
func (ps *PeerSet) SubscribeNewPeers(ch chan<- *peerConnection) event.Subscription
SubscribeNewPeers subscribes to peer arrival events.
func (*PeerSet) SubscribePeerDrops ¶
func (ps *PeerSet) SubscribePeerDrops(ch chan<- *peerConnection) event.Subscription
SubscribePeerDrops subscribes to peer departure events.
func (*PeerSet) Unregister ¶
Unregister removes a remote peer from the active set, disabling any further actions to/from that particular entity.
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
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 Ethereum network and when it's finished.
type SkeletonHeader ¶
SkeletonHeader is a simplified header fields struct used by fillSkeletonHeaders
type StartEvent ¶
type StartEvent struct{}
type StartFetchBlockEvent ¶
type SyncFinishedEvent ¶
type SyncFinishedEvent struct {
Peer Peer
}
type SyncMode ¶
type SyncMode int
SyncMode represents the synchronisation mode of the downloader.
func ToSyncMode ¶
type SyncProgress ¶
type SyncProgress struct { StartingBlock uint64 // Block number where sync began CurrentBlock uint64 // Current block number where sync is at HighestBlock uint64 // Highest alleged block number in the chain PulledStates uint64 // Number of state trie entries already downloaded KnownStates uint64 // Total number of state trie entries known about }
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 SyncProgress `json:"status"` }
SyncingResult provides information about the current synchronisation status for this node.