Documentation
¶
Index ¶
- Variables
- type Cache
- type Container
- func (c *Container) Add(tx types.BaseTx) (bool, error)
- func (c *Container) ByteSize() int64
- func (c *Container) CacheSize() int
- func (c *Container) First() types.BaseTx
- func (c *Container) Flush()
- func (c *Container) Full() bool
- func (c *Container) Get(index int) *containerItem
- func (c *Container) GetByHash(hash string) types.BaseTx
- func (c *Container) GetFeeRateByHash(hash string) util.String
- func (c *Container) Has(tx types.BaseTx) bool
- func (c *Container) HasByHash(hash string) bool
- func (c *Container) Last() types.BaseTx
- func (c *Container) Remove(txs ...types.BaseTx)
- func (c *Container) Size() int
- func (c *Container) SizeByAddr(addr identifier.Address) int
- func (c *Container) Sort()
- type NonceGetterFunc
- type Pool
- func (tp *Pool) ByteSize() int64
- func (tp *Pool) CacheSize() int
- func (tp *Pool) Find(iteratee func(tx types.BaseTx, feeRate util.String, timeAdded time.Time) bool) types.BaseTx
- func (tp *Pool) Flush()
- func (tp *Pool) GetByHash(hash string) types.BaseTx
- func (tp *Pool) GetFromCache() types.BaseTx
- func (tp *Pool) Has(tx types.BaseTx) bool
- func (tp *Pool) HasByHash(hash string) bool
- func (tp *Pool) Head() types.BaseTx
- func (tp *Pool) Put(tx types.BaseTx) (bool, error)
- func (tp *Pool) Remove(txs ...types.BaseTx)
- func (tp *Pool) Size() int
Constants ¶
This section is empty.
Variables ¶
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 (*Cache) Add ¶
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) 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 ¶
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 ¶
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) First ¶
First returns the transaction at the head of the container. Returns nil if container is empty
func (*Container) GetFeeRateByHash ¶
GetFeeRateByHash get a transaction's fee rate by its hash
func (*Container) Last ¶
Last returns the transaction at the back of the container. Returns nil if container is empty
func (*Container) SizeByAddr ¶
func (c *Container) SizeByAddr(addr identifier.Address) int
SizeByAddr returns the number of transactions signed by a given address
type NonceGetterFunc ¶
NonceGetterFunc describes a function for getting the nonce of an account matching the given address
type Pool ¶
PushPool wraps the transaction container providing a pool that can be used to store and manage transactions awaiting inclusion into blocks.
func New ¶
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 ¶
ByteSize gets the total byte size of all transactions in the pool. Note: The fee field of the transaction is not calculated.
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) GetFromCache ¶
GetFromCache gets a transaction from the cache. Blocks if cache channel is empty
func (*Pool) Put ¶
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).