fetcher

package
v1.13.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: GPL-3.0 Imports: 18 Imported by: 282

Documentation

Overview

Package fetcher contains the announcement based header, blocks or transaction synchronisation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockFetcher added in v1.9.11

type BlockFetcher struct {
	// contains filtered or unexported fields
}

BlockFetcher is responsible for accumulating block announcements from various peers and scheduling them for retrieval.

func NewBlockFetcher added in v1.9.11

func NewBlockFetcher(light bool, getHeader HeaderRetrievalFn, getBlock blockRetrievalFn, verifyHeader headerVerifierFn, broadcastBlock blockBroadcasterFn, chainHeight chainHeightFn, insertHeaders headersInsertFn, insertChain chainInsertFn, dropPeer peerDropFn) *BlockFetcher

NewBlockFetcher creates a block fetcher to retrieve blocks based on hash announcements.

func (*BlockFetcher) Enqueue added in v1.9.11

func (f *BlockFetcher) Enqueue(peer string, block *types.Block) error

Enqueue tries to fill gaps the fetcher's future import queue.

func (*BlockFetcher) FilterBodies added in v1.9.11

func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, time time.Time) ([][]*types.Transaction, [][]*types.Header)

FilterBodies extracts all the block bodies that were explicitly requested by the fetcher, returning those that should be handled differently.

func (*BlockFetcher) FilterHeaders added in v1.9.11

func (f *BlockFetcher) FilterHeaders(peer string, headers []*types.Header, time time.Time) []*types.Header

FilterHeaders extracts all the headers that were explicitly requested by the fetcher, returning those that should be handled differently.

func (*BlockFetcher) Notify added in v1.9.11

func (f *BlockFetcher) Notify(peer string, hash common.Hash, number uint64, time time.Time,
	headerFetcher headerRequesterFn, bodyFetcher bodyRequesterFn) error

Notify announces the fetcher of the potential availability of a new block in the network.

func (*BlockFetcher) Start added in v1.9.11

func (f *BlockFetcher) Start()

Start boots up the announcement based synchroniser, accepting and processing hash notifications and block fetches until termination requested.

func (*BlockFetcher) Stop added in v1.9.11

func (f *BlockFetcher) Stop()

Stop terminates the announcement based synchroniser, canceling all pending operations.

type HeaderRetrievalFn added in v1.9.19

type HeaderRetrievalFn func(common.Hash) *types.Header

HeaderRetrievalFn is a callback type for retrieving a header from the local chain.

type TxFetcher added in v1.9.11

type TxFetcher struct {
	// contains filtered or unexported fields
}

TxFetcher is responsible for retrieving new transaction based on announcements.

The fetcher operates in 3 stages:

  • Transactions that are newly discovered are moved into a wait list.
  • After ~500ms passes, transactions from the wait list that have not been broadcast to us in whole are moved into a queueing area.
  • When a connected peer doesn't have in-flight retrieval requests, any transaction queued up (and announced by the peer) are allocated to the peer and moved into a fetching status until it's fulfilled or fails.

The invariants of the fetcher are:

  • Each tracked transaction (hash) must only be present in one of the three stages. This ensures that the fetcher operates akin to a finite state automata and there's do data leak.
  • Each peer that announced transactions may be scheduled retrievals, but only ever one concurrently. This ensures we can immediately know what is missing from a reply and reschedule it.

func NewTxFetcher added in v1.9.11

func NewTxFetcher(hasTx func(common.Hash) bool, addTxs func([]*types.Transaction) []error, fetchTxs func(string, []common.Hash) error, dropPeer func(string)) *TxFetcher

NewTxFetcher creates a transaction fetcher to retrieve transaction based on hash announcements.

func NewTxFetcherForTests added in v1.9.11

func NewTxFetcherForTests(
	hasTx func(common.Hash) bool, addTxs func([]*types.Transaction) []error, fetchTxs func(string, []common.Hash) error, dropPeer func(string),
	clock mclock.Clock, rand *mrand.Rand) *TxFetcher

NewTxFetcherForTests is a testing method to mock out the realtime clock with a simulated version and the internal randomness with a deterministic one.

func (*TxFetcher) Drop added in v1.9.11

func (f *TxFetcher) Drop(peer string) error

Drop should be called when a peer disconnects. It cleans up all the internal data structures of the given node.

func (*TxFetcher) Enqueue added in v1.9.11

func (f *TxFetcher) Enqueue(peer string, txs []*types.Transaction, direct bool) error

Enqueue imports a batch of received transaction into the transaction pool and the fetcher. This method may be called by both transaction broadcasts and direct request replies. The differentiation is important so the fetcher can re-schedule missing transactions as soon as possible.

func (*TxFetcher) Notify added in v1.9.11

func (f *TxFetcher) Notify(peer string, types []byte, sizes []uint32, hashes []common.Hash) error

Notify announces the fetcher of the potential availability of a new batch of transactions in the network.

func (*TxFetcher) Start added in v1.9.11

func (f *TxFetcher) Start()

Start boots up the announcement based synchroniser, accepting and processing hash notifications and block fetches until termination requested.

func (*TxFetcher) Stop added in v1.9.11

func (f *TxFetcher) Stop()

Stop terminates the announcement based synchroniser, canceling all pending operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL