gas

package
v2.12.1-mercury06182024 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const BumpingHaltedLabel = "" /* 230-byte string literal not displayed */

Variables

View Source
var (
	ErrNoSuitableTransactions = pkgerrors.New("no suitable transactions")
)
View Source
var MaxStartTime = 10 * time.Second

MaxStartTime is the maximum amount of time we are allowed to spend trying to fill initial data on start. This must be capped because it can block the application from starting.

Functions

func BumpLegacyGasPriceOnly

func BumpLegacyGasPriceOnly(cfg bumpConfig, lggr logger.SugaredLogger, currentGasPrice, originalGasPrice *assets.Wei, maxGasPriceWei *assets.Wei) (gasPrice *assets.Wei, err error)

BumpLegacyGasPriceOnly will increase the price

func HexToInt64

func HexToInt64(input interface{}) int64

HexToInt64 performs the inverse of Int64ToHex Returns 0 on invalid input

func Int64ToHex

func Int64ToHex(n int64) string

Int64ToHex converts an int64 into go-ethereum's hex representation

Types

type ArbConfig

type ArbConfig interface {
	LimitMax() uint64
	BumpPercent() uint16
	BumpMin() *assets.Wei
}

type BlockHistoryConfig added in v2.3.0

type BlockHistoryConfig interface {
	evmconfig.BlockHistory
}

type BlockHistoryEstimator

type BlockHistoryEstimator struct {
	services.StateMachine
	// contains filtered or unexported fields
}

func (*BlockHistoryEstimator) BumpDynamicFee

func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, err error)

func (*BlockHistoryEstimator) BumpLegacyGas

func (b *BlockHistoryEstimator) BumpLegacyGas(_ context.Context, originalGasPrice *assets.Wei, gasLimit uint64, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)

func (*BlockHistoryEstimator) Close

func (b *BlockHistoryEstimator) Close() error

func (*BlockHistoryEstimator) EffectiveGasPrice

func (b *BlockHistoryEstimator) EffectiveGasPrice(block evmtypes.Block, tx evmtypes.Transaction) *assets.Wei

func (*BlockHistoryEstimator) EffectiveTipCap

func (b *BlockHistoryEstimator) EffectiveTipCap(block evmtypes.Block, tx evmtypes.Transaction) *assets.Wei

func (*BlockHistoryEstimator) FetchBlocks

func (b *BlockHistoryEstimator) FetchBlocks(ctx context.Context, head *evmtypes.Head) error

FetchBlocks fetches block history leading up to the given head.

func (*BlockHistoryEstimator) FetchBlocksAndRecalculate

func (b *BlockHistoryEstimator) FetchBlocksAndRecalculate(ctx context.Context, head *evmtypes.Head)

FetchBlocksAndRecalculate fetches block history leading up to head and recalculates gas price.

func (*BlockHistoryEstimator) GetDynamicFee

func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error)

func (*BlockHistoryEstimator) GetLegacyGas

func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, _ ...feetypes.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)

func (*BlockHistoryEstimator) HealthReport

func (b *BlockHistoryEstimator) HealthReport() map[string]error

func (*BlockHistoryEstimator) IsUsable added in v2.3.0

func (b *BlockHistoryEstimator) IsUsable(tx evmtypes.Transaction, block evmtypes.Block, chainType config.ChainType, minGasPrice *assets.Wei, lggr logger.Logger) bool

isUsable returns true if the tx is usable both generally and specifically for this Config.

func (*BlockHistoryEstimator) L1Oracle added in v2.12.0

func (b *BlockHistoryEstimator) L1Oracle() rollups.L1Oracle

func (*BlockHistoryEstimator) Name

func (b *BlockHistoryEstimator) Name() string

func (*BlockHistoryEstimator) OnNewLongestChain

func (b *BlockHistoryEstimator) OnNewLongestChain(_ context.Context, head *evmtypes.Head)

OnNewLongestChain recalculates and sets global gas price if a sampled new head comes in and we are not currently fetching

func (*BlockHistoryEstimator) Recalculate

func (b *BlockHistoryEstimator) Recalculate(head *evmtypes.Head)

Recalculate adds the given heads to the history and recalculates gas price.

func (*BlockHistoryEstimator) Start

Start starts BlockHistoryEstimator service. The provided context can be used to terminate Start sequence.

type Config

type Config interface {
	ChainType() config.ChainType
	FinalityDepth() uint32
	FinalityTagEnabled() bool
}

