mempool

package
v1.28.28 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: BSD-3-Clause Imports: 13 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// MaxTxSize is the maximum number of bytes a transaction can use to be
	// allowed into the mempool. Increased from 64 KiB to 2 MiB to support
	// large genesis configurations (e.g., ZOO chain genesis is ~613 KiB).
	MaxTxSize = 2 * constants.MiB
)

Variables

View Source
var (
	ErrDuplicateTx          = errors.New("duplicate tx")
	ErrTxTooLarge           = errors.New("tx too large")
	ErrMempoolFull          = errors.New("mempool is full")
	ErrConflictsWithOtherTx = errors.New("tx conflicts with other tx")
	// ErrAdmissionRejected wraps a rejection emitted by an AdmissionVerifier
	// configured via NewWithAdmissionVerifier. The wrapped error carries the
	// verifier's specific reason (e.g. NIZK proof invalid, fee bid below
	// floor, budget meter exhausted).
	ErrAdmissionRejected = errors.New("tx admission rejected")
)

Functions

func New

func New[T Tx](
	metrics Metrics,
) *mempool[T]

func NewWithAdmissionVerifier added in v1.28.28

func NewWithAdmissionVerifier[T Tx](
	metrics Metrics,
	verifier AdmissionVerifier[T],
) *mempool[T]

NewWithAdmissionVerifier constructs a mempool that runs verifier.VerifyAdmit on every Add() after the duplicate / size / space / conflict checks succeed. A nil verifier is equivalent to New — no admission gate is installed and behavior is byte-identical to the prior API.

This is the entry point for encrypted-payload tx pools per luxfi/node#115: validators construct a mempool partition with a verifier that runs signature + fee + NIZK checks (sourced from luxfi/precompile/fhe) so ciphertexts are admitted without decryption.

Types

type AdmissionVerifier added in v1.28.28

type AdmissionVerifier[T Tx] interface {
	VerifyAdmit(tx T) error
}

AdmissionVerifier is an optional admission gate. When configured via NewWithAdmissionVerifier the mempool calls VerifyAdmit on every Add() after the cheap structural checks (duplicate / size / space / conflict) pass and before the tx is inserted. A non-nil return rejects the tx; the returned error is wrapped in ErrAdmissionRejected and recorded as the drop reason.

Intended consumers: validators that admit encrypted-payload transactions (FHE ciphertext + NIZK proof of well-formedness) without decryption, per LP-066 / luxfi/precompile/fhe. The verifier runs signature verify + fee check + NIZK verify; the actual decryption never happens at admission time.

VerifyAdmit MUST be safe to call without holding any mempool lock — the mempool holds its own write lock across Add() and the call is made from within that critical section. Implementations that need to do expensive work (NIZK verification) should not perform additional locking that could re-enter the mempool.

type Mempool

type Mempool[T Tx] interface {
	Add(tx T) error
	Get(txID ids.ID) (T, bool)
	// Remove [txs] and any conflicts of [txs] from the mempool.
	Remove(txs ...T)

	// Peek returns the oldest tx in the mempool.
	Peek() (tx T, exists bool)

	// Iterate iterates over the txs until f returns false
	Iterate(f func(tx T) bool)

	// Note: dropped txs are added to droppedTxIDs but are not evicted from
	// unissued decision/staker txs. This allows previously dropped txs to be
	// possibly reissued.
	MarkDropped(txID ids.ID, reason error)
	GetDropReason(txID ids.ID) error

	// Len returns the number of txs in the mempool.
	Len() int

	// WaitForEvent waits until there is at least one tx in the mempool.
	WaitForEvent(ctx context.Context) (vm.Message, error)
}

type Metrics

type Metrics interface {
	Update(numTxs, bytesAvailable int)
}

func NewMetrics

func NewMetrics(namespace string, registerer metric.Registerer) (Metrics, error)

NewMetrics creates a new Metrics instance

type Tx

type Tx interface {
	InputIDs() set.Set[ids.ID]
	ID() ids.ID
	Size() int
}

Jump to

Keyboard shortcuts

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