Documentation ¶
Index ¶
- Constants
- Variables
- func IsPreCheckError(err error) bool
- func RegisterMempoolMessages(cdc *amino.Codec)
- func TxID(tx []byte) string
- type ErrMempoolIsFull
- type ErrPreCheck
- type Mempool
- func (mem *Mempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error)
- func (mem *Mempool) CheckTxWithInfo(tx types.Tx, cb func(*abci.Response), txInfo TxInfo) (err error)
- func (mem *Mempool) CloseWAL()
- func (mem *Mempool) EnableTxsAvailable()
- func (mem *Mempool) Flush()
- func (mem *Mempool) FlushAppConn() error
- func (mem *Mempool) InitWAL()
- func (mem *Mempool) Lock()
- func (mem *Mempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
- func (mem *Mempool) ReapMaxTxs(max int) types.Txs
- func (mem *Mempool) SetLogger(l log.Logger)
- func (mem *Mempool) Size() int
- func (mem *Mempool) TxsAvailable() <-chan struct{}
- func (mem *Mempool) TxsBytes() int64
- func (mem *Mempool) TxsFront() *clist.CElement
- func (mem *Mempool) TxsWaitChan() <-chan struct{}
- func (mem *Mempool) Unlock()
- func (mem *Mempool) Update(height int64, txs types.Txs, preCheck PreCheckFunc, postCheck PostCheckFunc) error
- type MempoolMessage
- type MempoolOption
- type MempoolReactor
- func (memR *MempoolReactor) AddPeer(peer p2p.Peer)
- func (memR *MempoolReactor) GetChannels() []*p2p.ChannelDescriptor
- func (memR *MempoolReactor) OnStart() error
- func (memR *MempoolReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
- func (memR *MempoolReactor) RemovePeer(peer p2p.Peer, reason interface{})
- func (memR *MempoolReactor) SetLogger(l log.Logger)
- type Metrics
- type PeerState
- type PostCheckFunc
- type PreCheckFunc
- type TxInfo
- type TxMessage
Constants ¶
const ( MempoolChannel = byte(0x30) // UnknownPeerID is the peer ID to use when running CheckTx when there is // no peer (e.g. RPC) UnknownPeerID uint16 = 0 )
const ( // MetricsSubsystem is a subsystem shared by all metrics exposed by this // package. MetricsSubsystem = "mempool" )
Variables ¶
var ( // ErrTxInCache is returned to the client if we saw tx earlier ErrTxInCache = errors.New("Tx already exists in cache") // ErrTxTooLarge means the tx is too big to be sent in a message to other peers ErrTxTooLarge = fmt.Errorf("Tx too large. Max size is %d", maxTxSize) )
Functions ¶
func IsPreCheckError ¶
IsPreCheckError returns true if err is due to pre check failure.
func RegisterMempoolMessages ¶
Types ¶
type ErrMempoolIsFull ¶
type ErrMempoolIsFull struct {
// contains filtered or unexported fields
}
ErrMempoolIsFull means Tendermint & an application can't handle that much load
func (ErrMempoolIsFull) Error ¶
func (e ErrMempoolIsFull) Error() string
type ErrPreCheck ¶
type ErrPreCheck struct {
Reason error
}
ErrPreCheck is returned when tx is too big
func (ErrPreCheck) Error ¶
func (e ErrPreCheck) Error() string
type Mempool ¶
type Mempool struct {
// contains filtered or unexported fields
}
Mempool is an ordered in-memory pool for transactions before they are proposed in a consensus round. Transaction validity is checked using the CheckTx abci message before the transaction is added to the pool. The Mempool uses a concurrent list structure for storing transactions that can be efficiently accessed by multiple concurrent readers.
func NewMempool ¶
func NewMempool( config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64, options ...MempoolOption, ) *Mempool
NewMempool returns a new Mempool with the given configuration and connection to an application.
func (*Mempool) CheckTx ¶
CheckTx executes a new transaction against the application to determine its validity and whether it should be added to the mempool. It blocks if we're waiting on Update() or Reap(). cb: A callback from the CheckTx command.
It gets called from another goroutine.
CONTRACT: Either cb will get called, or err returned.
func (*Mempool) CheckTxWithInfo ¶ added in v0.31.1
func (mem *Mempool) CheckTxWithInfo(tx types.Tx, cb func(*abci.Response), txInfo TxInfo) (err error)
CheckTxWithInfo performs the same operation as CheckTx, but with extra meta data about the tx. Currently this metadata is the peer who sent it, used to prevent the tx from being gossiped back to them.
func (*Mempool) CloseWAL ¶
func (mem *Mempool) CloseWAL()
CloseWAL closes and discards the underlying WAL file. Any further writes will not be relayed to disk.
func (*Mempool) EnableTxsAvailable ¶
func (mem *Mempool) EnableTxsAvailable()
EnableTxsAvailable initializes the TxsAvailable channel, ensuring it will trigger once every height when transactions are available. NOTE: not thread safe - should only be called once, on startup
func (*Mempool) Flush ¶
func (mem *Mempool) Flush()
Flush removes all transactions from the mempool and cache
func (*Mempool) FlushAppConn ¶
FlushAppConn flushes the mempool connection to ensure async reqResCb calls are done. E.g. from CheckTx.
func (*Mempool) InitWAL ¶
func (mem *Mempool) InitWAL()
InitWAL creates a directory for the WAL file and opens a file itself.
*panics* if can't create directory or open file. *not thread safe*
func (*Mempool) Lock ¶
func (mem *Mempool) Lock()
Lock locks the mempool. The consensus must be able to hold lock to safely update.
func (*Mempool) ReapMaxBytesMaxGas ¶
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).
func (*Mempool) ReapMaxTxs ¶
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).
func (*Mempool) TxsAvailable ¶
func (mem *Mempool) TxsAvailable() <-chan struct{}
TxsAvailable returns a channel which fires once for every height, and only when transactions are available in the mempool. NOTE: the returned channel may be nil if EnableTxsAvailable was not called.
func (*Mempool) TxsFront ¶
TxsFront returns the first transaction in the ordered list for peer goroutines to call .NextWait() on.
func (*Mempool) TxsWaitChan ¶
func (mem *Mempool) TxsWaitChan() <-chan struct{}
TxsWaitChan returns a channel to wait on transactions. It will be closed once the mempool is not empty (ie. the internal `mem.txs` has at least one element)
func (*Mempool) Update ¶
func (mem *Mempool) Update( height int64, txs types.Txs, preCheck PreCheckFunc, postCheck PostCheckFunc, ) error
Update informs the mempool that the given txs were committed and can be discarded. NOTE: this should be called *after* block is committed by consensus. NOTE: unsafe; Lock/Unlock must be managed by caller
type MempoolMessage ¶
type MempoolMessage interface{}
MempoolMessage is a message sent or received by the MempoolReactor.
type MempoolOption ¶
type MempoolOption func(*Mempool)
MempoolOption sets an optional parameter on the Mempool.
func WithPostCheck ¶
func WithPostCheck(f PostCheckFunc) MempoolOption
WithPostCheck sets a filter for the mempool to reject a tx if f(tx) returns false. This is ran after CheckTx.
func WithPreCheck ¶
func WithPreCheck(f PreCheckFunc) MempoolOption
WithPreCheck sets a filter for the mempool to reject a tx if f(tx) returns false. This is ran before CheckTx.
type MempoolReactor ¶
type MempoolReactor struct { p2p.BaseReactor Mempool *Mempool // contains filtered or unexported fields }
MempoolReactor handles mempool tx broadcasting amongst peers. It maintains a map from peer ID to counter, to prevent gossiping txs to the peers you received it from.
func NewMempoolReactor ¶
func NewMempoolReactor(config *cfg.MempoolConfig, mempool *Mempool) *MempoolReactor
NewMempoolReactor returns a new MempoolReactor with the given config and mempool.
func (*MempoolReactor) AddPeer ¶
func (memR *MempoolReactor) AddPeer(peer p2p.Peer)
AddPeer implements Reactor. It starts a broadcast routine ensuring all txs are forwarded to the given peer.
func (*MempoolReactor) GetChannels ¶
func (memR *MempoolReactor) GetChannels() []*p2p.ChannelDescriptor
GetChannels implements Reactor. It returns the list of channels for this reactor.
func (*MempoolReactor) OnStart ¶
func (memR *MempoolReactor) OnStart() error
OnStart implements p2p.BaseReactor.
func (*MempoolReactor) Receive ¶
func (memR *MempoolReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
Receive implements Reactor. It adds any received transactions to the mempool.
func (*MempoolReactor) RemovePeer ¶
func (memR *MempoolReactor) RemovePeer(peer p2p.Peer, reason interface{})
RemovePeer implements Reactor.
func (*MempoolReactor) SetLogger ¶
func (memR *MempoolReactor) SetLogger(l log.Logger)
SetLogger sets the Logger on the reactor and the underlying Mempool.
type Metrics ¶
type Metrics struct { // Size of the mempool. Size metrics.Gauge // Histogram of transaction sizes, in bytes. TxSizeBytes metrics.Histogram // Number of failed transactions. FailedTxs metrics.Counter // Number of times transactions are rechecked in the mempool. RecheckTimes metrics.Counter }
Metrics contains metrics exposed by this package. see MetricsProvider for descriptions.
func PrometheusMetrics ¶
PrometheusMetrics returns Metrics build using Prometheus client library. Optionally, labels can be provided along with their values ("foo", "fooValue").
type PeerState ¶
type PeerState interface {
GetHeight() int64
}
PeerState describes the state of a peer.
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 ¶
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 PreCheckAminoMaxBytes ¶
func PreCheckAminoMaxBytes(maxBytes int64) PreCheckFunc
PreCheckAminoMaxBytes checks that the size of the transaction plus the amino overhead is smaller or equal to the expected maxBytes.