gasprice

package
v1.9.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: GPL-3.0 Imports: 13 Imported by: 6

Documentation

Overview

Package gasprice contains Oracle type which recommends gas prices based on recent blocks. However, Klaytn uses invariant ChainConfig.UnitPrice and this value will not be changed until ChainConfig.UnitPrice is updated with governance.

Source Files

  • gasprice.go : implements Oracle struct which has a function to suggest appropriate gas price

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Blocks           int
	Percentile       int
	MaxHeaderHistory int
	MaxBlockHistory  int
	Default          *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, params Config, txPool TxPool) *Oracle

NewOracle returns a new oracle.

func (*Oracle) FeeHistory added in v1.8.0

func (oracle *Oracle) FeeHistory(
	ctx context.Context, blocks int,
	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 (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error)

SuggestPrice returns the recommended gas price.

type OracleBackend added in v1.8.0

type OracleBackend interface {
	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
	GetBlockReceipts(ctx context.Context, hash common.Hash) types.Receipts
	ChainConfig() *params.ChainConfig
	CurrentBlock() *types.Block
}

OracleBackend includes all necessary background APIs for oracle.

type TxPool added in v1.8.0

type TxPool interface {
	GasPrice() *big.Int
}

Jump to

Keyboard shortcuts

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