legacypool

package
v0.13.8-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: GPL-3.0, LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package legacypool implements the normal EVM execution transaction pool.

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

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

	Journal:   "",
	Rejournal: time.Hour,

	PriceLimit: 1,
	PriceBump:  10,

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

	Lifetime: 10 * time.Minute,
}

DefaultConfig contains the default configurations for the transaction pool.

Functions

This section is empty.

Types

type BlockChain

type BlockChain interface {
	// Config retrieves the chain's fork configuration.
	Config() *params.ChainConfig

	// CurrentBlock returns the current head of the chain.
	CurrentBlock() *types.Header

	// GetBlock retrieves a specific block, used during pool resets.
	GetBlock(hash common.Hash, number uint64) *types.Block

	// StateAt returns a state database for a given root hash (generally the head).
	StateAt(root common.Hash) (*state.StateDB, error)

	SenderCacher() *core.TxSenderCacher
}

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 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 LegacyPool

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

LegacyPool 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

func New(config Config, chain BlockChain) *LegacyPool

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

func (*LegacyPool) Add

func (pool *LegacyPool) Add(txs []*txpool.Transaction, local bool, sync bool) []error

Add enqueues a batch of transactions into the pool if they are valid. Depending on the local flag, full pricing contraints will or will not be applied.

If sync is set, the method will block until all internal maintenance related to the add is finished. Only use this during tests for determinism!

func (*LegacyPool) Close

func (pool *LegacyPool) Close() error

Close terminates the transaction pool.

func (*LegacyPool) Content

func (pool *LegacyPool) 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 (*LegacyPool) ContentFrom

func (pool *LegacyPool) 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 (*LegacyPool) Filter

func (pool *LegacyPool) Filter(tx *types.Transaction) bool

Filter returns whether the given transaction can be consumed by the legacy pool, specifically, whether it is a Legacy, AccessList or Dynamic transaction.

func (*LegacyPool) Get

func (pool *LegacyPool) Get(hash common.Hash) *txpool.Transaction

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

func (*LegacyPool) Has

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

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

func (*LegacyPool) HasLocal

func (pool *LegacyPool) HasLocal(hash common.Hash) bool

func (*LegacyPool) Init

func (pool *LegacyPool) Init(gasTip *big.Int, head *types.Header, reserve txpool.AddressReserver) error

Init sets the gas price needed to keep a transaction in the pool and the chain head to allow balance / nonce checks. The transaction journal will be loaded from disk and filtered based on the provided starting settings. The internal goroutines will be spun up and the pool deemed operational afterwards.

func (*LegacyPool) IteratePending

func (pool *LegacyPool) IteratePending(f func(tx *txpool.Transaction) bool) bool

IteratePending iterates over [pool.pending] until [f] returns false. The caller must not modify [tx]. Returns false if iteration was interrupted.

func (*LegacyPool) Locals

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

Locals retrieves the accounts currently considered local by the pool.

func (*LegacyPool) Nonce

func (pool *LegacyPool) 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 (*LegacyPool) Pending

func (pool *LegacyPool) Pending(enforceTips bool) map[common.Address][]*txpool.LazyTransaction

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.

The enforceTips parameter can be used to do an extra filtering on the pending transactions and only return those whose **effective** tip is large enough in the next pending execution environment.

func (*LegacyPool) PendingFrom

func (pool *LegacyPool) PendingFrom(addrs []common.Address, enforceTips bool) map[common.Address][]*txpool.LazyTransaction

PendingFrom returns the same set of transactions that would be returned from Pending restricted to only transactions from [addrs].

func (*LegacyPool) PendingWithBaseFee

func (pool *LegacyPool) PendingWithBaseFee(enforceTips bool, baseFee *big.Int) map[common.Address][]*txpool.LazyTransaction

If baseFee is nil, then pool.priced.urgent.baseFee is used.

func (*LegacyPool) Reset

func (pool *LegacyPool) Reset(oldHead, newHead *types.Header)

Reset implements txpool.SubPool, allowing the legacy pool's internal state to be kept in sync with the main transacion pool's internal state.

func (*LegacyPool) SetGasTip

func (pool *LegacyPool) 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 (*LegacyPool) SetMinFee

func (pool *LegacyPool) SetMinFee(minFee *big.Int)

func (*LegacyPool) Stats

func (pool *LegacyPool) Stats() (int, int)

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

func (*LegacyPool) Status

func (pool *LegacyPool) Status(hash common.Hash) txpool.TxStatus

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

func (*LegacyPool) SubscribeTransactions

func (pool *LegacyPool) SubscribeTransactions(ch chan<- core.NewTxsEvent) event.Subscription

SubscribeTransactions registers a subscription of NewTxsEvent and starts sending event to the given channel.

Jump to

Keyboard shortcuts

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