extras

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: GPL-3.0, LGPL-3.0 Imports: 16 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultFeeConfig = commontype.FeeConfig{
		GasLimit:        big.NewInt(8_000_000),
		TargetBlockRate: 2,

		MinBaseFee:               big.NewInt(25_000_000_000),
		TargetGas:                big.NewInt(15_000_000),
		BaseFeeChangeDenominator: big.NewInt(36),

		MinBlockGasCost:  big.NewInt(0),
		MaxBlockGasCost:  big.NewInt(1_000_000),
		BlockGasCostStep: big.NewInt(200_000),
	}

	SubnetEVMDefaultChainConfig = &ChainConfig{
		FeeConfig:          DefaultFeeConfig,
		NetworkUpgrades:    getDefaultNetworkUpgrades(upgrade.GetConfig(constants.MainnetID)),
		GenesisPrecompiles: Precompiles{},
	}

	TestChainConfig = &ChainConfig{
		AvalancheContext:   AvalancheContext{SnowCtx: utils.TestSnowContext()},
		FeeConfig:          DefaultFeeConfig,
		NetworkUpgrades:    getDefaultNetworkUpgrades(upgrade.GetConfig(constants.UnitTestID)),
		GenesisPrecompiles: Precompiles{},
	}

	TestPreSubnetEVMChainConfig = copyAndSet(TestChainConfig, func(c *ChainConfig) {
		c.NetworkUpgrades = NetworkUpgrades{
			SubnetEVMTimestamp: utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
			DurangoTimestamp:   utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
			EtnaTimestamp:      utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
			FortunaTimestamp:   utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
		}
	})

	TestSubnetEVMChainConfig = copyAndSet(TestChainConfig, func(c *ChainConfig) {
		c.NetworkUpgrades = NetworkUpgrades{
			SubnetEVMTimestamp: utils.NewUint64(0),
			DurangoTimestamp:   utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
			EtnaTimestamp:      utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
			FortunaTimestamp:   utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
		}
	})

	TestDurangoChainConfig = copyAndSet(TestChainConfig, func(c *ChainConfig) {
		c.NetworkUpgrades = NetworkUpgrades{
			SubnetEVMTimestamp: utils.NewUint64(0),
			DurangoTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			EtnaTimestamp:      utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
			FortunaTimestamp:   utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
		}
	})

	TestEtnaChainConfig = copyAndSet(TestChainConfig, func(c *ChainConfig) {
		c.NetworkUpgrades = NetworkUpgrades{
			SubnetEVMTimestamp: utils.NewUint64(0),
			DurangoTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			EtnaTimestamp:      utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			FortunaTimestamp:   utils.TimeToNewUint64(upgrade.UnscheduledActivationTime),
		}
	})

	TestFortunaChainConfig = copyAndSet(TestChainConfig, func(c *ChainConfig) {
		c.NetworkUpgrades = NetworkUpgrades{
			SubnetEVMTimestamp: utils.NewUint64(0),
			DurangoTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			EtnaTimestamp:      utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			FortunaTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
		}
	})

	TestGraniteChainConfig = copyAndSet(TestChainConfig, func(c *ChainConfig) {
		c.NetworkUpgrades = NetworkUpgrades{
			SubnetEVMTimestamp: utils.NewUint64(0),
			DurangoTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			EtnaTimestamp:      utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			FortunaTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
			GraniteTimestamp:   utils.TimeToNewUint64(upgrade.InitiallyActiveTime),
		}
	})
)

Functions

func IsForkTransition

func IsForkTransition(fork *uint64, parent *uint64, current uint64) bool

IsForkTransition returns true if `fork` activates during the transition from `parent` to `current`. Taking `parent` as a pointer allows for us to pass nil when checking forks that activate during genesis. Note: `parent` and `current` can be either both timestamp values, or both block number values, since this function works for both block number and timestamp activated forks.

Types

type AvalancheContext

type AvalancheContext struct {
	SnowCtx *snow.Context
}

AvalancheContext provides Avalanche specific context directly into the EVM.

type AvalancheRules

type AvalancheRules struct {
	IsSubnetEVM bool
	IsDurango   bool
	IsEtna      bool
	IsFortuna   bool
	IsGranite   bool
}

type ChainConfig

type ChainConfig struct {
	NetworkUpgrades // Config for timestamps that enable network upgrades.

	AvalancheContext `json:"-"` // Avalanche specific context set during VM initialization. Not serialized.

	FeeConfig          commontype.FeeConfig `json:"feeConfig"`                    // Set the configuration for the dynamic fee algorithm
	AllowFeeRecipients bool                 `json:"allowFeeRecipients,omitempty"` // Allows fees to be collected by block builders.
	GenesisPrecompiles Precompiles          `json:"-"`                            // Config for enabling precompiles from genesis. JSON encode/decode will be handled by the custom marshaler/unmarshaler.
	UpgradeConfig      `json:"-"`           // Config specified in upgradeBytes (avalanche network upgrades or enable/disabling precompiles). Not serialized.
}

