pool

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

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 container.
	ErrTxAlreadyAdded = fmt.Errorf("exact transaction already in the pool")

	// ErrSenderTxLimitReached is an error about a sender reaching the container's tx limit per sender
	ErrSenderTxLimitReached = fmt.Errorf("sender's pool transaction limit reached")

	// ErrFailedReplaceByFee means an attempt to replace by fee failed due to the replacement
	// tx having a lower/equal fee to the current
	ErrFailedReplaceByFee = fmt.Errorf("an existing transaction by " +
		"same sender and at same nonce exist in the mempool. To replace the " +
		"existing transaction, the new transaction fee must be higher")
)

Functions

This section is empty.

Types

type Cache

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

Cache describes a queue for transactions

func NewCache

func NewCache() *Cache

NewCache creates an instance of Cache

func (*Cache) Add

func (c *Cache) Add(tx types.BaseTx) error

Add adds a tx. Returns true if the tx was added to the cache. Returns false:

  • If there is an existing transaction from same sender and nonce exists.
  • If the transaction has spent more than MempoolTxTTL in the cache.

func (*Cache) Get

func (c *Cache) Get() types.BaseTx

Get returns a tx from the cache

func (*Cache) Has

func (c *Cache) Has(tx types.BaseTx) bool

Has checks if a tx with matching sender address and nonce exist in the cache

func (*Cache) Size

func (c *Cache) Size() int

Size returns the size of the cache

func (*Cache) SizeByAddr

func (c *Cache) SizeByAddr(addr identifier.Address) int

SizeByAddr returns the number of transactions signed by a given address

type Container

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

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

func NewContainer

func NewContainer(cap int, bus *emitter.Emitter, getNonce NonceGetterFunc) *Container

NewContainer creates a new Container

func NewTxContainerNoSort

func NewTxContainerNoSort(cap int, bus *emitter.Emitter, getNonce NonceGetterFunc) *Container

NewTxContainerNoSort creates a new container with sorting turned off

func (*Container) Add

func (c *Container) Add(tx types.BaseTx) (bool, error)

Add adds a transaction to the container.

After addition:

  • The pool is sorted (if sorting is enabled).
  • EvtMempoolTxAdded is fired.
  • Expired txs are removed from the container.

Returns true and nil if tx was added to the container. Returns false and nil if tx was added to the cache. Returns error if there was a problem with the tx.

func (*Container) ByteSize

func (c *Container) ByteSize() int64

ByteSize gets the total byte size of all transactions in the container. Note: The size of fee field of transactions are not calculated.

func (*Container) CacheSize

func (c *Container) CacheSize() int

CacheSize returns the size of the cache

func (*Container) First

func (c *Container) First() types.BaseTx

First returns the transaction at the head of the container. Returns nil if container is empty

func (*Container) Flush

func (c *Container) Flush()

Flush clears the container and caches

func (*Container) Full

func (c *Container) Full() bool

Full checks if the container's capacity has been reached

func (*Container) Get

func (c *Container) Get(index int) *containerItem

Get returns a transaction at the given index

func (*Container) GetByHash

func (c *Container) GetByHash(hash string) types.BaseTx

GetByHash get a transaction by its hash from the container

func (*Container) GetFeeRateByHash

func (c *Container) GetFeeRateByHash(hash string) util.String

GetFeeRateByHash get a transaction's fee rate by its hash

func (*Container) Has

func (c *Container) Has(tx types.BaseTx) bool

Has checks whether a transaction is in the container

func (*Container) HasByHash

func (c *Container) HasByHash(hash string) bool

HasByHash is like Has but accepts a transaction hash

func (*Container) Last

func (c *Container) Last() types.BaseTx

Last returns the transaction at the back of the container. Returns nil if container is empty

func (*Container) Remove

func (c *Container) Remove(txs ...types.BaseTx)

Remove removes a transaction

func (*Container) Size

func (c *Container) Size() int

Size returns the number of items in the container

func (*Container) SizeByAddr

func (c *Container) SizeByAddr(addr identifier.Address) int

SizeByAddr returns the number of transactions signed by a given address

func (*Container) Sort

func (c *Container) Sort()

Sort sorts the container

type NonceGetterFunc

type NonceGetterFunc func(addr string) (uint64, error)

NonceGetterFunc describes a function for getting the nonce of an account matching the given address

type Pool

type Pool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PushPool wraps the transaction container providing a pool that can be used to store and manage transactions awaiting inclusion into blocks.

func New

func New(cap int, keepers core.Keepers, bus *emitter.Emitter) *Pool

New creates a new instance of pool. cap is the max amount of transactions that can be maintained in the pool. keepers is the application data keeper provider. bus is the app's event emitter provider.

func (*Pool) ByteSize

func (tp *Pool) ByteSize() int64

ByteSize gets the total byte size of all transactions in the pool. Note: The fee field of the transaction is not calculated.

func (*Pool) CacheSize

func (tp *Pool) CacheSize() int

CacheSize returns the size of the cache

func (*Pool) Find

func (tp *Pool) Find(iteratee func(tx types.BaseTx, feeRate util.String, timeAdded time.Time) bool) types.BaseTx

Find Get iterates over the transactions and invokes iteratee for each transaction. The iteratee is invoked the transaction as the only argument. It immediately stops and returns the last retrieved transaction when the iteratee returns true.

func (*Pool) Flush

func (tp *Pool) Flush()

Flush clears the container and caches

func (*Pool) GetByHash

func (tp *Pool) GetByHash(hash string) types.BaseTx

GetByHash gets a transaction from the pool using its hash

func (*Pool) GetFromCache

func (tp *Pool) GetFromCache() types.BaseTx

GetFromCache gets a transaction from the cache. Blocks if cache channel is empty

func (*Pool) Has

func (tp *Pool) Has(tx types.BaseTx) bool

Has checks whether a transaction is in the pool

func (*Pool) HasByHash

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

HasByHash is like Has but accepts a hash

func (*Pool) Head

func (tp *Pool) Head() types.BaseTx

Head returns transaction from the top of the pool.

func (*Pool) Put

func (tp *Pool) Put(tx types.BaseTx) (bool, error)

Put adds a transaction.

  • Returns true and nil of tx was added to the pool.
  • Returns false and nil if tx was added to the cache.
  • Emits EvtMempoolTxCommitted if tx was successfully

CONTRACTS:

  • No two transactions with same sender, nonce and fee rate is allowed.
  • Transactions are always ordered by nonce (ASC) and fee rate (DESC).

func (*Pool) Remove

func (tp *Pool) Remove(txs ...types.BaseTx)

Remove removes one or many transactions

func (*Pool) Size

func (tp *Pool) Size() int

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