acp176

package
v1.14.1-db-metrics-fix Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

ACP176 implements the fee logic specified here: https://github.com/avalanche-foundation/ACPs/blob/main/ACPs/176-dynamic-evm-gas-limit-and-price-discovery-updates/README.md

Index

Constants

View Source
const (
	MinTargetPerSecond  = 1_000_000                                 // P
	TargetConversion    = MaxTargetChangeRate * MaxTargetExcessDiff // D
	MaxTargetExcessDiff = 1 << 15                                   // Q
	MinGasPrice         = 1                                         // M

	TimeToFillCapacity            = 5    // in seconds
	TargetToMax                   = 2    // multiplier to convert from target per second to max per second
	TargetToPriceUpdateConversion = 87   // 87 ~= 60 / ln(2) which makes the price double at most every ~60 seconds
	MaxTargetChangeRate           = 1024 // Controls the rate that the target can change per block.

	TargetToMaxCapacity = TargetToMax * TimeToFillCapacity
	MinMaxPerSecond     = MinTargetPerSecond * TargetToMax
	MinMaxCapacity      = MinMaxPerSecond * TimeToFillCapacity

	StateSize = 3 * wrappers.LongLen
)

Variables

View Source
var ErrStateInsufficientLength = errors.New("insufficient length for fee state")

Functions

func DesiredTargetExcess

func DesiredTargetExcess(desiredTarget gas.Gas) gas.Gas

DesiredTargetExcess calculates the optimal desiredTargetExcess given the desired target.

Types

type State

type State struct {
	Gas          gas.State
	TargetExcess gas.Gas // q
}

State represents the current state of the gas pricing and constraints.

func ParseState

func ParseState(bytes []byte) (State, error)

ParseState returns the state from the provided bytes. It is the inverse of State.Bytes. This function allows for additional bytes to be padded at the end of the provided bytes.

func (*State) AdvanceMilliseconds

func (s *State) AdvanceMilliseconds(milliseconds uint64)

AdvanceMilliseconds increases the gas capacity and decreases the gas excess based on the elapsed milliseconds. This is used in Granite.

func (*State) AdvanceSeconds

func (s *State) AdvanceSeconds(seconds uint64)

AdvanceSeconds increases the gas capacity and decreases the gas excess based on the elapsed seconds. This is used in Fortuna.

func (*State) Bytes

func (s *State) Bytes() []byte

Bytes returns the binary representation of the state.

func (*State) ConsumeGas

func (s *State) ConsumeGas(
	gasUsed uint64,
	extraGasUsed *big.Int,
) error

ConsumeGas decreases the gas capacity and increases the gas excess by gasUsed + extraGasUsed. If the gas capacity is insufficient, an error is returned.

func (*State) GasPrice

func (s *State) GasPrice() gas.Price

GasPrice returns the current required fee per gas.

GasPrice = MinGasPrice * e^(Excess / (Target() * TargetToPriceUpdateConversion))

func (*State) MaxCapacity

func (s *State) MaxCapacity() gas.Gas

MaxCapacity returns the maximum possible accrued gas capacity, `C`.

func (*State) Target

func (s *State) Target() gas.Gas

Target returns the target gas consumed per second, `T`.

Target = MinTargetPerSecond * e^(TargetExcess / TargetConversion)

func (*State) UpdateTargetExcess

func (s *State) UpdateTargetExcess(desiredTargetExcess gas.Gas)

UpdateTargetExcess updates the targetExcess to be as close as possible to the desiredTargetExcess without exceeding the maximum targetExcess change.

Jump to

Keyboard shortcuts

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