func (*ChainConfig) AllowedFeeRecipients

func (c *ChainConfig) AllowedFeeRecipients() bool

AllowedFeeRecipients returns the original AllowedFeeRecipients parameter contained in the genesis ChainConfig. Implements precompile.ChainConfig interface.

func (*ChainConfig) CheckConfigCompatible

func (c *ChainConfig) CheckConfigCompatible(newConfig *ethparams.ChainConfig, headNumber *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError

func (*ChainConfig) CheckConfigForkOrder

func (c *ChainConfig) CheckConfigForkOrder() error

func (*ChainConfig) Description

func (c *ChainConfig) Description() string

func (*ChainConfig) EnabledStatefulPrecompiles

func (c *ChainConfig) EnabledStatefulPrecompiles(blockTimestamp uint64) Precompiles

EnabledStatefulPrecompiles returns current stateful precompile configs that are enabled at [blockTimestamp].

func (*ChainConfig) GetActivatingPrecompileConfigs

func (c *ChainConfig) GetActivatingPrecompileConfigs(address common.Address, from *uint64, to uint64, upgrades []PrecompileUpgrade) []precompileconfig.Config

GetActivatingPrecompileConfigs returns all precompile upgrades configured to activate during the state transition from a block with timestamp [from] to a block with timestamp [to].

func (*ChainConfig) GetActivatingStateUpgrades

func (c *ChainConfig) GetActivatingStateUpgrades(from *uint64, to uint64, upgrades []StateUpgrade) []StateUpgrade

GetActivatingStateUpgrades returns all state upgrades configured to activate during the state transition from a block with timestamp [from] to a block with timestamp [to].

func (*ChainConfig) GetActivePrecompileConfig

func (c *ChainConfig) GetActivePrecompileConfig(address common.Address, timestamp uint64) precompileconfig.Config

GetActivePrecompileConfig returns the most recent precompile config corresponding to [address]. If none have occurred, returns nil.

func (*ChainConfig) GetFeeConfig

func (c *ChainConfig) GetFeeConfig() commontype.FeeConfig

GetFeeConfig returns the original FeeConfig contained in the genesis ChainConfig. Implements precompile.ChainConfig interface.

func (*ChainConfig) IsPrecompileEnabled

func (c *ChainConfig) IsPrecompileEnabled(address common.Address, timestamp uint64) bool

IsPrecompileEnabled returns whether precompile with `address` is enabled at `timestamp`.

func (*ChainConfig) MarshalJSON

func (c *ChainConfig) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of c. This is a custom marshaler to handle the Precompiles field.

func (*ChainConfig) UnmarshalJSON

func (c *ChainConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and stores the result in the object pointed to by c. This is a custom unmarshaler to handle the Precompiles field. Precompiles was presented as an inline object in the JSON. This custom unmarshaler ensures backwards compatibility with the old format.

func (*ChainConfig) Verify

func (c *ChainConfig) Verify() error

Verify verifies chain config.

type NetworkUpgrades

type NetworkUpgrades struct {
	// SubnetEVMTimestamp is a placeholder that activates Avalanche Upgrades prior to ApricotPhase6
	SubnetEVMTimestamp *uint64 `json:"subnetEVMTimestamp,omitempty"`
	// Durango activates the Shanghai Execution Spec Upgrade from Ethereum (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md#included-eips)
	// and Avalanche Warp Messaging.
	// Note: EIP-4895 is excluded since withdrawals are not relevant to the Avalanche C-Chain or Subnets running the EVM.
	DurangoTimestamp *uint64 `json:"durangoTimestamp,omitempty"`
	// Placeholder for EtnaTimestamp
	EtnaTimestamp *uint64 `json:"etnaTimestamp,omitempty"`
	// Fortuna has no effect on Subnet-EVM by itself, but is included for completeness.
	FortunaTimestamp *uint64 `json:"fortunaTimestamp,omitempty"`
	// Granite is a placeholder for the next upgrade.
	GraniteTimestamp *uint64 `json:"graniteTimestamp,omitempty"`
}

NetworkUpgrades contains timestamps that enable network upgrades. Avalanche specific network upgrades are also included here. (nil = no fork, 0 = already activated)

func (*NetworkUpgrades) Description

func (n *NetworkUpgrades) Description() string

func (*NetworkUpgrades) Equal

func (n *NetworkUpgrades) Equal(other *NetworkUpgrades) bool

func (*NetworkUpgrades) GetAvalancheRules

func (n *NetworkUpgrades) GetAvalancheRules(time uint64) AvalancheRules

func (NetworkUpgrades) IsDurango

func (n NetworkUpgrades) IsDurango(time uint64) bool

IsDurango returns whether time represents a block with a timestamp after the Durango upgrade time.

func (NetworkUpgrades) IsEtna

func (n NetworkUpgrades) IsEtna(time uint64) bool

IsEtna returns whether time represents a block with a timestamp after the Etna upgrade time.

func (*NetworkUpgrades) IsFortuna

func (n *NetworkUpgrades) IsFortuna(time uint64) bool

IsFortuna returns whether time represents a block with a timestamp after the Fortuna upgrade time.

func (*NetworkUpgrades) IsGranite

func (n *NetworkUpgrades) IsGranite(time uint64) bool

IsGranite returns whether time represents a block with a timestamp after the Granite upgrade time.

func (NetworkUpgrades) IsSubnetEVM

func (n NetworkUpgrades) IsSubnetEVM(time uint64) bool

IsSubnetEVM returns whether time represents a block with a timestamp after the SubnetEVM upgrade time.

func (*NetworkUpgrades) Override

func (n *NetworkUpgrades) Override(o *NetworkUpgrades)

func (*NetworkUpgrades) SetDefaults

func (n *NetworkUpgrades) SetDefaults(agoUpgrades upgrade.Config)

SetDefaults sets the default values for the network upgrades. This overrides deactivating the network upgrade by providing a timestamp of nil value.

type PrecompileUpgrade

type PrecompileUpgrade struct {
	precompileconfig.Config
}

PrecompileUpgrade is a helper struct embedded in UpgradeConfig. It is used to unmarshal the json into the correct precompile config type based on the key. Keys are defined in each precompile module, and registered in precompile/registry/registry.go.

func (*PrecompileUpgrade) MarshalJSON

func (u *PrecompileUpgrade) MarshalJSON() ([]byte, error)

MarshalJSON marshal the precompile config into json based on the precompile key. Ex: {"feeManagerConfig": {...}} where "feeManagerConfig" is the key

func (*PrecompileUpgrade) UnmarshalJSON

func (u *PrecompileUpgrade) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the json into the correct precompile config type based on the key. Keys are defined in each precompile module, and registered in precompile/registry/registry.go. Ex: {"feeManagerConfig": {...}} where "feeManagerConfig" is the key

type Precompiles

type Precompiles map[string]precompileconfig.Config

func (*Precompiles) UnmarshalJSON

func (ccp *Precompiles) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data into the ChainConfigPrecompiles. ChainConfigPrecompiles is a map of precompile module keys to their configuration.

type Rules

type Rules struct {
	// Rules for Avalanche releases
	AvalancheRules

	// Precompiles maps addresses to stateful precompiled contracts that are enabled
	// for this rule set.
	// Note: none of these addresses should conflict with the address space used by
	// any existing precompiles.
	Precompiles map[common.Address]precompileconfig.Config
	// Predicaters maps addresses to stateful precompile Predicaters
	// that are enabled for this rule set.
	Predicaters map[common.Address]precompileconfig.Predicater
	// AccepterPrecompiles map addresses to stateful precompile accepter functions
	// that are enabled for this rule set.
	AccepterPrecompiles map[common.Address]precompileconfig.Accepter
}

func (*Rules) IsPrecompileEnabled

func (r *Rules) IsPrecompileEnabled(addr common.Address) bool

IsPrecompileEnabled returns true if the precompile at `addr` is enabled for this rule set.

func (*Rules) PredicaterExists

func (r *Rules) PredicaterExists(addr common.Address) bool

func (*Rules) PredicatersExist

func (r *Rules) PredicatersExist() bool

type StateUpgrade

type StateUpgrade struct {
	BlockTimestamp *uint64 `json:"blockTimestamp,omitempty"`

	// map from account address to the modification to be made to the account.
	StateUpgradeAccounts map[common.Address]StateUpgradeAccount `json:"accounts"`
}

StateUpgrade describes the modifications to be made to the state during a state upgrade.

func (*StateUpgrade) Equal

func (s *StateUpgrade) Equal(other *StateUpgrade) bool

type StateUpgradeAccount

type StateUpgradeAccount struct {
	Code          hexutil.Bytes               `json:"code,omitempty"`
	Storage       map[common.Hash]common.Hash `json:"storage,omitempty"`
	BalanceChange *math.HexOrDecimal256       `json:"balanceChange,omitempty"`
}

StateUpgradeAccount describes the modifications to be made to an account during a state upgrade.

type UpgradeConfig

type UpgradeConfig struct {
	// Config for timestamps that enable network upgrades.
	NetworkUpgradeOverrides *NetworkUpgrades `json:"networkUpgradeOverrides,omitempty"`

	// Config for modifying state as a network upgrade.
	StateUpgrades []StateUpgrade `json:"stateUpgrades,omitempty"`

	// Config for enabling and disabling precompiles as network upgrades.
	PrecompileUpgrades []PrecompileUpgrade `json:"precompileUpgrades,omitempty"`
}

UpgradeConfig includes the following configs that may be specified in upgradeBytes: - Timestamps that enable avalanche network upgrades, - Enabling or disabling precompiles as network upgrades.

Jump to

Keyboard shortcuts

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