mempool

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckFn

type CheckFn func(ctx context.Context, tx *types.Tx) error

CheckFn is a function type for validating transactions.

type Mempool

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

Mempool maintains a thread-safe pool of unconfirmed transactions with size limits.

func New

func New(sz, txSz int64) *Mempool

New creates a new Mempool instance with a default max size of 200MB. See also SetMaxSize.

func (*Mempool) CapMaxTxSize added in v0.10.1

func (mp *Mempool) CapMaxTxSize(maxBlockSize int64)

CapMaxTxSize updates the maximum allowed transaction size based on the network parameter maxBlockSize.

func (*Mempool) Get

func (mp *Mempool) Get(txid types.Hash) *types.Tx

Get retrieves a transaction by its hash, returns nil if not found.

func (*Mempool) Have

func (mp *Mempool) Have(txid types.Hash) bool

Have checks if a transaction with the given hash exists in the mempool.

func (*Mempool) PeekN

func (mp *Mempool) PeekN(n, szLimit int) []*types.Tx

PeekN returns up to n transactions from the front of the queue without removing them, the number of transactions returned may be less than n if the total size in bytes of the transactions exceeds szLimit.

func (*Mempool) PreFetch

func (mp *Mempool) PreFetch(txid types.Hash) (bool, func())

PreFetch marks a transaction as being fetched. Returns true if the tx should be fetched. Always defer the returned "done" function if true is returned.

func (*Mempool) ReapN

func (mp *Mempool) ReapN(n int) []*types.Tx

ReapN removes and returns up to n transactions from the front of the queue.

func (*Mempool) RecheckTxs

func (mp *Mempool) RecheckTxs(ctx context.Context, fn CheckFn)

RecheckTxs validates all transactions in the mempool using the provided check function, removing any that fail validation. This function will check the transaction queue in order.

func (*Mempool) Remove

func (mp *Mempool) Remove(txid types.Hash)

Remove deletes a transaction from the mempool by its hash.

func (*Mempool) SetMaxSize

func (mp *Mempool) SetMaxSize(maxBytes int64)

SetMaxSize updates the maximum allowed size in bytes for the mempool.

func (*Mempool) SetMaxTxSize added in v0.10.1

func (mp *Mempool) SetMaxTxSize(maxBytes int64)

SetMaxSize updates the maximum allowed transaction size in bytes for the mempool.

func (*Mempool) Size

func (mp *Mempool) Size() (totalBytes, numTxns int)

Size returns the current total size in bytes and number of transactions in the mempool.

func (*Mempool) Store

func (mp *Mempool) Store(tx *types.Tx) error

Store adds a transaction to the mempool. It returns an error if the transaction cannot be stored, such as if the transaction already exists, exceeds the maximum allowed transaction size,or if the mempool is full. To remove a transaction, use [Remove]; this will panic with a nil pointer.

func (*Mempool) TxsAvailable

func (mp *Mempool) TxsAvailable() bool

TxsAvailable returns true if there are any transactions in the mempool.

Jump to

Keyboard shortcuts

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