txpool

package
v0.0.0-...-21186a8 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressReserver

type AddressReserver func(addr common.Address, reserve bool) error

AddressReserver is passed by the main transaction pool to subpools, so they may request (and relinquish) exclusive access to certain addresses.

type BlockChain

type BlockChain interface {
	// CurrentBlock returns the current head of the chain.
	CurrentBlock() *types.Header

	// SubscribeChainHeadEvent subscribes to new blocks being added to the chain.
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
}

BlockChain defines the minimal set of methods needed to back a tx pool with a chain. Exists to allow mocking the live chain out of tests.

type LazyTransaction

type LazyTransaction struct {
	Pool SubPool            // Transaction subpool to pull the real transaction up
	Hash common.Hash        // Transaction hash to pull up if needed
	Tx   *types.Transaction // Transaction if already resolved

	Time      time.Time // Time when the transaction was first seen
	GasFeeCap *big.Int  // Maximum fee per gas the transaction may consume
	GasTipCap *big.Int  // Maximum miner tip per gas the transaction can pay
}

LazyTransaction contains a small subset of the transaction properties that is enough for the miner and other APIs to handle large batches of transactions; and supports pulling up the entire transaction when really needed.

func (*LazyTransaction) Resolve

func (ltx *LazyTransaction) Resolve() *types.Transaction

Resolve retrieves the full transaction belonging to a lazy handle if it is still maintained by the transaction pool.

type SubPool

type SubPool interface {
	// Filter is a selector used to decide whether a transaction whould be added
	// to this particular subpool.
	Filter(tx *types.Transaction) bool

	// Init sets the base parameters of the subpool, allowing it to load any saved
	// transactions from disk and also permitting internal maintenance routines to
	// start up.
	//
	// These should not be passed as a constructor argument - nor should the pools
	// start by themselves - in order to keep multiple subpools in lockstep with
	// one another.
	Init(gasTip *big.Int, head *types.Header, reserve AddressReserver) error

	// Close terminates any background processing threads and releases any held
	// resources.
	Close() error

	// Reset retrieves the current state of the blockchain and ensures the content
	// of the transaction pool is valid with regard to the chain state.
	Reset(oldHead, newHead *types.Header)

	// SetGasTip updates the minimum price required by the subpool for a new
	// transaction, and drops all transactions below this threshold.
	SetGasTip(tip *big.Int)

	// Has returns an indicator whether subpool has a transaction cached with the
	// given hash.
	Has(hash common.Hash) bool

	// Get returns a transaction if it is contained in the pool, or nil otherwise.
	Get(hash common.Hash) *types.Transaction

	// Add enqueues a batch of transactions into the pool if they are valid. Due
	// to the large transaction churn, add may postpone fully integrating the tx
	// to a later point to batch multiple ones together.
	Add(txs []*types.Transaction, local bool, sync bool) []error

	// Pending retrieves all currently processable transactions, grouped by origin
	// account and sorted by nonce.
	Pending(enforceTips bool) map[common.Address][]*LazyTransaction

	// SubscribeTransactions subscribes to new transaction events.
	SubscribeTransactions(ch chan<- core.NewTxsEvent) event.Subscription

	// Nonce returns the next nonce of an account, with all transactions executable
	// by the pool already applied on top.
	Nonce(addr common.Address) uint64

	// Stats retrieves the current pool stats, namely the number of pending and the
	// number of queued (non-executable) transactions.
	Stats() (int, int)

	// Content retrieves the data content of the transaction pool, returning all the
	// pending as well as queued transactions, grouped by account and sorted by nonce.
	Content() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction)

	// ContentFrom retrieves the data content of the transaction pool, returning the
	// pending as well as queued transactions of this address, grouped by nonce.
	ContentFrom(addr common.Address) ([]*types.Transaction, []*types.Transaction)

	// EP-1
	// ***
	ContentMatches(src string) (map[common.Address]types.Transactions, map[common.Address]types.Transactions)

	// Locals retrieves the accounts currently considered local by the pool.
	Locals() []common.Address

	// Status returns the known status (unknown/pending/queued) of a transaction
	// identified by their hashes.
	Status(hash common.Hash) TxStatus
}

