txpool

package
v0.0.0-...-b5034c9 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PoolSize = 100
	PoolPage = 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type TransactionSet

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

TransactionSet represents a group of nonce sorted Transactions

func NewTransactionSet

func NewTransactionSet() *TransactionSet

NewTransactionSet generates and returns a new TransactionSet

func (*TransactionSet) Flatten

func (txset *TransactionSet) Flatten() core.Transactions

Flatten returns a flat slice of nonce-sorted transactions as core.Transactions.

func (*TransactionSet) Put

func (txset *TransactionSet) Put(txn *core.Transaction)

Put inserts the given txn into the set while maintaining the sorting

func (*TransactionSet) Remove

func (txset *TransactionSet) Remove(nonce uint64) bool

Remove removes the transaction with the given nonce from the set. Returns a bool indicating if the transaction was removed.

type TxnByNonce

type TxnByNonce core.Transactions

TxnByNonce implements the sort interface to allow sorting a list of transactions by their nonces. This is usually only useful for sorting transactions from a single account, otherwise a nonce comparison doesn't make much sense.

func (TxnByNonce) Len

func (s TxnByNonce) Len() int

Len returns the number of elements in the TxnByNonce. Implements the sort.Interface type

func (TxnByNonce) Less

func (s TxnByNonce) Less(i, j int) bool

Less returns whether the value at index i is less than the value at index j in the TxnByNonce. Implements the sort.Interface type.

func (TxnByNonce) Swap

func (s TxnByNonce) Swap(i, j int)

Swap switches the elements at index i and j in the TxnByNonce. Implements the sort.Interface type.

type TxnNoncePool

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

TxnNoncePool is a Transaction Pool that implements the TxnPool interface. Transactions inserted into the pool are pushed into the queued, and are concurrently processed and added to the pending set of transactions and the lookup directory.

func NewTxnNoncePool

func NewTxnNoncePool() *TxnNoncePool

NewTxnNoncePool generates and returns a new TxnNoncePool object

func (*TxnNoncePool) Active

func (pool *TxnNoncePool) Active() int

Active implements the TxnPool interface for TxnNoncePool. Returns the number of transactions in the active set.

func (*TxnNoncePool) Clear

func (pool *TxnNoncePool) Clear(transactions ...*core.Transaction)

Clear implements the TxnPool interface for TxnNoncePool. Accepts a variadic number of Transactions and removes each of them from the pool. The transaction is removed from both the active and pending set, wherever it may exist.

func (*TxnNoncePool) Contains

func (pool *TxnNoncePool) Contains(hash common.Hash) bool

Contains implements the TxnPool interface for TxnNoncePool. Returns whether the Transaction with given Hash is present in the active set of the pool

func (*TxnNoncePool) Fetch

func (pool *TxnNoncePool) Fetch() core.Transactions

Fetch implements the TxnPool interface for TxnNoncePool. Collects upto PoolPage number of Transactions from the pool's active set. The collected transactions are moved to the pending set and returned.

func (*TxnNoncePool) FetchFor

func (pool *TxnNoncePool) FetchFor(address common.Address) *TransactionSet

FetchFor implements the TxnPool interface for TxnNoncePool. Returns a TransactionSet object for address. (nil if no Transactions from address). All Transactions in the TransactionSet are moved from the active set into the pending set.

func (*TxnNoncePool) Insert

func (pool *TxnNoncePool) Insert(transactions ...*core.Transaction)

Insert implements the TxnPool interface for TxnNoncePool. Accepts a variadic number of Transactions and adds each one to the active set.

func (*TxnNoncePool) Pending

func (pool *TxnNoncePool) Pending() int

Pending implements the TxnPool interface for TxnNoncePool. Returns the number of transactions in the pending set.

func (*TxnNoncePool) Purge

func (pool *TxnNoncePool) Purge() int

Purge implements the TxnPool interface for TxnNoncePool. Resets the pool and removes all transactions from it.

func (*TxnNoncePool) Restore

func (pool *TxnNoncePool) Restore(transactions ...*core.Transaction)

Restore implements the TxnPool interface for TxnNoncePool. Accepts a variadic number of transactions and restores each of them from the pending set into the active set.

type TxnPool

type TxnPool interface {
	// Fetch collects Transactions from the pool.
	// They are not removed from the pool until Clear is called with that Transaction
	Fetch() core.Transactions
	// FetchFor collects Transactions from queue for a specific address
	// They are not removed from the pool until Clear is called with the Transaction
	FetchFor(common.Address) *TransactionSet

	// Insert inserts Transactions into the pool
	Insert(...*core.Transaction)
	// Contains returns whether a transaction exists for a given transaction hash.
	// Will return true only if the transaction exists in the active set.
	Contains(common.Hash) bool

	// Clear removes the given Transactions from the pending and active
	Clear(...*core.Transaction)
	// Restore attempts to restore the given Transaction from the pending set into to pool.
	Restore(...*core.Transaction)
	// Purge completely removes all Transactions pending or not from the pool
	Purge() int

	// Pending returns the number of transactions in the pending set
	// i.e, transaction that have been fetched from the pool but not cleared.
	Pending() int
	// Active returns the number of transactions in active set.
	// This does not include transactions in the pending set.
	Active() int
}

Jump to

Keyboard shortcuts

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