Documentation ¶
Overview ¶
Package downloader contains the manual full chain synchronization.
Index ¶
- Variables
- type BlockDag
- type DoneEvent
- type Downloader
- func (d *Downloader) Cancel()
- func (d *Downloader) DeliverAllToken(id string, headers []*modules.Header) error
- func (d *Downloader) DeliverBodies(id string, transactions [][]*modules.Transaction) (err error)
- func (d *Downloader) DeliverHeaders(id string, headers []*modules.Header) (err error)
- func (d *Downloader) DeliverNodeData(id string, data [][]byte) (err error)
- func (d *Downloader) FetchAllToken(id string) ([]*modules.Header, error)
- func (d *Downloader) GetFastStableIndex() uint64
- func (d *Downloader) Progress() palletone.SyncProgress
- func (d *Downloader) RegisterLightPeer(id string, version int, peer LightPeer) error
- func (d *Downloader) RegisterPeer(id string, version int, peer Peer) error
- func (d *Downloader) SetFastStableIndex(index uint64)
- func (d *Downloader) Synchronize(id string, head common.Hash, index uint64, mode SyncMode, ...) error
- func (d *Downloader) Synchronizing() bool
- func (d *Downloader) Terminate()
- func (d *Downloader) UnregisterPeer(id string) error
- type FailedEvent
- type FakePeer
- func (p *FakePeer) Head(ptncoin modules.AssetId) (common.Hash, *big.Int)
- func (p *FakePeer) RequestBodies(hashes []common.Hash) error
- func (p *FakePeer) RequestHeadersByHash(hash common.Hash, amount int, skip int, reverse bool) error
- func (p *FakePeer) RequestHeadersByNumber(assetId modules.AssetId, amount int, skip int, reverse bool) error
- func (p *FakePeer) RequestNodeData(hashes []common.Hash) error
- func (p *FakePeer) RequestReceipts(hashes []common.Hash) error
- type LightDag
- type LightPeer
- type Peer
- type PublicDownloaderAPI
- type StartEvent
- type SyncMode
- type SyncStatusSubscription
- type SyncingResult
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 MaxSkeletonSize = 128 // Number of header fetches to need for a skeleton assembly 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 * configure.EpochDuration // Maximum chain reorganization )
Functions ¶
This section is empty.
Types ¶
type BlockDag ¶
type BlockDag interface { LightDag GetUnitByHash(common.Hash) (*modules.Unit, error) GetCurrentUnit(token modules.AssetId) *modules.Unit FastSyncCommitHead(common.Hash) error //SaveDag(unit modules.Unit, isGenesis bool) (int, error) //InsertDag(modules.Units) (int, error) InsertDag(units modules.Units, is_stable bool) (int, error) UnstableHeadUnitProperty(asset modules.AssetId) (*modules.UnitProperty, error) }
BlockDag encapsulates functions required to sync a (full or fast) dag.
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
func New ¶
func New(mode SyncMode, mux *event.TypeMux, dropPeer peerDropFn, lightdag LightDag, dag BlockDag, txpool txspool.ITxPool) *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) DeliverAllToken ¶
func (d *Downloader) DeliverAllToken(id string, headers []*modules.Header) error
func (*Downloader) DeliverBodies ¶
func (d *Downloader) DeliverBodies(id string, transactions [][]*modules.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 []*modules.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)
DeliverNodeData injects a new batch of node state data received from a remote node.
func (*Downloader) FetchAllToken ¶
func (d *Downloader) FetchAllToken(id string) ([]*modules.Header, error)
func (*Downloader) GetFastStableIndex ¶ added in v1.0.3
func (d *Downloader) GetFastStableIndex() uint64
fastSyncIndex uint64
func (*Downloader) Progress ¶
func (d *Downloader) Progress() palletone.SyncProgress
Progress retrieves the synchronization boundaries, specifically the origin block where synchronization 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 synchronization the number of processed and the total number of known states are also returned. Otherwise these are zero.
func (*Downloader) RegisterLightPeer ¶
func (d *Downloader) RegisterLightPeer(id string, version int, peer LightPeer) error
RegisterLightPeer injects a light client peer, wrapping it so it appears as a regular peer.
func (*Downloader) RegisterPeer ¶
func (d *Downloader) RegisterPeer(id string, version int, 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) SetFastStableIndex ¶ added in v1.0.3
func (d *Downloader) SetFastStableIndex(index uint64)
func (*Downloader) Synchronize ¶ added in v1.0.2
func (d *Downloader) Synchronize(id string, head common.Hash, index uint64, mode SyncMode, assetId modules.AssetId) error
Synchronize 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) Synchronizing ¶ added in v1.0.2
func (d *Downloader) Synchronizing() bool
Synchronizing 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{}
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 ptndb.Database, dl *Downloader) *FakePeer
func (*FakePeer) RequestBodies ¶
RequestBodies implements downloader.Peer, returning a batch of block bodies corresponding to the specified block hashes.
func (*FakePeer) RequestHeadersByHash ¶
func (*FakePeer) RequestHeadersByNumber ¶
func (p *FakePeer) RequestHeadersByNumber(assetId modules.AssetId, amount int, skip int, reverse 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 LightDag ¶
type LightDag interface { HasHeader(common.Hash, uint64) bool GetHeaderByHash(common.Hash) (*modules.Header, error) CurrentHeader(token modules.AssetId) *modules.Header InsertLightHeader(headers []*modules.Header) (int, error) }
LightDag encapsulates functions required to synchronize a light chain.
type LightPeer ¶
type LightPeer interface { //Head() (common.Hash, *big.Int) Head(modules.AssetId) (common.Hash, *modules.ChainIndex) RequestHeadersByHash(common.Hash, int, int, bool) error RequestHeadersByNumber(*modules.ChainIndex, int, int, bool) error //RequestDagHeadersByHash(common.Hash, int, int, bool) error RequestLeafNodes() error }
LightPeer encapsulates the methods required to synchronize with a remote light peer.
type Peer ¶
type Peer interface { LightPeer RequestBodies([]common.Hash) error RequestNodeData([]common.Hash) error }
Peer encapsulates the methods required to synchronize 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 synchronization 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 synchronization 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 synchronizing with the PalletOne network and when it's finished.
type StartEvent ¶
type StartEvent struct{}
type SyncMode ¶
type SyncMode int
SyncMode represents the synchronization mode of the downloader.
func (SyncMode) MarshalText ¶
func (*SyncMode) UnmarshalText ¶
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 ethereum.SyncProgress `json:"status"` }
SyncingResult provides information about the current synchronization status for this node.