gasprice

package
v0.13.9-rc.3-acp118-no... Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: GPL-3.0, LGPL-3.0 Imports: 19 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// DefaultMaxCallBlockHistory is the number of blocks that can be fetched in
	// a single call to eth_feeHistory.
	DefaultMaxCallBlockHistory = 2048
	// DefaultMaxBlockHistory is the number of blocks from the last accepted
	// block that can be fetched in eth_feeHistory.
	//
	// DefaultMaxBlockHistory is chosen to be a value larger than the required
	// fee lookback window that MetaMask uses (20k blocks).
	DefaultMaxBlockHistory = 25_000
	// DefaultFeeHistoryCacheSize is chosen to be some value larger than
	// [DefaultMaxBlockHistory] to ensure all block lookups can be cached when
	// serving a fee history query.
	DefaultFeeHistoryCacheSize = 30_000
)

Variables

View Source
var (
	DefaultMaxPrice           = big.NewInt(150 * params.GWei)
	DefaultMinPrice           = big.NewInt(0 * params.GWei)
	DefaultMinBaseFee         = big.NewInt(params.ApricotPhase3InitialBaseFee)
	DefaultMinGasUsed         = big.NewInt(6_000_000) // block gas limit is 8,000,000
	DefaultMaxLookbackSeconds = uint64(80)
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Blocks specifies the number of blocks to fetch during gas price estimation.
	Blocks int
	// Percentile is a value between 0 and 100 that we use during gas price estimation to choose
	// the gas price estimate in which Percentile% of the gas estimate values in the array fall below it
	Percentile int
	// MaxLookbackSeconds specifies the maximum number of seconds that current timestamp
	// can differ from block timestamp in order to be included in gas price estimation
	MaxLookbackSeconds uint64
	// MaxCallBlockHistory specifies the maximum number of blocks that can be
	// fetched in a single eth_feeHistory call.
	MaxCallBlockHistory uint64
	// MaxBlockHistory specifies the furthest back behind the last accepted block that can
	// be requested by fee history.
	MaxBlockHistory uint64
	MaxPrice        *big.Int `toml:",omitempty"`
	MinPrice        *big.Int `toml:",omitempty"`
	MinGasUsed      *big.Int `toml:",omitempty"`
}

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle recommends gas prices based on the content of recent blocks. Suitable for both light and full clients.

func NewOracle

func NewOracle(backend OracleBackend, config Config) (*Oracle, error)

NewOracle returns a new gasprice oracle which can recommend suitable gasprice for newly created transaction.

func (*Oracle) EstimateBaseFee added in v0.6.0

func (oracle *Oracle) EstimateBaseFee(ctx context.Context) (*big.Int, error)

EstimateBaseFee returns an estimate of what the base fee will be on a block produced at the current time. If ApricotPhase3 has not been activated, it may return a nil value and a nil error.

func (*Oracle) FeeHistory added in v0.7.1

func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)

FeeHistory returns data relevant for fee estimation based on the specified range of blocks. The range can be specified either with absolute block numbers or ending with the latest or pending block. Backends may or may not support gathering data from the pending block or blocks older than a certain age (specified in maxHistory). The first block of the actually processed range is returned to avoid ambiguity when parts of the requested range are not available or when the head has changed during processing this request. Three arrays are returned based on the processed blocks:

  • reward: the requested percentiles of effective priority fees per gas of transactions in each block, sorted in ascending order and weighted by gas used.
  • baseFee: base fee per gas in the given block
  • gasUsedRatio: gasUsed/gasLimit in the given block

Note: baseFee includes the next block after the newest of the returned range, because this value can be derived from the newest block.

func (*Oracle) SuggestPrice

func (oracle *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error)

SuggestPrice returns an estimated price for legacy transactions.

func (*Oracle) SuggestTipCap added in v0.6.0

func (oracle *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error)

SuggestTipCap returns a tip cap so that newly created transaction can have a very high chance to be included in the following blocks.

Note, for legacy transactions and the legacy eth_gasPrice RPC call, it will be necessary to add the basefee to the returned number to fall back to the legacy behavior.

type OracleBackend added in v0.3.1

type OracleBackend interface {
	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
	ChainConfig() *params.ChainConfig
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
	SubscribeChainAcceptedEvent(ch chan<- core.ChainEvent) event.Subscription
	MinRequiredTip(ctx context.Context, header *types.Header) (*big.Int, error)
	LastAcceptedBlock() *types.Block
}

OracleBackend includes all necessary background APIs for oracle.

Jump to

Keyboard shortcuts

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