tendermint: github.com/tendermint/tendermint/mempool Index | Files

package mempool

import "github.com/tendermint/tendermint/mempool"

TODO: Better handle abci client errors. (make it automatically handle connection errors)

Index

Package Files

clist_mempool.go codec.go doc.go errors.go mempool.go metrics.go reactor.go

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")
)

func IsPreCheckError Uses

func IsPreCheckError(err error) bool

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

func RegisterMempoolMessages Uses

func RegisterMempoolMessages(cdc *amino.Codec)

type CListMempool Uses

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

CListMempool 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 NewCListMempool Uses

func NewCListMempool(
    config *cfg.MempoolConfig,
    proxyAppConn proxy.AppConnMempool,
    height int64,
    options ...CListMempoolOption,
) *CListMempool

NewCListMempool returns a new mempool with the given configuration and connection to an application.

func (*CListMempool) CheckTx Uses

func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error)

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 (*CListMempool) CheckTxWithInfo Uses

func (mem *CListMempool) CheckTxWithInfo(tx types.Tx, cb func(*abci.Response), txInfo TxInfo) (err error)

func (*CListMempool) CloseWAL Uses

func (mem *CListMempool) CloseWAL()

func (*CListMempool) EnableTxsAvailable Uses

func (mem *CListMempool) EnableTxsAvailable()

NOTE: not thread safe - should only be called once, on startup

func (*CListMempool) Flush Uses

func (mem *CListMempool) Flush()

func (*CListMempool) FlushAppConn Uses

func (mem *CListMempool) FlushAppConn() error

func (*CListMempool) InitWAL Uses

func (mem *CListMempool) InitWAL()

*panics* if can't create directory or open file. *not thread safe*

func (*CListMempool) Lock Uses

func (mem *CListMempool) Lock()

func (*CListMempool) ReapMaxBytesMaxGas Uses

func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs

func (*CListMempool) ReapMaxTxs Uses

func (mem *CListMempool) ReapMaxTxs(max int) types.Txs

func (*CListMempool) SetLogger Uses

func (mem *CListMempool) SetLogger(l log.Logger)

SetLogger sets the Logger.

func (*CListMempool) Size Uses

func (mem *CListMempool) Size() int

func (*CListMempool) TxsAvailable Uses

func (mem *CListMempool) TxsAvailable() <-chan struct{}

func (*CListMempool) TxsBytes Uses

func (mem *CListMempool) TxsBytes() int64

func (*CListMempool) TxsFront Uses

func (mem *CListMempool) TxsFront() *clist.CElement

TxsFront returns the first transaction in the ordered list for peer goroutines to call .NextWait() on. FIXME: leaking implementation details!

func (*CListMempool) TxsWaitChan Uses

func (mem *CListMempool) 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 (*CListMempool) Unlock Uses

func (mem *CListMempool) Unlock()

func (*CListMempool) Update Uses

func (mem *CListMempool) Update(
    height int64,
    txs types.Txs,
    deliverTxResponses []*abci.ResponseDeliverTx,
    preCheck PreCheckFunc,
    postCheck PostCheckFunc,
) error

type CListMempoolOption Uses

type CListMempoolOption func(*CListMempool)

CListMempoolOption sets an optional parameter on the mempool.

func WithMetrics Uses

func WithMetrics(metrics *Metrics) CListMempoolOption

WithMetrics sets the metrics.

func WithPostCheck Uses

func WithPostCheck(f PostCheckFunc) CListMempoolOption

WithPostCheck sets a filter for the mempool to reject a tx if f(tx) returns false. This is ran after CheckTx.

func WithPreCheck Uses

func WithPreCheck(f PreCheckFunc) CListMempoolOption

WithPreCheck sets a filter for the mempool to reject a tx if f(tx) returns false. This is ran before CheckTx.

type ErrMempoolIsFull Uses

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

