elconfig

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 8 Imported by: 0

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

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 ForkFilter

type ForkFilter struct {
	// contains filtered or unexported fields
}

ForkFilter validates fork IDs from remote nodes.

It checks if a remote fork ID is compatible with the local chain.

func NewForkFilter

func NewForkFilter(genesisHash [32]byte, config *ChainConfig, genesisTime uint64) *ForkFilter

NewForkFilter creates a new fork ID filter.

It pre-computes all valid fork IDs for the chain so that nodes on any valid fork (past, current, or future) are accepted.

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.

This implementation is permissive - it accepts any node that appears to be on the same chain, regardless of whether they're ahead or behind.

func (*ForkFilter) FilterStrict

func (f *ForkFilter) FilterStrict(id ForkID, currentBlock, currentTime uint64) error

FilterStrict performs strict fork ID validation.

Returns nil if valid, error describing the issue otherwise.

func (*ForkFilter) GetAllForkIDs

func (f *ForkFilter) GetAllForkIDs() []ForkID

GetAllForkIDs returns all valid fork IDs for debugging.

func (*ForkFilter) GetAllForkIDsWithNames

func (f *ForkFilter) GetAllForkIDsWithNames(genesisTime uint64) []ForkIDWithName

GetAllForkIDsWithNames returns all fork IDs along with their names. This is useful for displaying fork information in the UI.

func (*ForkFilter) GetCurrentForkID

func (f *ForkFilter) GetCurrentForkID(currentBlock, currentTime uint64) ForkID

GetCurrentForkID calculates the current fork ID based on chain state.

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

func ComputeAllForkIDs(genesisHash [32]byte, forksByBlock, forksByTime []uint64) []ForkID

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.

func (ForkID) String

func (id ForkID) String() string

String returns a human-readable representation of the fork ID.

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

func LoadGenesis(path string) (*Genesis, error)

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

func ParseGenesis(data []byte) (*Genesis, error)

ParseGenesis parses a genesis specification from JSON bytes.

func (*Genesis) GetChainConfig

func (g *Genesis) GetChainConfig() *ChainConfig

GetChainConfig returns the chain configuration.

func (*Genesis) GetChainID

func (g *Genesis) GetChainID() *big.Int

GetChainID returns the chain ID from the config.

func (*Genesis) GetTimestamp

func (g *Genesis) GetTimestamp() uint64

GetTimestamp returns the genesis timestamp.

Jump to

Keyboard shortcuts

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