customheader

package
v0.15.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: GPL-3.0, LGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Max time from current time allowed for blocks, before they're considered future blocks
	// and fail verification
	MaxFutureBlockTime = 10 * time.Second

	ErrBlockTooFarInFuture           = errors.New("block timestamp is too far in the future")
	ErrTimeMillisecondsRequired      = errors.New("TimeMilliseconds is required after Granite activation")
	ErrTimeMillisecondsMismatched    = errors.New("TimeMilliseconds does not match header.Time")
	ErrTimeMillisecondsBeforeGranite = errors.New("TimeMilliseconds should be nil before Granite activation")
	ErrMinDelayNotMet                = errors.New("minimum block delay not met")
	ErrGraniteClockBehindParent      = errors.New("current timestamp is not allowed to be behind than parent timestamp in Granite")
)
View Source
var (
	ErrInsufficientBlockGas = errors.New("insufficient gas to cover the block cost")
)

Functions

func BaseFee

func BaseFee(
	config *extras.ChainConfig,
	parent *types.Header,
	timeMS uint64,
) (*big.Int, error)

BaseFee takes the previous header and the timestamp of its child block and calculates the expected base fee for the child block.

Prior to AP3, the returned base fee will be nil.

func BlockGasCost

func BlockGasCost(
	config *extras.ChainConfig,
	parent *types.Header,
	timestamp uint64,
) *big.Int

BlockGasCost calculates the required block gas cost based on the parent header and the timestamp of the new block. Prior to AP4, the returned block gas cost will be nil. In Granite, the returned block gas cost will be 0.

func BlockGasCostWithStep

func BlockGasCostWithStep(
	parentCost *big.Int,
	step uint64,
	timeElapsed uint64,
) uint64

BlockGasCostWithStep calculates the required block gas cost based on the parent cost and the time difference between the parent block and new block.

This is a helper function that allows the caller to manually specify the step value to use.

func EstimateNextBaseFee

func EstimateNextBaseFee(
	config *extras.ChainConfig,
	parent *types.Header,
	timeMS uint64,
) (*big.Int, error)

EstimateNextBaseFee attempts to estimate the base fee of a block built at `timestamp` on top of `parent`.

If timestamp is before parent.Time or the AP3 activation time, then timestamp is set to the maximum of parent.Time and the AP3 activation time.

Warning: This function should only be used in estimation and should not be used when calculating the canonical base fee for a block.

func EstimateRequiredTip

func EstimateRequiredTip(
	config *extras.ChainConfig,
	header *types.Header,
) (*big.Int, error)

EstimateRequiredTip is the estimated tip a transaction would have needed to pay to be included in a given block (assuming it paid a tip proportional to its gas usage).

In reality, the consensus engine does not enforce a minimum tip on individual transactions. The only correctness check performed is that the sum of all tips is >= the required block fee.

This function will return nil for all return values prior to Apricot Phase 4.

func ExtraPrefix

func ExtraPrefix(
	config *extras.ChainConfig,
	parent *types.Header,
	header *types.Header,
	desiredTargetExcess *gas.Gas,
) ([]byte, error)

ExtraPrefix returns what the prefix of the header's Extra field should be based on the desired target excess.

If the `desiredTargetExcess` is nil, the parent's target excess is used.

func GasCapacity

func GasCapacity(
	config *extras.ChainConfig,
	parent *types.Header,
	timeMS uint64,
) (uint64, error)

GasCapacity takes the previous header and the timestamp of its child block and calculates the available gas that can be consumed in the child block.

func GasLimit

func GasLimit(
	config *extras.ChainConfig,
	parent *types.Header,
	timeMS uint64,
) (uint64, error)

GasLimit takes the previous header and the timestamp of its child block and calculates the gas limit for the child block.

func GetNextTimestamp

func GetNextTimestamp(parent *types.Header, now time.Time) time.Time

GetNextTimestamp calculates the time for the next header based on the parent's timestamp and the current time. This can return the parent time if now is before the parent time and TimeMilliseconds is not set (pre-Granite).

func MinDelayExcess

func MinDelayExcess(
	config *extras.ChainConfig,
	parent *types.Header,
	timestamp uint64,
	desiredMinDelayExcess *acp226.DelayExcess,
) (*acp226.DelayExcess, error)

MinDelayExcess calculates the minimum delay excess based on the parent, current header and the desired min delay excess. If the `desiredMinDelayExcess` is nil, the parent's delay excess is used.

func PredicateBytesFromExtra

func PredicateBytesFromExtra(rules extras.AvalancheRules, extra []byte) []byte

PredicateBytesFromExtra returns the predicate result bytes from the header's extra data. If the extra data is not long enough, an empty slice is returned.

func RemainingAtomicGasCapacity

func RemainingAtomicGasCapacity(
	config *extras.ChainConfig,
	parent *types.Header,
	header *types.Header,
) (uint64, error)

RemainingAtomicGasCapacity returns the maximum amount ExtDataGasUsed could be on `header` while still being valid based on the initial capacity and consumed gas.

func SetPredicateBytesInExtra

func SetPredicateBytesInExtra(rules extras.AvalancheRules, extra []byte, predicateBytes []byte) []byte

SetPredicateBytesInExtra sets the predicate result bytes in the header's extra data. If the extra data is not long enough (i.e., an incomplete header.Extra as built in the miner), it is padded with zeros.

func VerifyBlockFee

func VerifyBlockFee(
	baseFee *big.Int,
	requiredBlockGasCost *big.Int,
	txs []*types.Transaction,
	receipts []*types.Receipt,
	extraStateChangeContribution *big.Int,
) error

func VerifyExtra

func VerifyExtra(rules extras.AvalancheRules, extra []byte) error

VerifyExtra verifies that the header's Extra field is correctly formatted for rules.

TODO: Should this be merged with VerifyExtraPrefix?

func VerifyExtraPrefix

func VerifyExtraPrefix(
	config *extras.ChainConfig,
	parent *types.Header,
	header *types.Header,
) error

VerifyExtraPrefix verifies that the header's Extra field is correctly formatted.

func VerifyGasLimit

func VerifyGasLimit(
	config *extras.ChainConfig,
	parent *types.Header,
	header *types.Header,
) error

VerifyGasLimit verifies that the gas limit for the header is valid.

func VerifyGasUsed

func VerifyGasUsed(
	config *extras.ChainConfig,
	parent *types.Header,
	header *types.Header,
) error

VerifyGasUsed verifies that the gas used is less than or equal to the gas limit.

func VerifyMinDelayExcess

func VerifyMinDelayExcess(
	config *extras.ChainConfig,
	parent *types.Header,
	header *types.Header,
) error

VerifyMinDelayExcess verifies that the min delay excess in header is consistent.

func VerifyTime

func VerifyTime(extraConfig *extras.ChainConfig, parent *types.Header, header *types.Header, now time.Time) error

VerifyTime verifies that the header's Time and TimeMilliseconds fields are consistent with the given rules and the current time. This includes: - TimeMilliseconds is nil before Granite activation - TimeMilliseconds is non-nil after Granite activation - Time matches TimeMilliseconds/1000 after Granite activation - Time/TimeMilliseconds is not too far in the future - Time/TimeMilliseconds is non-decreasing - Minimum block delay is enforced

Types

This section is empty.

Jump to

Keyboard shortcuts

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