v1

package
v0.0.0-...-22ab5e0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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

func NewReactor(config *cfg.MempoolConfig, mempool *TxMempool, traceClient *trace.Client) *Reactor

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

func (*Reactor) AddPeer

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

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

GetChannels implements Reactor by returning the list of channels for this reactor.

func (*Reactor) InitPeer

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

InitPeer implements Reactor by creating a state for the peer.

func (*Reactor) OnStart

func (memR *Reactor) OnStart() error

OnStart implements p2p.BaseReactor.

func (*Reactor) Receive

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

func (*Reactor) ReceiveEnvelope

func (memR *Reactor) ReceiveEnvelope(e p2p.Envelope)

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

func (*Reactor) RemovePeer

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

RemovePeer implements Reactor.

func (*Reactor) SetLogger

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

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

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

func (txmp *TxMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo mempool.TxInfo) error

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

func (txmp *TxMempool) FlushAppConn() error

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

func (txmp *TxMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs

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

func (txmp *TxMempool) ReapMaxTxs(max int) types.Txs

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

func (txmp *TxMempool) RemoveTxByKey(txKey types.TxKey) error

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

func (txmp *TxMempool) Size() int

Size returns the number of valid transactions in the mempool. It is thread-safe.

func (*TxMempool) SizeBytes

func (txmp *TxMempool) SizeBytes() int64

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

func (txmp *TxMempool) TxsFront() *clist.CElement

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

type TxsMessage struct {
	Txs []types.Tx
}

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

func (w *WrappedTx) GasWanted() int64

GasWanted reports the application-assigned gas requirement of w.

func (*WrappedTx) HasPeer

func (w *WrappedTx) HasPeer(id uint16) bool

HasPeer reports whether the specified peer ID is a sender of w.

func (*WrappedTx) Priority

func (w *WrappedTx) Priority() int64

Priority reports the application-assigned priority of w.

func (*WrappedTx) Sender

func (w *WrappedTx) Sender() string

Sender reports the application-assigned sender of w.

func (*WrappedTx) SetGasWanted

func (w *WrappedTx) SetGasWanted(gas int64)

SetGasWanted sets the application-assigned gas requirement of w.

func (*WrappedTx) SetPeer

func (w *WrappedTx) SetPeer(id uint16)

SetPeer adds the specified peer ID as a sender of w.

func (*WrappedTx) SetPriority

func (w *WrappedTx) SetPriority(p int64)

SetPriority sets the application-assigned priority of w.

func (*WrappedTx) SetSender

func (w *WrappedTx) SetSender(sender string)

SetSender sets the application-assigned sender of w.

func (*WrappedTx) Size

func (w *WrappedTx) Size() int64

Size reports the size of the raw transaction in bytes.

Jump to

Keyboard shortcuts

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