mempool

package
v0.37.9 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: Apache-2.0 Imports: 14 Imported by: 41

Documentation

Index

Constants

View Source
const (
	MempoolChannel = byte(0x30)

	// PeerCatchupSleepIntervalMS defines how much time to sleep if a peer is behind
	PeerCatchupSleepIntervalMS = 100

	// UnknownPeerID is the peer ID to use when running CheckTx when there is
	// no peer (e.g. RPC)
	UnknownPeerID uint16 = 0

	MaxActiveIDs = math.MaxUint16
)
View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
	// package.
	MetricsSubsystem = "mempool"
)

Variables

View Source
var ErrTxInCache = errors.New("tx already exists in cache")

ErrTxInCache is returned to the client if we saw tx earlier

Functions

func IsPreCheckError

func IsPreCheckError(err error) bool

IsPreCheckError returns true if err is due to pre check failure.

Types

type ErrMempoolIsFull

type ErrMempoolIsFull struct {
	NumTxs      int
	MaxTxs      int
	TxsBytes    int64
	MaxTxsBytes int64
}

ErrMempoolIsFull defines an error where CometBFT and the application cannot handle that much load.

func (ErrMempoolIsFull) Error

func (e ErrMempoolIsFull) Error() string

type ErrPreCheck

type ErrPreCheck struct {
	Reason error
}

ErrPreCheck defines an error where a transaction fails a pre-check.

func (ErrPreCheck) Error

func (e ErrPreCheck) Error() string

type ErrTxTooLarge

type ErrTxTooLarge struct {
	Max    int
	Actual int
}

ErrTxTooLarge defines an error when a transaction is too big to be sent in a message to other peers.

func (ErrTxTooLarge) Error

func (e ErrTxTooLarge) Error() string

type LRUTxCache

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

LRUTxCache maintains a thread-safe LRU cache of raw transactions. The cache only stores the hash of the raw transaction.

func NewLRUTxCache

func NewLRUTxCache(cacheSize int) *LRUTxCache

func (*LRUTxCache) GetList

func (c *LRUTxCache) GetList() *list.List

GetList returns the underlying linked-list that backs the LRU cache. Note, this should be used for testing purposes only!

func (*LRUTxCache) Has

func (c *LRUTxCache) Has(tx types.Tx) bool

func (*LRUTxCache) Push

func (c *LRUTxCache) Push(tx types.Tx) bool

func (*LRUTxCache) Remove

func (c *LRUTxCache) Remove(tx types.Tx)

func (*LRUTxCache) Reset

func (c *LRUTxCache) Reset()

type Mempool

type Mempool interface {
	// CheckTx executes a new transaction against the application to determine
	// its validity and whether it should be added to the mempool.
	CheckTx(tx types.Tx, callback func(*abci.Response), txInfo TxInfo) error

	// RemoveTxByKey removes a transaction, identified by its key,
	// from the mempool.
	RemoveTxByKey(txKey types.TxKey) error

	// ReapMaxBytesMaxGas reaps transactions from the mempool up to maxBytes
	// bytes total with the condition that the total gasWanted must be less than
	// maxGas.
	//
	// If both maxes are negative, there is no cap on the size of all returned
	// transactions (~ all available transactions).
	ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs

	// ReapMaxTxs reaps up to max transactions from the mempool. If max is
	// negative, there is no cap on the size of all returned transactions
	// (~ all available transactions).
	ReapMaxTxs(max int) types.Txs

	// Lock locks the mempool. The consensus must be able to hold lock to safely
	// update.
	// Before acquiring the lock, it signals the mempool that a new update is coming.
	// If the mempool is still rechecking at this point, it should be considered full.
	Lock()

	// Unlock unlocks the mempool.
	Unlock()

	// Update informs the mempool that the given txs were committed and can be
	// discarded.
	//
	// NOTE:
	// 1. This should be called *after* block is committed by consensus.
	// 2. Lock/Unlock must be managed by the caller.
	Update(
		blockHeight int64,
		blockTxs types.Txs,
		deliverTxResponses []*abci.ResponseDeliverTx,
		newPreFn PreCheckFunc,
		newPostFn PostCheckFunc,
	) error

	// FlushAppConn flushes the mempool connection to ensure async callback calls
	// are done, e.g. from CheckTx.
	//
	// NOTE:
	// 1. Lock/Unlock must be managed by caller.
	FlushAppConn() error

	// Flush removes all transactions from the mempool and caches.
	Flush()

	// TxsAvailable returns a channel which fires once for every height, and only
	// when transactions are available in the mempool.
	//
	// NOTE:
	// 1. The returned channel may be nil if EnableTxsAvailable was not called.
	TxsAvailable() <-chan struct{}

	// EnableTxsAvailable initializes the TxsAvailable channel, ensuring it will
	// trigger once every height when transactions are available.
	EnableTxsAvailable()

	// Size returns the number of transactions in the mempool.
	Size() int

	// SizeBytes returns the total size of all txs in the mempool.
	SizeBytes() int64
}

