txpool

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: GPL-3.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContainerFull is an error about a full container
	ErrContainerFull = fmt.Errorf("container is full")

	// ErrTxAlreadyAdded is an error about a transaction
	// that is in the pool.
	ErrTxAlreadyAdded = fmt.Errorf("exact transaction already in the pool")
)

Functions

This section is empty.

Types

type ContainerItem

type ContainerItem struct {
	Tx      types.Transaction
	FeeRate util.String
}

ContainerItem represents the a container item. It wraps a transaction and its related information

type TxContainer

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

TxContainer represents the internal container used by TxPool. It provides a Put operation with automatic sorting by fee rate and nonce. The container is thread-safe.

func NewQueueNoSort

func NewQueueNoSort(cap int64) *TxContainer

NewQueueNoSort creates a new container with sorting turned off

func (*TxContainer) Add

func (q *TxContainer) Add(tx types.Transaction) bool

Add adds a transaction to the end of the container. Returns false if container capacity has been reached. It computes the fee rate and sorts the transactions after addition.

func (*TxContainer) ByteSize

func (q *TxContainer) ByteSize() int64

ByteSize gets the total byte size of all transactions in the container

func (*TxContainer) First

func (q *TxContainer) First() types.Transaction

First returns a single transaction at head. Returns nil if container is empty

func (*TxContainer) Full

func (q *TxContainer) Full() bool

Full checks if the container's capacity has been reached

func (*TxContainer) Has

func (q *TxContainer) Has(tx types.Transaction) bool

Has checks whether a transaction is in the container

func (*TxContainer) HasByHash

func (q *TxContainer) HasByHash(hash string) bool

HasByHash is like Has but accepts a transaction hash

func (*TxContainer) IFind

func (q *TxContainer) IFind(predicate func(types.Transaction) bool) types.Transaction

IFind iterates over the transactions and passes each to the predicate function. When the predicate returns true, it stops and returns the last transaction that was passed to the predicate.

Do not modify the transaction in the predicate as it is a pointer to the transaction in container.

func (*TxContainer) Last

func (q *TxContainer) Last() types.Transaction

Last returns a single transaction at head. Returns nil if container is empty

func (*TxContainer) Remove

func (q *TxContainer) Remove(txs ...types.Transaction)

Remove removes a transaction

func (*TxContainer) Size

func (q *TxContainer) Size() int64

Size returns the number of items in the container

func (*TxContainer) Sort

func (q *TxContainer) Sort()

Sort sorts the container

type TxPool

type TxPool struct {
	sync.RWMutex // general mutex
	// contains filtered or unexported fields
}

TxPool defines a structure and functionalities of a transaction pool which is responsible for collecting, validating and providing processed transactions for block inclusion and propagation.

func New

func New(cap int64) *TxPool

New creates a new instance of TxPool Cap size is the max amount of transactions we can have in the queue at any given time. If it is full, transactions will be dropped.

func (*TxPool) ByteSize

func (tp *TxPool) ByteSize() int64

ByteSize gets the total byte size of all transactions in the pool

func (*TxPool) Container

func (tp *TxPool) Container() types.TxContainer

Container gets the underlying transaction container

func (*TxPool) Has

func (tp *TxPool) Has(tx types.Transaction) bool

Has checks whether a transaction is in the pool

func (*TxPool) HasByHash

func (tp *TxPool) HasByHash(hash string) bool

HasByHash is like Has but accepts a hash

func (*TxPool) Put

func (tp *TxPool) Put(tx types.Transaction) error

Put adds a transaction

func (*TxPool) PutSilently

func (tp *TxPool) PutSilently(tx types.Transaction) error

PutSilently is like Put but it does not emit an event on success.

func (*TxPool) SenderHasTxWithSameNonce

func (tp *TxPool) SenderHasTxWithSameNonce(address util.String, nonce uint64) bool

SenderHasTxWithSameNonce checks whether a transaction with a matching sender address and nonce exist in the pool

func (*TxPool) SetEventEmitter

func (tp *TxPool) SetEventEmitter(ee *emitter.Emitter)

SetEventEmitter sets the event emitter

func (*TxPool) Size

func (tp *TxPool) Size() int64

Size gets the total number of transactions in the pool

Jump to

Keyboard shortcuts

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