Networking: peers, discovery, ports #
Summary #
specborn run | specborn checkpoint-sync | |
|---|---|---|
| Consensus peers | discovered from --bootnodes ENR,... and/or listed in --peers FILE; at most --max-peers (16) connections | --peers FILE, or discovered from --bootnodes FILE |
| Execution (eth) peers | discovered (discv5 records with an eth entry, discv4) and listed in --el-peers FILE; at most --max-el-peers (4) connections to discovered peers, the peers of --el-peers dialed in addition (not counted toward that limit); only when the node has a JSON-RPC server or a transaction pool | none |
| Discovery | discv5 and discv4 for the whole run (with --bootnodes) | discv5, a bounded walk at start (at most 60 s), again when fewer than 8 peers are connected |
| UDP | discv5 on --discovery-port (default: a port the system chooses), discv4 on another system-chosen port; both bound on all interfaces | one socket during a discovery walk (--discovery-port N) |
| Listening TCP ports for peers | none | none |
| Local TCP ports | JSON-RPC 127.0.0.1:8545 (unless --no-rpc); beacon API 127.0.0.1:5052 (only with --beacon-api) | none |
| Inbound peer connections | not accepted (no listener) | not accepted |
specborn only dials out to peers. Its execution layer gets the payloads it executes inside the consensus layer's blocks and envelopes, in the same process; its eth sessions exist to exchange transactions and to serve chain data, not to sync.
The peers file #
--peers FILE lists consensus peers, one per line:
# label is free text for your logs; the peer id is the libp2p peer id (base58)
cl lighthouse-1 127.0.0.1 33000 16Uiu2HAm...
cl teku-1 127.0.0.1 33001 16Uiu2HAm...
- Each line is
cl <label> <ipv4> <tcp port> <peer id>, fields separated by spaces. Blank lines and lines whose first word starts with#are ignored; any other line is an error and the node does not start (peers: bad line: …). - IPv4 addresses only; port 1 to 65535; the peer id must parse as a libp2p peer id. You can read a beacon node's peer id from its standard API,
/eth/v1/node/identity, and its libp2p TCP port from its configuration. - The node dials these peers and keeps dialing them when they disconnect (after a pause). With
--bootnodes, it also dials the peers discovery finds. There is no allowlist or denylist: every message from every peer is judged by the protocol rules only.
Execution peers #
--el-peers FILE lists execution peers (eth protocol over RLPx), one per line:
el geth-1 127.0.0.1 30303 2b0f…(128 hex digits: the node's secp256k1 public key, without the 04 prefix)
- Each line is
el <label> <ipv4> <tcp port> <public key>; the public key is the 64-byte node key of the peer'senode://URL, in hex (a0xprefix is accepted). Blank lines and lines starting with#are ignored; any other line stops the start (el-peers: bad line: …). - These are dialed in addition to the execution peers discovery finds.
- The node opens eth sessions only when it has something to use them for: a JSON-RPC server (the default) or a transaction pool (the default whenever there is a JSON-RPC server or
--el-peers). With--no-rpc --no-pool, it opens none. - On these sessions the node exchanges transactions (eth/69 to eth/71 announcements and requests; JSON-RPC) and answers requests for headers, bodies and receipts from its JSON-RPC store (the newest 8,192 blocks). It sends a
Pingevery 15 seconds and redials a lost peer with a growing pause.
Discovery and bootnodes #
specborn run --bootnodes ENR[,ENR...] takes discv5 node records on the command line (comma-separated; the flag may be repeated). specborn checkpoint-sync --bootnodes FILE takes a file with one enr: record per line, such as the bootstrap_nodes.yaml that networks publish in their configuration repositories.
In specborn run (docs/pieces/node.md W7r12, W7r13):
- discv5 walks the network from the bootnode records with
FINDNODE; a record is used as a consensus peer if itseth2entry carries a fork digest of this chain, and as an execution peer if itsethentry names this chain's fork hash; records with anethentry and a UDP port are also walked with discv4; - every record is size-bounded and signature-checked (once) before use; the table keeps at most 256 records, at most 4 per IPv4 address, 16 per /24 and 16 brought by any one answering node; at most 64 datagrams are read per loop iteration and at most 16 of them per source address, the rest dropped before any decryption or signature check;
- the node's own record carries no IP address, so it is not advertised as reachable, and other nodes do not dial it;
- the node keeps at most 64 known consensus peers and evicts unresponsive ones; no list of nodes is preferred or excluded.
The checkpoint-sync command does a bounded discv5 walk instead (at most 1,024 records, 16 queries at once, 60 seconds or 48 consensus peers; docs/pieces/cpsync.md §14.6).
specborn contains no built-in bootnode: the records are yours. On Hoodi the project used the records published in eth-clients/hoodi (Tests/Cpsync/live/cpsync-hoodi.sh).
Known limit: on a local devnet whose execution clients find each other only through their own bootnode, discovery found every execution client only after that bootnode was configured to answer with the devnet's records (docs/pieces/node.md W7r13.9, open item OPEN-node-el-discovery for the standard devnet).
Ports, NAT and firewalls #
specborn listens on no TCP port for peers, so there is nothing to forward on a router and no inbound TCP rule to open. It needs:
- outbound TCP to the peers' libp2p and RLPx ports;
- for discovery, outbound UDP to the bootnodes' and other nodes' discovery ports, and the replies back (normally allowed by a stateful firewall). The discv5 socket is bound on all interfaces at
--discovery-port; choose a fixed port if your firewall needs one; - nothing from outside for JSON-RPC (
127.0.0.1:8545) or the beacon API (127.0.0.1:5052): they are bound to the loopback address and cannot be reached from another machine. Keep it that way; if you need remote access, use an SSH tunnel or an authenticating proxy.
The cost of not listening: other nodes cannot dial specborn, so it relies on peers that accept inbound connections and adds no inbound capacity to the network. Some peers may disconnect a node that relays little or no gossip (the checkpoint-sync command relays none; what specborn run relays is below). Listening for inbound peers is planned.
What the node exchanges with peers #
- libp2p: TCP, Noise XX handshake, yamux or mplex stream multiplexing, multistream-select (piece
libp2p). - req/resp (
specborn run): it asks forStatus,MetaData,BeaconBlocksByRange,ExecutionPayloadEnvelopesByRange,DataColumnSidecarsByRangeand the…ByRootmethods. It answersStatus,Ping,MetaDataandGoodbye, and serves the blocks of the newest 512 roots it holds, the column sidecars of the newest 128 and the payload envelopes it accepted, by range and by root; itsStatusannounces the oldest slot it serves asearliest_available_slot. Older history is not served (open item OPEN-node-serve). Inbound requests are metered per peer and in total; over the limit, answers are delayed, never refused (docs/pieces/node.mdW7r7, W7r8). - gossipsub: it subscribes to
beacon_block,execution_payload, thedata_column_sidecarsubnets of the columns it samples,payload_attestation_message(unless--no-ptc) and, with--aggregates,beacon_aggregate_and_proof. It forwards (relays to its other peers) onlybeacon_blockmessages that pass the gossip validation rules of their fork: on a Fulu chain, and on a crossing chain before the Gloas fork, the Fulu rules; in Gloas, the Gloas rules. Once the chain is in Gloas it also forwardsexecution_payloadmessages that pass theirs. The forwarding check runs when a message arrives, against the node's state as of its previous loop iteration, and it does not runprocess_slots. A valid message it cannot judge then is not forwarded, although the node may still validate and import it afterwards. That covers a block whose parent the node does not hold yet, and a block whose expected proposer is not in its parent state's lookahead. A block whose slot belongs to a different fork than its topic is not forwarded either. No other message is forwarded: data column sidecars, payload attestations, aggregates and the messages of the validator subnets below are processed locally, not relayed (docs/pieces/node.md§W7.1, the wire hookRun.hookForF). With--validator-keysit also subscribes to the attestation and sync-committee subnets its duties need and tobeacon_aggregate_and_proof,sync_committee_contribution_and_proof,proposer_slashing,attester_slashing,voluntary_exitandbls_to_execution_change, whose messages it checks and keeps for its block proposals (nodeTopicsinSpecborn/Net/Gossip/Eth.lean). It publishes its own attestations, aggregates, sync-committee messages and contributions, PTC votes, blocks with their data column sidecars, and Gloas execution payload envelopes (Validators). A proposal's own messages go out in batches of 16, and each connection takes only what fits in its 4 MiB output buffer; the rest waits for that connection alone and is dropped for it after 2 s (pieces blobpub, blobpub2; thepropose: sidecars of slot …andpeer N: no room for own messages …lines). The gossip router's heartbeat and score decay run on the monotonic clock, so a step of the wall clock does not stall them (piece gossipclock). If the router makes a choice it must not make, it is replaced by a fresh router, and its scores, backoffs and seen-message cache are lost (with--verbose:router: illegal choice …; gossip router reset …). - eth (RLPx, devp2p): see Execution peers.
Misbehaving peers #
All peer input is untrusted and bounded (docs/pieces/node.md §8):
- gossip is validated before it reaches the fork choice, cheapest checks first;
- a connection that sends 16 rejected messages within 384 seconds is closed, and that configured peer is not redialed for 600 seconds; the gossip score penalises the sender of every rejected block or envelope;
- queues, batches, held blocks and column pools all have fixed bounds;
- a peer's claimed head is clamped to the wall-clock slot;
- a peer whose sync or by-root column request times out (by-root: 6 s), fails, or is answered with nothing it should have had (after 3 such empty answers in a row) or with a column it was not asked for, is not asked again for 30 s, doubling with each further recent failure up to 5 minutes; a good answer, or 10 minutes without a failure, forgets them, and for range sync, when every peer that has the slot is failing, the one whose last failure is oldest is still asked (
Specborn/Node/Sync/Plan.lean, pieces syncpeer to syncpeer7;peer N: data_column_sidecars_by_root request … unanswered for 6 s; not asked for … s); - a libp2p session that makes no progress (no input consumed across 16 resumes) is closed (
peer N: closed (session stalled: …), piece wirestall).
These are behaviour-based and temporary: no address or peer id is put on a fixed list. Apart from the gossip router's peer scores (gossipsub v1.1, kept per peer id and retained for up to an hour after a disconnect), specborn run keeps no score per peer id; the checkpoint-sync command also keeps a temporary, decaying score per peer id for invalid data-column sidecars, at most 1,024 of them (Checkpoint sync).