Documentation ¶
Index ¶
- type PeerState
- type Reactor
- func (memR *Reactor) AddPeer(peer p2p.Peer)
- func (memR *Reactor) GetChannels() []*p2p.ChannelDescriptor
- func (memR *Reactor) InitPeer(peer p2p.Peer) p2p.Peer
- func (memR *Reactor) OnStart() error
- func (memR *Reactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte)
- func (memR *Reactor) ReceiveEnvelope(e p2p.Envelope)
- func (memR *Reactor) RemovePeer(peer p2p.Peer, reason interface{})
- func (memR *Reactor) SetLogger(l log.Logger)
- type TxMempool
- func (txmp *TxMempool) CheckToPurgeExpiredTxs()
- func (txmp *TxMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo mempool.TxInfo) error
- func (txmp *TxMempool) EnableTxsAvailable()
- func (txmp *TxMempool) Flush()
- func (txmp *TxMempool) FlushAppConn() error
- func (txmp *TxMempool) Lock()
- func (txmp *TxMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
- func (txmp *TxMempool) ReapMaxTxs(max int) types.Txs
- func (txmp *TxMempool) RemoveTxByKey(txKey types.TxKey) error
- func (txmp *TxMempool) Size() int
- func (txmp *TxMempool) SizeBytes() int64
- func (txmp *TxMempool) TxsAvailable() <-chan struct{}
- func (txmp *TxMempool) TxsFront() *clist.CElement
- func (txmp *TxMempool) TxsWaitChan() <-chan struct{}
- func (txmp *TxMempool) Unlock()
- func (txmp *TxMempool) Update(blockHeight int64, blockTxs types.Txs, ...) error
- type TxMempoolOption
- type TxsMessage
- type WrappedTx
- func (w *WrappedTx) GasWanted() int64
- func (w *WrappedTx) HasPeer(id uint16) bool
- func (w *WrappedTx) Priority() int64
- func (w *WrappedTx) Sender() string
- func (w *WrappedTx) SetGasWanted(gas int64)
- func (w *WrappedTx) SetPeer(id uint16)
- func (w *WrappedTx) SetPriority(p int64)
- func (w *WrappedTx) SetSender(sender string)
- func (w *WrappedTx) Size() int64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PeerState ¶
type PeerState interface {
GetHeight() int64
}
PeerState describes the state of a peer.
type Reactor ¶
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 ¶
NewReactor returns a new Reactor with the given config and mempool.
func (*Reactor) AddPeer ¶
AddPeer implements Reactor. It starts a broadcast routine ensuring all txs are forwarded to the given peer.
func (*Reactor) GetChannels ¶
func (memR *Reactor) GetChannels() []*p2p.ChannelDescriptor
GetChannels implements Reactor by returning the list of channels for this reactor.
func (*Reactor) ReceiveEnvelope ¶
ReceiveEnvelope implements Reactor. It adds any received transactions to the mempool.
func (*Reactor) RemovePeer ¶
RemovePeer implements Reactor.
type TxMempool ¶
type TxMempool struct {
// contains filtered or unexported fields
}
TxMempool implements 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) CheckToPurgeExpiredTxs ¶
func (txmp *TxMempool) CheckToPurgeExpiredTxs()
CheckToPurgeExpiredTxs checks if there has been adequate time since the last time the txpool looped through all transactions and if so, performs a purge of any transaction that has expired according to the TTLDuration. This is thread safe.
func (*TxMempool) CheckTx ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Size returns the number of valid transactions in the mempool. It is thread-safe.
func (*TxMempool) SizeBytes ¶
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 ¶
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.
func WithTraceClient ¶
func WithTraceClient(tc *trace.Client) TxMempoolOption
type TxsMessage ¶
TxsMessage is a Message containing transactions.
func (*TxsMessage) String ¶
func (m *TxsMessage) String() string
String returns a string representation of the TxsMessage.
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) SetGasWanted ¶
SetGasWanted sets the application-assigned gas requirement of w.
func (*WrappedTx) SetPriority ¶
SetPriority sets the application-assigned priority of w.