v1

package
v0.0.0-...-2be2167 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TxMempool

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

TxMempool implemements the Mempool interface and allows the application to set priority values on transactions in the CheckTx response. When selecting transactions to include in a block, higher-priority transactions are chosen first. When evicting transactions from the mempool for size constraints, lower-priority transactions are evicted sooner.

Within the mempool, transactions are ordered by time of arrival, and are gossiped to the rest of the network based on that order (gossip order does not take priority into account).

func NewTxMempool

func NewTxMempool(
	logger log.Logger,
	cfg *config.MempoolConfig,
	proxyAppConn proxy.AppConnMempool,
	height int64,
	options ...TxMempoolOption,
) *TxMempool

NewTxMempool constructs a new, empty priority mempool at the specified initial height and using the given config and options.

func (*TxMempool) CheckTx

func (txmp *TxMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo mempool.TxInfo) error

CheckTx adds the given transaction to the mempool if it fits and passes the application's ABCI CheckTx method.

CheckTx reports an error without adding tx if:

- The size of tx exceeds the configured maximum transaction size. - The pre-check hook is defined and reports an error for tx. - The transaction already exists in the cache. - The proxy connection to the application fails.

If tx passes all of the above conditions, it is passed (asynchronously) to the application's ABCI CheckTx method and this CheckTx method returns nil. If cb != nil, it is called when the ABCI request completes to report the application response.

If the application accepts the transaction and the mempool is full, the mempool evicts one or more of the lowest-priority transaction whose priority is (strictly) lower than the priority of tx and whose size together exceeds the size of tx, and adds tx instead. If no such transactions exist, tx is discarded.

func (*TxMempool) EnableTxsAvailable

func (txmp *TxMempool) EnableTxsAvailable()

EnableTxsAvailable enables the mempool to trigger events when transactions are available on a block by block basis.

func (*TxMempool) Flush

func (txmp *TxMempool) Flush()

Flush purges the contents of the mempool and the cache, leaving both empty. The current height is not modified by this operation.

func (*TxMempool) FlushAppConn

func (txmp *TxMempool) FlushAppConn() error

FlushAppConn executes FlushSync on the mempool's proxyAppConn.

The caller must hold an exclusive mempool lock (by calling txmp.Lock) before calling FlushAppConn.

func (*TxMempool) Lock

func (txmp *TxMempool) Lock()

Lock obtains a write-lock on the mempool. A caller must be sure to explicitly release the lock when finished.

func (*TxMempool) ReapMaxBytesMaxGas

