Documentation
¶
Overview ¶
Package bootnode implements a universal Ethereum bootnode supporting both Execution Layer (EL) and Consensus Layer (CL) discovery.
The bootnode supports:
- Discovery v4 (discv4) for EL nodes
- Discovery v5 (discv5) for both EL and CL nodes
- Dual routing tables (separate for EL and CL)
- Fork-aware filtering
- Protocol multiplexing (both protocols on same UDP port)
Index ¶
- type Config
- type ENRManager
- func (m *ENRManager) FilterCLNode(record *enr.Record) bool
- func (m *ENRManager) FilterELNode(record *enr.Record) (bool, elconfig.ForkID)
- func (m *ENRManager) GetCLFilter() *clconfig.ForkDigestFilter
- func (m *ENRManager) GetELFilter() *elconfig.ForkFilter
- func (m *ENRManager) UpdateENR(currentBlock, currentTime uint64) error
- func (m *ENRManager) UpdateENRWithIP(ip net.IP, port uint16) error
- func (m *ENRManager) UpdateENRWithIP6(ip net.IP, port uint16) error
- type Service
- func (s *Service) CLConfig() *clconfig.Config
- func (s *Service) CLENR() (string, error)
- func (s *Service) CLLocalNode() *v5node.Node
- func (s *Service) CLNodeDB() *nodes.NodeDB
- func (s *Service) CLTable() *nodes.FlatTable
- func (s *Service) ELConfig() *elconfig.ChainConfig
- func (s *Service) ELENR() (string, error)
- func (s *Service) ELLocalNode() *v5node.Node
- func (s *Service) ELNodeDB() *nodes.NodeDB
- func (s *Service) ELTable() *nodes.FlatTable
- func (s *Service) ENRManager() *ENRManager
- func (s *Service) GenericENR(node *v5node.Node) (string, error)
- func (s *Service) HasSeparateIdentities() bool
- func (s *Service) LocalNode() *v5node.Node
- func (s *Service) Start() error
- func (s *Service) StartTime() time.Time
- func (s *Service) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// PrivateKey is the node's secp256k1 private key (required)
PrivateKey *ecdsa.PrivateKey
// Database is the shared database for both EL and CL nodes (required)
Database *db.Database
// BindIP is the IP address to bind to (default: 0.0.0.0)
BindIP net.IP
// BindPort is the UDP port to bind to (default: 30303)
BindPort uint16
// ENRIP is the IP address to advertise in ENR (optional, auto-detected if nil)
ENRIP net.IP
// ENRIP6 is the IPv6 address to advertise in ENR (optional)
ENRIP6 net.IP
// ENRIPProvided/ENRIP6Provided record whether the advertised IP was explicitly
// configured (vs auto-detected). An explicit address is authoritative and
// overrides a stored ENR on restart; an auto-detected one does not, so a
// learned/discovered address survives.
ENRIPProvided bool
ENRIP6Provided bool
// ENRPort is the UDP port to advertise in ENR (default: same as BindPort)
ENRPort uint16
// Per-layer overrides for migrating from separate EL and CL bootnodes that
// have distinct node keys. Any field left zero falls back to the shared
// value above.
ELPrivateKey *ecdsa.PrivateKey
CLPrivateKey *ecdsa.PrivateKey
ELBindPort uint16
CLBindPort uint16
ELENRPort uint16
CLENRPort uint16
// ELConfig is the EL chain configuration (optional, nil disables EL support)
ELConfig *elconfig.ChainConfig
// ELGenesisHash is the EL genesis block hash (required if ELConfig is set)
ELGenesisHash [32]byte
// ELGenesisTime is the EL genesis block timestamp (required if ELConfig is set)
ELGenesisTime uint64
// ELBootnodes is the list of initial EL bootnodes (ENR or enode format)
ELBootnodes []string
// CLConfig is the CL beacon chain configuration (optional, nil disables CL support)
CLConfig *clconfig.Config
// CLBootnodes is the list of initial CL bootnodes (ENR format only)
CLBootnodes []string
// MaxActiveNodes is the maximum active nodes per table (default: 500)
MaxActiveNodes int
// MaxNodesPerIP is the maximum nodes allowed per IP address (default: 10)
MaxNodesPerIP int
// PingInterval is how often to ping nodes (default: 30s)
PingInterval time.Duration
// MaxNodeAge is the maximum age before considering a node dead (default: 24h)
MaxNodeAge time.Duration
// MaxFailures is the maximum consecutive failures before removing a node (default: 3)
MaxFailures int
// EnableDiscv4 enables Discovery v4 protocol (default: true)
EnableDiscv4 bool
// EnableDiscv5 enables Discovery v5 protocol (default: true)
EnableDiscv5 bool
// SessionLifetime is the discv5 session lifetime (default: 12 hours)
SessionLifetime time.Duration
// MaxSessions is the maximum number of discv5 sessions (default: 1024)
MaxSessions int
// EnableIPDiscovery enables automatic IP discovery from PONG responses (default: false)
EnableIPDiscovery bool
// GracePeriod is the grace period for accepting old fork digests (default: 60 minutes)
GracePeriod time.Duration
// Logger is the logger instance (optional)
Logger logrus.FieldLogger
}
Config contains configuration for the universal bootnode.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a configuration with sensible defaults.
You must set at least:
- PrivateKey
- Database
- One of: ELConfig or CLConfig (or both)
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults fills in default values for unset fields.
type ENRManager ¶
type ENRManager struct {
// contains filtered or unexported fields
}
ENRManager handles ENR creation and updates for a single identity.
The fork filters are always built for whatever layers the chain config enables (so any manager can classify a remote node), but the eth/eth2 fields written into this manager's own record are gated by servesEL/servesCL.
func NewENRManager ¶
func NewENRManager(cfg *Config, key *ecdsa.PrivateKey, localNode *v5node.Node, servesEL, servesCL bool) *ENRManager
NewENRManager creates a new ENR manager for one identity.
func (*ENRManager) FilterCLNode ¶
func (m *ENRManager) FilterCLNode(record *enr.Record) bool
FilterCLNode checks if a CL node's fork digest is valid.
Returns true if the node should be accepted, false otherwise.
func (*ENRManager) FilterELNode ¶
FilterELNode checks if an EL node's fork ID is valid.
Returns true if the node should be accepted, false otherwise.
func (*ENRManager) GetCLFilter ¶
func (m *ENRManager) GetCLFilter() *clconfig.ForkDigestFilter
GetCLFilter returns the CL fork digest filter (may be nil).
func (*ENRManager) GetELFilter ¶
func (m *ENRManager) GetELFilter() *elconfig.ForkFilter
GetELFilter returns the EL fork filter (may be nil).
func (*ENRManager) UpdateENR ¶
func (m *ENRManager) UpdateENR(currentBlock, currentTime uint64) error
UpdateENR updates the local ENR with current eth and eth2 fields.
This should be called:
- On startup
- After fork transitions
- When head changes significantly (for EL fork ID Next field)
func (*ENRManager) UpdateENRWithIP ¶
func (m *ENRManager) UpdateENRWithIP(ip net.IP, port uint16) error
UpdateENRWithIP updates the local ENR with a new IPv4 address and UDP port.
func (*ENRManager) UpdateENRWithIP6 ¶
func (m *ENRManager) UpdateENRWithIP6(ip net.IP, port uint16) error
UpdateENRWithIP6 updates the local ENR with a new IPv6 address and UDP port.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the universal bootnode service.
It provides:
- Dual protocol support (discv4 + discv5)
- Dual layer support (EL + CL)
- Separate routing tables for each layer
- Fork-aware filtering
func New ¶
New creates a new universal bootnode service.
Example:
config := bootnode.DefaultConfig()
config.PrivateKey = privKey
config.Database = db
config.ELConfig = elConfig
config.CLConfig = clConfig
service, err := bootnode.New(config)
if err != nil {
log.Fatal(err)
}
defer service.Stop()
func (*Service) CLConfig ¶
CLConfig returns the CL beacon chain configuration (may be nil if CL disabled).
func (*Service) CLENR ¶ added in v0.0.3
CLENR returns the CL identity's ENR with the EL-only eth field removed. Empty if CL is disabled. See ELENR for the shared- vs separate-key behavior.
func (*Service) CLLocalNode ¶ added in v0.0.3
CLLocalNode returns the CL identity's local node (nil if CL disabled).
func (*Service) ELConfig ¶
func (s *Service) ELConfig() *elconfig.ChainConfig
ELConfig returns the EL chain configuration (may be nil if EL disabled).
func (*Service) ELENR ¶ added in v0.0.3
ELENR returns the EL identity's ENR with the CL-only eth2 field removed — the record to hand to EL clients, some of which reject an ENR carrying eth2. In shared-key mode this strips eth2 from the combined record; with separate keys the EL record already omits eth2, so the strip is a no-op. Empty if EL is disabled.
func (*Service) ELLocalNode ¶ added in v0.0.3
ELLocalNode returns the EL identity's local node (nil if EL disabled).
func (*Service) ENRManager ¶
func (s *Service) ENRManager() *ENRManager
ENRManager returns the ENR manager.
func (*Service) GenericENR ¶ added in v0.0.3
GenericENR returns the base64 ENR for the given identity's node with the fork fields (eth/eth2) removed. This is the record to commit to static bootnode lists, which omit fork filtering so the bootnode is accepted regardless of the client's fork state; the bootnode still advertises the full fork-filtered ENR for live discovery.
func (*Service) HasSeparateIdentities ¶ added in v0.0.3
HasSeparateIdentities reports whether EL and CL run under distinct node IDs.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clconfig provides Ethereum Consensus Layer configuration parsing.
|
Package clconfig provides Ethereum Consensus Layer configuration parsing. |
|
Package elconfig implements Execution Layer config parsing and fork ID calculation.
|
Package elconfig implements Execution Layer config parsing and fork ID calculation. |