Mempool defines the mempool interface.

Updates to the mempool need to be synchronized with committing a block so applications can reset their transient state on Commit.

type Metrics

type Metrics struct {
	// Number of uncommitted transactions in the mempool.
	Size metrics.Gauge

	// Total size of the mempool in bytes.
	SizeBytes metrics.Gauge

	// Histogram of transaction sizes in bytes.
	TxSizeBytes metrics.Histogram `metrics_buckettype:"exp" metrics_bucketsizes:"1,3,7"`

	// Number of failed transactions.
	FailedTxs metrics.Counter

	// RejectedTxs defines the number of rejected transactions. These are
	// transactions that passed CheckTx but failed to make it into the mempool
	// due to resource limits, e.g. mempool is full and no lower priority
	// transactions exist in the mempool.
	//metrics:Number of rejected transactions.
	RejectedTxs metrics.Counter

	// EvictedTxs defines the number of evicted transactions. These are valid
	// transactions that passed CheckTx and existed in the mempool but were later
	// evicted to make room for higher priority valid transactions that passed
	// CheckTx.
	//metrics:Number of evicted transactions.
	EvictedTxs metrics.Counter

	// Number of times transactions are rechecked in the mempool.
	RecheckTimes metrics.Counter

	// Number of connections being actively used for gossiping transactions
	// (experimental feature).
	ActiveOutboundConnections metrics.Gauge
}

Metrics contains metrics exposed by this package. see MetricsProvider for descriptions.

func NopMetrics

func NopMetrics() *Metrics

func PrometheusMetrics

func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics

type NopMempool added in v0.37.4

type NopMempool struct{}

NopMempool is a mempool that does nothing.

The ABCI app is responsible for storing, disseminating, and proposing transactions. See [ADR-111](../docs/architecture/adr-111-nop-mempool.md).

func (*NopMempool) CheckTx added in v0.37.4

func (*NopMempool) CheckTx(types.Tx, func(*abci.Response), TxInfo) error

CheckTx always returns an error.

func (*NopMempool) EnableTxsAvailable added in v0.37.4

func (*NopMempool) EnableTxsAvailable()

EnableTxsAvailable does nothing.

func (*NopMempool) Flush added in v0.37.4

func (*NopMempool) Flush()

Flush does nothing.

func (*NopMempool) FlushAppConn added in v0.37.4

func (*NopMempool) FlushAppConn() error

FlushAppConn does nothing.

func (*NopMempool) Lock added in v0.37.4

func (*NopMempool) Lock()

Lock does nothing.

func (*NopMempool) ReapMaxBytesMaxGas added in v0.37.4

func (*NopMempool) ReapMaxBytesMaxGas(int64, int64) types.Txs

ReapMaxBytesMaxGas always returns nil.

func (*NopMempool) ReapMaxTxs added in v0.37.4

func (*NopMempool) ReapMaxTxs(int) types.Txs

ReapMaxTxs always returns nil.

func (*NopMempool) RemoveTxByKey added in v0.37.4

func (*NopMempool) RemoveTxByKey(types.TxKey) error

RemoveTxByKey always returns an error.

func (*NopMempool) SetTxRemovedCallback added in v0.37.4

func (*NopMempool) SetTxRemovedCallback(func(txKey types.TxKey))

SetTxRemovedCallback does nothing.

func (*NopMempool) Size added in v0.37.4

func (*NopMempool) Size() int

Size always returns 0.

func (*NopMempool) SizeBytes added in v0.37.4

func (*NopMempool) SizeBytes() int64

SizeBytes always returns 0.

func (*NopMempool) TxsAvailable added in v0.37.4

func (*NopMempool) TxsAvailable() <-chan struct{}

TxsAvailable always returns nil.

func (*NopMempool) Unlock added in v0.37.4

func (*NopMempool) Unlock()

Unlock does nothing.

func (*NopMempool) Update added in v0.37.4

