txpool

package
v0.2509.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PendingCheckTransaction added in v0.2202.0

type PendingCheckTransaction struct {
	*TxQueueMeta
	// contains filtered or unexported fields
}

PendingCheckTransaction is a transaction pending checks.

type TransactionPool

type TransactionPool interface {
	// Start starts the service.
	Start() error

	// Stop halts the service.
	Stop()

	// Quit returns a channel that will be closed when the service terminates.
	Quit() <-chan struct{}

	// Has reports whether a transaction with the given hash is in the pool.
	Has(hash hash.Hash) bool

	// Get returns the transaction with the given hash if it is in the pool.
	Get(hash hash.Hash) ([]byte, bool)

	// All returns all transactions currently queued in the transaction pool.
	All() [][]byte

	// SubmitTx adds the transaction into the transaction pool, first performing checks on it by
	// invoking the runtime. This method waits for the checks to complete.
	SubmitTx(ctx context.Context, tx []byte, local bool, discard bool) (*protocol.CheckTxResult, error)

	// SubmitTxNoWait adds the transaction into the transaction pool and returns immediately.
	SubmitTxNoWait(tx []byte, local bool) error

	// SubmitProposedBatch adds the given (possibly new) transaction batch into the current
	// proposal queue.
	SubmitProposedBatch(batch [][]byte)

	// PromoteProposedBatch promotes the specified transactions that are already in the transaction
	// pool into the current proposal queue and returns a set of known transactions.
	//
	// For any missing transactions nil will be returned in their place and the map of missing
	// transactions will be populated accordingly.
	PromoteProposedBatch(batch []hash.Hash) ([]*TxQueueMeta, map[hash.Hash]int)

	// ClearProposedBatch clears the proposal queue.
	ClearProposedBatch()

	// RejectTxs indicates that given transaction hashes have been rejected during block processing.
	// Queues that can remove those transactions will do so. Additionally, these transactions will
	// be removed from the already seen cache as they can potentially become valid in the future.
	RejectTxs(txs []hash.Hash)

	// HandleTxsUsed indicates that given transaction hashes are processed in a block. Queues that
	// can remove those transactions will do so.
	HandleTxsUsed(txs []hash.Hash)

	// GetSchedulingSuggestion returns a list of transactions to schedule. This begins a
	// scheduling session, which suppresses transaction rechecking and republishing. Subsequently
	// call GetSchedulingExtra for more transactions.
	GetSchedulingSuggestion(limit int) []*TxQueueMeta

	// GetSchedulingExtra returns transactions to schedule.
	//
	// Offset specifies the transaction hash that should serve as an offset when returning
	// transactions from the pool. Transactions will be skipped until the given hash is encountered
	// and only the following transactions will be returned.
	GetSchedulingExtra(offset *hash.Hash, limit int) []*TxQueueMeta

	// ProcessBlock updates the last known runtime block information.
	ProcessBlock(bi *runtime.BlockInfo)

	// ProcessIncomingMessages loads transactions from incoming messages into the pool.
	ProcessIncomingMessages(inMsgs []*message.IncomingMessage)

	// WatchCheckedTransactions subscribes to notifications about new transactions being available
	// in the transaction pool for scheduling.
	WatchCheckedTransactions() (<-chan []*PendingCheckTransaction, pubsub.ClosableSubscription)
}

TransactionPool is an interface for managing a pool of transactions.

func New

func New(
	runtimeID common.Namespace,
	cfg config.Config,
	runtime host.Runtime,
	history history.History,
	txPublisher TransactionPublisher,
) TransactionPool

New creates a new transaction pool instance.

type TransactionPublisher

type TransactionPublisher interface {
	// PublishTx publishes a transaction to remote peers.
	PublishTx(ctx context.Context, tx []byte) error

	// GetMinRepublishInterval returns the minimum republish interval that needs to be respected by
	// the caller. If PublishTx is called for the same transaction more quickly, the transaction
	// may be dropped and not published.
	GetMinRepublishInterval() time.Duration
}

TransactionPublisher is an interface representing a mechanism for publishing transactions.

type TxQueueMeta added in v0.2202.0

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

TxQueueMeta stores some queuing-related metadata alongside a raw transaction.

func (*TxQueueMeta) FirstSeen added in v0.2202.0

func (t *TxQueueMeta) FirstSeen() time.Time

FirstSeen returns the time the transaction was first seen.

func (*TxQueueMeta) Hash added in v0.2202.0

func (t *TxQueueMeta) Hash() hash.Hash

Hash returns the hash of the transaction binary data.

func (*TxQueueMeta) Raw added in v0.2202.0

func (t *TxQueueMeta) Raw() []byte

Raw returns the raw transaction data.

func (*TxQueueMeta) Size added in v0.2202.0

func (t *TxQueueMeta) Size() int

Size returns the size (in bytes) of the raw transaction data.

type UsableTransactionSource added in v0.2202.0

type UsableTransactionSource interface {
	// Get returns the specific tx, if it is in this queue.
	Get(hash hash.Hash) (*TxQueueMeta, bool)
	// All returns all transactions without removing them.
	All() []*TxQueueMeta
}

UsableTransactionSource is a place to retrieve txs that are "good enough." "Good enough" variously means CheckTx'd, came from roothash incoming message, or came from our own node.

Directories

Path Synopsis
Package config implements the txpool configuration options.
Package config implements the txpool configuration options.

Jump to

Keyboard shortcuts

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