txmgr

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 9 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcGasFeeCap

func CalcGasFeeCap(baseFee, gasTipCap *big.Int) *big.Int

CalcGasFeeCap deterministically computes the recommended gas fee cap given the base fee and gasTipCap. The resulting gasFeeCap is equal to:

gasTipCap + 2*baseFee.

Types

type Config

type Config struct {
	// ResubmissionTimeout is the interval at which, if no previously
	// published transaction has been mined, the new tx with a bumped gas
	// price will be published. Only one publication at MaxGasPrice will be
	// attempted.
	ResubmissionTimeout time.Duration

	// RequireQueryInterval is the interval at which the tx manager will
	// query the backend to check for confirmations after a tx at a
	// specific gas price has been published.
	ReceiptQueryInterval time.Duration

	// NumConfirmations specifies how many blocks are need to consider a
	// transaction confirmed.
	NumConfirmations uint64

	// SafeAbortNonceTooLowCount specifies how many ErrNonceTooLow observations
	// are required to give up on a tx at a particular nonce without receiving
	// confirmation.
	SafeAbortNonceTooLowCount uint64
}

Config houses parameters for altering the behavior of a SimpleTxManager.

type ReceiptSource

type ReceiptSource interface {
	// BlockNumber returns the most recent block number.
	BlockNumber(ctx context.Context) (uint64, error)

	// TransactionReceipt queries the backend for a receipt associated with
	// txHash. If lookup does not fail, but the transaction is not found,
	// nil should be returned for both values.
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
}

ReceiptSource is a minimal function signature used to detect the confirmation of published txs.

NOTE: This is a subset of bind.DeployBackend.

type SendState

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

SendState tracks information about the publication state of a given txn. In this context, a txn may correspond to multiple different txn hashes due to varying gas prices, though we treat them all as the same logical txn. This struct is primarily used to determine whether or not the txmgr should abort a given txn and retry with a higher nonce.

func NewSendState

func NewSendState(safeAbortNonceTooLowCount uint64) *SendState

NewSendState parameterizes a new SendState from the passed safeAbortNonceTooLowCount.

func (*SendState) IsWaitingForConfirmation

func (s *SendState) IsWaitingForConfirmation() bool

IsWaitingForConfirmation returns true if we have at least one confirmation on one of our txs.

func (*SendState) ProcessSendError

func (s *SendState) ProcessSendError(err error)

ProcessSendError should be invoked with the error returned for each publication. It is safe to call this method with nil or arbitrary errors. Currently it only acts on errors containing the ErrNonceTooLow message.

func (*SendState) ShouldAbortImmediately

func (s *SendState) ShouldAbortImmediately() bool

ShouldAbortImmediately returns true if the txmgr should give up on trying a given txn with the target nonce. For now, this only happens if we see an extended period of getting ErrNonceTooLow without having a txn mined.

func (*SendState) TxMined

func (s *SendState) TxMined(txHash common.Hash)

TxMined records that the txn with txnHash has been mined and is await confirmation. It is safe to call this function multiple times.

func (*SendState) TxNotMined

func (s *SendState) TxNotMined(txHash common.Hash)

TxMined records that the txn with txnHash has not been mined or has been reorg'd out. It is safe to call this function multiple times.

type SendTransactionFunc

type SendTransactionFunc = func(ctx context.Context, tx *types.Transaction) error

type SimpleTxManager

type SimpleTxManager struct {
	Config // embed the config directly
	// contains filtered or unexported fields
}

SimpleTxManager is a implementation of TxManager that performs linear fee bumping of a tx until it confirms.

func NewSimpleTxManager

func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ReceiptSource) *SimpleTxManager

NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.

func (*SimpleTxManager) Send

func (m *SimpleTxManager) Send(ctx context.Context, updateGasPrice UpdateGasPriceFunc, sendTx SendTransactionFunc) (*types.Receipt, error)

Send is used to publish a transaction with incrementally higher gas prices until the transaction eventually confirms. This method blocks until an invocation of sendTx returns (called with differing gas prices). The method may be canceled using the passed context.

NOTE: Send should be called by AT MOST one caller at a time.

type TxManager

type TxManager interface {
	// Send is used to publish a transaction with incrementally higher gas
	// prices until the transaction eventually confirms. This method blocks
	// until an invocation of sendTx returns (called with differing gas
	// prices). The method may be canceled using the passed context.
	//
	// NOTE: Send should be called by AT MOST one caller at a time.
	Send(ctx context.Context, updateGasPrice UpdateGasPriceFunc, sendTxn SendTransactionFunc) (*types.Receipt, error)
}

TxManager is an interface that allows callers to reliably publish txs, bumping the gas price if needed, and obtain the receipt of the resulting tx.

type UpdateGasPriceFunc

type UpdateGasPriceFunc = func(ctx context.Context) (*types.Transaction, error)

UpdateGasPriceSendTxFunc defines a function signature for publishing a desired tx with a specific gas price. Implementations of this signature should also return promptly when the context is canceled.

Jump to

Keyboard shortcuts

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