Documentation
¶
Index ¶
- func IsEmpty[C comparable](mempool sdkmempool.Mempool) error
- type PriorityNonceIterator
- type PriorityNonceMempool
- func (mp *PriorityNonceMempool[C]) CountTx() int
- func (mp *PriorityNonceMempool[C]) Insert(ctx context.Context, tx sdk.Tx) error
- func (mp *PriorityNonceMempool[C]) NextSenderTx(sender string) sdk.Tx
- func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error
- func (mp *PriorityNonceMempool[C]) Select(_ context.Context, _ [][]byte) sdkmempool.Iterator
- type PriorityNonceMempoolConfig
- type TxPriority
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEmpty ¶
func IsEmpty[C comparable](mempool sdkmempool.Mempool) error
Types ¶
type PriorityNonceIterator ¶
type PriorityNonceIterator[C comparable] struct { // contains filtered or unexported fields }
PriorityNonceIterator defines an iterator that is used for mempool iteration on Select().
func (*PriorityNonceIterator[C]) Next ¶
func (i *PriorityNonceIterator[C]) Next() sdkmempool.Iterator
type PriorityNonceMempool ¶
type PriorityNonceMempool[C comparable] 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 DefaultPriorityMempool ¶
func DefaultPriorityMempool() *PriorityNonceMempool[int64]
DefaultPriorityMempool returns a priorityNonceMempool with no options.
func NewPriorityMempool ¶
func NewPriorityMempool[C comparable](cfg PriorityNonceMempoolConfig[C]) *PriorityNonceMempool[C]
NewPriorityMempool returns the SDK's default mempool implementation which returns txs in a partial order by 2 dimensions; priority, and sender-nonce.
func (*PriorityNonceMempool[C]) CountTx ¶
func (mp *PriorityNonceMempool[C]) CountTx() int
CountTx returns the number of transactions in the mempool.
func (*PriorityNonceMempool[C]) Insert ¶
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[C]) NextSenderTx ¶
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[C]) Remove ¶
Remove removes a transaction from the mempool in O(log n) time, returning an error if unsuccessful.
func (*PriorityNonceMempool[C]) Select ¶
func (mp *PriorityNonceMempool[C]) Select(_ context.Context, _ [][]byte) sdkmempool.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.
type PriorityNonceMempoolConfig ¶
type PriorityNonceMempoolConfig[C comparable] struct { // TxPriority defines the transaction priority and comparator. TxPriority TxPriority[C] // OnRead is a callback to be called when a tx is read from the mempool. OnRead func(tx sdk.Tx) // TxReplacement is 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. TxReplacement func(op, np C, oTx, nTx sdk.Tx) bool // MaxTx sets the maximum number of transactions allowed in the mempool with // the semantics: // - if MaxTx == 0, there is no cap on the number of transactions in the mempool // - if MaxTx > 0, the mempool will cap the number of transactions it stores, // and will prioritize transactions by their priority and sender-nonce // (sequence number) when evicting transactions. // - if MaxTx < 0, `Insert` is a no-op. MaxTx int }
PriorityNonceMempoolConfig defines the configuration used to configure the PriorityNonceMempool.
func DefaultPriorityNonceMempoolConfig ¶
func DefaultPriorityNonceMempoolConfig() PriorityNonceMempoolConfig[int64]
type TxPriority ¶
type TxPriority[C comparable] struct { // GetTxPriority returns the priority of the transaction. A priority must be // comparable via Compare. GetTxPriority func(ctx context.Context, tx sdk.Tx) C // CompareTxPriority compares two transaction priorities. The result should be // 0 if a == b, -1 if a < b, and +1 if a > b. Compare func(a, b C) int // MinValue defines the minimum priority value, e.g. MinInt64. This value is // used when instantiating a new iterator and comparing weights. MinValue C }
TxPriority defines a type that is used to retrieve and compare transaction priorities. Priorities must be comparable.
func NewDefaultTxPriority ¶
func NewDefaultTxPriority() TxPriority[int64]
NewDefaultTxPriority returns a TxPriority comparator using ctx.Priority as the defining transaction priority.