gas

package
v1.12.1-beta0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ArbGasInfoAddress is the address of the "Precompiled contract that exists in every Arbitrum chain."
	// https://github.com/OffchainLabs/nitro/blob/f7645453cfc77bf3e3644ea1ac031eff629df325/contracts/src/precompiles/ArbGasInfo.sol
	ArbGasInfoAddress = "0x000000000000000000000000000000000000006C"
	// ArbGasInfo_getPricesInArbGas is the a hex encoded call to:
	// `function getPricesInArbGas() external view returns (uint256, uint256, uint256);`
	ArbGasInfo_getPricesInArbGas = "02199f34"
)
View Source
const BumpingHaltedLabel = "" /* 230-byte string literal not displayed */

Variables

View Source
var (
	ErrBumpGasExceedsLimit = errors.New("gas bump exceeds limit")
	ErrBump                = errors.New("gas bump failed")
)
View Source
var ErrConnectivity = errors.New("transaction propagation issue: transactions are not being mined")
View Source
var (
	ErrNoSuitableTransactions = errors.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 Config, lggr logger.SugaredLogger, currentGasPrice, originalGasPrice *assets.Wei, originalGasLimit uint32, maxGasPriceWei *assets.Wei) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error)

BumpLegacyGasPriceOnly will increase the price and apply multiplier to the gas limit

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

func IsBumpErr

func IsBumpErr(err error) bool

Types

type ArbConfig added in v1.8.1

type ArbConfig interface {
	EvmGasLimitMax() uint32
}

type BlockHistoryEstimator

type BlockHistoryEstimator struct {
	utils.StartStopOnce
	// contains filtered or unexported fields
}

func (*BlockHistoryEstimator) BumpDynamicFee

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

func (*BlockHistoryEstimator) BumpLegacyGas

func (b *BlockHistoryEstimator) BumpLegacyGas(_ context.Context, originalGasPrice *assets.Wei, gasLimit uint32, maxGasPriceWei *assets.Wei, attempts []PriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, err error)

func (*BlockHistoryEstimator) GetLegacyGas

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

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 {
	BlockHistoryEstimatorBatchSize() uint32
	BlockHistoryEstimatorBlockDelay() uint16
	BlockHistoryEstimatorBlockHistorySize() uint16
	BlockHistoryEstimatorCheckInclusionPercentile() uint16
	BlockHistoryEstimatorCheckInclusionBlocks() uint16
	BlockHistoryEstimatorEIP1559FeeCapBufferBlocks() uint16
	BlockHistoryEstimatorTransactionPercentile() uint16
	ChainType() config.ChainType
	EvmEIP1559DynamicFees() bool
	EvmFinalityDepth() uint32
	EvmGasBumpPercent() uint16
	EvmGasBumpThreshold() uint64
	EvmGasBumpWei() *assets.Wei
	EvmGasFeeCapDefault() *assets.Wei
	EvmGasLimitMax() uint32
	EvmGasLimitMultiplier() float32
	EvmGasPriceDefault() *assets.Wei
	EvmGasTipCapDefault() *assets.Wei
	EvmGasTipCapMinimum() *assets.Wei
	EvmMaxGasPriceWei() *assets.Wei
	EvmMinGasPriceWei() *assets.Wei
	GasEstimatorMode() string
}

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 Config, lggr logger.SugaredLogger, currentTipCap, currentBaseFee *assets.Wei, originalFee DynamicFee, originalGasLimit uint32, maxGasPriceWei *assets.Wei) (bumped DynamicFee, chainSpecificGasLimit uint32, err error)

BumpDynamicFeeOnly bumps the tip cap and max gas price if necessary

type Estimator

type Estimator interface {
	OnNewLongestChain(context.Context, *evmtypes.Head)
	Start(context.Context) error
	Close() error
	// 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 uint32, maxGasPriceWei *assets.Wei, opts ...Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, 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 uint32, maxGasPriceWei *assets.Wei, attempts []PriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint32, 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, gasLimit uint32, maxGasPriceWei *assets.Wei, attempts []PriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint32, err error)
}

Estimator provides an interface for estimating gas price and limit

func NewArbitrumEstimator added in v1.8.1

func NewArbitrumEstimator(lggr logger.Logger, cfg ArbConfig, rpcClient rpcClient, ethClient ethClient) Estimator

func NewBlockHistoryEstimator

func NewBlockHistoryEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config, chainID big.Int) Estimator

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 NewEstimator

func NewEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config) Estimator

NewEstimator returns the estimator for a given config

func NewFixedPriceEstimator

func NewFixedPriceEstimator(cfg Config, lggr logger.Logger) Estimator

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

func NewL2SuggestedPriceEstimator added in v1.8.1

func NewL2SuggestedPriceEstimator(lggr logger.Logger, client rpcClient) Estimator

NewL2SuggestedPriceEstimator returns a new Estimator which uses the L2 suggested gas price.

type Opt

type Opt int

Opt is an option for a gas estimator

const (
	// OptForceRefetch forces the estimator to bust a cache if necessary
	OptForceRefetch Opt = iota
)

type PriorAttempt added in v1.10.0

type PriorAttempt interface {
	GetGasPrice() *assets.Wei
	DynamicFee() DynamicFee
	GetChainSpecificGasLimit() uint32
	GetBroadcastBeforeBlockNum() *int64
	GetHash() common.Hash
	GetTxType() int
}

Directories

Path Synopsis
cmd
arbgas
arbgas takes a single URL argument and prints the result of three GetLegacyGas calls to the Arbitrum gas estimator.
arbgas takes a single URL argument and prints the result of three GetLegacyGas calls to the Arbitrum gas estimator.

Jump to

Keyboard shortcuts

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