Documentation ¶
Overview ¶
Package downloader contains the manual full chain synchronisation.
Index ¶
- Variables
- type BlockChain
- type DoneEvent
- type DownloadTester
- func (dl *DownloadTester) CurrentBlock() *types.Block
- func (dl *DownloadTester) CurrentFastBlock() *types.Block
- func (dl *DownloadTester) CurrentHeader() *types.Header
- func (dl *DownloadTester) FastSyncCommitHead(hash common.Hash) error
- func (dl *DownloadTester) GetBlockByHash(hash common.Hash) *types.Block
- func (dl *DownloadTester) GetBlockNumber() uint64
- func (dl *DownloadTester) GetDownloader() *Downloader
- func (dl *DownloadTester) GetGenesis() *types.Block
- func (dl *DownloadTester) GetHeaderByHash(hash common.Hash) *types.Header
- func (dl *DownloadTester) GetTd(hash common.Hash, number uint64) *big.Int
- func (dl *DownloadTester) HasBlock(hash common.Hash, number uint64) bool
- func (dl *DownloadTester) HasFastBlock(hash common.Hash, number uint64) bool
- func (dl *DownloadTester) HasHeader(hash common.Hash, number uint64) bool
- func (dl *DownloadTester) InsertChain(blocks types.Blocks) (int, error)
- func (dl *DownloadTester) InsertHeaderChain(headers []*types.Header, checkFreq int) (int, error)
- func (dl *DownloadTester) InsertReceiptChain(blocks types.Blocks, receipts []types.Receipts) (int, error)
- func (dl *DownloadTester) NewPeer(id string, version int, hashes []common.Hash, ...) error
- func (dl *DownloadTester) NewSlowPeer(id string, version int, hashes []common.Hash, ...) error
- func (dl *DownloadTester) Rollback(hashes []common.Hash)
- func (dl *DownloadTester) Terminate()
- type DownloadTesterPeer
- func (dlp *DownloadTesterPeer) Head() (common.Hash, *big.Int)
- func (dlp *DownloadTesterPeer) RequestBodies(hashes []common.Hash, isFastchain bool, call uint32) error
- func (dlp *DownloadTesterPeer) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool, isFastchain bool) error
- func (dlp *DownloadTesterPeer) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool, isFastchain bool) error
- func (dlp *DownloadTesterPeer) RequestNodeData(hashes []common.Hash, isFastchain bool) error
- func (dlp *DownloadTesterPeer) RequestReceipts(hashes []common.Hash, isFastchain bool) error
- type Downloader
- func (d *Downloader) Cancel()
- func (d *Downloader) DeliverBodies(id string, transactions [][]*types.Transaction, signs [][]*types.PbftSign, ...) (err error)
- func (d *Downloader) DeliverHeaders(id string, headers []*types.Header, call uint32) (err error)
- func (d *Downloader) DeliverReceipts(id string, receipts [][]*types.Receipt) (err error)
- func (d *Downloader) FetchHeight(id string, number uint64) (*types.Header, error)
- func (d *Downloader) GetBlockChain() BlockChain
- func (d *Downloader) GetLightChain() LightChain
- func (d *Downloader) Progress() icechain.SyncProgress
- func (d *Downloader) RegisterLightPeer(id string, version int, peer ice.LightPeer) error
- func (d *Downloader) RegisterPeer(id string, version int, peer ice.Peer) error
- func (d *Downloader) SetHeader(remote *types.Header)
- func (d *Downloader) SetSD(Sdownloader SDownloader)
- func (d *Downloader) SetSync(StateSync ice.StateSyncInter)
- func (d *Downloader) SetSyncStatsChainHeightLast(number uint64)
- func (d *Downloader) Synchronise(id string, head common.Hash, mode SyncMode, origin uint64, height uint64) error
- func (d *Downloader) Synchronising() bool
- func (d *Downloader) Terminate()
- func (d *Downloader) UnregisterPeer(id string) error
- type FailedEvent
- type FakePeer
- func (p *FakePeer) Head() (common.Hash, *big.Int)
- func (p *FakePeer) RequestBodies(hashes []common.Hash, isFastchain bool) error
- func (p *FakePeer) RequestHeadersByHash(hash common.Hash, amount int, skip int, reverse bool, isFastchain bool) error
- func (p *FakePeer) RequestHeadersByNumber(number uint64, amount int, skip int, reverse bool, isFastchain bool) error
- func (p *FakePeer) RequestNodeData(hashes []common.Hash, isFastchain bool) error
- func (p *FakePeer) RequestReceipts(hashes []common.Hash, isFastchain bool) error
- type FloodingTestPeer
- type LightChain
- type SDownloader
- type StartEvent
- type SyncMode
Constants ¶
This section is empty.
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 MaxBodyFetch = 128 // Amount of block bodies to be fetched per retrieval request MaxReceiptFetch = 256 // Amount of transaction receipts to allow fetching per request MaxStateFetch = 384 // Amount of node state values to allow fetching per request MaxForkAncestry = 3 * params.EpochDuration // Maximum chain reorganisation )
Functions ¶
This section is empty.
Types ¶
type BlockChain ¶
type BlockChain interface { LightChain // 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) (int, error) // InsertReceiptChain inserts a batch of receipts into the local chain. InsertReceiptChain(types.Blocks, []types.Receipts) (int, error) }
BlockChain encapsulates functions required to sync a (full or fast) blockchain.
type DownloadTester ¶
type DownloadTester struct {
// contains filtered or unexported fields
}
downloadTester is a test simulator for mocking out local block chain.
func NewTester ¶
func NewTester(testdb *icedb.MemDatabase, stateDb icedb.Database) *DownloadTester
newTester creates a new downloader test mocker.
func (*DownloadTester) CurrentBlock ¶
func (dl *DownloadTester) CurrentBlock() *types.Block
CurrentBlock retrieves the current head block from the canonical chain.
func (*DownloadTester) CurrentFastBlock ¶
func (dl *DownloadTester) CurrentFastBlock() *types.Block
CurrentFastBlock retrieves the current head fast-sync block from the canonical chain.
func (*DownloadTester) CurrentHeader ¶
func (dl *DownloadTester) CurrentHeader() *types.Header
CurrentHeader retrieves the current head header from the canonical chain.
func (*DownloadTester) FastSyncCommitHead ¶
func (dl *DownloadTester) FastSyncCommitHead(hash common.Hash) error
FastSyncCommitHead manually sets the head block to a given hash.
func (*DownloadTester) GetBlockByHash ¶
func (dl *DownloadTester) GetBlockByHash(hash common.Hash) *types.Block
GetBlock retrieves a block from the testers canonical chain.
func (*DownloadTester) GetBlockNumber ¶
func (dl *DownloadTester) GetBlockNumber() uint64
func (*DownloadTester) GetDownloader ¶
func (dl *DownloadTester) GetDownloader() *Downloader
func (*DownloadTester) GetGenesis ¶
func (dl *DownloadTester) GetGenesis() *types.Block
func (*DownloadTester) GetHeaderByHash ¶
func (dl *DownloadTester) GetHeaderByHash(hash common.Hash) *types.Header
GetHeader retrieves a header from the testers canonical chain.
func (*DownloadTester) GetTd ¶
GetTd retrieves the block's total difficulty from the canonical chain.
func (*DownloadTester) HasBlock ¶
func (dl *DownloadTester) HasBlock(hash common.Hash, number uint64) bool
HasBlock checks if a block is present in the testers canonical chain.
func (*DownloadTester) HasFastBlock ¶
func (dl *DownloadTester) HasFastBlock(hash common.Hash, number uint64) bool
HasFastBlock checks if a block is present in the testers canonical chain.
func (*DownloadTester) HasHeader ¶
func (dl *DownloadTester) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a header is present in the testers canonical chain.
func (*DownloadTester) InsertChain ¶
func (dl *DownloadTester) InsertChain(blocks types.Blocks) (int, error)
InsertChain injects a new batch of blocks into the simulated chain.
func (*DownloadTester) InsertHeaderChain ¶
InsertHeaderChain injects a new batch of headers into the simulated chain.
func (*DownloadTester) InsertReceiptChain ¶
func (dl *DownloadTester) InsertReceiptChain(blocks types.Blocks, receipts []types.Receipts) (int, error)
InsertReceiptChain injects a new batch of receipts into the simulated chain.
func (*DownloadTester) NewPeer ¶
func (dl *DownloadTester) NewPeer(id string, version int, hashes []common.Hash, headers map[common.Hash]*types.Header, blocks map[common.Hash]*types.Block, receipts map[common.Hash]types.Receipts) error
newPeer registers a new block download source into the downloader.
func (*DownloadTester) NewSlowPeer ¶
func (dl *DownloadTester) NewSlowPeer(id string, version int, hashes []common.Hash, headers map[common.Hash]*types.Header, blocks map[common.Hash]*types.Block, receipts map[common.Hash]types.Receipts, delay time.Duration) error
newSlowPeer registers a new block download source into the downloader, with a specific delay time on processing the network packets sent to it, simulating potentially slow network IO.
func (*DownloadTester) Rollback ¶
func (dl *DownloadTester) Rollback(hashes []common.Hash)
Rollback removes some recently added elements from the chain.
func (*DownloadTester) Terminate ¶
func (dl *DownloadTester) Terminate()
terminate aborts any operations on the embedded downloader and releases all held resources.
type DownloadTesterPeer ¶
type DownloadTesterPeer struct {
// contains filtered or unexported fields
}
func (*DownloadTesterPeer) Head ¶
func (dlp *DownloadTesterPeer) Head() (common.Hash, *big.Int)
Head constructs a function to retrieve a peer's current head hash and total difficulty.
func (*DownloadTesterPeer) RequestBodies ¶
func (dlp *DownloadTesterPeer) RequestBodies(hashes []common.Hash, isFastchain bool, call uint32) error
RequestBodies constructs a getBlockBodies method associated with a particular peer in the download tester. The returned function can be used to retrieve batches of block bodies from the particularly requested peer.
func (*DownloadTesterPeer) RequestHeadersByHash ¶
func (dlp *DownloadTesterPeer) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool, isFastchain bool) error
RequestHeadersByHash constructs a GetBlockHeaders function based on a hashed origin; associated with a particular peer in the download tester. The returned function can be used to retrieve batches of headers from the particular peer.
func (*DownloadTesterPeer) RequestHeadersByNumber ¶
func (dlp *DownloadTesterPeer) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool, isFastchain bool) error
RequestHeadersByNumber constructs a GetBlockHeaders function based on a numbered origin; associated with a particular peer in the download tester. The returned function can be used to retrieve batches of headers from the particular peer.
func (*DownloadTesterPeer) RequestNodeData ¶
func (dlp *DownloadTesterPeer) RequestNodeData(hashes []common.Hash, isFastchain bool) error
RequestNodeData constructs a getNodeData method associated with a particular peer in the download tester. The returned function can be used to retrieve batches of node state data from the particularly requested peer.
func (*DownloadTesterPeer) RequestReceipts ¶
func (dlp *DownloadTesterPeer) RequestReceipts(hashes []common.Hash, isFastchain bool) error
RequestReceipts constructs a getReceipts method associated with a particular peer in the download tester. The returned function can be used to retrieve batches of block receipts from the particularly requested peer.
type Downloader ¶
type Downloader struct { StateSync ice.StateSyncInter // contains filtered or unexported fields }
func New ¶
func New(mode SyncMode, stateDb icedb.Database, mux *event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer ice.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, signs [][]*types.PbftSign, infos [][]*types.CommitteeMember, call uint32) (err error)
DeliverBodies injects a new batch of block bodies received from a remote node.
func (*Downloader) DeliverHeaders ¶
DeliverHeaders injects a new batch of block headers received from a remote node into the download schedule.
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) FetchHeight ¶
fetchHeight retrieves the head header of the remote peer to aid in estimating the total time a pending synchronisation would take.
func (*Downloader) GetBlockChain ¶
func (d *Downloader) GetBlockChain() BlockChain
func (*Downloader) GetLightChain ¶
func (d *Downloader) GetLightChain() LightChain
func (*Downloader) Progress ¶
func (d *Downloader) Progress() icechain.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) RegisterLightPeer ¶
RegisterLightPeer injects a light client peer, wrapping it so it appears as a regular peer.
func (*Downloader) RegisterPeer ¶
RegisterPeer injects a new download peer into the set of block source to be used for fetching hashes and blocks from.
func (*Downloader) SetHeader ¶
func (d *Downloader) SetHeader(remote *types.Header)
func (*Downloader) SetSD ¶
func (d *Downloader) SetSD(Sdownloader SDownloader)
func (*Downloader) SetSync ¶
func (d *Downloader) SetSync(StateSync ice.StateSyncInter)
func (*Downloader) SetSyncStatsChainHeightLast ¶
func (d *Downloader) SetSyncStatsChainHeightLast(number uint64)
func (*Downloader) Synchronise ¶
func (d *Downloader) Synchronise(id string, head common.Hash, mode SyncMode, origin uint64, height uint64) 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 FakePeer ¶
type FakePeer struct {
// contains filtered or unexported fields
}
FakePeer is a mock downloader peer that operates on a local database instance instead of being an actual live node. It's useful for testing and to implement sync commands from an existing local database.
func NewFakePeer ¶
func NewFakePeer(id string, db icedb.Database, hc *core.HeaderChain, dl *Downloader) *FakePeer
NewFakePeer creates a new mock downloader peer with the given data sources.
func (*FakePeer) Head ¶
Head implements downloader.Peer, returning the current head hash and number of the best known header.
func (*FakePeer) RequestBodies ¶
RequestBodies implements downloader.Peer, returning a batch of block bodies corresponding to the specified block hashes.
func (*FakePeer) RequestHeadersByHash ¶
func (p *FakePeer) RequestHeadersByHash(hash common.Hash, amount int, skip int, reverse bool, isFastchain bool) error
RequestHeadersByHash implements downloader.Peer, returning a batch of headers defined by the origin hash and the associated query parameters.
func (*FakePeer) RequestHeadersByNumber ¶
func (p *FakePeer) RequestHeadersByNumber(number uint64, amount int, skip int, reverse bool, isFastchain bool) error
RequestHeadersByNumber implements downloader.Peer, returning a batch of headers defined by the origin number and the associated query parameters.
func (*FakePeer) RequestNodeData ¶
RequestNodeData implements downloader.Peer, returning a batch of state trie nodes corresponding to the specified trie hashes.
type FloodingTestPeer ¶
type FloodingTestPeer struct {
// contains filtered or unexported fields
}
type LightChain ¶
type LightChain interface { // HasHeader verifies a header's presence in the local chain. HasHeader(common.Hash, uint64) bool // CurrentHeader retrieves the head header from the local chain. CurrentHeader() *types.Header // InsertHeaderChain inserts a batch of headers into the local chain. InsertHeaderChain([]*types.Header, int) (int, error) // Rollback removes a few recently added elements from the local chain. Rollback([]common.Hash) }
LightChain encapsulates functions required to synchronise a light chain.
type SDownloader ¶
type SDownloader interface {
SyncStateFd(root common.Hash) ice.StateSyncInter
}
type StartEvent ¶
type StartEvent struct{}
type SyncMode ¶
type SyncMode int
SyncMode represents the synchronisation mode of the downloader.