package fetcher

import "github.com/ethereum/go-ethereum/eth/fetcher"

Index

Types

type TxFetcher

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

TxFetcher is responsible for retrieving new transaction based on announcements.

The fetcher operates in 3 stages:

The invariants of the fetcher are:

func NewTxFetcher

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

func NewTxFetcherForTests(
	hasTx func(common.Hash) bool, addTxs func([]*types.Transaction) []error, fetchTxs func(string, []common.Hash) error, dropPeer func(string),
	clock mclock.Clock, realTime func() time.Time, 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

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

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

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

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

func (f *TxFetcher) Stop()

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

Source Files

tx_fetcher.go

Version
v1.15.11 (latest)
Published
May 5, 2025
Platform
linux/amd64
Imports
13 packages
Last checked
1 day ago

Tools for package owners.