Documentation ¶
Index ¶
- Constants
- Variables
- func CLIFlags(envPrefix string) []cli.Flag
- func CLIFlagsWithDefaults(envPrefix string, defaults DefaultFlagValues) []cli.Flag
- func DefaultGasPriceEstimatorFn(ctx context.Context, backend ETHBackend) (*big.Int, *big.Int, *big.Int, error)
- func MakeSidecar(blobs []*eth.Blob) (*types.BlobTxSidecar, []common.Hash, error)
- type CLIConfig
- type Config
- type DefaultFlagValues
- type ETHBackend
- type GasPriceEstimatorFn
- type Queue
- type SendResponse
- type SendState
- type SimpleTxManager
- func (m *SimpleTxManager) API() rpc.API
- func (m *SimpleTxManager) BlockNumber(ctx context.Context) (uint64, error)
- func (m *SimpleTxManager) Close()
- func (m *SimpleTxManager) From() common.Address
- func (m *SimpleTxManager) GetBumpFeeRetryTime() time.Duration
- func (m *SimpleTxManager) GetFeeLimitMultiplier() uint64
- func (m *SimpleTxManager) GetFeeThreshold() *big.Int
- func (m *SimpleTxManager) GetMinBaseFee() *big.Int
- func (m *SimpleTxManager) GetMinBlobFee() *big.Int
- func (m *SimpleTxManager) GetMinPriorityFee() *big.Int
- func (m *SimpleTxManager) IsClosed() bool
- func (m *SimpleTxManager) Send(ctx context.Context, candidate TxCandidate) (*types.Receipt, error)
- func (m *SimpleTxManager) SendAsync(ctx context.Context, candidate TxCandidate, ch chan SendResponse)
- func (m *SimpleTxManager) SetBumpFeeRetryTime(val time.Duration)
- func (m *SimpleTxManager) SetFeeLimitMultiplier(val uint64)
- func (m *SimpleTxManager) SetFeeThreshold(val *big.Int)
- func (m *SimpleTxManager) SetMinBaseFee(val *big.Int)
- func (m *SimpleTxManager) SetMinBlobFee(val *big.Int)
- func (m *SimpleTxManager) SetMinPriorityFee(val *big.Int)
- func (m *SimpleTxManager) SuggestGasPriceCaps(ctx context.Context) (*big.Int, *big.Int, *big.Int, error)
- type SimpleTxmgrAPI
- func (a *SimpleTxmgrAPI) GetBumpFeeRetryTime(_ context.Context) time.Duration
- func (a *SimpleTxmgrAPI) GetFeeThreshold(_ context.Context) *big.Int
- func (a *SimpleTxmgrAPI) GetMinBaseFee(_ context.Context) *big.Int
- func (a *SimpleTxmgrAPI) GetMinBlobFee(_ context.Context) *big.Int
- func (a *SimpleTxmgrAPI) GetMinPriorityFee(_ context.Context) *big.Int
- func (a *SimpleTxmgrAPI) SetBumpFeeRetryTime(_ context.Context, val time.Duration)
- func (a *SimpleTxmgrAPI) SetFeeThreshold(_ context.Context, val *big.Int)
- func (a *SimpleTxmgrAPI) SetMinBaseFee(_ context.Context, val *big.Int)
- func (a *SimpleTxmgrAPI) SetMinBlobFee(_ context.Context, val *big.Int)
- func (a *SimpleTxmgrAPI) SetMinPriorityFee(_ context.Context, val *big.Int)
- type TestTxManager
- type TxCandidate
- type TxManager
- type TxReceipt
Constants ¶
const ( // Duplicated L1 RPC flag L1RPCFlagName = "l1-eth-rpc" // Key Management Flags (also have signer client flags) MnemonicFlagName = "mnemonic" HDPathFlagName = "hd-path" PrivateKeyFlagName = "private-key" // TxMgr Flags (new + legacy + some shared flags) NumConfirmationsFlagName = "num-confirmations" SafeAbortNonceTooLowCountFlagName = "safe-abort-nonce-too-low-count" FeeLimitMultiplierFlagName = "fee-limit-multiplier" FeeLimitThresholdFlagName = "txmgr.fee-limit-threshold" MinBaseFeeFlagName = "txmgr.min-basefee" MinTipCapFlagName = "txmgr.min-tip-cap" ResubmissionTimeoutFlagName = "resubmission-timeout" NetworkTimeoutFlagName = "network-timeout" TxSendTimeoutFlagName = "txmgr.send-timeout" TxNotInMempoolTimeoutFlagName = "txmgr.not-in-mempool-timeout" ReceiptQueryIntervalFlagName = "txmgr.receipt-query-interval" )
Variables ¶
var ( SequencerHDPathFlag = &cli.StringFlag{ Name: "sequencer-hd-path", Usage: "DEPRECATED: The HD path used to derive the sequencer wallet from the " + "mnemonic. The mnemonic flag must also be set.", EnvVars: []string{"OP_BATCHER_SEQUENCER_HD_PATH"}, } L2OutputHDPathFlag = &cli.StringFlag{ Name: "l2-output-hd-path", Usage: "DEPRECATED:The HD path used to derive the l2output wallet from the " + "mnemonic. The mnemonic flag must also be set.", EnvVars: []string{"OP_PROPOSER_L2_OUTPUT_HD_PATH"}, } )
var ( DefaultBatcherFlagValues = DefaultFlagValues{ NumConfirmations: uint64(10), SafeAbortNonceTooLowCount: uint64(3), FeeLimitMultiplier: uint64(5), FeeLimitThresholdGwei: 100.0, MinTipCapGwei: 1.0, MinBaseFeeGwei: 1.0, ResubmissionTimeout: 48 * time.Second, NetworkTimeout: 10 * time.Second, TxSendTimeout: 10 * time.Minute, TxNotInMempoolTimeout: 2 * time.Minute, ReceiptQueryInterval: 12 * time.Second, } DefaultChallengerFlagValues = DefaultFlagValues{ NumConfirmations: uint64(3), SafeAbortNonceTooLowCount: uint64(3), FeeLimitMultiplier: uint64(5), FeeLimitThresholdGwei: 100.0, MinTipCapGwei: 1.0, MinBaseFeeGwei: 1.0, ResubmissionTimeout: 24 * time.Second, NetworkTimeout: 10 * time.Second, TxSendTimeout: 2 * time.Minute, TxNotInMempoolTimeout: 1 * time.Minute, ReceiptQueryInterval: 12 * time.Second, } )
var ( ErrBlobFeeLimit = errors.New("blob fee limit reached") ErrClosed = errors.New("transaction manager is closed") )
var ( // Returned by CriticalError when the system is unable to get the tx into the mempool in the // allotted time ErrMempoolDeadlineExpired = errors.New("failed to get tx into the mempool") )
Functions ¶
func CLIFlagsWithDefaults ¶ added in v1.2.0
func CLIFlagsWithDefaults(envPrefix string, defaults DefaultFlagValues) []cli.Flag
func DefaultGasPriceEstimatorFn ¶ added in v1.9.4
func MakeSidecar ¶ added in v1.5.0
MakeSidecar builds & returns the BlobTxSidecar and corresponding blob hashes from the raw blob data.
Types ¶
type CLIConfig ¶ added in v1.0.2
type CLIConfig struct { L1RPCURL string Mnemonic string HDPath string SequencerHDPath string L2OutputHDPath string PrivateKey string SignerCLIConfig opsigner.CLIConfig NumConfirmations uint64 SafeAbortNonceTooLowCount uint64 FeeLimitMultiplier uint64 FeeLimitThresholdGwei float64 MinBaseFeeGwei float64 MinTipCapGwei float64 ResubmissionTimeout time.Duration ReceiptQueryInterval time.Duration NetworkTimeout time.Duration TxSendTimeout time.Duration TxNotInMempoolTimeout time.Duration }
func NewCLIConfig ¶ added in v1.1.2
func NewCLIConfig(l1RPCURL string, defaults DefaultFlagValues) CLIConfig
func ReadCLIConfig ¶ added in v1.0.2
func ReadCLIConfig(ctx *cli.Context) CLIConfig
type Config ¶
type Config struct { Backend ETHBackend // 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 atomic.Int64 // The multiplier applied to fee suggestions to put a hard limit on fee increases. FeeLimitMultiplier atomic.Uint64 // Minimum threshold (in Wei) at which the FeeLimitMultiplier takes effect. // On low-fee networks, like test networks, this allows for arbitrary fee bumps // below this threshold. FeeLimitThreshold atomic.Pointer[big.Int] // Minimum base fee (in Wei) to assume when determining tx fees. MinBaseFee atomic.Pointer[big.Int] // Minimum tip cap (in Wei) to enforce when determining tx fees. MinTipCap atomic.Pointer[big.Int] MinBlobTxFee atomic.Pointer[big.Int] // ChainID is the chain ID of the L1 chain. ChainID *big.Int // TxSendTimeout is how long to wait for sending a transaction. // By default it is unbounded. If set, this is recommended to be at least 20 minutes. TxSendTimeout time.Duration // TxNotInMempoolTimeout is how long to wait before aborting a transaction send if the transaction does not // make it to the mempool. If the tx is in the mempool, TxSendTimeout is used instead. TxNotInMempoolTimeout time.Duration // NetworkTimeout is the allowed duration for a single network request. // This is intended to be used for network requests that can be replayed. NetworkTimeout time.Duration // ReceiptQueryInterval 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 // Signer is used to sign transactions when the gas price is increased. Signer opcrypto.SignerFn From common.Address // GasPriceEstimatorFn is used to estimate the gas price for a transaction. // If nil, DefaultGasPriceEstimatorFn is used. GasPriceEstimatorFn GasPriceEstimatorFn }
Config houses parameters for altering the behavior of a SimpleTxManager.
type DefaultFlagValues ¶ added in v1.2.0
type DefaultFlagValues struct { NumConfirmations uint64 SafeAbortNonceTooLowCount uint64 FeeLimitMultiplier uint64 FeeLimitThresholdGwei float64 MinTipCapGwei float64 MinBaseFeeGwei float64 ResubmissionTimeout time.Duration NetworkTimeout time.Duration TxSendTimeout time.Duration TxNotInMempoolTimeout time.Duration ReceiptQueryInterval time.Duration }
type ETHBackend ¶
type ETHBackend interface { // BlockNumber returns the most recent block number. BlockNumber(ctx context.Context) (uint64, error) // CallContract executes an eth_call against the provided contract. CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, 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) // SendTransaction submits a signed transaction to L1. SendTransaction(ctx context.Context, tx *types.Transaction) error // These functions are used to estimate what the base fee & priority fee should be set to. // TODO: Maybe need a generic interface to support different RPC providers HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) SuggestGasTipCap(ctx context.Context) (*big.Int, error) // NonceAt returns the account nonce of the given account. // The block number can be nil, in which case the nonce is taken from the latest known block. NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) // PendingNonceAt returns the pending nonce. PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) // EstimateGas returns an estimate of the amount of gas needed to execute the given // transaction against the current pending block. EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) // Close the underlying eth connection Close() }
ETHBackend is the set of methods that the transaction manager uses to resubmit gas & determine when transactions are included on L1.
type GasPriceEstimatorFn ¶ added in v1.9.4
type Queue ¶ added in v1.0.6
type Queue[T any] struct { // contains filtered or unexported fields }
func NewQueue ¶ added in v1.0.6
NewQueue creates a new transaction sending Queue, with the following parameters:
- ctx: runtime context of the queue. If canceled, all ongoing send processes are canceled.
- txMgr: transaction manager to use for transaction sending
- maxPending: max number of pending txs at once (0 == no limit)
func (*Queue[T]) Send ¶ added in v1.0.6
func (q *Queue[T]) Send(id T, candidate TxCandidate, receiptCh chan TxReceipt[T])
Send will wait until the number of pending txs is below the max pending, and then send the next tx.
The actual tx sending is non-blocking, with the receipt returned on the provided receipt channel. If the channel is unbuffered, the goroutine is blocked from completing until the channel is read from.
func (*Queue[T]) TrySend ¶ added in v1.0.6
func (q *Queue[T]) TrySend(id T, candidate TxCandidate, receiptCh chan TxReceipt[T]) bool
TrySend sends the next tx, but only if the number of pending txs is below the max pending.
Returns false if there is no room in the queue to send. Otherwise, the transaction is queued and this method returns true.
The actual tx sending is non-blocking, with the receipt returned on the provided receipt channel. If the channel is unbuffered, the goroutine is blocked from completing until the channel is read from.
type SendResponse ¶ added in v1.9.3
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.
func NewSendState ¶
NewSendState creates a new send state
func NewSendStateWithNow ¶ added in v1.0.2
func NewSendStateWithNow(safeAbortNonceTooLowCount uint64, unableToSendTimeout time.Duration, now func() time.Time) *SendState
NewSendStateWithNow creates a new send state with the provided clock.
func (*SendState) CriticalError ¶ added in v1.7.2
CriticalError returns a non-nil error if the txmgr should give up on trying a given txn with the target nonce. This occurs when the set of errors recorded indicates that no further progress can be made on this transaction, or if there is an incompatible tx type currently in the mempool.
func (*SendState) IsWaitingForConfirmation ¶
IsWaitingForConfirmation returns true if we have at least one confirmation on one of our txs.
func (*SendState) ProcessSendError ¶
ProcessSendError should be invoked with the error returned for each publication. It is safe to call this method with nil or arbitrary errors.
func (*SendState) TxMined ¶
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 ¶
TxNotMined 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 SimpleTxManager ¶
type SimpleTxManager struct {
// 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, m metrics.TxMetricer, cfg CLIConfig) (*SimpleTxManager, error)
NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
func NewSimpleTxManagerFromConfig ¶ added in v1.1.6
func NewSimpleTxManagerFromConfig(name string, l log.Logger, m metrics.TxMetricer, conf *Config) (*SimpleTxManager, error)
NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
func (*SimpleTxManager) API ¶ added in v1.9.1
func (m *SimpleTxManager) API() rpc.API
func (*SimpleTxManager) BlockNumber ¶ added in v1.1.2
func (m *SimpleTxManager) BlockNumber(ctx context.Context) (uint64, error)
func (*SimpleTxManager) Close ¶ added in v1.4.2
func (m *SimpleTxManager) Close()
Close closes the underlying connection, and sets the closed flag. once closed, the tx manager will refuse to send any new transactions, and may abandon pending ones.
func (*SimpleTxManager) From ¶ added in v1.0.2
func (m *SimpleTxManager) From() common.Address
func (*SimpleTxManager) GetBumpFeeRetryTime ¶ added in v1.9.1
func (m *SimpleTxManager) GetBumpFeeRetryTime() time.Duration
func (*SimpleTxManager) GetFeeLimitMultiplier ¶ added in v1.9.1
func (m *SimpleTxManager) GetFeeLimitMultiplier() uint64
func (*SimpleTxManager) GetFeeThreshold ¶ added in v1.9.1
func (m *SimpleTxManager) GetFeeThreshold() *big.Int
func (*SimpleTxManager) GetMinBaseFee ¶ added in v1.9.1
func (m *SimpleTxManager) GetMinBaseFee() *big.Int
func (*SimpleTxManager) GetMinBlobFee ¶ added in v1.9.1
func (m *SimpleTxManager) GetMinBlobFee() *big.Int
func (*SimpleTxManager) GetMinPriorityFee ¶ added in v1.9.1
func (m *SimpleTxManager) GetMinPriorityFee() *big.Int
func (*SimpleTxManager) IsClosed ¶ added in v1.7.2
func (m *SimpleTxManager) IsClosed() bool
IsClosed returns true if the tx manager is closed.
func (*SimpleTxManager) Send ¶
func (m *SimpleTxManager) Send(ctx context.Context, candidate TxCandidate) (*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.
The transaction manager handles all signing. If and only if the gas limit is 0, the transaction manager will do a gas estimation.
NOTE: Send can be called concurrently, the nonce will be managed internally.
func (*SimpleTxManager) SendAsync ¶ added in v1.9.3
func (m *SimpleTxManager) SendAsync(ctx context.Context, candidate TxCandidate, ch chan SendResponse)
func (*SimpleTxManager) SetBumpFeeRetryTime ¶ added in v1.9.1
func (m *SimpleTxManager) SetBumpFeeRetryTime(val time.Duration)
func (*SimpleTxManager) SetFeeLimitMultiplier ¶ added in v1.9.1
func (m *SimpleTxManager) SetFeeLimitMultiplier(val uint64)
func (*SimpleTxManager) SetFeeThreshold ¶ added in v1.9.1
func (m *SimpleTxManager) SetFeeThreshold(val *big.Int)
func (*SimpleTxManager) SetMinBaseFee ¶ added in v1.9.1
func (m *SimpleTxManager) SetMinBaseFee(val *big.Int)
func (*SimpleTxManager) SetMinBlobFee ¶ added in v1.9.1
func (m *SimpleTxManager) SetMinBlobFee(val *big.Int)
func (*SimpleTxManager) SetMinPriorityFee ¶ added in v1.9.1
func (m *SimpleTxManager) SetMinPriorityFee(val *big.Int)
func (*SimpleTxManager) SuggestGasPriceCaps ¶ added in v1.9.0
func (m *SimpleTxManager) SuggestGasPriceCaps(ctx context.Context) (*big.Int, *big.Int, *big.Int, error)
SuggestGasPriceCaps suggests what the new tip, base fee, and blob base fee should be based on the current L1 conditions. `blobBaseFee` will be nil if 4844 is not yet active.
type SimpleTxmgrAPI ¶ added in v1.9.1
type SimpleTxmgrAPI struct {
// contains filtered or unexported fields
}
func (*SimpleTxmgrAPI) GetBumpFeeRetryTime ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) GetBumpFeeRetryTime(_ context.Context) time.Duration
func (*SimpleTxmgrAPI) GetFeeThreshold ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) GetFeeThreshold(_ context.Context) *big.Int
func (*SimpleTxmgrAPI) GetMinBaseFee ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) GetMinBaseFee(_ context.Context) *big.Int
func (*SimpleTxmgrAPI) GetMinBlobFee ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) GetMinBlobFee(_ context.Context) *big.Int
func (*SimpleTxmgrAPI) GetMinPriorityFee ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) GetMinPriorityFee(_ context.Context) *big.Int
func (*SimpleTxmgrAPI) SetBumpFeeRetryTime ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) SetBumpFeeRetryTime(_ context.Context, val time.Duration)
func (*SimpleTxmgrAPI) SetFeeThreshold ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) SetFeeThreshold(_ context.Context, val *big.Int)
func (*SimpleTxmgrAPI) SetMinBaseFee ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) SetMinBaseFee(_ context.Context, val *big.Int)
func (*SimpleTxmgrAPI) SetMinBlobFee ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) SetMinBlobFee(_ context.Context, val *big.Int)
func (*SimpleTxmgrAPI) SetMinPriorityFee ¶ added in v1.9.1
func (a *SimpleTxmgrAPI) SetMinPriorityFee(_ context.Context, val *big.Int)
type TestTxManager ¶ added in v1.9.0
type TestTxManager struct { *SimpleTxManager // contains filtered or unexported fields }
func (*TestTxManager) JamTxPool ¶ added in v1.9.0
func (m *TestTxManager) JamTxPool(ctx context.Context, candidate TxCandidate) error
JamTxPool sends a transaction intended to get stuck in the txpool, and should be used ONLY for testing. It is non-blocking. See WaitOnJammingTx if you wish to wait on the transaction to clear.
func (*TestTxManager) WaitOnJammingTx ¶ added in v1.9.0
func (m *TestTxManager) WaitOnJammingTx(ctx context.Context) error
WaitOnJammingTx can be called after JamTxPool in order to wait on the jam transaction clearing.
type TxCandidate ¶
type TxCandidate struct { // TxData is the transaction calldata to be used in the constructed tx. TxData []byte // Blobs to send along in the tx (optional). If len(Blobs) > 0 then a blob tx // will be sent instead of a DynamicFeeTx. Blobs []*eth.Blob // To is the recipient of the constructed tx. Nil means contract creation. To *common.Address // GasLimit is the gas limit to be used in the constructed tx. GasLimit uint64 // Value is the value to be used in the constructed tx. Value *big.Int }
TxCandidate is a transaction candidate that can be submitted to ask the TxManager to construct a transaction with gas price bounds.
type TxManager ¶
type TxManager interface { // Send is used to create & send a transaction. It will handle increasing // the gas price & ensuring that the transaction remains in the transaction pool. // It can be stopped by canceling the provided context; however, the transaction // may be included on L1 even if the context is canceled. // // NOTE: Send can be called concurrently, the nonce will be managed internally. // // Callers using both Blob and non-Blob transactions should check to see if the returned error // is ErrAlreadyReserved, which indicates an incompatible transaction may be stuck in the // mempool and is in need of replacement or cancellation. Send(ctx context.Context, candidate TxCandidate) (*types.Receipt, error) // SendAsync is used to create & send a transaction asynchronously. It has similar internal // semantics to Send, however it returns a channel that will receive the result of the // send operation once it completes. Transactions crafted synchronously - that is, nonce // management and gas estimation happen prior to the method returning. This allows callers // that rely on predictable nonces to send multiple transactions in parallel while preserving // the order of nonce increments. SendAsync(ctx context.Context, candidate TxCandidate, ch chan SendResponse) // From returns the sending address associated with the instance of the transaction manager. // It is static for a single instance of a TxManager. From() common.Address // BlockNumber returns the most recent block number from the underlying network. BlockNumber(ctx context.Context) (uint64, error) // API returns an rpc api interface which can be customized for each TxManager implementation API() rpc.API // Close the underlying connection Close() IsClosed() bool // SuggestGasPriceCaps suggests what the new tip, base fee, and blob base fee should be based on // the current L1 conditions. `blobBaseFee` will be nil if 4844 is not yet active. SuggestGasPriceCaps(ctx context.Context) (tipCap *big.Int, baseFee *big.Int, blobBaseFee *big.Int, err 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.