mempool

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package mempool defines a few mempool services which can be used in conjunction with your consensus implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTxNotFound           = errors.New("tx not found in mempool")
	ErrMempoolTxMaxCapacity = errors.New("pool reached max tx capacity")
)
View Source
var DefaultMaxTx = -1

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxTxs defines the maximum number of transactions that can be in the mempool.
	MaxTxs int `` /* 219-byte string literal not displayed */
}

Config defines the configurations for the SDK built-in app-side mempool implementations.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration for the SDK built-in app-side mempool implementations.

type Iterator

type Iterator[T transaction.Tx] interface {
	// Next returns the next transaction from the mempool. If there are no more
	// transactions, it returns nil.
	Next() Iterator[T]

	// Tx returns the transaction at the current position of the iterator.
	Tx() T
}

Iterator defines an app-side mempool iterator interface that is as minimal as possible. The order of iteration is determined by the app-side mempool implementation.

type Mempool

type Mempool[T transaction.Tx] interface {
	// Insert attempts to insert a Tx into the app-side mempool returning
	// an error upon failure.
	Insert(context.Context, T) error

	// Select returns an Iterator over the app-side mempool. If txs are specified,
	// then they shall be incorporated into the Iterator. The Iterator is not thread-safe to use.
	Select(context.Context, []T) Iterator[T]

	// SelectBy use callback to iterate over the mempool, it's thread-safe to use.
	SelectBy(context.Context, []T, func(T) bool)

	// CountTx returns the number of transactions currently in the mempool.
	CountTx() int

	// Remove attempts to remove a transaction from the mempool, returning an error
	// upon failure.
	Remove(T) error
}

Mempool defines the required methods of an application's mempool.

type NoOpMempool

type NoOpMempool[T transaction.Tx] struct{}

NoOpMempool defines a no-op mempool. Transactions are completely discarded and ignored when BaseApp interacts with the mempool.

Note: When this mempool is used, it assumed that an application will rely on CometBFT's transaction ordering defined in `RequestPrepareProposal`, which is FIFO-ordered by default.

func (NoOpMempool[T]) CountTx

func (NoOpMempool[T]) CountTx() int

func (NoOpMempool[T]) Insert

func (NoOpMempool[T]) Insert(context.Context, T) error

func (NoOpMempool[T]) Remove

func (NoOpMempool[T]) Remove(T) error

func (NoOpMempool[T]) Select

func (NoOpMempool[T]) Select(context.Context, []T) Iterator[T]

func (NoOpMempool[T]) SelectBy

func (NoOpMempool[T]) SelectBy(context.Context, []T, func(T) bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