Documentation ¶
Index ¶
- Constants
- Variables
- type LRUTxCache
- type PeerState
- type Reactor
- func (memR *Reactor) GetChannels() []*p2p.ChannelDescriptor
- func (memR *Reactor) InitPeer(peer p2p.Peer) p2p.Peer
- func (memR *Reactor) OnStart() error
- func (memR *Reactor) OnStop()
- 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 ReactorOptions
- type SeenTxSet
- func (s *SeenTxSet) Add(txKey types.TxKey, peer uint16)
- func (s *SeenTxSet) Get(txKey types.TxKey) map[uint16]struct{}
- func (s *SeenTxSet) Has(txKey types.TxKey, peer uint16) bool
- func (s *SeenTxSet) Len() int
- func (s *SeenTxSet) Prune(limit time.Time)
- func (s *SeenTxSet) Remove(txKey types.TxKey, peer uint16)
- func (s *SeenTxSet) RemoveKey(txKey types.TxKey)
- func (s *SeenTxSet) RemovePeer(peer uint16)
- func (s *SeenTxSet) Reset()
- type TxPool
- func (txmp *TxPool) CheckToPurgeExpiredTxs()
- func (txmp *TxPool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo mempool.TxInfo) error
- func (txmp *TxPool) EnableTxsAvailable()
- func (txmp *TxPool) Flush()
- func (txmp *TxPool) FlushAppConn() error
- func (txmp *TxPool) Get(txKey types.TxKey) (types.Tx, bool)
- func (txmp *TxPool) Has(txKey types.TxKey) bool
- func (txmp *TxPool) Height() int64
- func (txmp *TxPool) IsRejectedTx(txKey types.TxKey) bool
- func (txmp *TxPool) Lock()
- func (txmp *TxPool) PeerHasTx(peer uint16, txKey types.TxKey)
- func (txmp *TxPool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
- func (txmp *TxPool) ReapMaxTxs(max int) types.Txs
- func (txmp *TxPool) RemoveTxByKey(txKey types.TxKey) error
- func (txmp *TxPool) Size() int
- func (txmp *TxPool) SizeBytes() int64
- func (txmp *TxPool) TryAddNewTx(tx types.Tx, key types.TxKey, txInfo mempool.TxInfo) (*abci.ResponseCheckTx, error)
- func (txmp *TxPool) TxsAvailable() <-chan struct{}
- func (txmp *TxPool) Unlock()
- func (txmp *TxPool) Update(blockHeight int64, blockTxs types.Txs, ...) error
- type TxPoolOption
Constants ¶
const ( // default duration to wait before considering a peer non-responsive // and searching for the tx from a new peer DefaultGossipDelay = 200 * time.Millisecond // Content Addressable Tx Pool gossips state based messages (SeenTx and WantTx) on a separate channel // for cross compatibility MempoolStateChannel = byte(0x31) )
Variables ¶
var ( ErrTxInMempool = errors.New("tx already exists in mempool") ErrTxAlreadyRejected = errors.New("tx was previously rejected") )
Functions ¶
This section is empty.
Types ¶
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. NOTE: This has been copied from mempool/cache with the main difference of using tx keys instead of raw transactions.
func NewLRUTxCache ¶
func NewLRUTxCache(cacheSize int) *LRUTxCache
func (*LRUTxCache) Remove ¶
func (c *LRUTxCache) Remove(txKey types.TxKey)
func (*LRUTxCache) Reset ¶
func (c *LRUTxCache) Reset()
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 logic amongst peers. For the main logic behind the protocol, refer to `ReceiveEnvelope` or to the english spec under /.spec.md
func NewReactor ¶
func NewReactor(mempool *TxPool, opts *ReactorOptions) (*Reactor, error)
NewReactor returns a new Reactor with the given config and mempool.
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 processes one of three messages: Txs, SeenTx, WantTx.
func (*Reactor) RemovePeer ¶
RemovePeer implements Reactor. For all current outbound requests to this peer it will find a new peer to rerequest the same transactions.
type ReactorOptions ¶
type ReactorOptions struct { // ListenOnly means that the node will never broadcast any of the transactions that // it receives. This is useful for keeping transactions private ListenOnly bool // MaxTxSize is the maximum size of a transaction that can be received MaxTxSize int // MaxGossipDelay is the maximum allotted time that the reactor expects a transaction to // arrive before issuing a new request to a different peer MaxGossipDelay time.Duration // TraceClient is the trace client for collecting trace level events TraceClient *trace.Client }
func (*ReactorOptions) VerifyAndComplete ¶
func (opts *ReactorOptions) VerifyAndComplete() error
type SeenTxSet ¶
type SeenTxSet struct {
// contains filtered or unexported fields
}
SeenTxSet records transactions that have been seen by other peers but not yet by us
func NewSeenTxSet ¶
func NewSeenTxSet() *SeenTxSet
func (*SeenTxSet) RemovePeer ¶
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool 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 first. Transactions themselves are unordered (A map is used). They can be broadcast in an order different from the order to which transactions are entered. There is no guarantee when CheckTx passes that a transaction has been successfully broadcast to any of its peers.
A TTL can be set to remove transactions after a period of time or a number of heights.
A cache of rejectedTxs can be set in the mempool config. Transactions that are rejected because of `CheckTx` or other validity checks will be instantly rejected if they are seen again. Committed transactions are also added to this cache. This serves somewhat as replay protection but applications should implement something more comprehensive
func NewTxPool ¶
func NewTxPool( logger log.Logger, cfg *config.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64, options ...TxPoolOption, ) *TxPool
NewTxPool constructs a new, empty content addressable txpool at the specified initial height and using the given config and options.
func (*TxPool) CheckToPurgeExpiredTxs ¶
func (txmp *TxPool) 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 (*TxPool) CheckTx ¶
CheckTx adds the given transaction to the mempool if it fits and passes the application's ABCI CheckTx method. This should be viewed as the entry method for new transactions into the network. In practice this happens via an RPC endpoint
func (*TxPool) EnableTxsAvailable ¶
func (txmp *TxPool) EnableTxsAvailable()
EnableTxsAvailable enables the mempool to trigger events when transactions are available on a block by block basis.
func (*TxPool) Flush ¶
func (txmp *TxPool) Flush()
Flush purges the contents of the mempool and the cache, leaving both empty. The current height is not modified by this operation.
func (*TxPool) 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 (*TxPool) Get ¶
Get retrieves a transaction based on the key. It returns a bool if the transaction exists or not
func (*TxPool) IsRejectedTx ¶
IsRejectedTx returns true if the transaction was recently rejected and is currently within the cache
func (*TxPool) 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 (*TxPool) 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 (*TxPool) RemoveTxByKey ¶
RemoveTxByKey removes the transaction with the specified key from the mempool. It adds it to the rejectedTxCache so it will not be added again
func (*TxPool) Size ¶
Size returns the number of valid transactions in the mempool. It is thread-safe.
func (*TxPool) SizeBytes ¶
SizeBytes returns the total sum in bytes of all the valid transactions in the mempool. It is thread-safe.
func (*TxPool) TryAddNewTx ¶
func (txmp *TxPool) TryAddNewTx(tx types.Tx, key types.TxKey, txInfo mempool.TxInfo) (*abci.ResponseCheckTx, error)
TryAddNewTx attempts to add a tx that has not already been seen before. It first marks it as seen to avoid races with the same tx. It then call `CheckTx` so that the application can validate it. If it passes `CheckTx`, the new transaction is added to the mempool as long as it has sufficient priority and space else if evicted it will return an error
func (*TxPool) TxsAvailable ¶
func (txmp *TxPool) 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 (*TxPool) Update ¶
func (txmp *TxPool) 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 TxPoolOption ¶
type TxPoolOption func(*TxPool)
TxPoolOption sets an optional parameter on the TxPool.
func WithMetrics ¶
func WithMetrics(metrics *mempool.Metrics) TxPoolOption
WithMetrics sets the mempool's metrics collector.
func WithPostCheck ¶
func WithPostCheck(f mempool.PostCheckFunc) TxPoolOption
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) TxPoolOption
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.