txpool

package
v1.10.71 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: GPL-3.0, GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyKnown is returned if the transactions is already contained
	// within the pool.
	ErrAlreadyKnown = errors.New("already known")

	// ErrInvalidSender is returned if the transaction contains an invalid signature.
	ErrInvalidSender = errors.New("invalid sender")

	// ErrUnderpriced is returned if a transaction's gas price is below the minimum
	// configured for the transaction pool.
	ErrUnderpriced = errors.New("transaction underpriced")

	// ErrTxPoolOverflow is returned if the transaction pool is full and can't accept
	// another remote transaction.
	ErrTxPoolOverflow = errors.New("txpool is full")

	// ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced
	// with a different one without the required price bump.
	ErrReplaceUnderpriced = errors.New("replacement transaction underpriced")

	// ErrGasLimit is returned if a transaction's requested gas limit exceeds the
	// maximum allowance of the current block.
	ErrGasLimit = errors.New("exceeds block gas limit")

	// ErrNegativeValue is a sanity error to ensure no one is able to specify a
	// transaction with a negative value.
	ErrNegativeValue = errors.New("negative value")

	// ErrOversizedData is returned if the input data of a transaction is greater
	// than some meaningful limit a user might use. This is not a consensus error
	// making the transaction invalid, rather a DOS protection.
	ErrOversizedData = errors.New("oversized data")

	// ErrFutureReplacePending is returned if a future transaction replaces a pending
	// transaction. Future transactions should only be able to replace other future transactions.
	ErrFutureReplacePending = errors.New("future transaction tries to replace pending")

	// ErrOverdraft is returned if a transaction would cause the senders balance to go negative
	// thus invalidating a potential large number of transactions.
	ErrOverdraft = errors.New("transaction would cause overdraft")
)
View Source
var DefaultConfig = Config{
	Journal:   "transactions.rlp",
	Rejournal: time.Hour,

	PriceLimit: 1,
	PriceBump:  10,

	AccountSlots: 16,
	GlobalSlots:  4096 + 1024,
	AccountQueue: 64,
	GlobalQueue:  1024,

	Lifetime: 3 * time.Hour,
}

DefaultConfig contains the default configurations for the transaction pool.

View Source
var (
	ErrAlreadyReserved = errors.New("address already reserved")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Locals    []common.Address // Addresses that should be treated by default as local
	NoLocals  bool             // Whether local transaction handling should be disabled
	Journal   string           // Journal of local transactions to survive node restarts
	Rejournal time.Duration    // Time interval to regenerate the local transaction journal

	PriceLimit uint64 // Minimum gas price to enforce for acceptance into the pool
	PriceBump  uint64 // Minimum price bump percentage to replace an already existing transaction (nonce)

	AccountSlots uint64 // Number of executable transaction slots guaranteed per account
	GlobalSlots  uint64 // Maximum number of executable transaction slots for all accounts
	AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account
	GlobalQueue  uint64 // Maximum number of non-executable transaction slots for all accounts

	Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
}

Config are the configuration parameters of the transaction pool.

type PendingFilter added in v1.10.65

type PendingFilter struct {
	GasLimitCap uint64 // Maximum gas can be used for a single transaction execution (0 means no limit)
}

type ReservationHandle added in v1.10.67

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

ReservationHandle is a named handle on ReservationTracker. It is held by subpools to make reservations for accounts it is tracking. The id is used to determine which pool owns an address and disallows non-owners to hold or release addresses it doesn't own.

func (*ReservationHandle) Has added in v1.10.67

func (h *ReservationHandle) Has(address common.Address) bool

Has implements the Reserver interface.

func (*ReservationHandle) Hold added in v1.10.67

func (h *ReservationHandle) Hold(addr common.Address) error

Hold implements the Reserver interface.

func (*ReservationHandle) Release added in v1.10.67

func (h *ReservationHandle) Release(addr common.Address) error

Release implements the Reserver interface.

type ReservationTracker added in v1.10.67

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

ReservationTracker is a struct shared between different subpools. It is used to reserve the account and ensure that one address cannot initiate transactions, authorizations, and other state-changing behaviors in different pools at the same time.

func NewReservationTracker added in v1.10.67

func NewReservationTracker() *ReservationTracker

NewReservationTracker initializes the account reservation tracker.

func (*ReservationTracker) NewHandle added in v1.10.67

func (r *ReservationTracker) NewHandle(id int) *ReservationHandle

NewHandle creates a named handle on the ReservationTracker. The handle identifies the subpool so ownership of reservations can be determined.

type Reserver added in v1.10.67

type Reserver interface {
	// Hold attempts to reserve the specified account address for the given pool.
	// Returns an error if the account is already reserved.
	Hold(addr common.Address) error

	// Release attempts to release the reservation for the specified account.
	// Returns an error if the address is not reserved or is reserved by another pool.
	Release(addr common.Address) error

	// Has returns a flag indicating if the address has been reserved by a pool
	// other than one with the current Reserver handle.
	Has(address common.Address) bool
}

Reserver is an interface for creating and releasing owned reservations in the ReservationTracker struct, which is shared between subpools.

type TxPool

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

TxPool contains all currently known transactions. 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.

The pool separates processable transactions (which can be applied to the current state) and future transactions. Transactions move between those two states over time as they are received and processed.

func New added in v1.10.67

func New(config Config, chainconfig *params.ChainConfig, chain blockChain) *TxPool

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

func (*TxPool) AddLocal

func (pool *TxPool) AddLocal(tx *types.Transaction) error

AddLocal enqueues a single local transaction into the pool if it is valid. This is a convenience wrapper aroundd AddLocals.

func (*TxPool) AddLocals

func (pool *TxPool) AddLocals(txs []*types.Transaction) []error

AddLocals enqueues a batch of transactions into the pool if they are valid, marking the senders as a local ones, ensuring they go around the local pricing constraints.

This method is used to add transactions from the RPC API and performs synchronous pool reorganization and event propagation.

func (*TxPool) AddRemote deprecated

func (pool *TxPool) AddRemote(tx *types.Transaction) error

AddRemote enqueues a single transaction into the pool if it is valid. This is a convenience wrapper around AddRemotes.

Deprecated: use AddRemotes

func (*TxPool) AddRemotes

func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error

AddRemotes enqueues a batch of transactions into the pool if they are valid. If the senders are not among the locally tracked ones, full pricing constraints will apply.

This method is used to add transactions from the p2p network and does not wait for pool reorganization and internal event propagation.

func (*TxPool) AddRemotesSync

func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error

This is like AddRemotes, but waits for pool reorganization. Tests use this method.

func (*TxPool) Content

func (pool *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 (pool *TxPool) ContentFrom(addr common.Address) (types.Transactions, types.Transactions)

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) Get

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

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

func (*TxPool) Has

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

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

func (*TxPool) Locals

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

Locals retrieves the accounts currently considered local by the pool.

func (*TxPool) Nonce

func (pool *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 (pool *TxPool) Pending(filter PendingFilter) map[common.Address]types.Transactions

Pending retrieves all currently processable transactions, grouped by origin account and sorted by nonce. The returned transaction set is a copy and can be freely modified by calling code.

func (*TxPool) SetGasPrice

func (pool *TxPool) SetGasPrice(price *big.Int)

SetGasPrice updates the minimum price required by the transaction pool for a new transaction, and drops all transactions below this threshold.

func (*TxPool) Stats

func (pool *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 (pool *TxPool) Status(hash common.Hash) TxStatus

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

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop terminates the transaction pool.

func (*TxPool) SubscribeNewTxsEvent

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

SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending event 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
)

Jump to

Keyboard shortcuts

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