mempool

package
v0.105.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInsufficientFunds is returned when the Sender is not able to pay for
	// the transaction being added irrespective of the other contents of the
	// pool.
	ErrInsufficientFunds = errors.New("insufficient funds")
	// ErrConflict is returned when the transaction being added is incompatible
	// with the contents of the memory pool (Sender doesn't have enough GAS
	// to pay for all transactions in the pool).
	ErrConflict = errors.New("conflicts: insufficient funds for all pooled tx")
	// ErrDup is returned when the transaction being added is already present
	// in the memory pool.
	ErrDup = errors.New("already in the memory pool")
	// ErrOOM is returned when the transaction just doesn't fit in the memory
	// pool because of its capacity constraints.
	ErrOOM = errors.New("out of memory")
	// ErrConflictsAttribute is returned when the transaction conflicts with other transactions
	// due to its (or theirs) Conflicts attributes.
	ErrConflictsAttribute = errors.New("conflicts with memory pool due to Conflicts attribute")
	// ErrOracleResponse is returned when the mempool already contains a transaction
	// with the same oracle response ID and higher network fee.
	ErrOracleResponse = errors.New("conflicts with memory pool due to OracleResponse attribute")
)

Functions

This section is empty.

Types

type Feer

type Feer interface {
	FeePerByte() int64
	GetUtilityTokenBalance(util.Uint160) *big.Int
	BlockHeight() uint32
}

Feer is an interface that abstracts the implementation of the fee calculation.

type Pool

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

Pool stores the unconfirmed transactions.

func New added in v0.92.0

func New(capacity int, payerIndex int, enableSubscriptions bool, updateMetricsCb func(int)) *Pool

New returns a new Pool struct.

func (*Pool) Add

func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error

Add tries to add the given transaction to the Pool.

func (*Pool) ContainsKey

func (mp *Pool) ContainsKey(hash util.Uint256) bool

ContainsKey checks if the transactions hash is in the Pool.

func (*Pool) Count

func (mp *Pool) Count() int

Count returns the total number of uncofirmed transactions.

func (*Pool) GetVerifiedTransactions

func (mp *Pool) GetVerifiedTransactions() []*transaction.Transaction

GetVerifiedTransactions returns a slice of transactions with their fees.

func (*Pool) HasConflicts added in v0.92.0

func (mp *Pool) HasConflicts(t *transaction.Transaction, fee Feer) bool

HasConflicts returns true if the transaction is already in the pool or in the Conflicts attributes of the pooled transactions or has Conflicts attributes against the pooled transactions.

func (*Pool) IterateVerifiedTransactions added in v0.102.0

func (mp *Pool) IterateVerifiedTransactions(cont func(tx *transaction.Transaction, data any) bool)

IterateVerifiedTransactions iterates through verified transactions and invokes function `cont`. Iterations continue while the function `cont` returns true. Function `cont` is executed within a read-locked memory pool, thus IterateVerifiedTransactions will block any write mempool operation, use it with care. Do not modify transaction or data via `cont`.

func (*Pool) Remove

func (mp *Pool) Remove(hash util.Uint256, feer Feer)

Remove removes an item from the mempool if it exists there (and does nothing if it doesn't).

func (*Pool) RemoveStale

func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool, feer Feer)

RemoveStale filters verified transactions through the given function keeping only the transactions for which it returns true result. It's used to quickly drop a part of the mempool that is now invalid after the block acceptance.

func (*Pool) RunSubscriptions added in v0.93.0

func (mp *Pool) RunSubscriptions()

RunSubscriptions runs subscriptions goroutine if mempool subscriptions are enabled. You should manually free the resources by calling StopSubscriptions on mempool shutdown.

func (*Pool) SetResendThreshold added in v0.78.2

func (mp *Pool) SetResendThreshold(h uint32, f func(*transaction.Transaction, any))

SetResendThreshold sets a threshold after which the transaction will be considered stale and returned for retransmission by `GetStaleTransactions`.

func (*Pool) StopSubscriptions added in v0.93.0

func (mp *Pool) StopSubscriptions()

StopSubscriptions stops mempool events loop.

func (*Pool) SubscribeForTransactions added in v0.93.0

func (mp *Pool) SubscribeForTransactions(ch chan<- mempoolevent.Event)

SubscribeForTransactions adds the given channel to the new mempool event broadcasting, so when there is a new transactions added to the mempool or an existing transaction removed from the mempool, you'll receive it via this channel. Make sure you're not changing the received mempool events, as it may affect the functionality of other subscribers.

func (*Pool) TryGetData added in v0.92.0

func (mp *Pool) TryGetData(hash util.Uint256) (any, bool)

TryGetData returns data associated with the specified transaction if it exists in the memory pool.

func (*Pool) TryGetValue

func (mp *Pool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool)

TryGetValue returns a transaction and its fee if it exists in the memory pool.

func (*Pool) UnsubscribeFromTransactions added in v0.93.0

func (mp *Pool) UnsubscribeFromTransactions(ch chan<- mempoolevent.Event)

UnsubscribeFromTransactions unsubscribes the given channel from new mempool notifications, you can close it afterwards. Passing non-subscribed channel is a no-op.

func (*Pool) Verify

func (mp *Pool) Verify(tx *transaction.Transaction, feer Feer) bool

Verify checks if the Sender of the tx is able to pay for it (and all the other transactions in the pool). If yes, the transaction tx is a valid transaction and the function returns true. If no, the transaction tx is considered to be invalid, the function returns false.

Jump to

Keyboard shortcuts

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