SubPool represents a specialized transaction pool that lives on its own (e.g. blob pool). Since independent of how many specialized pools we have, they do need to be updated in lockstep and assemble into one coherent view for block production, this interface defines the common methods that allow the primary transaction pool to manage the subpools.

type TxPool

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

TxPool is an aggregator for various transaction specific pools, collectively tracking all the transactions deemed interesting by the node. Transactions enter the pool when they are received from the network or submitted locally. They exit the pool when they are included in the blockchain or evicted due to resource constraints.

func New

func New(gasTip *big.Int, chain BlockChain, subpools []SubPool) (*TxPool, error)

New creates a new transaction pool to gather, sort and filter inbound transactions from the network.

func (*TxPool) Add

func (p *TxPool) Add(txs []*types.Transaction, local bool, sync bool) []error

Add enqueues a batch of transactions into the pool if they are valid. Due to the large transaction churn, add may postpone fully integrating the tx to a later point to batch multiple ones together.

func (*TxPool) Close

func (p *TxPool) Close() error

Close terminates the transaction pool and all its subpools.

func (*TxPool) Content

func (p *TxPool) Content() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction)

Content retrieves the data content of the transaction pool, returning all the pending as well as queued transactions, grouped by account and sorted by nonce.

func (*TxPool) ContentFrom

func (p *TxPool) ContentFrom(addr common.Address) ([]*types.Transaction, []*types.Transaction)

ContentFrom retrieves the data content of the transaction pool, returning the pending as well as queued transactions of this address, grouped by nonce.

func (*TxPool) ContentMatches

func (p *TxPool) ContentMatches(src string) (map[common.Address]types.Transactions, map[common.Address]types.Transactions)

EP-1 START ***

func (*TxPool) Get

func (p *TxPool) Get(hash common.Hash) *types.Transaction

Get returns a transaction if it is contained in the pool, or nil otherwise.

func (*TxPool) Has

func (p *TxPool) Has(hash common.Hash) bool

Has returns an indicator whether the pool has a transaction cached with the given hash.

func (*TxPool) Locals

func (p *TxPool) Locals() []common.Address

Locals retrieves the accounts currently considered local by the pool.

func (*TxPool) Nonce

func (p *TxPool) Nonce(addr common.Address) uint64

Nonce returns the next nonce of an account, with all transactions executable by the pool already applied on top.

func (*TxPool) Pending

func (p *TxPool) Pending(enforceTips bool) map[common.Address][]*LazyTransaction

Pending retrieves all currently processable transactions, grouped by origin account and sorted by nonce.

func (*TxPool) SetGasTip

func (p *TxPool) SetGasTip(tip *big.Int)

SetGasTip updates the minimum gas tip required by the transaction pool for a new transaction, and drops all transactions below this threshold.

func (*TxPool) Stats

func (p *TxPool) Stats() (int, int)

Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.

func (*TxPool) Status

func (p *TxPool) Status(hash common.Hash) TxStatus

Status returns the known status (unknown/pending/queued) of a transaction identified by their hashes.

func (*TxPool) SubscribeNewTxsEvent

func (p *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription

SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending events to the given channel.

type TxStatus

type TxStatus uint

TxStatus is the current status of a transaction as seen by the pool.

const (
	TxStatusUnknown TxStatus = iota
	TxStatusQueued
	TxStatusPending
	TxStatusIncluded
)

Directories

Path Synopsis
Package blobpool implements the EIP-4844 blob transaction pool.
Package blobpool implements the EIP-4844 blob transaction pool.
Package legacypool implements the normal EVM execution transaction pool.
Package legacypool implements the normal EVM execution transaction pool.

Jump to

Keyboard shortcuts

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