mempool

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DuplicateTxError = MempoolError("Transaction already seen")
View Source
const FastsyncSkipTxError = MempoolError("Skip tx during fastsync")
View Source
const MaxMempoolTxCount int = 25600

Variables

This section is empty.

Functions

func Fuzz

func Fuzz(data []byte) int

Types

type Mempool

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

Mempool manages the transactions submitted by the clients or relayed from peers

func CreateMempool

func CreateMempool(dispatcher *dp.Dispatcher, engine *consensus.ConsensusEngine) *Mempool

CreateMempool creates an instance of Mempool

func (*Mempool) BroadcastTx

func (mp *Mempool) BroadcastTx(tx common.Bytes)

BroadcastTx broadcast given raw transaction to the network

func (*Mempool) BroadcastTxUnsafe

func (mp *Mempool) BroadcastTxUnsafe(tx common.Bytes)

BroadcastTxUnsafe is the non-locking version of BroadcastTx

func (*Mempool) Flush

func (mp *Mempool) Flush()

Flush removes all transactions from the Mempool and the transactionBookkeeper

func (*Mempool) GetCandidateTransactionHashes

func (mp *Mempool) GetCandidateTransactionHashes() []string

GetCandidateTransactions returns all the currently candidate transactions

func (*Mempool) GetTransactionStatus

func (mp *Mempool) GetTransactionStatus(hash string) (TxStatus, bool)

func (*Mempool) InsertTransaction

func (mp *Mempool) InsertTransaction(rawTx common.Bytes) error

InsertTransaction inserts the incoming transaction to mempool (submitted by the clients or relayed from peers)

func (*Mempool) Lock

func (mp *Mempool) Lock()

Lock is for the caller to lock/unlock the Mempool and perform safely update

func (*Mempool) Reap

func (mp *Mempool) Reap(maxNumTxs int) []common.Bytes

Reap returns a list of valid raw transactions and remove these transactions from the candidate pool. maxNumTxs == 0 means none, maxNumTxs < 0 means uncapped. Note that Reap does NOT remove the transactions from the candidateTxs list. Instead, the consensus engine needs to call the Mempool.Update() function to remove the committed transactions RUNTIME COMPLEXITY: k*log(n), where k is the number transactions to reap, and n is the number of transactions in the candidate pool.

func (*Mempool) ReapUnsafe

func (mp *Mempool) ReapUnsafe(maxNumTxs int) []common.Bytes

ReapUnsafe is the non-locking version of Reap.

func (*Mempool) SetLedger

func (mp *Mempool) SetLedger(ledger core.Ledger)

SetLedger sets the ledger for the mempool

func (*Mempool) Size

func (mp *Mempool) Size() int

Size returns the number of transactions in the Mempool

func (*Mempool) Start

func (mp *Mempool) Start(ctx context.Context) error

Start needs to be called when the Mempool starts

func (*Mempool) Stop

func (mp *Mempool) Stop()

Stop needs to be called when the Mempool stops

func (*Mempool) Unlock

func (mp *Mempool) Unlock()

Unlock is for the caller to lock/unlock the Mempool and perform safely update

func (*Mempool) Update

func (mp *Mempool) Update(committedRawTxs []common.Bytes)

Update removes the committed transactions from the transaction candidate list RUNTIME COMPLEXITY: O(k + n), where k is the number committed raw transactions, and n is the number of transactions in the candidate pool.

func (*Mempool) UpdateUnsafe

func (mp *Mempool) UpdateUnsafe(committedRawTxs []common.Bytes)

UpdateUnsafe is the non-locking version of Update. Caller must call Mempool.Lock() before calling this method.

func (*Mempool) Wait

func (mp *Mempool) Wait()

Wait suspends the caller goroutine

type MempoolError

type MempoolError string

func (MempoolError) Error

func (m MempoolError) Error() string

type MempoolMessageHandler

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

MempoolMessageHandler handles the messages received over the ChannelIDTransaction channel

func CreateMempoolMessageHandler

func CreateMempoolMessageHandler(mempool *Mempool) *MempoolMessageHandler

CreateMempoolMessageHandler create an instance of the MempoolMessageHandler

func (*MempoolMessageHandler) EncodeMessage

func (mmh *MempoolMessageHandler) EncodeMessage(message interface{}) (common.Bytes, error)

EncodeMessage implements the p2p.MessageHandler interface

func (*MempoolMessageHandler) GetChannelIDs

func (mmh *MempoolMessageHandler) GetChannelIDs() []common.ChannelIDEnum

GetChannelIDs implements the p2p.MessageHandler interface

func (*MempoolMessageHandler) HandleMessage

func (mmh *MempoolMessageHandler) HandleMessage(message types.Message) error

HandleMessage implements the p2p.MessageHandler interface

func (*MempoolMessageHandler) ParseMessage

func (mmh *MempoolMessageHandler) ParseMessage(peerID string, channelID common.ChannelIDEnum, rawMessageBytes common.Bytes) (types.Message, error)

ParseMessage implements the p2p.MessageHandler interface

type TxRecord

type TxRecord struct {
	Hash      string
	Status    TxStatus
	CreatedAt time.Time
}

func (*TxRecord) IsOutdated

func (r *TxRecord) IsOutdated() bool

type TxStatus

type TxStatus int
const (
	TxStatusPending TxStatus = iota
	TxStatusAbandoned
)

Jump to

Keyboard shortcuts

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