txpool

package
v0.2300.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReplacementTxPriorityTooLow = errors.New("txpool: replacement tx priority too low")
	ErrQueueFull                   = errors.New("txpool: schedule queue is full")
)

Functions

This section is empty.

Types

type MainQueueTransaction added in v0.2202.0

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

MainQueueTransaction is a transaction and its metadata in the main queue.

func (*MainQueueTransaction) Priority added in v0.2202.0

func (tx *MainQueueTransaction) Priority() uint64

Priority returns the transaction priority.

func (*MainQueueTransaction) Sender added in v0.2202.0

func (tx *MainQueueTransaction) Sender() string

Sender returns the transaction sender.

func (*MainQueueTransaction) SenderSeq added in v0.2202.0

func (tx *MainQueueTransaction) SenderSeq() uint64

SenderSeq returns the per-sender sequence number.

func (*MainQueueTransaction) String added in v0.2202.0

func (tx *MainQueueTransaction) String() string

String returns a string representation of a transaction.

type PendingCheckTransaction added in v0.2202.0

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

PendingCheckTransaction is a transaction pending checks.

type RecheckableTransactionStore added in v0.2202.0

type RecheckableTransactionStore interface {
	// TakeAll removes all txs and returns them.
	TakeAll() []*TxQueueMeta
	// OfferChecked adds a tx that is checked.
	OfferChecked(tx *TxQueueMeta, meta *protocol.CheckTxMetadata) error
}

RecheckableTransactionStore provides methods for rechecking.

type RepublishableTransactionSource added in v0.2202.0

type RepublishableTransactionSource interface {
	// GetTxsToPublish gets txs that this queue wants to publish.
	GetTxsToPublish() []*TxQueueMeta
}

RepublishableTransactionSource is a place to get txs that we want to push.

type RuntimeHostProvisioner

type RuntimeHostProvisioner interface {
	// WaitHostedRuntime waits for the hosted runtime to be provisioned and returns it.
	WaitHostedRuntime(ctx context.Context) (host.RichRuntime, error)
}

RuntimeHostProvisioner is a runtime host provisioner.

type TransactionMeta

type TransactionMeta struct {
	// Local is a flag indicating that the transaction was obtained from a local client.
	Local bool

	// Discard is a flag indicating that the transaction should be discarded after checks.
	Discard bool
}

TransactionMeta contains the per-transaction metadata.

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{}

	// 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, meta *TransactionMeta) (*protocol.CheckTxResult, error)

	// SubmitTxNoWait adds the transaction into the transaction pool and returns immediately.
	SubmitTxNoWait(tx []byte, meta *TransactionMeta) 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()

	// 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, followed by FinishScheduling.
	GetSchedulingSuggestion(countHint uint32) []*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 uint32) []*TxQueueMeta

	// FinishScheduling finishes a scheduling session, which resumes transaction rechecking and
	// republishing.
	FinishScheduling()

	// GetKnownBatch gets a set of known transactions from the transaction pool.
	//
	// For any missing transactions nil will be returned in their place and the map of missing
	// transactions will be populated accordingly.
	GetKnownBatch(batch []hash.Hash) ([]*TxQueueMeta, map[hash.Hash]int)

	// 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)

	// PendingCheckSize returns the number of transactions currently pending to be checked.
	PendingCheckSize() int
}

TransactionPool is an interface for managing a pool of transactions.

func New

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

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 {
	// GetSchedulingSuggestion returns some number of txs to give to the scheduler as part of the initial
	// batch.
	GetSchedulingSuggestion(countHint uint32) []*TxQueueMeta
	// GetTxByHash returns the specific tx, if it is in this queue. The bool is like `value, ok := txMap[key]`. Used
	// for resolving a batch from hashes and serving txSync.
	GetTxByHash(h hash.Hash) *TxQueueMeta
	// HandleTxsUsed is a callback to indicate that the scheduler is done with a set of txs, by hash. For most
	// implementations, remove it from internal storage.
	HandleTxsUsed(hashes []hash.Hash)
}

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