cat

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: 22 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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) Has

func (c *LRUTxCache) Has(txKey types.TxKey) bool

func (*LRUTxCache) Push

func (c *LRUTxCache) Push(txKey types.TxKey) bool

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) 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 Service.

func (*Reactor) OnStop

func (memR *Reactor) OnStop()

OnStop implements Service

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 processes one of three messages: Txs, SeenTx, WantTx.

func (*Reactor) RemovePeer

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

RemovePeer implements Reactor. For all current outbound requests to this peer it will find a new peer to rerequest the same transactions.

func (*Reactor) SetLogger

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

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

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

func (s *SeenTxSet) Add(txKey types.TxKey, peer uint16)

func (*SeenTxSet) Get

func (s *SeenTxSet) Get(txKey types.TxKey) map[uint16]struct{}

func (*SeenTxSet) Has

func (s *SeenTxSet) Has(txKey types.TxKey, peer uint16) bool

func (*SeenTxSet) Len

func (s *SeenTxSet) Len() int

Len returns the amount of cached items. Mostly used for testing.

func (*SeenTxSet) Prune

func (s *SeenTxSet) Prune(limit time.Time)

func (*SeenTxSet) Remove

func (s *SeenTxSet) Remove(txKey types.TxKey, peer uint16)

func (*SeenTxSet) RemoveKey

func (s *SeenTxSet) RemoveKey(txKey types.TxKey)

func (*SeenTxSet) RemovePeer

func (s *SeenTxSet) RemovePeer(peer uint16)

func (*SeenTxSet) Reset

func (s *SeenTxSet) Reset()

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

func (txmp *TxPool) 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. 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

func (txmp *TxPool) 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 (*TxPool) Get

func (txmp *TxPool) Get(txKey types.TxKey) (types.Tx, bool)

Get retrieves a transaction based on the key. It returns a bool if the transaction exists or not

func (*TxPool) Has

func (txmp *TxPool) Has(txKey types.TxKey) bool

Has returns true if the transaction is currently in the mempool

func (*TxPool) Height

func (txmp *TxPool) Height() int64

Height returns the latest height that the mempool is at

func (*TxPool) IsRejectedTx

func (txmp *TxPool) IsRejectedTx(txKey types.TxKey) bool

IsRejectedTx returns true if the transaction was recently rejected and is currently within the cache

func (*TxPool) Lock

func (txmp *TxPool) Lock()

Lock is a noop as ABCI calls are serialized

func (*TxPool) PeerHasTx

func (txmp *TxPool) PeerHasTx(peer uint16, txKey types.TxKey)

PeerHasTx marks that the transaction has been seen by a peer.

func (*TxPool) ReapMaxBytesMaxGas

func (txmp *TxPool) 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 (*TxPool) ReapMaxTxs

func (txmp *TxPool) 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 (*TxPool) RemoveTxByKey

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

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

func (txmp *TxPool) Size() int

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

func (*TxPool) SizeBytes

func (txmp *TxPool) SizeBytes() int64

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

func (txmp *TxPool) Unlock()

Unlock is a noop as ABCI calls are serialized

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.

Jump to

Keyboard shortcuts

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