func (txmp *TxMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs

ReapMaxBytesMaxGas returns a slice of valid transactions that fit within the size and gas constraints. The results are ordered by nonincreasing priority, with ties broken by increasing order of arrival. Reaping transactions does not remove them from the mempool.

If maxBytes < 0, no limit is set on the total size in bytes. If maxGas < 0, no limit is set on the total gas cost.

If the mempool is empty or has no transactions fitting within the given constraints, the result will also be empty.

func (*TxMempool) ReapMaxTxs

func (txmp *TxMempool) ReapMaxTxs(max int) types.Txs

ReapMaxTxs returns up to max transactions from the mempool. The results are ordered by nonincreasing priority with ties broken by increasing order of arrival. Reaping transactions does not remove them from the mempool.

If max < 0, all transactions in the mempool are reaped.

The result may have fewer than max elements (possibly zero) if the mempool does not have that many transactions available.

func (*TxMempool) RemoveTxByKey

func (txmp *TxMempool) RemoveTxByKey(txKey types.TxKey) error

RemoveTxByKey removes the transaction with the specified key from the mempool. It reports an error if no such transaction exists. This operation does not remove the transaction from the cache.

func (*TxMempool) Size

func (txmp *TxMempool) Size() int

Size returns the number of valid transactions in the mempool. It is thread-safe.

func (*TxMempool) SizeBytes

func (txmp *TxMempool) SizeBytes() int64

SizeBytes return the total sum in bytes of all the valid transactions in the mempool. It is thread-safe.

func (*TxMempool) TxsAvailable

func (txmp *TxMempool) TxsAvailable() <-chan struct{}

TxsAvailable returns a channel which fires once for every height, and only when transactions are available in the mempool. It is thread-safe.

func (*TxMempool) TxsFront

func (txmp *TxMempool) TxsFront() *clist.CElement

TxsFront returns the frontmost element of the pending transaction list. It will be nil if the mempool is empty.

func (*TxMempool) TxsWaitChan

func (txmp *TxMempool) TxsWaitChan() <-chan struct{}

TxsWaitChan returns a channel that is closed when there is at least one transaction available to be gossiped.

func (*TxMempool) Unlock

func (txmp *TxMempool) Unlock()

Unlock releases a write-lock on the mempool.

func (*TxMempool) Update

func (txmp *TxMempool) Update(
	blockHeight int64,
	blockTxs types.Txs,
	deliverTxResponses []*abci.ResponseDeliverTx,
	newPreFn mempool.PreCheckFunc,
	newPostFn mempool.PostCheckFunc,
) error

Update removes all the given transactions from the mempool and the cache, and updates the current block height. The blockTxs and deliverTxResponses must have the same length with each response corresponding to the tx at the same offset.

If the configuration enables recheck, Update sends each remaining transaction after removing blockTxs to the ABCI CheckTx method. Any transactions marked as invalid during recheck are also removed.

The caller must hold an exclusive mempool lock (by calling txmp.Lock) before calling Update.

type TxMempoolOption

type TxMempoolOption func(*TxMempool)

TxMempoolOption sets an optional parameter on the TxMempool.

func WithMetrics

func WithMetrics(metrics *mempool.Metrics) TxMempoolOption

WithMetrics sets the mempool's metrics collector.

func WithPostCheck

func WithPostCheck(f mempool.PostCheckFunc) TxMempoolOption

WithPostCheck sets a filter for the mempool to reject a transaction if f(tx, resp) returns an error. This is executed after CheckTx. It only applies to the first created block. After that, Update overwrites the existing value.

func WithPreCheck

func WithPreCheck(f mempool.PreCheckFunc) TxMempoolOption

WithPreCheck sets a filter for the mempool to reject a transaction if f(tx) returns an error. This is executed before CheckTx. It only applies to the first created block. After that, Update() overwrites the existing value.

type WrappedTx

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

WrappedTx defines a wrapper around a raw transaction with additional metadata that is used for indexing.

func (*WrappedTx) GasWanted

func (w *WrappedTx) GasWanted() int64

GasWanted reports the application-assigned gas requirement of w.

func (*WrappedTx) HasPeer

func (w *WrappedTx) HasPeer(id uint16) bool

HasPeer reports whether the specified peer ID is a sender of w.

func (*WrappedTx) Priority

func (w *WrappedTx) Priority() int64

Priority reports the application-assigned priority of w.

func (*WrappedTx) Sender

func (w *WrappedTx) Sender() string

Sender reports the application-assigned sender of w.

func (*WrappedTx) SetGasWanted

func (w *WrappedTx) SetGasWanted(gas int64)

SetGasWanted sets the application-assigned gas requirement of w.

func (*WrappedTx) SetPeer

func (w *WrappedTx) SetPeer(id uint16)

SetPeer adds the specified peer ID as a sender of w.

func (*WrappedTx) SetPriority

func (w *WrappedTx) SetPriority(p int64)

SetPriority sets the application-assigned priority of w.

func (*WrappedTx) SetSender

func (w *WrappedTx) SetSender(sender string)

SetSender sets the application-assigned sender of w.

func (*WrappedTx) Size

func (w *WrappedTx) Size() int64

Size reports the size of the raw transaction in bytes.

Jump to

Keyboard shortcuts

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