gasprice

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMaxPrice    = big.NewInt(500 * params.GWei)
	DefaultIgnorePrice = big.NewInt(2 * params.Wei)

	DefaultMinSuggestedPriorityFee = big.NewInt(1e8 * params.Wei) // 0.1 gwei, for Optimism fee suggestion
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Blocks           int
	Percentile       int
	MaxHeaderHistory uint64
	MaxBlockHistory  uint64
	Default          *big.Int `toml:",omitempty"`
	MaxPrice         *big.Int `toml:",omitempty"`
	IgnorePrice      *big.Int `toml:",omitempty"`

	MinSuggestedPriorityFee *big.Int `toml:",omitempty"` // for Optimism fee suggestion
}

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, params Config) *Oracle

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

func (*Oracle) FeeHistory

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) SuggestOptimismPriorityFee

func (oracle *Oracle) SuggestOptimismPriorityFee(ctx context.Context, h *types.Header, headHash common.Hash) *big.Int

SuggestOptimismPriorityFee returns a max priority fee value that can be used such that newly created transactions have a very high chance to be included in the following blocks, using a simplified and more predictable algorithm appropriate for chains like Optimism with a single known block builder.

In the typical case, which results whenever the last block had room for more transactions, this function returns a minimum suggested priority fee value. Otherwise it returns the higher of this minimum suggestion or 10% over the median effective priority fee from the last block.

Rationale: For a chain such as Optimism where there is a single block builder whose behavior is known, we know priority fee (as long as it is non-zero) has no impact on the probability for tx inclusion as long as there is capacity for it in the block. In this case then, there's no reason to return any value higher than some fixed minimum. Blocks typically reach capacity only under extreme events such as airdrops, meaning predicting whether the next block is going to be at capacity is difficult *except* in the case where we're already experiencing the increased demand from such an event. We therefore expect whether the last known block is at capacity to be one of the best predictors of whether the next block is likely to be at capacity. (An even better predictor is to look at the state of the transaction pool, but we want an algorithm that works even if the txpool is private or unavailable.)

In the event the next block may be at capacity, the algorithm should allow for average fees to rise in order to reach a market price that appropriately reflects demand. We accomplish this by returning a suggestion that is a significant amount (10%) higher than the median effective priority fee from the previous block.

func (*Oracle) SuggestTipCap

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

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)
	PendingBlockAndReceipts() (*types.Block, types.Receipts)
	ChainConfig() *params.ChainConfig
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
}

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