v0

package
v0.0.0-...-fb002f8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CListMempool

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

func NewCListMempool(
	cfg *config.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

func (mem *CListMempool) CheckTx(
	tx types.Tx,
	cb func(*abci.Response),
	txInfo mempool.TxInfo,
) 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.

Safe for concurrent use by multiple goroutines.

func (*CListMempool) EnableTxsAvailable

func (mem *CListMempool) EnableTxsAvailable()

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

func (*CListMempool) Flush

func (mem *CListMempool) Flush()

XXX: Unsafe! Calling Flush may leave mempool in inconsistent state.

func (*CListMempool) FlushAppConn

func (mem *CListMempool) FlushAppConn() error

Lock() must be help by the caller during execution.

func (*CListMempool) Lock

func (mem *CListMempool) Lock()

Safe for concurrent use by multiple goroutines.

func (*CListMempool) ReapMaxBytesMaxGas

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

Safe for concurrent use by multiple goroutines.

func (*CListMempool) ReapMaxTxs

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

Safe for concurrent use by multiple goroutines.

func (*CListMempool) RemoveTxByKey

func (mem *CListMempool) RemoveTxByKey(txKey types.TxKey) error

RemoveTxByKey removes a transaction from the mempool by its TxKey index.

func (*CListMempool) SetLogger

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

SetLogger sets the Logger.

func (*CListMempool) Size

func (mem *CListMempool) Size() int

Safe for concurrent use by multiple goroutines.

func (*CListMempool) SizeBytes

func (mem *CListMempool) SizeBytes() int64

Safe for concurrent use by multiple goroutines.

func (*CListMempool) TxsAvailable

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

Safe for concurrent use by multiple goroutines.

func (*CListMempool) TxsFront

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!

Safe for concurrent use by multiple goroutines.

func (*CListMempool) TxsWaitChan

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)

Safe for concurrent use by multiple goroutines.

func (*CListMempool) Unlock

func (mem *CListMempool) Unlock()

Safe for concurrent use by multiple goroutines.

func (*CListMempool) Update

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

Lock() must be help by the caller during execution.

type CListMempoolOption

type CListMempoolOption func(*CListMempool)

CListMempoolOption sets an optional parameter on the mempool.

func WithMetrics

func WithMetrics(metrics *mempool.Metrics) CListMempoolOption

WithMetrics sets the metrics.

func WithPostCheck

func WithPostCheck(f mempool.PostCheckFunc) CListMempoolOption

WithPostCheck sets a filter for the mempool to reject a tx if f(tx) returns false. This is ran after CheckTx. Only applies to the first created block. After that, Update overwrites the existing value.

func WithPreCheck

func WithPreCheck(f mempool.PreCheckFunc) CListMempoolOption

WithPreCheck sets a filter for the mempool to reject a tx if f(tx) returns false. This is ran before CheckTx. Only applies to the first created block. After that, Update overwrites the existing value.

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 *CListMempool) *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)

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

Jump to

Keyboard shortcuts

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