mempool

package
v0.47.14 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 78

Documentation

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 = 0

Functions

func IsEmpty

func IsEmpty(mempool Mempool) error

Types

type Iterator

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

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

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 interface {
	// Insert attempts to insert a Tx into the app-side mempool returning
	// an error upon failure.
	Insert(context.Context, sdk.Tx) error

	// Select returns an Iterator over the app-side mempool. If txs are specified,
	// then they shall be incorporated into the Iterator. The Iterator must
	// closed by the caller.
	Select(context.Context, [][]byte) Iterator

	// 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(sdk.Tx) error
}

func DefaultPriorityMempool

func DefaultPriorityMempool() Mempool

DefaultPriorityMempool returns a priorityNonceMempool with no options.

type NoOpMempool

type NoOpMempool 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 Tendermint's transaction ordering defined in `RequestPrepareProposal`, which is FIFO-ordered by default.

func (NoOpMempool) CountTx

func (NoOpMempool) CountTx() int

func (NoOpMempool) Insert

func (NoOpMempool) Remove

func (NoOpMempool) Remove(sdk.Tx) error

func (NoOpMempool) Select

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

type PriorityNonceIterator

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

func (*PriorityNonceIterator) Next

func (i *PriorityNonceIterator) Next() Iterator

func (*PriorityNonceIterator) Tx

func (i *PriorityNonceIterator) Tx() sdk.Tx

type PriorityNonceMempool

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

PriorityNonceMempool is a mempool implementation that stores txs in a partially ordered set by 2 dimensions: priority, and sender-nonce (sequence number). Internally it uses one priority ordered skip list and one skip list per sender ordered by sender-nonce (sequence number). When there are multiple txs from the same sender, they are not always comparable by priority to other sender txs and must be partially ordered by both sender-nonce and priority.

func NewPriorityMempool

func NewPriorityMempool(opts ...PriorityNonceMempoolOption) *PriorityNonceMempool

NewPriorityMempool returns the SDK's default mempool implementation which returns txs in a partial order by 2 dimensions; priority, and sender-nonce.

func (*PriorityNonceMempool) CountTx

func (mp *PriorityNonceMempool) CountTx() int

CountTx returns the number of transactions in the mempool.

func (*PriorityNonceMempool) Insert

func (mp *PriorityNonceMempool) Insert(ctx context.Context, tx sdk.Tx) error

Insert attempts to insert a Tx into the app-side mempool in O(log n) time, returning an error if unsuccessful. Sender and nonce are derived from the transaction's first signature.

Transactions are unique by sender and nonce. Inserting a duplicate tx is an O(log n) no-op.

Inserting a duplicate tx with a different priority overwrites the existing tx, changing the total order of the mempool.

func (*PriorityNonceMempool) NextSenderTx

func (mp *PriorityNonceMempool) NextSenderTx(sender string) sdk.Tx

NextSenderTx returns the next transaction for a given sender by nonce order, i.e. the next valid transaction for the sender. If no such transaction exists, nil will be returned.

func (*PriorityNonceMempool) Remove

func (mp *PriorityNonceMempool) Remove(tx sdk.Tx) error

Remove removes a transaction from the mempool in O(log n) time, returning an error if unsuccessful.

func (*PriorityNonceMempool) Select

func (mp *PriorityNonceMempool) Select(_ context.Context, _ [][]byte) Iterator

Select returns a set of transactions from the mempool, ordered by priority and sender-nonce in O(n) time. The passed in list of transactions are ignored. This is a readonly operation, the mempool is not modified.

The maxBytes parameter defines the maximum number of bytes of transactions to return.

NOTE: It is not safe to use this iterator while removing transactions from the underlying mempool.

type PriorityNonceMempoolOption

type PriorityNonceMempoolOption func(*PriorityNonceMempool)

func PriorityNonceWithMaxTx

func PriorityNonceWithMaxTx(maxTx int) PriorityNonceMempoolOption

PriorityNonceWithMaxTx sets the maximum number of transactions allowed in the mempool with the semantics:

<0: disabled, `Insert` is a no-op 0: unlimited >0: maximum number of transactions allowed

func PriorityNonceWithOnRead

func PriorityNonceWithOnRead(onRead func(tx sdk.Tx)) PriorityNonceMempoolOption

PriorityNonceWithOnRead sets a callback to be called when a tx is read from the mempool.

func PriorityNonceWithTxReplacement

func PriorityNonceWithTxReplacement(txReplacementRule func(op, np int64, oTx, nTx sdk.Tx) bool) PriorityNonceMempoolOption

PriorityNonceWithTxReplacement sets a callback to be called when duplicated transaction nonce detected during mempool insert. An application can define a transaction replacement rule based on tx priority or certain transaction fields.

type SenderNonceMempool

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

SenderNonceMempool is a mempool that prioritizes transactions within a sender by nonce, the lowest first, but selects a random sender on each iteration. The mempool is iterated by:

1) Maintaining a separate list of nonce ordered txs per sender 2) For each select iteration, randomly choose a sender and pick the next nonce ordered tx from their list 3) Repeat 1,2 until the mempool is exhausted

Note that PrepareProposal could choose to stop iteration before reaching the end if maxBytes is reached.

func NewSenderNonceMempool

func NewSenderNonceMempool(opts ...SenderNonceOptions) *SenderNonceMempool

NewSenderNonceMempool creates a new mempool that prioritizes transactions by nonce, the lowest first, picking a random sender on each iteration.

func (*SenderNonceMempool) CountTx

func (snm *SenderNonceMempool) CountTx() int

CountTx returns the total count of txs in the mempool.

func (*SenderNonceMempool) Insert

func (snm *SenderNonceMempool) Insert(_ context.Context, tx sdk.Tx) error

Insert adds a tx to the mempool. It returns an error if the tx does not have at least one signer. Note, priority is ignored.

func (*SenderNonceMempool) NextSenderTx

func (mp *SenderNonceMempool) NextSenderTx(sender string) sdk.Tx

NextSenderTx returns the next transaction for a given sender by nonce order, i.e. the next valid transaction for the sender. If no such transaction exists, nil will be returned.

func (*SenderNonceMempool) Remove

func (snm *SenderNonceMempool) Remove(tx sdk.Tx) error

Remove removes a tx from the mempool. It returns an error if the tx does not have at least one signer or the tx was not found in the pool.

func (*SenderNonceMempool) Select

func (snm *SenderNonceMempool) Select(_ context.Context, _ [][]byte) Iterator

Select returns an iterator ordering transactions the mempool with the lowest nonce of a random selected sender first.

NOTE: It is not safe to use this iterator while removing transactions from the underlying mempool.

type SenderNonceOptions

type SenderNonceOptions func(mp *SenderNonceMempool)

func SenderNonceMaxTxOpt

func SenderNonceMaxTxOpt(maxTx int) SenderNonceOptions

SenderNonceMaxTxOpt Option To set limit of max tx when calling the constructor NewSenderNonceMempool.

Example:

NewSenderNonceMempool(SenderNonceMaxTxOpt(100))

func SenderNonceSeedOpt

func SenderNonceSeedOpt(seed int64) SenderNonceOptions

SenderNonceSeedOpt Option To add a Seed for random type when calling the constructor NewSenderNonceMempool.

Example:

random_seed := int64(1000)
NewSenderNonceMempool(SenderNonceSeedTxOpt(random_seed))

Jump to

Keyboard shortcuts

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