Documentation ¶
Index ¶
- Constants
- Variables
- func BumpLegacyGasPriceOnly(cfg Config, lggr logger.SugaredLogger, ...) (gasPrice *big.Int, chainSpecificGasLimit uint64, err error)
- func HexToInt64(input interface{}) int64
- func Int64ToHex(n int64) string
- func IsBumpErr(err error) bool
- type Block
- type BlockHistoryEstimator
- func (b *BlockHistoryEstimator) BumpDynamicFee(originalFee DynamicFee, originalGasLimit uint64) (bumped DynamicFee, chainSpecificGasLimit uint64, err error)
- func (b *BlockHistoryEstimator) BumpLegacyGas(originalGasPrice *big.Int, gasLimit uint64) (bumpedGasPrice *big.Int, chainSpecificGasLimit uint64, err error)
- func (b *BlockHistoryEstimator) Close() error
- func (b *BlockHistoryEstimator) EffectiveGasPrice(block Block, tx Transaction) *big.Int
- func (b *BlockHistoryEstimator) EffectiveTipCap(block Block, tx Transaction) *big.Int
- func (b *BlockHistoryEstimator) FetchBlocks(ctx context.Context, head *evmtypes.Head) error
- func (b *BlockHistoryEstimator) FetchBlocksAndRecalculate(ctx context.Context, head *evmtypes.Head)
- func (b *BlockHistoryEstimator) GetDynamicFee(gasLimit uint64) (fee DynamicFee, chainSpecificGasLimit uint64, err error)
- func (b *BlockHistoryEstimator) GetLegacyGas(_ []byte, gasLimit uint64, _ ...Opt) (gasPrice *big.Int, chainSpecificGasLimit uint64, err error)
- func (b *BlockHistoryEstimator) OnNewLongestChain(ctx context.Context, head *evmtypes.Head)
- func (b *BlockHistoryEstimator) Recalculate(head *evmtypes.Head)
- func (b *BlockHistoryEstimator) RollingBlockHistory() []Block
- func (b *BlockHistoryEstimator) Start(ctx context.Context) error
- type Config
- type DynamicFee
- type Estimator
- func NewBlockHistoryEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config, chainID big.Int) Estimator
- func NewEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config) Estimator
- func NewFixedPriceEstimator(cfg Config, lggr logger.Logger) Estimator
- func NewOptimism2Estimator(lggr logger.Logger, config Config, client optimismRPCClient) Estimator
- func NewOptimismEstimator(lggr logger.Logger, config Config, client optimismRPCClient) Estimator
- type Opt
- type OptimismGasPricesResponse
- type Transaction
- type TxType
Constants ¶
const LegacyTxType = TxType(0x0)
Variables ¶
var ( ErrBumpGasExceedsLimit = errors.New("gas bump exceeds limit") ErrBump = errors.New("gas bump failed") )
var (
ErrNoSuitableTransactions = errors.New("no suitable transactions")
)
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 *big.Int, originalGasLimit uint64) (gasPrice *big.Int, chainSpecificGasLimit uint64, 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 ¶
Int64ToHex converts an int64 into go-ethereum's hex representation
Types ¶
type Block ¶
type Block struct { Number int64 Hash common.Hash ParentHash common.Hash BaseFeePerGas *big.Int Timestamp time.Time Transactions []Transaction }
Block represents an ethereum block This type is only used for the block history estimator, and can be expensive to unmarshal. Don't add unnecessary fields here.
func (Block) MarshalJSON ¶
MarshalJSON implements json marshalling for Block
func (*Block) UnmarshalJSON ¶
UnmarshalJSON unmarshals to a Block
type BlockHistoryEstimator ¶
type BlockHistoryEstimator struct { utils.StartStopOnce // contains filtered or unexported fields }
func (*BlockHistoryEstimator) BumpDynamicFee ¶
func (b *BlockHistoryEstimator) BumpDynamicFee(originalFee DynamicFee, originalGasLimit uint64) (bumped DynamicFee, chainSpecificGasLimit uint64, err error)
func (*BlockHistoryEstimator) BumpLegacyGas ¶
func (*BlockHistoryEstimator) Close ¶
func (b *BlockHistoryEstimator) Close() error
func (*BlockHistoryEstimator) EffectiveGasPrice ¶
func (b *BlockHistoryEstimator) EffectiveGasPrice(block Block, tx Transaction) *big.Int
func (*BlockHistoryEstimator) EffectiveTipCap ¶
func (b *BlockHistoryEstimator) EffectiveTipCap(block Block, tx Transaction) *big.Int
func (*BlockHistoryEstimator) FetchBlocks ¶
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(gasLimit uint64) (fee DynamicFee, chainSpecificGasLimit uint64, err error)
func (*BlockHistoryEstimator) GetLegacyGas ¶
func (*BlockHistoryEstimator) OnNewLongestChain ¶
func (b *BlockHistoryEstimator) OnNewLongestChain(ctx 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) RollingBlockHistory ¶
func (b *BlockHistoryEstimator) RollingBlockHistory() []Block
type Config ¶
type Config interface { BlockHistoryEstimatorBatchSize() uint32 BlockHistoryEstimatorBlockDelay() uint16 BlockHistoryEstimatorBlockHistorySize() uint16 BlockHistoryEstimatorTransactionPercentile() uint16 BlockHistoryEstimatorEIP1559FeeCapBufferBlocks() uint16 ChainType() config.ChainType EvmEIP1559DynamicFees() bool EvmFinalityDepth() uint32 EvmGasBumpPercent() uint16 EvmGasBumpThreshold() uint64 EvmGasBumpWei() *big.Int EvmGasFeeCapDefault() *big.Int EvmGasLimitMultiplier() float32 EvmGasPriceDefault() *big.Int EvmGasTipCapDefault() *big.Int EvmGasTipCapMinimum() *big.Int EvmMaxGasPriceWei() *big.Int EvmMinGasPriceWei() *big.Int GasEstimatorMode() string }
Config defines an interface for configuration in the gas package
type DynamicFee ¶
DynamicFee encompasses both FeeCap and TipCap for EIP1559 transactions
func BumpDynamicFeeOnly ¶
func BumpDynamicFeeOnly(config Config, lggr logger.SugaredLogger, currentTipCap *big.Int, currentBaseFee *big.Int, originalFee DynamicFee, originalGasLimit uint64) (bumped DynamicFee, chainSpecificGasLimit uint64, 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(calldata []byte, gasLimit uint64, opts ...Opt) (gasPrice *big.Int, chainSpecificGasLimit uint64, err error) BumpLegacyGas(originalGasPrice *big.Int, gasLimit uint64) (bumpedGasPrice *big.Int, chainSpecificGasLimit uint64, err error) GetDynamicFee(gasLimit uint64) (fee DynamicFee, chainSpecificGasLimit uint64, err error) BumpDynamicFee(original DynamicFee, gasLimit uint64) (bumped DynamicFee, chainSpecificGasLimit uint64, err error) }
Estimator provides an interface for estimating gas price and limit
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 ¶
NewEstimator returns the estimator for a given config
func NewFixedPriceEstimator ¶
NewFixedPriceEstimator returns a new "FixedPrice" estimator which will always use the config default values for gas prices and limits
func NewOptimism2Estimator ¶
NewOptimism2Estimator returns a new optimism 2.0 estimator
type OptimismGasPricesResponse ¶
OptimismGasPricesResponse is the shape of the response when calling rollup_gasPrices
func (*OptimismGasPricesResponse) UnmarshalJSON ¶
func (g *OptimismGasPricesResponse) UnmarshalJSON(b []byte) error
type Transaction ¶
type Transaction struct { GasPrice *big.Int GasLimit uint64 MaxFeePerGas *big.Int MaxPriorityFeePerGas *big.Int Type TxType Hash common.Hash }
Transaction represents an ethereum transaction Use our own type because geth's type has validation failures on e.g. zero gas used, which can occur on other chains. This type is only used for the block history estimator, and can be expensive to unmarshal. Don't add unnecessary fields here.
func (*Transaction) UnmarshalJSON ¶
func (t *Transaction) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a Transaction