Update does nothing.

type NopMempoolReactor added in v0.37.4

type NopMempoolReactor struct {
	service.BaseService
}

NopMempoolReactor is a mempool reactor that does nothing.

func NewNopMempoolReactor added in v0.37.4

func NewNopMempoolReactor() *NopMempoolReactor

NewNopMempoolReactor returns a new `nop` reactor.

To be used only in RPC.

func (*NopMempoolReactor) AddPeer added in v0.37.4

func (*NopMempoolReactor) AddPeer(p2p.Peer)

AddPeer does nothing.

func (*NopMempoolReactor) GetChannels added in v0.37.4

func (*NopMempoolReactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels always returns nil.

func (*NopMempoolReactor) InitPeer added in v0.37.4

func (*NopMempoolReactor) InitPeer(p2p.Peer) p2p.Peer

InitPeer always returns nil.

func (*NopMempoolReactor) ReceiveEnvelope added in v0.37.4

func (*NopMempoolReactor) ReceiveEnvelope(p2p.Envelope)

Receive does nothing.

func (*NopMempoolReactor) RemovePeer added in v0.37.4

func (*NopMempoolReactor) RemovePeer(p2p.Peer, interface{})

RemovePeer does nothing.

func (*NopMempoolReactor) SetSwitch added in v0.37.4

func (*NopMempoolReactor) SetSwitch(*p2p.Switch)

SetSwitch does nothing.

func (*NopMempoolReactor) WaitSync added in v0.37.4

func (*NopMempoolReactor) WaitSync() bool

WaitSync always returns false.

type NopTxCache

type NopTxCache struct{}

NopTxCache defines a no-op raw transaction cache.

func (NopTxCache) Has

func (NopTxCache) Has(types.Tx) bool

func (NopTxCache) Push

func (NopTxCache) Push(types.Tx) bool

func (NopTxCache) Remove

func (NopTxCache) Remove(types.Tx)

func (NopTxCache) Reset

func (NopTxCache) Reset()

type PostCheckFunc

type PostCheckFunc func(types.Tx, *abci.ResponseCheckTx) error

PostCheckFunc is an optional filter executed after CheckTx and rejects transaction if false is returned. An example would be to ensure a transaction doesn't require more gas than available for the block.

func PostCheckMaxGas

func PostCheckMaxGas(maxGas int64) PostCheckFunc

PostCheckMaxGas checks that the wanted gas is smaller or equal to the passed maxGas. Returns nil if maxGas is -1.

type PreCheckFunc

type PreCheckFunc func(types.Tx) error

PreCheckFunc is an optional filter executed before CheckTx and rejects transaction if false is returned. An example would be to ensure that a transaction doesn't exceeded the block size.

func PreCheckMaxBytes

func PreCheckMaxBytes(maxBytes int64) PreCheckFunc

PreCheckMaxBytes checks that the size of the transaction is smaller or equal to the expected maxBytes.

type TxCache

type TxCache interface {
	// Reset resets the cache to an empty state.
	Reset()

	// Push adds the given raw transaction to the cache and returns true if it was
	// newly added. Otherwise, it returns false.
	Push(tx types.Tx) bool

	// Remove removes the given raw transaction from the cache.
	Remove(tx types.Tx)

	// Has reports whether tx is present in the cache. Checking for presence is
	// not treated as an access of the value.
	Has(tx types.Tx) bool
}

TxCache defines an interface for raw transaction caching in a mempool. Currently, a TxCache does not allow direct reading or getting of transaction values. A TxCache is used primarily to push transactions and removing transactions. Pushing via Push returns a boolean telling the caller if the transaction already exists in the cache or not.

type TxInfo

type TxInfo struct {
	// SenderID is the internal peer ID used in the mempool to identify the
	// sender, storing two bytes with each transaction instead of 20 bytes for
	// the types.NodeID.
	SenderID uint16

	// SenderP2PID is the actual p2p.ID of the sender, used e.g. for logging.
	SenderP2PID p2p.ID
}

TxInfo are parameters that get passed when attempting to add a tx to the mempool.

type TxKey

type TxKey [sha256.Size]byte

TxKey is the fixed length array key used as an index.

Directories

Path Synopsis
TODO: Better handle abci client errors.
TODO: Better handle abci client errors.
Deprecated: Priority mempool will be removed in the next major release.
Deprecated: Priority mempool will be removed in the next major release.

Jump to

Keyboard shortcuts

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