mempool

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package mempool implements Dingo's transaction pool. It accepts transactions from local clients (N2C) and relayed txsubmission traffic (N2N), validates them against the current ledger state, and holds them until they are included in a block or evicted.

Mempool is the top-level type. It validates every submitted transaction through the ledger package — UTxO resolution, fees, ExUnit budgets, validity interval, size, and all 41 UTxO validation rules — before admitting it. Transactions outside their validity interval relative to the current tip are rejected at submission time rather than held until expiry.

Eviction and watermarks

The pool uses a two-level watermark scheme:

  • EvictionWatermark — above this fill level, lowest-priority txs are evicted to make room for higher-priority ones
  • RejectionWatermark — above this fill level, new submissions are rejected outright

Eviction is driven by transaction priority (fee density), not arrival order. This keeps the pool stable under burst submission without unfairly discarding high-value txs.

Events

  • MempoolAddTxEventType — a tx was admitted to the pool
  • MempoolRemoveTxEventType — a tx was removed (included, evicted, or expired)

Index

Constants

View Source
const (
	AddTransactionEventType    event.EventType = "mempool.add_tx"
	RemoveTransactionEventType event.EventType = "mempool.remove_tx"

	DefaultEvictionWatermark  = 0.90
	DefaultRejectionWatermark = 0.95
	DefaultTransactionTTL     = 5 * time.Minute
	DefaultCleanupInterval    = 1 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddTransactionEvent

type AddTransactionEvent struct {
	Hash string
	Body []byte
	Type uint
}

type Mempool

type Mempool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMempool

func NewMempool(config MempoolConfig) *Mempool

func (*Mempool) AddConsumer

func (m *Mempool) AddConsumer(connId ouroboros.ConnectionId) *MempoolConsumer

func (*Mempool) AddTransaction

func (m *Mempool) AddTransaction(txType uint, txBytes []byte) error

func (*Mempool) Consumer

func (m *Mempool) Consumer(connId ouroboros.ConnectionId) *MempoolConsumer

func (*Mempool) GetTransaction

func (m *Mempool) GetTransaction(txHash string) (MempoolTransaction, bool)

func (*Mempool) RemoveConsumer

func (m *Mempool) RemoveConsumer(connId ouroboros.ConnectionId)

func (*Mempool) RemoveTransaction

func (m *Mempool) RemoveTransaction(txHash string)

func (*Mempool) Stop added in v0.18.0

func (m *Mempool) Stop(ctx context.Context) error

func (*Mempool) Transactions added in v0.2.2

func (m *Mempool) Transactions() []MempoolTransaction

type MempoolConfig added in v0.13.0

type MempoolConfig struct {
	PromRegistry       prometheus.Registerer
	Validator          TxValidator
	Logger             *slog.Logger
	EventBus           *event.EventBus
	MempoolCapacity    int64
	TransactionTTL     time.Duration
	CleanupInterval    time.Duration
	EvictionWatermark  float64
	RejectionWatermark float64
	CurrentSlotFunc    func() uint64 // returns current slot for early TX rejection
}

type MempoolConsumer

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

func (*MempoolConsumer) ClearCache

func (m *MempoolConsumer) ClearCache()

func (*MempoolConsumer) GetTxFromCache

func (m *MempoolConsumer) GetTxFromCache(hash string) *MempoolTransaction

func (*MempoolConsumer) NextTx

func (m *MempoolConsumer) NextTx(blocking bool) *MempoolTransaction

func (*MempoolConsumer) RemoveTxFromCache

func (m *MempoolConsumer) RemoveTxFromCache(hash string)

type MempoolFullError added in v0.13.0

type MempoolFullError struct {
	CurrentSize int
	TxSize      int
	Capacity    int64
}

func (*MempoolFullError) Error added in v0.13.0

func (e *MempoolFullError) Error() string

type MempoolTransaction

type MempoolTransaction struct {
	LastSeen time.Time
	Hash     string
	Cbor     []byte
	Type     uint
}

type RemoveTransactionEvent

type RemoveTransactionEvent struct {
	Hash string
}

type TxValidator added in v0.14.0

type TxValidator interface {
	ValidateTx(tx gledger.Transaction) error
	ValidateTxWithOverlay(
		tx gledger.Transaction,
		consumedUtxos map[string]struct{},
		createdUtxos map[string]lcommon.Utxo,
	) error
}

TxValidator defines the interface for transaction validation needed by mempool.

Jump to

Keyboard shortcuts

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