Config defines an interface for configuration in the gas package

type DynamicFee

type DynamicFee struct {
	FeeCap *assets.Wei
	TipCap *assets.Wei
}

DynamicFee encompasses both FeeCap and TipCap for EIP1559 transactions

func BumpDynamicFeeOnly

func BumpDynamicFeeOnly(config bumpConfig, feeCapBufferBlocks uint16, lggr logger.SugaredLogger, currentTipCap, currentBaseFee *assets.Wei, originalFee DynamicFee, maxGasPriceWei *assets.Wei) (bumped DynamicFee, err error)

BumpDynamicFeeOnly bumps the tip cap and max gas price if necessary

type EvmEstimator

type EvmEstimator interface {
	headtracker.HeadTrackable[*evmtypes.Head, common.Hash]
	services.Service

	// GetLegacyGas Calculates initial gas fee for non-EIP1559 transaction
	// maxGasPriceWei parameter is the highest possible gas fee cap that the function will return
	GetLegacyGas(ctx context.Context, calldata []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, opts ...feetypes.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
	// BumpLegacyGas Increases gas price and/or limit for non-EIP1559 transactions
	// if the bumped gas fee is greater than maxGasPriceWei, the method returns an error
	// attempts must:
	//   - be sorted in order from highest price to lowest price
	//   - all be of transaction type 0x0 or 0x1
	BumpLegacyGas(ctx context.Context, originalGasPrice *assets.Wei, gasLimit uint64, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)
	// GetDynamicFee Calculates initial gas fee for gas for EIP1559 transactions
	// maxGasPriceWei parameter is the highest possible gas fee cap that the function will return
	GetDynamicFee(ctx context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error)
	// BumpDynamicFee Increases gas price and/or limit for non-EIP1559 transactions
	// if the bumped gas fee or tip caps are greater than maxGasPriceWei, the method returns an error
	// attempts must:
	//   - be sorted in order from highest price to lowest price
	//   - all be of transaction type 0x2
	BumpDynamicFee(ctx context.Context, original DynamicFee, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, err error)

	L1Oracle() rollups.L1Oracle
}

Estimator provides an interface for estimating gas price and limit

func NewArbitrumEstimator

func NewArbitrumEstimator(lggr logger.Logger, cfg ArbConfig, ethClient feeEstimatorClient, l1Oracle rollups.ArbL1GasOracle) EvmEstimator

func NewBlockHistoryEstimator

func NewBlockHistoryEstimator(lggr logger.Logger, ethClient feeEstimatorClient, cfg chainConfig, eCfg estimatorGasEstimatorConfig, bhCfg BlockHistoryConfig, chainID big.Int, l1Oracle rollups.L1Oracle) EvmEstimator

NewBlockHistoryEstimator returns a new BlockHistoryEstimator that listens for new heads and updates the base gas price dynamically based on the configured percentile of gas prices in that block

func NewFixedPriceEstimator

func NewFixedPriceEstimator(cfg fixedPriceEstimatorConfig, ethClient feeEstimatorClient, bhCfg fixedPriceEstimatorBlockHistoryConfig, lggr logger.Logger, l1Oracle rollups.L1Oracle) EvmEstimator

NewFixedPriceEstimator returns a new "FixedPrice" estimator which will always use the config default values for gas prices and limits

func NewSuggestedPriceEstimator added in v2.8.0

func NewSuggestedPriceEstimator(lggr logger.Logger, client feeEstimatorClient, cfg suggestedPriceConfig, l1Oracle rollups.L1Oracle) EvmEstimator

NewSuggestedPriceEstimator returns a new Estimator which uses the suggested gas price.

type EvmFee

type EvmFee struct {
	// legacy fees
	Legacy *assets.Wei

	// dynamic/EIP1559 fees
	DynamicFeeCap *assets.Wei
	DynamicTipCap *assets.Wei
}

func (EvmFee) String

func (fee EvmFee) String() string

func (EvmFee) ValidDynamic added in v2.2.0

func (fee EvmFee) ValidDynamic() bool

type EvmFeeEstimator

type EvmFeeEstimator interface {
	services.Service
	headtracker.HeadTrackable[*evmtypes.Head, common.Hash]

	// L1Oracle returns the L1 gas price oracle only if the chain has one, e.g. OP stack L2s and Arbitrum.
	L1Oracle() rollups.L1Oracle
	GetFee(ctx context.Context, calldata []byte, feeLimit uint64, maxFeePrice *assets.Wei, opts ...feetypes.Opt) (fee EvmFee, chainSpecificFeeLimit uint64, err error)
	BumpFee(ctx context.Context, originalFee EvmFee, feeLimit uint64, maxFeePrice *assets.Wei, attempts []EvmPriorAttempt) (bumpedFee EvmFee, chainSpecificFeeLimit uint64, err error)

	// GetMaxCost returns the total value = max price x fee units + transferred value
	GetMaxCost(ctx context.Context, amount assets.Eth, calldata []byte, feeLimit uint64, maxFeePrice *assets.Wei, opts ...feetypes.Opt) (*big.Int, error)
}

EvmFeeEstimator provides a unified interface that wraps EvmEstimator and can determine if legacy or dynamic fee estimation should be used

func NewEstimator

func NewEstimator(lggr logger.Logger, ethClient feeEstimatorClient, cfg Config, geCfg evmconfig.GasEstimator) EvmFeeEstimator

NewEstimator returns the estimator for a given config

func NewEvmFeeEstimator added in v2.12.0

func NewEvmFeeEstimator(lggr logger.Logger, newEstimator func(logger.Logger) EvmEstimator, eip1559Enabled bool, geCfg GasEstimatorConfig) EvmFeeEstimator

type EvmPriorAttempt

type EvmPriorAttempt struct {
	ChainSpecificFeeLimit   uint64
	BroadcastBeforeBlockNum *int64
	TxHash                  common.Hash
	TxType                  int
	GasPrice                *assets.Wei
	DynamicFee              DynamicFee
}

type GasEstimatorConfig added in v2.3.0

type GasEstimatorConfig interface {
	EIP1559DynamicFees() bool
	BumpPercent() uint16
	BumpThreshold() uint64
	BumpMin() *assets.Wei
	FeeCapDefault() *assets.Wei
	LimitMax() uint64
	LimitMultiplier() float32
	PriceDefault() *assets.Wei
	TipCapDefault() *assets.Wei
	TipCapMin() *assets.Wei
	PriceMin() *assets.Wei
	PriceMax() *assets.Wei
	Mode() string
}

type SuggestedPriceEstimator added in v2.8.0

type SuggestedPriceEstimator struct {
	services.StateMachine

	GasPrice *assets.Wei
	// contains filtered or unexported fields
}

SuggestedPriceEstimator is an Estimator which uses the suggested gas price from eth_gasPrice.

func (*SuggestedPriceEstimator) BumpDynamicFee added in v2.8.0

func (*SuggestedPriceEstimator) BumpDynamicFee(_ context.Context, _ DynamicFee, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, err error)

func (*SuggestedPriceEstimator) BumpLegacyGas added in v2.8.0

func (o *SuggestedPriceEstimator) BumpLegacyGas(ctx context.Context, originalFee *assets.Wei, feeLimit uint64, maxGasPriceWei *assets.Wei, _ []EvmPriorAttempt) (newGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)

Refreshes the gas price by making a call to the RPC in case the current one has gone stale. Adds the larger of BumpPercent and BumpMin configs as a buffer on top of the price returned from the RPC. The only reason bumping logic would be called on the SuggestedPriceEstimator is if there was a significant price spike between the last price update and when the tx was submitted. Refreshing the price helps ensure the latest market changes are accounted for.

func (*SuggestedPriceEstimator) Close added in v2.8.0

func (o *SuggestedPriceEstimator) Close() error

func (*SuggestedPriceEstimator) GetDynamicFee added in v2.8.0

func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ *assets.Wei) (fee DynamicFee, err error)

func (*SuggestedPriceEstimator) GetLegacyGas added in v2.8.0

func (o *SuggestedPriceEstimator) GetLegacyGas(ctx context.Context, _ []byte, GasLimit uint64, maxGasPriceWei *assets.Wei, opts ...feetypes.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error)

func (*SuggestedPriceEstimator) HealthReport added in v2.8.0

func (o *SuggestedPriceEstimator) HealthReport() map[string]error

func (*SuggestedPriceEstimator) L1Oracle added in v2.12.0

func (*SuggestedPriceEstimator) Name added in v2.8.0

func (o *SuggestedPriceEstimator) Name() string

func (*SuggestedPriceEstimator) OnNewLongestChain added in v2.8.0

func (o *SuggestedPriceEstimator) OnNewLongestChain(context.Context, *evmtypes.Head)

func (*SuggestedPriceEstimator) Start added in v2.8.0

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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