Documentation ¶
Index ¶
- func IsEmpty[C comparable](mempool sdkmempool.Mempool) error
- type BBMempool
- func (m *BBMempool) Contains(tx sdk.Tx) (bool, error)
- func (m *BBMempool) CountTx() int
- func (m *BBMempool) GetLane(name string) (Lane, error)
- func (m *BBMempool) GetTxDistribution() map[string]int
- func (m *BBMempool) Insert(ctx context.Context, tx sdk.Tx) error
- func (m *BBMempool) Match(tx sdk.Tx) (Lane, error)
- func (m *BBMempool) Registry() []Lane
- func (m *BBMempool) Remove(tx sdk.Tx) error
- func (m *BBMempool) Select(_ context.Context, _ [][]byte) sdkmempool.Iterator
- func (m *BBMempool) ValidateBasic() error
- type BaseLaneConfig
- type BlockProposal
- type Lane
- type LaneProposal
- type Mempool
- type PrepareLanesHandler
- 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 ProcessLanesHandler
- type Proposal
- func (p *Proposal) AddVoteExtension(voteExtension []byte)
- func (p *Proposal) Contains(tx []byte) bool
- func (p *Proposal) GetMaxTxBytes() int64
- func (p *Proposal) GetNumTxs() int
- func (p *Proposal) GetProposal() [][]byte
- func (p *Proposal) GetTotalTxBytes() int64
- func (p *Proposal) GetTxs() [][]byte
- func (p *Proposal) GetVoteExtensions() [][]byte
- func (p *Proposal) UpdateProposal(lane LaneProposal, partialProposalTxs [][]byte) error
- 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 BBMempool ¶
type BBMempool struct {
// contains filtered or unexported fields
}
Mempool defines the Blockbuster mempool implement. It contains a registry of lanes, which allows for customizable block proposal construction.
func NewMempool ¶
NewMempool returns a new Blockbuster mempool. The blockbuster mempool is comprised of a registry of lanes. Each lane is responsible for selecting transactions according to its own selection logic. The lanes are ordered according to their priority. The first lane in the registry has the highest priority. Proposals are verified according to the order of the lanes in the registry. Basic mempool API, such as insertion, removal, and contains, are delegated to the first lane that matches the transaction. Each transaction should only belong in one lane.
func (*BBMempool) Contains ¶
Contains returns true if the transaction is contained in the mempool. It checks the first lane that it matches to.
func (*BBMempool) CountTx ¶
CountTx returns the total number of transactions in the mempool. This will be the sum of the number of transactions in each lane.
func (*BBMempool) GetTxDistribution ¶
GetTxDistribution returns the number of transactions in each lane.
func (*BBMempool) Insert ¶
Insert will insert a transaction into the mempool. It inserts the transaction into the first lane that it matches.
func (*BBMempool) Match ¶
Match will return the lane that the transaction belongs to. It matches to the first lane where lane.Match(tx) is true.
func (*BBMempool) Remove ¶
Remove removes a transaction from the mempool based on the first lane that it matches.
func (*BBMempool) Select ¶
Insert returns a nil iterator.
TODO: - Determine if it even makes sense to return an iterator. What does that even mean in the context where you have multiple lanes? - Perhaps consider implementing and returning a no-op iterator?
func (*BBMempool) ValidateBasic ¶
ValidateBasic validates the mempools configuration.
type BaseLaneConfig ¶
type BaseLaneConfig struct { Logger log.Logger TxEncoder sdk.TxEncoder TxDecoder sdk.TxDecoder AnteHandler sdk.AnteHandler // 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 sdk.Dec // IgnoreList defines the list of lanes to ignore when processing transactions. This // is useful for when you want lanes to exist after the default lane. For example, // say there are two lanes: default and free. The free lane should be processed after // the default lane. In this case, the free lane should be added to the ignore list // of the default lane. Otherwise, the transactions that belong to the free lane // will be processed by the default lane. IgnoreList []Lane }
BaseLaneConfig defines the basic functionality needed for a lane.
func NewBaseLaneConfig ¶
func NewBaseLaneConfig(logger log.Logger, txEncoder sdk.TxEncoder, txDecoder sdk.TxDecoder, anteHandler sdk.AnteHandler, maxBlockSpace sdk.Dec) BaseLaneConfig
NewLaneConfig returns a new LaneConfig. This will be embedded in a lane.
func (*BaseLaneConfig) ValidateBasic ¶
func (c *BaseLaneConfig) ValidateBasic() error
ValidateBasic validates the lane configuration.
type BlockProposal ¶
type BlockProposal interface { // UpdateProposal updates the proposal with the given transactions. There are a // few invarients that are checked: // 1. The total size of the proposal must be less than the maximum number of bytes allowed. // 2. The total size of the partial proposal must be less than the maximum number of bytes allowed for // the lane. UpdateProposal(lane LaneProposal, partialProposalTxs [][]byte) error // GetMaxTxBytes returns the maximum number of bytes that can be included in the proposal. GetMaxTxBytes() int64 // GetTotalTxBytes returns the total number of bytes currently included in the proposal. GetTotalTxBytes() int64 // GetTxs returns the transactions in the proposal. GetTxs() [][]byte // GetNumTxs returns the number of transactions in the proposal. GetNumTxs() int // Contains returns true if the proposal contains the given transaction. Contains(tx []byte) bool // AddVoteExtension adds a vote extension to the proposal. AddVoteExtension(voteExtension []byte) // GetVoteExtensions returns the vote extensions in the proposal. GetVoteExtensions() [][]byte // GetProposal returns all of the transactions in the proposal along with the vote extensions // at the top of the proposal. GetProposal() [][]byte }
BlockProposal is the interface/APIs that are required for proposal creation + interacting with and updating proposals. BlockProposals are iteratively updated as each lane prepares its partial proposal. Each lane must call UpdateProposal with its partial proposal in PrepareLane. BlockProposals can also include vote extensions, which are included at the top of the proposal.
type Lane ¶
type Lane interface { sdkmempool.Mempool // Name returns the name of the lane. Name() string // Match determines if a transaction belongs to this lane. Match(tx sdk.Tx) bool // VerifyTx verifies the transaction belonging to this lane. VerifyTx(ctx sdk.Context, tx sdk.Tx) error // Contains returns true if the mempool contains the given transaction. Contains(tx sdk.Tx) (bool, error) // PrepareLane builds a portion of the block. It inputs the maxTxBytes that can be // included in the proposal for the given lane, the partial proposal, and a function // to call the next lane in the chain. The next lane in the chain will be called with // the updated proposal and context. PrepareLane(ctx sdk.Context, proposal BlockProposal, maxTxBytes int64, next PrepareLanesHandler) (BlockProposal, error) // ProcessLaneBasic validates that transactions belonging to this lane are not misplaced // in the block proposal. ProcessLaneBasic(txs []sdk.Tx) error // ProcessLane verifies this lane's portion of a proposed block. It inputs the transactions // that may belong to this lane and a function to call the next lane in the chain. The next // lane in the chain will be called with the updated context and filtered down transactions. ProcessLane(ctx sdk.Context, proposalTxs []sdk.Tx, next ProcessLanesHandler) (sdk.Context, error) // SetAnteHandler sets the lane's antehandler. SetAnteHandler(antehander sdk.AnteHandler) // Logger returns the lane's logger. Logger() log.Logger // GetMaxBlockSpace returns the max block space for the lane as a relative percentage. GetMaxBlockSpace() sdk.Dec }
Lane defines an interface used for block construction
type LaneProposal ¶
type LaneProposal interface { // Logger returns the lane's logger. Logger() log.Logger // GetMaxBlockSpace returns the maximum block space for the lane as a relative percentage. GetMaxBlockSpace() sdk.Dec // Name returns the name of the lane. Name() string }
LaneProposal defines the interface/APIs that are required for the proposal to interact with a lane.
type Mempool ¶
type Mempool interface { sdkmempool.Mempool // Registry returns the mempool's lane registry. Registry() []Lane // Contains returns true if the transaction is contained in the mempool. Contains(tx sdk.Tx) (bool, error) // GetTxDistribution returns the number of transactions in each lane. GetTxDistribution() map[string]int // Match will return the lane that the transaction belongs to. Match(tx sdk.Tx) (Lane, error) // GetLane returns the lane with the given name. GetLane(name string) (Lane, error) }
Mempool defines the Blockbuster mempool interface.
type PrepareLanesHandler ¶
type PrepareLanesHandler func(ctx sdk.Context, proposal BlockProposal) (BlockProposal, error)
PrepareLanesHandler wraps all of the lanes Prepare function into a single chained function. You can think of it like an AnteHandler, but for preparing proposals in the context of lanes instead of modules.
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 ProcessLanesHandler ¶
ProcessLanesHandler wraps all of the lanes Process functions into a single chained function. You can think of it like an AnteHandler, but for processing proposals in the context of lanes instead of modules.
type Proposal ¶
type Proposal struct {
// contains filtered or unexported fields
}
Proposal defines a block proposal type.
func NewProposal ¶
NewProposal returns a new empty proposal.
func (*Proposal) AddVoteExtension ¶
AddVoteExtension adds a vote extension to the proposal.
func (*Proposal) GetMaxTxBytes ¶
GetMaxTxBytes returns the maximum number of bytes that can be included in the proposal.
func (*Proposal) GetProposal ¶
GetProposal returns all of the transactions in the proposal along with the vote extensions at the top of the proposal.
func (*Proposal) GetTotalTxBytes ¶
GetTotalTxBytes returns the total number of bytes currently included in the proposal.
func (*Proposal) GetVoteExtensions ¶
GetVoteExtensions returns the vote extensions in the proposal.
func (*Proposal) UpdateProposal ¶
func (p *Proposal) UpdateProposal(lane LaneProposal, partialProposalTxs [][]byte) error
UpdateProposal updates the proposal with the given transactions and total size. There are a few invarients that are checked:
- The total size of the proposal must be less than the maximum number of bytes allowed.
- The total size of the partial proposal must be less than the maximum number of bytes allowed for the lane.
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.