mempool

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BasicCheck = true
	StateCheck = false
)

BasicCheck for check signature in checkTX

View Source
const (
	//MempoolChannel ID
	MempoolChannel = byte(0x30)

	ReceiveCacheMaxLength = 10000 // Max Length of Receive
)

Variables

View Source
var (
	// GoodTxRebroadcastTime determines when to rebroadcast goodTx
	GoodTxRebroadcastTime = 30 * time.Second
	// GoodTxDropTime determines when to drop goodTx
	GoodTxDropTime = 60 * time.Second
)
View Source
var (
	// BroadcastTxFunc is called when we broadcast tx
	BroadcastTxFunc = defaultBroadcastTx
)
View Source
var ErrTxNotATransaction = fmt.Errorf("tx is not a transaction")

ErrTxNotATransaction ...

View Source
var (
	HandleReceiveMsgFunc = defaultHandReceiveMsg
)

Functions

func RegisterMempoolMessages

func RegisterMempoolMessages()

Types

type App

type App interface {
	GetNonce(addr common.Address) uint64
	GetBalance(addr common.Address) *big.Int
	CheckTx(tx types.Tx, checkType bool) error
}

type MemFunc

type MemFunc func(*Mempool)

MemFunc sets an optional parameter on the Mempool.

func WithMetrics

func WithMetrics(metrics *Metrics) MemFunc

WithMetrics sets the metrics.

type Mempool

type Mempool struct {
	// contains filtered or unexported fields
}

Mempool 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 NewMempool

func NewMempool(config *cfg.MempoolConfig, height uint64, sw p2p.P2PManager, options ...MemFunc) *Mempool

NewMempool returns a new Mempool with the given configuration and height.

func (*Mempool) AddTx

func (mem *Mempool) AddTx(peerID string, tx types.Tx) (err error)

AddTx add good txs in a concurrent linked-list @Note: Caller should print the error log

func (*Mempool) EnableTxsAvailable

func (mem *Mempool) EnableTxsAvailable()

EnableTxsAvailable initializes the TxsAvailable channel, ensuring it will trigger once every height when transactions are available. NOTE: not thread safe - should only be called once, on startup

func (*Mempool) GetTxFromCache added in v0.1.1

func (mem *Mempool) GetTxFromCache(hash common.Hash) types.Tx

GetTxFromCache ...

func (*Mempool) GoodTxsSize

func (mem *Mempool) GoodTxsSize() int

GoodTxsSize returns goodTxs list length.

func (*Mempool) KeyImageExists

func (m *Mempool) KeyImageExists(key lktypes.Key) bool

func (*Mempool) KeyImagePush

func (m *Mempool) KeyImagePush(key lktypes.Key) bool

func (*Mempool) KeyImageRemove

func (m *Mempool) KeyImageRemove(key lktypes.Key)

func (*Mempool) KeyImageRemoveKeys

func (m *Mempool) KeyImageRemoveKeys(keys []*lktypes.Key)

func (*Mempool) KeyImageReset

func (m *Mempool) KeyImageReset()

-------UTXO----------

func (*Mempool) Lock

func (mem *Mempool) Lock()

Lock locks the mempool. The consensus must be able to hold lock to safely update.

func (*Mempool) Reap

func (mem *Mempool) Reap(maxTxs int) types.Txs

Reap returns a list of transactions currently in the mempool. If maxTxs is -1, there is no cap on the number of returned transactions.

func (*Mempool) SetApp

func (mem *Mempool) SetApp(a App)

SetApp set application handle

func (*Mempool) SetLogger

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

SetLogger sets the Logger.

func (*Mempool) SetReceiveP2pTx

func (mem *Mempool) SetReceiveP2pTx(on bool)

SetReceiveP2pTx ...

func (*Mempool) SpecGoodTxsSize

func (mem *Mempool) SpecGoodTxsSize() int

SpecGoodTxsSize returns specGoodList length.

func (*Mempool) Stats

func (mem *Mempool) Stats() (int, int, int)

Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.

func (*Mempool) Stop

func (mem *Mempool) Stop()

Stop ...

func (*Mempool) TxsAvailable

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

TxsAvailable returns a channel which fires once for every height, and only when transactions are available in the mempool. NOTE: the returned channel may be nil if EnableTxsAvailable was not called.

func (*Mempool) UTXOTxsSize added in v0.1.1

func (mem *Mempool) UTXOTxsSize() int

UTXOTxsSize return pure utxoTxs list length.

func (*Mempool) Unlock

func (mem *Mempool) Unlock()

Unlock unlocks the mempool.

func (*Mempool) Update

func (mem *Mempool) Update(height uint64, txs types.Txs) error

Update informs the mempool that the given txs were committed and can be discarded. NOTE: this should be called *after* block is committed by consensus. NOTE: unsafe; Lock/Unlock must be managed by caller

type MempoolMessage

type MempoolMessage interface{}

MempoolMessage is a message sent or received by the MempoolReactor.

type MempoolReactor

type MempoolReactor struct {
	p2p.BaseReactor

	Mempool *Mempool
	// contains filtered or unexported fields
}

MempoolReactor handles mempool tx broadcasting amongst peers.

func NewMempoolReactor

func NewMempoolReactor(config *cfg.MempoolConfig, mempool *Mempool) *MempoolReactor

NewMempoolReactor returns a new MempoolReactor with the given config and mempool.

func (*MempoolReactor) AddPeer

func (memR *MempoolReactor) AddPeer(peer p2p.Peer)

AddPeer implements Reactor. It starts a broadcast routine ensuring all txs are forwarded to the given peer.

func (*MempoolReactor) GetChannels

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

GetChannels implements Reactor. It returns the list of channels for this reactor.

func (*MempoolReactor) GetMutilSignCache

func (memR *MempoolReactor) GetMutilSignCache() *clist.CList

func (*MempoolReactor) GetRecvCache

func (memR *MempoolReactor) GetRecvCache() *clist.CList

func (*MempoolReactor) OnStart

func (memR *MempoolReactor) OnStart() error

OnStart implements p2p.BaseReactor.

func (*MempoolReactor) Receive

func (memR *MempoolReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)

Receive implements Reactor. It adds any received transactions to the cache.

func (*MempoolReactor) RemovePeer

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

RemovePeer implements Reactor.

func (*MempoolReactor) SetLogger

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

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

type Metrics

type Metrics struct {
	// Size of the mempool.
	Size metrics.Gauge
}

Metrics contains metrics exposed by this package. see MetricsProvider for descriptions.

func NopMetrics

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics

func PrometheusMetrics() *Metrics

PrometheusMetrics returns Metrics build using Prometheus client library.

type PeerState

type PeerState interface {
	GetHeight() uint64
}

PeerState describes the state of a peer.

type RecieveMessage

type RecieveMessage struct {
	PeerID string
	Tx     types.Tx
}

type TxHashMessage added in v0.1.1

type TxHashMessage struct {
	Hashs []common.Hash
	Kind  TxHashMessageKind
}

TxHashMessage --

func (TxHashMessage) String added in v0.1.1

func (m TxHashMessage) String() string

type TxHashMessageKind added in v0.1.1

type TxHashMessageKind int
const (
	TxHashNotify TxHashMessageKind
	TxHashRequest
)

type TxMessage

type TxMessage struct {
	Tx types.Tx
}

TxMessage is a MempoolMessage containing a transaction.

func (TxMessage) String

func (m TxMessage) String() string

String returns a string representation of the TxMessage.

Jump to

Keyboard shortcuts

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