gas

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package gas handles generating deterministic gas price estimates. because our implementation requires each client to arrive at the same. digest for each transaction to sign, and gas is a factor in generating that transaction hash. we can't just call SuggestPrice(). This module handles deterministic gas price and will (TODO!) in the future handle gas limit determinations.

Index

Constants

This section is empty.

Variables

View Source
var DefaultGasPriceEstimate = big.NewInt(int64(params.GWei))

DefaultGasPriceEstimate estimates the default gas price. This is exposed as a variable so it can be modified by tests, but will be removed in a future version.

Functions

func BumpByPercent

func BumpByPercent(gasPrice *big.Int, percentIncrease int) *big.Int

BumpByPercent bumps a gas price by a percentage.

func BumpGasFees

func BumpGasFees(opts *bind.TransactOpts, percentIncrease int, gasBlock *types.Block, maxPrice *big.Int)

BumpGasFees bumps the gas price by percent increase. In the case of legacy txes this bumps the gas price in the case of fees, this bumps both the tip and fee cap by percent. If the fee cap exceeds the percent bump but the fee cap doesn't and the fee cap is still below the tip cap the new fee cap is used without bumping the tip cap.

func CompareGas

func CompareGas(x *types.Transaction, y *types.Transaction, gasBlock *types.Block) int

CompareGas allows for gas comparisons between txes. In the case of an eip-1559 txOpts and a non-eip 1559 txOpts the eip-1559 txOpts we follow the mempool logic of setting the gasTipCap and the GasFeeCap to the same value legacy txes do not use effectivegastipcap since base fee is not present in non-eip 1559 chains This is done because the current mempool logic (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)

for non bumps (checking confirmations, etc) a nil gas block can be added which will order by tip (according to geth)

gas block here.

-1 if x <  y
 0 if x == y
+1 if x >  y

func FeeGreaterThan

func FeeGreaterThan(tx *types.Transaction, threshold *big.Int) bool

FeeGreaterThan determines if gas for a transaction is greater than threshold. This is used to enforce limits. DynamicFeeTxes set gas price to FeeTipCap so this will work for both.

func GetConfig

func GetConfig() gasprice.Config

GetConfig ges the gas price config.

func IsDynamicTx

func IsDynamicTx(opts *bind.TransactOpts) bool

IsDynamicTx determines if a transaction is dynamic based on the options passed in. this follows the same logic as the abi binder in determining what txOpts type to use. see: https://github.com/ethereum/go-ethereum/blob/b20bc5c0cae6901209610c5f53f01401b6f7974e/accounts/abi/bind/base.go#L310

func OptsToComparableTx

func OptsToComparableTx(opts *bind.TransactOpts) (comparableTx *types.Transaction)

OptsToComparableTx converts transaction options to a transaction. This should be used for comparisons only.

Types

type PriceEstimator

type PriceEstimator interface {
	// EstimateGasPrice estimates a gas price deterministically at a given height
	EstimateGasPrice(ctx context.Context, height uint64, config gasprice.Config) (*big.Int, error)
}

PriceEstimator handles estimating gas prices for type 0 txes on evm based chains. The logic is entirely derived from eth's SuggestPrice() logic (see: https://git.io/JZFlE), but designed to be deterministic from a given block height (with older block gas price estimations garbage collected). This is needed because, unlike in cases with a single signer gas prices need to be estimated deterministically. This is done by deriving the price at a given height (taken from the event log in cases where an event is being handles) and then following eth's estimation logic on the last n blocks. All clients arrive at the same price every time. The client is responsible for determining the height they wish to get the gas price at and coordinating this if the event log is cross chain.

func NewGasPriceEstimator

func NewGasPriceEstimator(ctx context.Context, oracle backend.OracleBackendChain) (g PriceEstimator)

NewGasPriceEstimator creates a gas estimator for v0 transactions.

type Setter

type Setter interface {
	// SetGasFeeByBlock gets a deterministic gas price based on the block
	SetGasFeeByBlock(ctx context.Context, transactor *bind.TransactOpts, gasBlock uint64, maxPrice *big.Int) error
	// SetGasFee sets a gas fee non-deterministically. This is useful for speeding up tests
	SetGasFee(ctx context.Context, transactor *bind.TransactOpts, londonBlock uint64, maxPrice *big.Int) error
}

Setter handles setting gas prices/fees in both pre (v0) and post (v2) eip-1559 transactions. this allows the setter to work on both ethereum and third party rpcs regardless of eip-1559 support.

func NewGasSetter

func NewGasSetter(ctx context.Context, oracle backend.OracleBackendChain) Setter

NewGasSetter creates a new gas setter for v0 & v2 transactions depending on the chain settings.

Directories

Path Synopsis
Package backend contains the common oracle backend for gas estimators
Package backend contains the common oracle backend for gas estimators
Package londinium as the name implies, contains the pre-london version of the gas price estimation
Package londinium as the name implies, contains the pre-london version of the gas price estimation
Package london provides wrappers to deterministically generate a tip cap + fee cap for evm based chains.
Package london provides wrappers to deterministically generate a tip cap + fee cap for evm based chains.

Jump to

Keyboard shortcuts

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