txpool

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0, LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyKnown    = errors.New("already known")
	ErrConflict        = errors.New("conflict present")
	ErrInsufficientFee = errors.New("insufficient fee")
	ErrMempoolFull     = errors.New("mempool full")
)

Functions

This section is empty.

Types

type Mempool

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

Mempool is a simple mempool for atomic transactions

func NewMempool

func NewMempool(
	txs *Txs,
	registerer prometheus.Registerer,
	verify func(tx *atomic.Tx) error,
) (*Mempool, error)

func (*Mempool) Add

func (m *Mempool) Add(tx *atomic.Tx) error

Add attempts to add tx to the mempool as a Remote transaction. It is assumed the snow context lock is not held.

func (*Mempool) AddLocalTx

func (m *Mempool) AddLocalTx(tx *atomic.Tx) error

AddLocalTx attempts to add tx to the mempool as a Local transaction.

Local transactions are not checked for recent verification failures prior to performing verification. Even if a Local transaction failed verification recently, the mempool will attempt to re-verify it.

func (*Mempool) AddRemoteTx

func (m *Mempool) AddRemoteTx(tx *atomic.Tx) error

AddRemoteTx attempts to add tx to the mempool as a Remote transaction.

Remote transactions are checked for recent verification failures prior to performing verification. If a Remote transaction failed verification recently it will not be added to the mempool.

func (*Mempool) ForceAddTx

func (m *Mempool) ForceAddTx(tx *atomic.Tx) error

ForceAddTx forcibly adds a tx to the mempool and bypasses all verification.

func (*Mempool) GetFilter

func (m *Mempool) GetFilter() ([]byte, []byte)

type Txs

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

Txs stores the transactions inside of the mempool.

Transactions in the mempool can be in 1 of 4 statuses:

  • Pending: Pending transactions are eligible for the block builder to attempt to include in the next block being built.
  • Current: Current transactions are included inside of a block currently being built.
  • Issued: Issued transactions were included inside of a block built by this node.
  • Discarded: Discarded transactions were previously in the the mempool, but were then deemed to be invalid. To prevent additional future work, these transactions may be assumed to be invalid in the future.

func NewTxs

func NewTxs(ctx *snow.Context, maxSize int) *Txs

func (*Txs) CancelCurrentTx

func (t *Txs) CancelCurrentTx(txID ids.ID)

CancelCurrentTx attempts to mark the Current transaction as Pending.

This should be called after Txs.NextTx returned the transaction and it couldn't be included in the block, but should not be discarded. For example, CancelCurrentTx should be called if including the transaction will put the block above the atomic tx gas limit.

func (*Txs) CancelCurrentTxs

func (t *Txs) CancelCurrentTxs()

CancelCurrentTxs attempts to mark all Current transactions as Pending.

This should be called after building a block failed due to an error unrelated to the transactions.

func (*Txs) DiscardCurrentTx

func (t *Txs) DiscardCurrentTx(txID ids.ID)

DiscardCurrentTx marks the Current transaction as Discarded.

This should be called after Txs.NextTx returned the transaction and it failed verification. For example, DiscardCurrentTx should be called if including the transaction would produce a conflict with an ancestor block.

func (*Txs) DiscardCurrentTxs

func (t *Txs) DiscardCurrentTxs()

DiscardCurrentTxs marks all Current transactions as Discarded.

This should be called after building a block failed due to an error related to the transactions.

func (*Txs) GetPendingTx

func (t *Txs) GetPendingTx(txID ids.ID) (*atomic.Tx, bool)

GetPendingTx returns the transaction if it is Pending.

func (*Txs) GetTx

func (t *Txs) GetTx(txID ids.ID) (tx *atomic.Tx, discarded bool, found bool)

GetTx returns the transaction along with if it is Discarded.

func (*Txs) Has

func (t *Txs) Has(txID ids.ID) bool

Has returns true if the mempool contains the transaction in either the Pending, Current, or Issued state.

func (*Txs) IssueCurrentTxs

func (t *Txs) IssueCurrentTxs()

IssueCurrentTxs marks all Current transactions as Issued.

func (*Txs) Iterate

func (t *Txs) Iterate(f func(tx *atomic.Tx) bool)

Iterate applies f to all Pending transactions. If f returns false, the iteration stops early.

func (*Txs) NextTx

func (t *Txs) NextTx() (*atomic.Tx, bool)

NextTx returns the highest paying Pending transaction from the mempool and marks it as Current.

func (*Txs) PendingLen

func (t *Txs) PendingLen() int

PendingLen returns the number of pending transactions.

func (*Txs) RemoveTx

func (t *Txs) RemoveTx(tx *atomic.Tx)

RemoveTx removes the transaction from the mempool, including removal of the Discarded status.

func (*Txs) SubscribePendingTxs

func (t *Txs) SubscribePendingTxs() <-chan struct{}

SubscribePendingTxs returns a channel that signals when there is a transaction added to the mempool.

Jump to

Keyboard shortcuts

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