Documentation
¶
Overview ¶
Package downloader contains the manual full chain synchronisation.
Index ¶
- Constants
- Variables
- type BlockChain
- type Downloader
- func (d *Downloader) BeaconDevSync(header *types.Header) error
- func (d *Downloader) BeaconExtend(head *types.Header) error
- func (d *Downloader) BeaconSync(head *types.Header, final *types.Header) error
- func (d *Downloader) Cancel()
- func (d *Downloader) ConfigSyncMode() SyncMode
- func (d *Downloader) DeliverSnapPacket(peer *snap.Peer, packet snap.Packet) error
- func (d *Downloader) GetHeader(hash common.Hash) (*types.Header, error)
- func (d *Downloader) Progress() ethereum.SyncProgress
- func (d *Downloader) RegisterPeer(id string, version uint, peer Peer) error
- func (d *Downloader) RegisterSnapPeer(p *snap.Peer) error
- func (d *Downloader) SetBadBlockCallback(onBadBlock badBlockFn)
- func (d *Downloader) SnapSyncVersion() uint
- func (d *Downloader) SubscribeSyncEvents(ch chan<- SyncEvent) event.Subscription
- func (d *Downloader) Terminate()
- func (d *Downloader) UnregisterPeer(id string) error
- func (d *Downloader) UnregisterSnapPeer(p *snap.Peer) error
- type DownloaderAPI
- type Peer
- type SyncEvent
- type SyncEventType
- type SyncMode
- type SyncStatusSubscription
- type SyncingResult
Constants ¶
const ( // Deprecated: use ethconfig.FullSync FullSync = ethconfig.FullSync // Deprecated: use ethconfig.SnapSync SnapSync = ethconfig.SnapSync )
Variables ¶
var ( MaxBlockFetch = 128 // Number of blocks to be fetched per retrieval request MaxHeaderFetch = 192 // Number of block headers to be fetched per retrieval request MaxReceiptFetch = 256 // Number of transaction receipts to allow fetching per request MaxBALFetch = 128 // Number of block access lists to allow fetching per request )
Functions ¶
This section is empty.
Types ¶
type BlockChain ¶ added in v1.6.7
type BlockChain interface {
// HasHeader verifies a header's presence in the local chain.
HasHeader(common.Hash, uint64) bool
// HasState checks if state trie is fully present in the database or not.
HasState(root 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
// SetHead rewinds the local chain to a new head.
SetHead(uint64) error
// HasBlock verifies a block's presence in the local chain.
HasBlock(common.Hash, uint64) bool
// HasFastBlock verifies a snap block's presence in the local chain.
HasFastBlock(common.Hash, uint64) bool
// GetCanonicalHash returns the canonical hash for the block at the given
// number, or the zero hash if no canonical block is present at that height.
GetCanonicalHash(uint64) common.Hash
// GetBlockByHash retrieves a block from the local chain.
GetBlockByHash(common.Hash) *types.Block
// CurrentBlock retrieves the head block from the local chain.
CurrentBlock() *types.Header
// CurrentSnapBlock retrieves the head snap block from the local chain.
CurrentSnapBlock() *types.Header
// SnapSyncStart explicitly notifies the chain that snap sync is scheduled and
// marks chain mutations as disallowed.
SnapSyncStart() error
// SnapSyncComplete directly commits the head block to a certain entity.
SnapSyncComplete(hash common.Hash, isSnapV2 bool) error
// Config retrieves the chain's fork configuration.
Config() *params.ChainConfig
// InsertHeadersBeforeCutoff inserts a batch of headers before the configured
// chain cutoff into the ancient store.
InsertHeadersBeforeCutoff([]*types.Header) (int, error)
// InsertChain inserts a batch of blocks into the local chain.
InsertChain(types.Blocks) (int, error)
// InterruptInsert disables or enables chain insertion.
InterruptInsert(on bool)
// InsertReceiptChain inserts a batch of blocks along with their receipts
// into the local chain. Blocks older than the specified `ancientLimit`
// are stored directly in the ancient store, while newer blocks are stored
// in the live key-value store.
InsertReceiptChain(types.Blocks, []rlp.RawValue, uint64) (int, error)
// Snapshots returns the blockchain snapshot tree to paused it during sync.
Snapshots() *snapshot.Tree
// TrieDB retrieves the low level trie database used for interacting
// with trie nodes.
TrieDB() *triedb.Database
// HistoryPruningCutoff returns the configured history pruning point.
// Block bodies along with the receipts will be skipped for synchronization.
HistoryPruningCutoff() (uint64, common.Hash)
}
BlockChain encapsulates functions required to sync a (full or snap) blockchain.
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
func New ¶
func New(stateDb ethdb.Database, mode ethconfig.SyncMode, chain BlockChain, dropPeer peerDropFn, success func(), snapV2 bool) *Downloader
New creates a new downloader to fetch hashes and blocks from remote peers.
func (*Downloader) BeaconDevSync ¶ added in v1.13.3
func (d *Downloader) BeaconDevSync(header *types.Header) error
BeaconDevSync is a development helper to test synchronization by providing a block hash instead of header to run the beacon sync against.
The method will reach out to the network to retrieve the header of the sync target instead of receiving it from the consensus node.
Note, this must not be used in live code. If the forkchcoice endpoint where to use this instead of giving us the payload first, then essentially nobody in the network would have the block yet that we'd attempt to retrieve.
func (*Downloader) BeaconExtend ¶ added in v1.10.17
func (d *Downloader) BeaconExtend(head *types.Header) error
BeaconExtend is an optimistic version of BeaconSync, where an attempt is made to extend the current beacon chain with a new header, but in case of a mismatch, the old sync will not be terminated and reorged, rather the new head is dropped.
This is useful if a beacon client is feeding us large chunks of payloads to run, but is not setting the head after each.
func (*Downloader) BeaconSync ¶ added in v1.10.17
BeaconSync is the post-merge version of the chain synchronization, where the chain is not downloaded from genesis onward, rather from trusted head announces backwards.
Internally backfilling and state sync is done the same way, but the header retrieval and scheduling is replaced.
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) ConfigSyncMode ¶ added in v1.17.0
func (d *Downloader) ConfigSyncMode() SyncMode
ConfigSyncMode returns the sync mode configured for the node. The actual running sync mode can differ from this.
func (*Downloader) DeliverSnapPacket ¶ added in v1.10.0
DeliverSnapPacket is invoked from a peer's message handler when it transmits a data packet for the local node to consume.
func (*Downloader) GetHeader ¶ added in v1.16.0
GetHeader tries to retrieve the header with a given hash from a random peer.
func (*Downloader) Progress ¶ added in v1.3.1
func (d *Downloader) Progress() ethereum.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 snap 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) RegisterSnapPeer ¶ added in v1.17.4
func (d *Downloader) RegisterSnapPeer(p *snap.Peer) error
RegisterSnapPeer registers a snap peer with the active state syncer. Peers that negotiated a snap version below the syncer's minimum are skipped — e.g. the snap/2 syncer skips snap/1-only peers, which cannot answer its BAL requests.
func (*Downloader) SetBadBlockCallback ¶ added in v1.10.21
func (d *Downloader) SetBadBlockCallback(onBadBlock badBlockFn)
SetBadBlockCallback sets the callback to run when a bad block is hit by the block processor. This method is not thread safe and should be set only once on startup before system events are fired.
func (*Downloader) SnapSyncVersion ¶ added in v1.17.4
func (d *Downloader) SnapSyncVersion() uint
SnapSyncVersion returns the snap protocol version of the active state syncer. Peers negotiating a lower version cannot serve its requests.
func (*Downloader) SubscribeSyncEvents ¶ added in v1.17.3
func (d *Downloader) SubscribeSyncEvents(ch chan<- SyncEvent) event.Subscription
SubscribeSyncEvents creates a subscription for downloader sync events
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.
func (*Downloader) UnregisterSnapPeer ¶ added in v1.17.4
func (d *Downloader) UnregisterSnapPeer(p *snap.Peer) error
UnregisterSnapPeer removes a snap peer from the active state syncer. It mirrors RegisterSnapPeer's version gate: a peer below the active syncer's version was never registered, so there is nothing to remove.
type DownloaderAPI ¶ added in v1.10.20
type DownloaderAPI struct {
// contains filtered or unexported fields
}
DownloaderAPI 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 NewDownloaderAPI ¶ added in v1.10.20
func NewDownloaderAPI(d *Downloader, chain *core.BlockChain) *DownloaderAPI
NewDownloaderAPI creates a new DownloaderAPI. The API has an internal event loop that listens for events from the downloader through the event feed. In case it receives one of these events it broadcasts it to all syncing subscriptions that are installed through the installSyncSubscription channel.
func (*DownloaderAPI) SubscribeSyncStatus ¶ added in v1.10.20
func (api *DownloaderAPI) 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 be a SyncingResult or false.
func (*DownloaderAPI) Syncing ¶ added in v1.10.20
func (api *DownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error)
Syncing provides information when this node starts synchronising with the Ethereum network and when it's finished.
type Peer ¶ added in v1.6.7
type Peer interface {
RequestHeadersByHash(common.Hash, int, int, bool, chan *eth.Response) (*eth.Request, error)
RequestHeadersByNumber(uint64, int, int, bool, chan *eth.Response) (*eth.Request, error)
RequestBodies([]common.Hash, chan *eth.Response) (*eth.Request, error)
RequestReceipts([]common.Hash, []uint64, []uint64, chan *eth.Response) (*eth.Request, error)
RequestBALs([]common.Hash, chan *eth.Response) (*eth.Request, error)
// BlockRange returns the range of blocks the peer announced to serve
// (bodies and receipts), nil if it never announced one.
//
// Headers are always assumed to be available for the full range of
// blocks from genesis.
BlockRange() *eth.BlockRangeUpdatePacket
}
Peer encapsulates the methods required to synchronise with a remote full peer.
type SyncEvent ¶ added in v1.17.3
type SyncEvent struct {
Type SyncEventType
Mode ethconfig.SyncMode
Err error // Set when Type is SyncFailed
Latest *types.Header // Set when Type is SyncCompleted
}
SyncEvent represents a downloader synchronization event
type SyncEventType ¶ added in v1.17.3
type SyncEventType int
SyncEventType represents the type of sync event
const ( SyncStarted SyncEventType = iota SyncFailed SyncCompleted )
type SyncMode ¶ added in v1.3.1
SyncMode defines the sync method of the downloader. Deprecated: use ethconfig.SyncMode instead
type SyncStatusSubscription ¶ added in v1.5.0
type SyncStatusSubscription struct {
// contains filtered or unexported fields
}
SyncStatusSubscription represents a syncing subscription.
func (*SyncStatusSubscription) Unsubscribe ¶ added in v1.5.0
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 ¶ added in v1.4.0
type SyncingResult struct {
Syncing bool `json:"syncing"`
Status ethereum.SyncProgress `json:"status"`
}
SyncingResult provides information about the current synchronisation status for this node.