mempool

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyExists transaction with the same txid already exists in mempool.
	ErrAlreadyExists = errors.New("already exists")
	// ErrAlreadyExistsInBlockchain transaction with the same txid already exists in blockchain.
	ErrAlreadyExistsInBlockchain = errors.New("already exists in blockchain")
	// ErrNullifierExists nullifier(s) already exists in the mempool state.
	ErrNullifierExists = errors.New("nullifier(s) already exists in the mempool")
)

Functions

This section is empty.

Types

type HashMap

type HashMap struct {

	// spent key images from the transactions in the pool
	// spentkeyImages map[keyImage]bool.
	Capacity uint32
	// contains filtered or unexported fields
}

HashMap represents a pool implementation based on golang map. The generic solution to bench against.

func (HashMap) Clone

func (m HashMap) Clone() []transactions.ContractCall

Clone the entire pool.

func (*HashMap) Close added in v0.4.4

func (m *HashMap) Close()

Close empty implementation of Pool.Close.

func (*HashMap) Contain added in v0.6.0

func (m *HashMap) Contain(txID []byte) bool

Contain returns true if the given key is in the pool.

func (*HashMap) ContainAnyNullifiers added in v0.6.0

func (m *HashMap) ContainAnyNullifiers(nullifiers [][]byte) (bool, []byte)

ContainAnyNullifiers implements Pool.ContainAnyNullifiers.

func (*HashMap) Create added in v0.4.4

func (m *HashMap) Create(path string) error

Create instantiates hashmap and sort index.

func (*HashMap) Delete added in v0.4.3

func (m *HashMap) Delete(txID []byte) error

Delete a key in the hashmap.

func (HashMap) FilterByType added in v0.3.0

func (m HashMap) FilterByType(filterType transactions.TxType) []transactions.ContractCall

FilterByType returns all transactions for a specific type that are currently in the HashMap.

func (*HashMap) Get added in v0.3.0

func (m *HashMap) Get(txID []byte) transactions.ContractCall

Get returns a tx for a given txID if it exists.

func (*HashMap) GetTxsByNullifier added in v0.6.0

func (m *HashMap) GetTxsByNullifier(nullifier []byte) ([][]byte, error)

GetTxsByNullifier implements Pool.GetTxsByNullifier. The implementation is naive and may need refactoring if it deals with large amount of transactions.

func (*HashMap) Len

func (m *HashMap) Len() int

Len returns the number of tx entries.

func (*HashMap) Put

func (m *HashMap) Put(t TxDesc) error

Put sets the value for the given key. It overwrites any previous value for that key.

func (*HashMap) Range

func (m *HashMap) Range(fn func(k txHash, t TxDesc) error) error

Range iterates through all tx entries.

func (*HashMap) RangeSort added in v0.2.0

func (m *HashMap) RangeSort(fn func(k txHash, t TxDesc) (bool, error)) error

RangeSort iterates through all tx entries sorted by Fee in a descending order.

func (*HashMap) Size

func (m *HashMap) Size() uint32

Size of the txs.

type Mempool

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

Mempool is a storage for the chain transactions that are valid according to the current chain state and can be included in the next block.

func NewMempool

func NewMempool(db database.DB, eventBus *eventbus.EventBus, rpcBus *rpcbus.RPCBus, verifier transactions.UnconfirmedTxProber) *Mempool

NewMempool instantiates and initializes node mempool.

func (*Mempool) Loop added in v0.4.4

func (m *Mempool) Loop(ctx context.Context)

Loop listens for GetMempoolTxs request and topics.AcceptedBlock events.

func (*Mempool) OnClose added in v0.4.4

func (m *Mempool) OnClose()

OnClose performs mempool cleanup procedure. It's called on canceling mempool context.

func (*Mempool) ProcessTx added in v0.4.0

func (m *Mempool) ProcessTx(srcPeerID string, msg message.Message) ([]bytes.Buffer, error)

ProcessTx processes a Transaction wire message.

func (*Mempool) RequestUpdates added in v0.6.0

func (m *Mempool) RequestUpdates()

RequestUpdates sends topics.MemPool to N Kadcast Network nodes.

func (*Mempool) Run

func (m *Mempool) Run(ctx context.Context)

Run spawns the mempool lifecycle routines.

type Pool

type Pool interface {
	// Create instantiates the underlying data storage.
	Create(path string) error
	// Put sets the value for the given key. It overwrites any previous value
	// for that key.
	Put(t TxDesc) error
	// Get retrieves a transaction for a given txID, if it exists.
	Get(txID []byte) transactions.ContractCall

	// GetTxsByNullifier returns a set of hashes of all transactions that
	// contain a given nullifier.
	GetTxsByNullifier(nullifier []byte) ([][]byte, error)

	// ContainAnyNullifiers returns true if any pool transaction contains any of
	// the given nullifiers.
	ContainAnyNullifiers(nullifiers [][]byte) (bool, []byte)

	// Contain returns true if the given key is in the pool.
	Contain(key []byte) bool
	// Delete a key in the pool.
	Delete(key []byte) error
	// Clone the entire pool.
	Clone() []transactions.ContractCall

	// FilterByType returns all verified transactions for a specific type.
	FilterByType(transactions.TxType) []transactions.ContractCall

	// Size is total number of bytes of all txs marshaling size.
	Size() uint32
	// Len returns the number of tx entries.
	Len() int

	// Range iterates through all tx entries.
	Range(fn func(k txHash, t TxDesc) error) error

	// RangeSort iterates through all tx entries sorted by Fee
	// in a descending order.
	RangeSort(fn func(k txHash, t TxDesc) (bool, error)) error

	// Close closes backend.
	Close()
}

Pool represents a transaction pool of the verified txs only.

type TxDesc

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

TxDesc encapsulates both tx raw and meta data.

Jump to

Keyboard shortcuts

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