Documentation
¶
Overview ¶
Package elconfig implements Execution Layer config parsing and fork ID calculation.
This package provides functionality to:
- Parse geth-format chain configs
- Calculate EIP-2124 fork IDs
- Validate fork IDs from remote nodes
Index ¶
- func GatherForks(config *ChainConfig, genesisTime uint64) (forksByBlock, forksByTime []uint64)
- func MarshalChainConfig(config *ChainConfig) ([]byte, error)
- func WriteChainConfig(path string, config *ChainConfig) error
- type ChainConfig
- type FilterStats
- type ForkFilter
- func (f *ForkFilter) Filter(id ForkID) bool
- func (f *ForkFilter) GetAllForkIDs() []ForkID
- func (f *ForkFilter) GetAllForkIDsWithNames() []ForkIDWithName
- func (f *ForkFilter) GetCurrentForkID(currentBlock, currentTime uint64) ForkID
- func (f *ForkFilter) GetStats() FilterStats
- func (f *ForkFilter) RecordAdmission(acceptedNode bool, id ForkID)
- type ForkID
- type ForkIDWithName
- type ForkInfo
- type Genesis
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GatherForks ¶
func GatherForks(config *ChainConfig, genesisTime uint64) (forksByBlock, forksByTime []uint64)
GatherForks extracts fork block numbers and timestamps from a chain config.
Parameters:
- config: The chain configuration
- genesisTime: Genesis block timestamp
Returns two sorted lists: fork block numbers and fork timestamps.
func MarshalChainConfig ¶
func MarshalChainConfig(config *ChainConfig) ([]byte, error)
MarshalChainConfig serializes a chain config to JSON.
func WriteChainConfig ¶
func WriteChainConfig(path string, config *ChainConfig) error
WriteChainConfig writes a chain config to a JSON file.
Types ¶
type ChainConfig ¶
type ChainConfig struct {
ChainID *big.Int `json:"chainId"`
// contains filtered or unexported fields
}
ChainConfig represents an Execution Layer chain configuration.
This is fork-independent and dynamically parses fork data from config fields.
func LoadChainConfig ¶
func LoadChainConfig(path string) (*ChainConfig, error)
LoadChainConfig loads a chain config from a JSON file.
The file should be in geth's chain config format.
Example:
config, err := LoadChainConfig("/path/to/mainnet.json")
if err != nil {
log.Fatal(err)
}
func ParseChainConfig ¶
func ParseChainConfig(data []byte) (*ChainConfig, error)
ParseChainConfig parses a chain config from JSON bytes.
func (*ChainConfig) GetAllForks ¶
func (c *ChainConfig) GetAllForks() []ForkInfo
GetAllForks returns all forks in chronological order. Block-based forks come before time-based forks.
type FilterStats ¶ added in v0.0.4
type FilterStats struct {
TotalChecks uint64
Accepted uint64
Rejected uint64
LastRejectedID ForkID
}
FilterStats is a snapshot of admission outcomes.
type ForkFilter ¶
type ForkFilter struct {
// contains filtered or unexported fields
}
ForkFilter validates fork IDs from remote nodes.
It ports go-ethereum's EIP-2124 validation ruleset evaluated with a static head stance: a bootnode tracks no chain head, so every block-scheduled fork is treated as passed (exact on post-merge networks, which can only schedule forks by time) and the time head is the wall clock at validation time.
func NewForkFilter ¶
func NewForkFilter(genesisHash [32]byte, config *ChainConfig, genesisTime uint64) *ForkFilter
NewForkFilter creates a new fork ID filter.
It pre-computes the canonical fork checksum chain so remote fork IDs can be validated with go-ethereum's ruleset.
Parameters:
- genesisHash: Genesis block hash
- config: Chain configuration
- genesisTime: Genesis block timestamp
Returns a filter that can validate remote fork IDs.
func (*ForkFilter) Filter ¶
func (f *ForkFilter) Filter(id ForkID) bool
Filter checks if a fork ID is valid for this chain.
Returns true if the fork ID is acceptable, false otherwise.
func (*ForkFilter) GetAllForkIDs ¶
func (f *ForkFilter) GetAllForkIDs() []ForkID
GetAllForkIDs returns all valid fork IDs for debugging. Copied because validate reads allForkIDs to decide admission; mutating it would corrupt peer filtering.
func (*ForkFilter) GetAllForkIDsWithNames ¶
func (f *ForkFilter) GetAllForkIDsWithNames() []ForkIDWithName
GetAllForkIDsWithNames returns all fork IDs along with their names. This is useful for displaying fork information in the UI.
Multiple upgrades activating at one block or timestamp share a single fork ID, so names are grouped per deduplicated boundary instead of paired positionally.
func (*ForkFilter) GetCurrentForkID ¶
func (f *ForkFilter) GetCurrentForkID(currentBlock, currentTime uint64) ForkID
GetCurrentForkID calculates the current fork ID based on chain state.
func (*ForkFilter) GetStats ¶ added in v0.0.4
func (f *ForkFilter) GetStats() FilterStats
GetStats returns a snapshot of the admission outcomes.
func (*ForkFilter) RecordAdmission ¶ added in v0.0.4
func (f *ForkFilter) RecordAdmission(acceptedNode bool, id ForkID)
RecordAdmission records an admission decision for the stats surface. Its only caller is ENRManager.AdmitELNode, which owns the eth-entry gate; the pure predicate path (ClassifyELNode) must never reach here.
type ForkID ¶
type ForkID struct {
Hash [4]byte // CRC32 checksum
Next uint64 // Next fork (0 if no upcoming forks)
}
ForkID represents an EIP-2124 fork identifier.
A fork ID consists of:
- Hash: CRC32 checksum of genesis + passed fork numbers
- Next: Next upcoming fork (block number or timestamp)
func ComputeAllForkIDs ¶
ComputeAllForkIDs calculates all possible fork IDs for a chain.
This is useful for creating a filter that accepts nodes on any valid fork of the chain (past, current, or future).
Returns a list of all valid fork IDs.
func ComputeForkID ¶
func ComputeForkID(genesisHash [32]byte, forksByBlock, forksByTime []uint64, currentBlock, currentTime uint64) ForkID
ComputeForkID calculates the fork ID for a given chain state.
Parameters:
- genesisHash: The genesis block hash
- forksByBlock: Fork block numbers (sorted)
- forksByTime: Fork timestamps (sorted)
- currentBlock: Current head block number
- currentTime: Current head timestamp
Returns the fork ID representing the current state.
type ForkIDWithName ¶
type ForkIDWithName struct {
ForkID ForkID
Name string
Activation uint64 // Block number or timestamp
IsTime bool // True if activation is timestamp, false if block number
}
ForkIDWithName pairs a fork ID with its name and activation point.
type ForkInfo ¶
type ForkInfo struct {
Name string // Fork name (e.g., "homestead", "shanghai")
Block *uint64 // Block number (nil for time-based forks)
Timestamp *uint64 // Timestamp (nil for block-based forks)
}
ForkInfo contains information about a fork activation.
type Genesis ¶
type Genesis struct {
Config *ChainConfig `json:"config"`
Timestamp uint64 `json:"timestamp,string"`
Alloc map[string]interface{} `json:"alloc,omitempty"`
}
Genesis represents an Execution Layer genesis specification. This is a minimal version focused on extracting metadata needed for bootnode operation.
func LoadGenesis ¶
LoadGenesis loads a genesis file and parses both the config and metadata.
The genesis file should be in geth's genesis format (JSON).
Example:
genesis, err := LoadGenesis("/path/to/genesis.json")
if err != nil {
log.Fatal(err)
}
func ParseGenesis ¶
ParseGenesis parses a genesis specification from JSON bytes.
func (*Genesis) GetChainConfig ¶
func (g *Genesis) GetChainConfig() *ChainConfig
GetChainConfig returns the chain configuration.
func (*Genesis) GetChainID ¶
GetChainID returns the chain ID from the config.
func (*Genesis) GetTimestamp ¶
GetTimestamp returns the genesis timestamp.