mempool

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 11 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMsgAuctionBidFromTx

func GetMsgAuctionBidFromTx(tx sdk.Tx) (*buildertypes.MsgAuctionBid, error)

GetMsgAuctionBidFromTx attempts to retrieve a MsgAuctionBid from an sdk.Tx if one exists. If a MsgAuctionBid does exist and other messages are also present, an error is returned. If no MsgAuctionBid is present, <nil, nil> is returned.

func IsEmpty

func IsEmpty[C comparable](mempool sdkmempool.Mempool) error

Types

type AuctionBidInfo

type AuctionBidInfo struct {
	Bidder       sdk.AccAddress
	Bid          sdk.Coin
	Transactions [][]byte
	Timeout      uint64
	Signers      []map[string]struct{}
}

AuctionBidInfo defines the information about a bid to the auction house.

type AuctionFactory

type AuctionFactory interface {
	// WrapBundleTransaction defines a function that wraps a bundle transaction into a sdk.Tx. Since
	// this is a potentially expensive operation, we allow each application chain to define how
	// they want to wrap the transaction such that it is only called when necessary (i.e. when the
	// transaction is being considered in the proposal handlers).
	WrapBundleTransaction(tx []byte) (sdk.Tx, error)

	// GetAuctionBidInfo defines a function that returns the bid info from an auction transaction.
	GetAuctionBidInfo(tx sdk.Tx) (*AuctionBidInfo, error)
}

AuctionFactory defines the interface for processing auction transactions. It is a wrapper around all of the functionality that each application chain must implement in order for auction processing to work.

func NewDefaultAuctionFactory

func NewDefaultAuctionFactory(txDecoder sdk.TxDecoder) AuctionFactory

NewDefaultAuctionFactory returns a default auction factory interface implementation.

type AuctionMempool

type AuctionMempool struct {

	// AuctionFactory implements the functionality required to process auction transactions.
	AuctionFactory
	// contains filtered or unexported fields
}

AuctionMempool defines an auction mempool. It can be seen as an extension of an SDK PriorityNonceMempool, i.e. a mempool that supports <sender, nonce> two-dimensional priority ordering, with the additional support of prioritizing and indexing auction bids.

func NewAuctionMempool

func NewAuctionMempool(txDecoder sdk.TxDecoder, txEncoder sdk.TxEncoder, maxTx int, config AuctionFactory) *AuctionMempool

func (*AuctionMempool) AuctionBidSelect

func (am *AuctionMempool) AuctionBidSelect(ctx context.Context) sdkmempool.Iterator

AuctionBidSelect returns an iterator over auction bids transactions only.

func (*AuctionMempool) Contains

func (am *AuctionMempool) Contains(tx sdk.Tx) (bool, error)

Contains returns true if the transaction is contained in the mempool.

func (*AuctionMempool) CountAuctionTx

func (am *AuctionMempool) CountAuctionTx() int

func (*AuctionMempool) CountTx

func (am *AuctionMempool) CountTx() int

func (*AuctionMempool) GetTopAuctionTx

func (am *AuctionMempool) GetTopAuctionTx(ctx context.Context) sdk.Tx

GetTopAuctionTx returns the highest bidding transaction in the auction mempool.

func (*AuctionMempool) Insert

func (am *AuctionMempool) Insert(ctx context.Context, tx sdk.Tx) error

Insert inserts a transaction into the mempool based on the transaction type (normal or auction).

func (*AuctionMempool) Remove

func (am *AuctionMempool) Remove(tx sdk.Tx) error

Remove removes a transaction from the mempool based on the transaction type (normal or auction).

func (*AuctionMempool) Select

func (am *AuctionMempool) Select(ctx context.Context, txs [][]byte) sdkmempool.Iterator

type DefaultAuctionFactory

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

DefaultAuctionFactory defines a default implmentation for the auction factory interface for processing auction transactions.

func (*DefaultAuctionFactory) GetAuctionBidInfo

func (config *DefaultAuctionFactory) GetAuctionBidInfo(tx sdk.Tx) (*AuctionBidInfo, error)

GetAuctionBidInfo defines a default function that returns the auction bid info from an auction transaction. In the default case, the auction bid info is stored in the MsgAuctionBid message.

func (*DefaultAuctionFactory) WrapBundleTransaction

func (config *DefaultAuctionFactory) WrapBundleTransaction(tx []byte) (sdk.Tx, error)

WrapBundleTransaction defines a default function that wraps a transaction that is included in the bundle into a sdk.Tx. In the default case, the transaction that is included in the bundle will be the raw bytes of an sdk.Tx so we can just decode it.

type Mempool

type Mempool interface {
	// Inherit the methods of the SDK's Mempool interface.
	sdkmempool.Mempool

	// GetTopAuctionTx returns the top auction bid transaction in the mempool.
	GetTopAuctionTx(ctx context.Context) sdk.Tx

	// CoutnAuctionTx returns the number of auction bid transactions in the mempool.
	CountAuctionTx() int

	// AuctionBidSelect returns an iterator over the auction bid transactions in the mempool.
	AuctionBidSelect(ctx context.Context) sdkmempool.Iterator

	// Contains returns true if the mempool contains the given transaction.
	Contains(tx sdk.Tx) (bool, error)

	// AuctionFactory implements the functionality required to process auction transactions.
	AuctionFactory
}

Mempool defines the interface for a POB mempool.

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

func (*PriorityNonceIterator[C]) Tx

func (i *PriorityNonceIterator[C]) Tx() sdk.Tx

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

func (mp *PriorityNonceMempool[C]) 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[C]) NextSenderTx

func (mp *PriorityNonceMempool[C]) 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[C]) Remove

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

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 AuctionTxPriority

func AuctionTxPriority(config AuctionFactory) TxPriority[string]

AuctionTxPriority returns a TxPriority over auction bid transactions only. It is to be used in the auction index only.

func NewDefaultTxPriority

func NewDefaultTxPriority() TxPriority[int64]

NewDefaultTxPriority returns a TxPriority comparator using ctx.Priority as the defining transaction priority.

type TxWithTimeoutHeight

type TxWithTimeoutHeight interface {
	sdk.Tx

	GetTimeoutHeight() uint64
}

TxWithTimeoutHeight is used to extract timeouts from sdk.Tx transactions. In the case where, timeouts are explicitly set on the sdk.Tx, we can use this interface to extract the timeout.

Jump to

Keyboard shortcuts

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