Documentation ¶
Index ¶
- func IsEmpty[C comparable](mempool sdkmempool.Mempool) error
- type BaseLane
- func (l *BaseLane) GetMaxBlockSpace() math.LegacyDec
- func (l *BaseLane) GetTxInfo(ctx sdk.Context, tx sdk.Tx) (utils.TxWithInfo, error)
- func (l *BaseLane) Logger() log.Logger
- func (l *BaseLane) Match(ctx sdk.Context, tx sdk.Tx) bool
- func (l *BaseLane) Name() string
- func (l *BaseLane) PrepareLane(ctx sdk.Context, proposal proposals.Proposal, next block.PrepareLanesHandler) (proposals.Proposal, error)
- func (l *BaseLane) ProcessLane(ctx sdk.Context, proposal proposals.Proposal, txs []sdk.Tx, ...) (proposals.Proposal, error)
- func (l *BaseLane) TxDecoder() sdk.TxDecoder
- func (l *BaseLane) TxEncoder() sdk.TxEncoder
- func (l *BaseLane) ValidateBasic() error
- func (l *BaseLane) VerifyNoMatches(ctx sdk.Context, txs []sdk.Tx) error
- func (l *BaseLane) VerifyTx(ctx sdk.Context, tx sdk.Tx, simulate bool) error
- func (l *BaseLane) WithOptions(options ...LaneOption) *BaseLane
- type DefaultProposalHandler
- type LaneConfig
- type LaneOption
- func WithAnteHandler(anteHandler sdk.AnteHandler) LaneOption
- func WithMatchHandler(matchHandler MatchHandler) LaneOption
- func WithMempool(mempool block.LaneMempool) LaneOption
- func WithMempoolConfigs[C comparable](cfg LaneConfig, txPriority TxPriority[C]) LaneOption
- func WithPrepareLaneHandler(prepareLaneHandler PrepareLaneHandler) LaneOption
- func WithProcessLaneHandler(processLaneHandler ProcessLaneHandler) LaneOption
- type MatchHandler
- type Mempool
- func (cm *Mempool[C]) Compare(ctx sdk.Context, this sdk.Tx, other sdk.Tx) (int, error)
- func (cm *Mempool[C]) Contains(tx sdk.Tx) bool
- func (cm *Mempool[C]) CountTx() int
- func (cm *Mempool[C]) Insert(ctx context.Context, tx sdk.Tx) error
- func (cm *Mempool[C]) Priority(ctx sdk.Context, tx sdk.Tx) any
- func (cm *Mempool[C]) Remove(tx sdk.Tx) error
- func (cm *Mempool[C]) Select(ctx context.Context, txs [][]byte) sdkmempool.Iterator
- type PrepareLaneHandler
- 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 ProcessLaneHandler
- 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 BaseLane ¶
type BaseLane struct { // LaneMempool is the mempool that is responsible for storing transactions // that are waiting to be processed. block.LaneMempool // contains filtered or unexported fields }
BaseLane is a generic implementation of a lane. It is meant to be used as a base for other lanes to be built on top of. It provides a default implementation of the MatchHandler, PrepareLaneHandler, ProcessLaneHandler, and CheckOrderHandler. To extend this lane, you must either utilize the default handlers or construct your own that you pass into the base/setters.
func NewBaseLane ¶
func NewBaseLane( cfg LaneConfig, laneName string, options ...LaneOption, ) (*BaseLane, error)
NewBaseLane returns a new lane base. When creating this lane, the type of the lane must be specified. The type of the lane is directly associated with the type of the mempool that is used to store transactions that are waiting to be processed.
func (*BaseLane) GetMaxBlockSpace ¶
GetMaxBlockSpace returns the maximum amount of block space that the lane is allowed to consume as a percentage of the total block space.
func (*BaseLane) GetTxInfo ¶ added in v1.3.0
GetTxInfo returns various information about the transaction that belongs to the lane including its priority, signer's, sequence number, size and more.
func (*BaseLane) Match ¶
Match returns true if the transaction should be processed by this lane. This function first determines if the transaction matches the lane and then checks if the transaction is on the ignore list. If the transaction is on the ignore list, it returns false.
func (*BaseLane) PrepareLane ¶
func (l *BaseLane) PrepareLane( ctx sdk.Context, proposal proposals.Proposal, next block.PrepareLanesHandler, ) (proposals.Proposal, error)
PrepareLane will prepare a partial proposal for the lane. It will select transactions from the lane respecting the selection logic of the prepareLaneHandler. It will then update the partial proposal with the selected transactions. If the proposal is unable to be updated, we return an error. The proposal will only be modified if it passes all of the invariant checks.
func (*BaseLane) ProcessLane ¶
func (l *BaseLane) ProcessLane( ctx sdk.Context, proposal proposals.Proposal, txs []sdk.Tx, next block.ProcessLanesHandler, ) (proposals.Proposal, error)
ProcessLane verifies that the transactions included in the block proposal are valid respecting the verification logic of the lane (processLaneHandler). If any of the transactions are invalid, we return an error. If all of the transactions are valid, we return the updated proposal.
func (*BaseLane) ValidateBasic ¶
ValidateBasic ensures that the lane was constructed properly. In the case that the lane was not constructed with proper handlers, default handlers are set.
func (*BaseLane) VerifyNoMatches ¶ added in v1.3.0
VerifyNoMatches returns an error if any of the transactions match the lane.
func (*BaseLane) VerifyTx ¶ added in v1.1.0
VerifyTx verifies that the transaction is valid respecting the ante verification logic of of the antehandler chain.
func (*BaseLane) WithOptions ¶ added in v1.3.0
func (l *BaseLane) WithOptions(options ...LaneOption) *BaseLane
WithOptions returns a new lane with the given options.
type DefaultProposalHandler ¶ added in v1.3.0
type DefaultProposalHandler struct {
// contains filtered or unexported fields
}
DefaultProposalHandler returns a default implementation of the PrepareLaneHandler and ProcessLaneHandler.
func NewDefaultProposalHandler ¶ added in v1.3.0
func NewDefaultProposalHandler(lane *BaseLane) *DefaultProposalHandler
NewDefaultProposalHandler returns a new default proposal handler.
func (*DefaultProposalHandler) PrepareLaneHandler ¶ added in v1.3.0
func (h *DefaultProposalHandler) PrepareLaneHandler() PrepareLaneHandler
DefaultPrepareLaneHandler returns a default implementation of the PrepareLaneHandler. It selects all transactions in the mempool that are valid and not already in the partial proposal. It will continue to reap transactions until the maximum blockspace/gas for this lane has been reached. Additionally, any transactions that are invalid will be returned.
func (*DefaultProposalHandler) ProcessLaneHandler ¶ added in v1.3.0
func (h *DefaultProposalHandler) ProcessLaneHandler() ProcessLaneHandler
DefaultProcessLaneHandler returns a default implementation of the ProcessLaneHandler. It verifies the following invariants:
- Transactions belonging to the lane must be contiguous from the beginning of the partial proposal.
- Transactions that do not belong to the lane must be contiguous from the end of the partial proposal.
- Transactions must be ordered respecting the priority defined by the lane (e.g. gas price).
- Transactions must be valid according to the verification logic of the lane.
type LaneConfig ¶
type LaneConfig struct { Logger log.Logger TxEncoder sdk.TxEncoder TxDecoder sdk.TxDecoder AnteHandler sdk.AnteHandler // SignerExtractor defines the interface used for extracting the expected signers of a transaction // from the transaction. SignerExtractor signer_extraction.Adapter // MaxBlockSpace defines the relative percentage of block space that can be // used by this lane. NOTE: If this is set to zero, then there is no limit // on the number of transactions that can be included in the block for this // lane (up to maxTxBytes as provided by the request). This is useful for the default lane. MaxBlockSpace math.LegacyDec // MaxTxs 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. MaxTxs int }
LaneConfig defines the basic configurations needed for a lane.
func NewLaneConfig ¶
func NewLaneConfig( logger log.Logger, txEncoder sdk.TxEncoder, txDecoder sdk.TxDecoder, anteHandler sdk.AnteHandler, signerExtractor signer_extraction.Adapter, maxBlockSpace math.LegacyDec, ) LaneConfig
NewLaneConfig returns a new LaneConfig. This will be embedded in a lane.
func (*LaneConfig) ValidateBasic ¶
func (c *LaneConfig) ValidateBasic() error
ValidateBasic validates the lane configuration.
type LaneOption ¶ added in v1.3.0
type LaneOption func(*BaseLane)
LaneOption defines a function that can be used to set options on a lane.
func WithAnteHandler ¶ added in v1.3.0
func WithAnteHandler(anteHandler sdk.AnteHandler) LaneOption
WithAnteHandler sets the ante handler for the lane.
func WithMatchHandler ¶ added in v1.3.0
func WithMatchHandler(matchHandler MatchHandler) LaneOption
WithMatchHandler sets the match handler for the lane. This handler is called when a new transaction is being submitted to the lane and the lane needs to determine if the transaction should be processed by the lane.
func WithMempool ¶ added in v1.3.0
func WithMempool(mempool block.LaneMempool) LaneOption
WithMempool sets the mempool for the lane. This mempool is used to store transactions that are waiting to be processed.
func WithMempoolConfigs ¶ added in v1.3.0
func WithMempoolConfigs[C comparable](cfg LaneConfig, txPriority TxPriority[C]) LaneOption
WithMempoolConfigs sets the mempool for the lane with the given lane config and TxPriority struct. This mempool is used to store transactions that are waiting to be processed.
func WithPrepareLaneHandler ¶ added in v1.3.0
func WithPrepareLaneHandler(prepareLaneHandler PrepareLaneHandler) LaneOption
WithPrepareLaneHandler sets the prepare lane handler for the lane. This handler is called when a new proposal is being requested and the lane needs to submit transactions it wants included in the block.
func WithProcessLaneHandler ¶ added in v1.3.0
func WithProcessLaneHandler(processLaneHandler ProcessLaneHandler) LaneOption
WithProcessLaneHandler sets the process lane handler for the lane. This handler is called when a new proposal is being verified and the lane needs to verify that the transactions included in the proposal are valid respecting the verification logic of the lane.
type MatchHandler ¶
MatchHandler is utilized to determine if a transaction should be included in the lane. This function can be a stateless or stateful check on the transaction.
func DefaultMatchHandler ¶
func DefaultMatchHandler() MatchHandler
DefaultMatchHandler returns a default implementation of the MatchHandler. It matches all transactions.
func NewMatchHandler ¶ added in v1.3.0
func NewMatchHandler(mh MatchHandler, ignoreMHs ...MatchHandler) MatchHandler
NewMatchHandler returns a match handler that matches transactions that match the lane and do not match with any of the provided match handlers. In the context of building an application, you would want to use this to ignore the match handlers of other lanes in the application.
type Mempool ¶
type Mempool[C comparable] struct { // contains filtered or unexported fields }
Mempool defines a mempool that orders transactions based on the txPriority. The mempool is a wrapper on top of the SDK's Priority Nonce mempool. It include's additional helper functions that allow users to determine if a transaction is already in the mempool and to compare the priority of two transactions.
func NewMempool ¶
func NewMempool[C comparable](txPriority TxPriority[C], txEncoder sdk.TxEncoder, extractor signer_extraction.Adapter, maxTx int) *Mempool[C]
NewMempool returns a new Mempool.
func (*Mempool[C]) Compare ¶
Compare determines the relative priority of two transactions belonging in the same lane. There are two cases to consider:
- The transactions have the same signer. In this case, we compare the sequence numbers.
- The transactions have different signers. In this case, we compare the priorities of the transactions.
Compare will return -1 if this transaction has a lower priority than the other transaction, 0 if they have the same priority, and 1 if this transaction has a higher priority than the other transaction.
func (*Mempool[C]) Select ¶
Select returns an iterator of all transactions in the mempool. NOTE: If you remove a transaction from the mempool while iterating over the transactions, the iterator will not be aware of the removal and will continue to iterate over the removed transaction. Be sure to reset the iterator if you remove a transaction.
type PrepareLaneHandler ¶
type PrepareLaneHandler func( ctx sdk.Context, proposal proposals.Proposal, limit proposals.LaneLimits, ) (txsToInclude []sdk.Tx, txsToRemove []sdk.Tx, err error)
PrepareLaneHandler is responsible for preparing transactions to be included in the block from a given lane. Given a lane, this function should return the transactions to include in the block, the transactions that must be removed from the lane, and an error if one occurred.
func NoOpPrepareLaneHandler ¶
func NoOpPrepareLaneHandler() PrepareLaneHandler
NoOpPrepareLaneHandler returns a no-op prepare lane handler. This should only be used for testing.
func PanicPrepareLaneHandler ¶
func PanicPrepareLaneHandler() PrepareLaneHandler
PanicPrepareLaneHandler returns a prepare lane handler that panics. This should only be used for testing.
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(extractor signer_extraction.DefaultAdapter) *PriorityNonceMempool[int64]
DefaultPriorityMempool returns a priorityNonceMempool with no options.
func NewPriorityMempool ¶
func NewPriorityMempool[C comparable](cfg PriorityNonceMempoolConfig[C], extractor signer_extraction.Adapter) *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 ProcessLaneHandler ¶
type ProcessLaneHandler func(ctx sdk.Context, partialProposal []sdk.Tx) ( txsFromLane []sdk.Tx, remainingTxs []sdk.Tx, err error, )
ProcessLaneHandler is responsible for processing transactions that are included in a block and belong to a given lane. The handler must return the transactions that were successfully processed and the transactions that it cannot process because they belong to a different lane.
func NoOpProcessLaneHandler ¶
func NoOpProcessLaneHandler() ProcessLaneHandler
NoOpProcessLaneHandler returns a no-op process lane handler. This should only be used for testing.
func PanicProcessLaneHandler ¶
func PanicProcessLaneHandler() ProcessLaneHandler
PanicProcessLanesHandler returns a process lanes handler that panics. This should only be used for testing.
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 DefaultTxPriority ¶
func DefaultTxPriority() TxPriority[string]
DefaultTxPriority returns a default implementation of the TxPriority. It prioritizes transactions by their fee.
func NewDefaultTxPriority ¶
func NewDefaultTxPriority() TxPriority[int64]
NewDefaultTxPriority returns a TxPriority comparator using ctx.Priority as the defining transaction priority.