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 ¶
- func StaticHead() (block, timestamp uint64)
- type Config
- type Discv5Stats
- type ENRManager
- func (m *ENRManager) AdmitCLNode(record *enr.Record) bool
- func (m *ENRManager) AdmitELNode(record *enr.Record) (bool, elconfig.ForkID)
- func (m *ENRManager) ClassifyCLNode(record *enr.Record) bool
- func (m *ENRManager) ClassifyELNode(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) (bool, 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) GetStats() Stats
- 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
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StaticHead ¶ added in v0.0.4
func StaticHead() (block, timestamp uint64)
StaticHead returns the head a bootnode evaluates fork schedules at. It tracks no chain, so every block-scheduled fork counts as passed (exact on post-merge networks, which can only schedule forks by time) and the time head is the wall clock.
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
// ServeAll disables EL/CL classification and fork-ID/digest filtering. Every
// discovered node is pooled (into every enabled table) and served to every
// requester, turning the bootnode into a plain discv5 rendezvous that relays
// all peers regardless of eth/eth2 fields. Default: false (classify + filter).
ServeAll 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: true). An explicitly configured ENRIP/ENRIP6 is never overridden
// by discovery regardless of this setting.
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 Discv5Stats ¶ added in v0.0.4
type Discv5Stats struct {
InvalidPackets int
FilteredResponses int
FindNodeReceived int
PendingHandshakes int
PendingChallenges int
}
Discv5Stats is the deliberate subset of protocol.HandlerStats the web UI renders, summed per identity.
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) AdmitCLNode ¶ added in v0.0.4
func (m *ENRManager) AdmitCLNode(record *enr.Record) bool
AdmitCLNode is ClassifyCLNode plus stats. Call it from admission paths only.
func (*ENRManager) AdmitELNode ¶ added in v0.0.4
AdmitELNode is ClassifyELNode plus stats. Call it from admission paths only.
Records with no eth entry are consensus nodes, not wrong-fork execution nodes, and are not counted (see services.AdmissionRejectedLayer).
func (*ENRManager) ClassifyCLNode ¶ added in v0.0.4
func (m *ENRManager) ClassifyCLNode(record *enr.Record) bool
ClassifyCLNode reports whether a record is a consensus node on an accepted fork digest.
It is pure: no counter moves. Use it for per-packet layer classification, and AdmitCLNode when the result decides admission.
func (*ENRManager) ClassifyELNode ¶ added in v0.0.4
ClassifyELNode reports whether a record is an execution node on a compatible fork, along with the fork ID it advertised.
It is pure: no counter moves. Use it for per-packet layer classification, and AdmitELNode when the result decides admission.
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) (bool, error)
UpdateENR updates the local ENR with current eth and eth2 fields, reporting whether the record actually changed.
It is a no-op when the computed fields already match the published record, so periodic callers do not churn the sequence number (peers re-fetch a record on every bump).
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) GetStats ¶ added in v0.0.4
GetStats returns a snapshot of the service's discovery counters.
func (*Service) HasSeparateIdentities ¶ added in v0.0.3
HasSeparateIdentities reports whether EL and CL run under distinct node IDs.
type Stats ¶ added in v0.0.4
type Stats struct {
Lookups services.LookupStats
Ping services.PingStats
Discv5 Discv5Stats
Discv4 v4protocol.HandlerStats
HasV4 bool
Sessions session.Stats
Packets transport.MetricsSnapshot
}
Stats aggregates the live counters the web UI renders. Everything here is summed across both layers (EL and CL lookup services) and across all discovery identities, of which there are two when separate EL and CL keys are configured.
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. |