ErrMempoolIsFull means Tendermint & an application can't handle that much load

func (ErrMempoolIsFull) Error Uses

func (e ErrMempoolIsFull) Error() string

type ErrPreCheck Uses

type ErrPreCheck struct {
    Reason error
}

ErrPreCheck is returned when tx is too big

func (ErrPreCheck) Error Uses

func (e ErrPreCheck) Error() string

type ErrTxTooLarge Uses

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

ErrTxTooLarge means the tx is too big to be sent in a message to other peers

func (ErrTxTooLarge) Error Uses

func (e ErrTxTooLarge) Error() string

type Mempool Uses

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)) 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.
    CheckTxWithInfo(tx types.Tx, callback func(*abci.Response), txInfo TxInfo) 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.
    Lock()

    // Unlock unlocks the mempool.
    Unlock()

    // 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
    Update(blockHeight int64, blockTxs types.Txs, deliverTxResponses []*abci.ResponseDeliverTx, newPreFn PreCheckFunc, newPostFn PostCheckFunc) error

    // FlushAppConn flushes the mempool connection to ensure async reqResCb calls are
    // done. E.g. from CheckTx.
    FlushAppConn() error

    // Flush removes all transactions from the mempool and cache
    Flush()

    // 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.
    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

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

    // InitWAL creates a directory for the WAL file and opens a file itself.
    InitWAL()

    // CloseWAL closes and discards the underlying WAL file.
    // Any further writes will not be relayed to disk.
    CloseWAL()
}

Mempool defines the mempool interface.

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

type MempoolMessage Uses

type MempoolMessage interface{}

MempoolMessage is a message sent or received by the Reactor.

type Metrics Uses

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 NopMetrics Uses

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics Uses

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

PrometheusMetrics returns Metrics build using Prometheus client library. Optionally, labels can be provided along with their values ("foo", "fooValue").

type PeerState Uses

type PeerState interface {
    GetHeight() int64
}

PeerState describes the state of a peer.

type PostCheckFunc Uses

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 Uses

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 Uses

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 PreCheckAminoMaxBytes Uses

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.

type Reactor Uses

type Reactor struct {
    p2p.BaseReactor
    // contains filtered or unexported fields
}

Reactor 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 NewReactor Uses

func NewReactor(config *cfg.MempoolConfig, mempool *CListMempool) *Reactor

NewReactor returns a new Reactor with the given config and mempool.

func (*Reactor) AddPeer Uses

func (memR *Reactor) AddPeer(peer p2p.Peer)

AddPeer implements Reactor. It starts a broadcast routine ensuring all txs are forwarded to the given peer.

func (*Reactor) GetChannels Uses

func (memR *Reactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor. It returns the list of channels for this reactor.

func (*Reactor) OnStart Uses

func (memR *Reactor) OnStart() error

OnStart implements p2p.BaseReactor.

func (*Reactor) Receive Uses

func (memR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)

Receive implements Reactor. It adds any received transactions to the mempool.

func (*Reactor) RemovePeer Uses

func (memR *Reactor) RemovePeer(peer p2p.Peer, reason interface{})

RemovePeer implements Reactor.

func (*Reactor) SetLogger Uses

func (memR *Reactor) SetLogger(l log.Logger)

SetLogger sets the Logger on the reactor and the underlying mempool.

type TxInfo Uses

type TxInfo struct {
    // We don't use p2p.ID here because it's too big. The gain is to store max 2
    // bytes with each tx to identify the sender rather than 20 bytes.
    SenderID uint16
}

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

type TxMessage Uses

type TxMessage struct {
    Tx types.Tx
}

TxMessage is a MempoolMessage containing a transaction.

func (*TxMessage) String Uses

func (m *TxMessage) String() string

String returns a string representation of the TxMessage.

Package mempool imports 24 packages (graph) and is imported by 14 packages. Updated 2019-09-10. Refresh now. Tools for package owners.