Peer-to-peer networking
The peer-to-peer system gives each Celestia node a stable network identity and a secure libp2p host. It connects the node to the correct network, finds useful peers, carries chain and share messages, checks inbound reachability, and limits network resource use. It is one of the service groups assembled by the node assembly and exposes operator controls through the RPC services.
Network role
The p2p system applies network policy according to the node role. A role determines how the node uses routing, whether it checks public reachability, how it manages resources, and which peers it seeks or serves.
The network name also defines the peer and discovery scope. Supported long-running networks have built-in entry data. Private and custom networks need operator-supplied peer and network data. The network choice must match the node’s stored data; the node configuration page describes the wider configuration rules.
Host construction
Role-specific assembly
The p2p module builds a shared host and service set, then adds services that match the node role. Bridge nodes add reachability checks, bootstrap connections, and share-focused resource limits. Light nodes use resource limits that scale with the available system instead.
References: nodebuilder/…/module.go• L13-50
Identity and lifecycle
The libp2p host uses a private key from the node keystore. That key produces one PeerID, so the node keeps the same network identity after a restart. The host receives the configured listen addresses and closes with the node lifecycle.
The host also identifies the node’s network, role, software version, and commit to other peers. This gives peers enough context to place the connection in the correct network and role group.
References: nodebuilder/…/identity.go• L14-56 nodebuilder/…/host.go• L36-67 nodebuilder/…/host.go• L70-123 nodebuilder/…/addrs.go• L11-22
Transports and security
The host supports several transport paths so peers can connect across different network conditions. Its address set covers TCP, QUIC, WebTransport, and direct WebRTC. WebSocket transport is also available, including secure WebSocket support when the deployment provides certificates.
Multipath TCP listeners are disabled by default, so the host does not rely on that transport unless the runtime setting changes.
The host uses libp2p security and stream multiplexing. It can map ports on suitable local networks, but it does not use circuit relays. The design favors direct connections and publishes only addresses that the operator marks as usable.
References: nodebuilder/…/host.go• L83-114 nodebuilder/…/tls.go• L19-59 nodebuilder/…/config.go• L35-66 nodebuilder/…/mptcp_test.go• L10-14
Address publication
Listen addresses tell the host where to accept inbound connections. Announce addresses tell peers where to dial the node. A no-announce list removes local or undialable listen addresses from the peer-facing result, while explicit announce addresses support controlled deployments.
This separation lets a node listen on private interfaces without telling remote peers to use those interfaces.
References: nodebuilder/…/config.go• L12-20 nodebuilder/…/config.go• L35-66 nodebuilder/…/addrs.go• L25-61
Network metrics
The host can expose native libp2p metrics through the node’s telemetry path. Metrics use the node’s Prometheus registerer when observability is enabled; otherwise libp2p metrics remain disabled. This keeps network measurements available without requiring a separate metrics server.
References: nodebuilder/…/metrics.go• L9-32 nodebuilder/…/host.go• L107-114 nodebuilder/…/module.go• L13-34
Routing and discovery
DHT routing
The node uses a network-scoped Kademlia DHT to route peer connections. Light nodes use the DHT as clients. Bridge nodes use it as servers. The DHT starts after host construction and uses the configured entry peers to join the network.
The host also supports routed connections. When a caller has a PeerID but no address, routing can find an address before the host connects.
References: nodebuilder/…/routing.go• L16-56 nodebuilder/…/host.go• L30-34
Bootstrap connectivity
Bootstrap peers provide the first links into a network. Mainnet and Mocha use built-in peer lists. Private, Corto, and custom networks require supplied configuration. A bootstrapper connects to the known peers so it can help other nodes enter the network.
The CELESTIA_BOOTSTRAPPER=true setting enables this behavior. The node attempts all listed peers in parallel and logs an individual failure without stopping the other attempts. Bootstrap and mutual peers are protected from normal connection trimming.
The bootstrap flow turns configured network entry points into durable links. This diagram shows how the node validates, parses, and uses those points.
flowchart LR
A[Network choice] --> B[Validate network]
B --> C[Load bootstrap addresses]
C --> D[Parse peer addresses]
D --> E{Bootstrapper enabled?}
E -- No --> F[Use peers for network entry]
E -- Yes --> G[Connect to listed peers]
G --> H[Protect successful links]
References: nodebuilder/…/bootstrap.go• L14-59 nodebuilder/…/bootstrap.go• L81-114 nodebuilder/…/network.go• L12-67 nodebuilder/…/genesis.go• L7-30 nodebuilder/…/misc.go• L17-67
Peer discovery
Discovery uses a rendezvous topic built from a role tag and the p2p protocol version. Full and archival groups represent the main peer services. Full and bridge nodes advertise the full-node service, while light nodes find full nodes.
Discovery accepts a peer only after it connects to that peer. A lost connection removes the peer and starts another search. Accepted peers stay protected from connection-manager pruning for their discovery group.
References: nodebuilder/…/p2p_constructors.go• L21-31 nodebuilder/…/p2p_constructors.go• L41-99 nodebuilder/…/p2p_constructors.go• L102-148 share/…/discovery.go• L42-110 share/…/discovery.go• L211-243 share/…/discovery.go• L341-392
Pubsub networks
GossipSub control
The node-wide pubsub service uses GossipSub to spread chain-related messages through an overlay. Peer scores limit the effect of bad behavior. Bootstrap peers and mutual peers receive special treatment so they can support network entry and explicit peering.
Bootstrap nodes use a different overlay shape. They mainly pass peer information and traffic between network parts instead of forming the normal mesh.
References: nodebuilder/…/pubsub.go• L21-91 nodebuilder/…/pubsub.go• L108-175
Share notifications
The share layer uses a separate network-scoped pubsub channel for notifications about recent extended data squares. A notification carries a block height and data hash. A bridge node can publish these notices, while consumers use them to learn which share data may be available.
The channel checks messages before delivery. It rejects bad encodings, impossible heights, empty hashes, and invalid hashes. The notice points to data; separate share retrieval services fetch that data.
References: share/…/pubsub.go• L18-56 share/…/pubsub.go• L59-119 share/…/pubsub.go• L122-146 nodebuilder/…/module.go• L98-160
Reachability and resource controls
NAT reachability
Bridge nodes run a NAT service that reports whether the host appears publicly reachable. A non-public result warns that other nodes may not be able to create inbound connections. Light nodes do not enable this service in the p2p module.
Reachability is a signal, not a guarantee that every announced address works. The advertised address and the network port setup must still match the deployment.
References: nodebuilder/…/host.go• L107-112 nodebuilder/…/reachability.go• L10-43 nodebuilder/…/p2p.go• L166-177
Connection policy
The connection manager keeps active connections between role-specific low and high limits. It protects mutual peers, bootstrap peers, and peers retained by discovery from normal pruning. The connection gater blocks selected peers and closes an existing connection when an operator blocks it; unblocking does not reconnect the peer.
Connection protection preserves required links. Gating is an operator choice that prevents a peer from connecting.
References: nodebuilder/…/misc.go• L17-73 share/…/discovery.go• L151-170 share/…/discovery.go• L378-392 nodebuilder/…/p2p.go• L179-207
Resource limits
The resource manager limits network use. Its limits start from libp2p defaults and scale to available system resources. Bridge nodes add service and protocol limits for share exchange. Light nodes use the scaled general limits.
Bootstrap and mutual-peer addresses are allowlisted so required control links are not treated like arbitrary inbound traffic. The p2p API reports resource state and bandwidth totals for diagnosis.
References: nodebuilder/…/resources.go• L16-35 nodebuilder/…/resources.go• L37-68 nodebuilder/…/p2p.go• L85-97 nodebuilder/…/p2p.go• L210-228
Operational interface
P2P administration
The p2p module provides an admin interface for inspecting and changing live network state. Operators can inspect identity, addresses, peers, connections, NAT status, pubsub membership, bandwidth, and resource use. They can also connect to or close peers, manage blocked and protected peers, and ping a peer.
The command-line p2p client calls these operations through JSON-RPC. The RPC service wiring page explains how internal services become external node operations.
References: nodebuilder/…/p2p.go• L38-107 nodebuilder/…/p2p.go• L265-289 nodebuilder/…/p2p.go• L22-43 nodebuilder/…/p2p.go• L53-80
Change checklist
When these files or sections are changed, remember to consider these:
- Keep network validation, network identity, entry peers, and genesis data aligned. A recognized name can still lack the data needed to join or verify a network.
- Keep the bootstrapper setting and bootstrap connection policy aligned with the network entry plan.
- Keep discovery role tags and protocol versions aligned across nodes that must find one another.
- Keep listen addresses, announce rules, and deployment port settings aligned. A valid listen address can still be unusable when announced.
- Review pubsub scoring, bootstrap behavior, and mutual-peer settings together because they shape the overlay.
- Keep share-notification validation and share-exchange resource limits compatible across nodes.
- When adding a required long-lived peer, review both connection protection and resource allowlisting.
- Keep optional libp2p metrics registration aligned with the node telemetry path so network measurements are either captured or intentionally disabled.
- Keep transport defaults aligned with deployment assumptions. Multipath TCP is disabled unless the runtime setting changes.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The node uses the wrong network choice or entry-peer list | It joins the wrong routing and discovery scope or cannot join at all | Use one validated network choice with matching network data and peers |
| A bootstrapper has no usable entry peers | It does not strengthen network entry links | Enable bootstrapper mode only with reachable peers for that network |
| A private or undialable listen address is announced | Peers learn an address that cannot accept their connections | Remove it from announcements or provide a reachable announce address |
| Discovery tags or protocol versions differ between nodes | Healthy nodes do not find each other | Change the discovery version and its deployment set together |
| NAT remains non-public for a bridge node | Other peers may fail to dial the node | Expose the p2p port and verify the announced address and mapping |
| A required peer is not protected or allowlisted | Connection pruning or resource limits can remove a required link | Configure connection protection and resource allowlisting together |
| Share notifications or share-exchange limits are incompatible | Share discovery or retrieval can stall, or peer resource use can grow unsafely | Review notification checks and share-exchange limits as one contract |
| Libp2p metrics are enabled without the node telemetry registration path | Network measurements are absent from the expected telemetry output | Enable the p2p metrics option with the node's telemetry setup |
| A deployment assumes Multipath TCP without changing the runtime setting | The host uses its normal transport paths instead of Multipath TCP | Set and verify the runtime option when Multipath TCP is required |
Key files
| File | Why to read it |
|---|---|
| nodebuilder/…/module.go | Shows the p2p service graph and role-specific construction path. |
| nodebuilder/…/host.go | Defines host identity inputs, transports, security, reachability, and lifecycle. |
| nodebuilder/…/metrics.go | Shows how optional native libp2p metrics enter the node telemetry path. |
| nodebuilder/…/config.go | Defines address, peering, and connection-facing settings. |
| nodebuilder/…/mptcp_test.go | Confirms that Multipath TCP listeners are disabled by default. |
| nodebuilder/…/network.go | Defines valid network names and aliases. |
| nodebuilder/…/bootstrap.go | Defines network entry peers, bootstrapper mode, and bootstrap connections. |
| nodebuilder/…/routing.go | Connects the network-scoped DHT to peer routing and host startup. |
| share/…/discovery.go | Shows how discovered peers become connected and managed peers. |
| nodebuilder/…/pubsub.go | Defines node-wide GossipSub behavior and peer scoring. |
| share/…/pubsub.go | Defines the share-notification channel and validation boundary. |
| nodebuilder/…/resources.go | Defines scaled resource limits and required-peer allowlisting. |
| nodebuilder/…/p2p.go | Defines the administrative p2p contract and observability surface. |