Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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:
- 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 no 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 ¶
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, 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 ¶
Drop should be called when a peer disconnects. It cleans up all the internal data structures of the given node.
func (*TxFetcher) Enqueue ¶
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 ¶
Notify announces the fetcher of the potential availability of a new batch of transactions in the network.