这是一个实验性功能。 它已经在多种网络条件和扰动下进行了测试,但在生产主网链上启用之前, 你仍应先针对自己的具体工作负载完成验证。
仅可与 AdaptiveSync 搭配使用
这是一个基于 go-libp2p 的实验性网络层。 它为点对点通信引入了新的传输层和连接管理层, 同时保持面向 reactor 的 CometBFT API 不变。 参与方仍然使用相同的核心 p2p 概念(Switch、Peer、PeerSet、Reactor、Envelope 等)。 这些抽象之下的传输实现从 comet-p2p 切换为 lib-p2p。 lib-p2p 是一个被广泛使用的网络栈,提供可用于生产环境的点对点能力, 并且支持多种语言实现和多种传输协议(TCP、QUIC、WebSockets 等)。 你可以在 CometBFT 代码库中参考以下实现:

性能与活性

在高负载条件下,传统的 comet-p2p 可能会成为现代区块链工作负载的网络瓶颈:
  • 在并发消息压力下更容易发生拥塞。
  • 流和消息处理在面对流量突增时扩展性较弱。
  • 当其余栈已经完成优化时,这会限制端到端吞吐量。
lib-p2p 集成通过原生的面向流传输、并发接收流水线以及按 reactor 自动伸缩的工作池来解决这些问题, 有助于降低队列压力并改善高负载下的消息流动。 除了原始吞吐量提升之外,这还通过让对等节点通信和区块传播在持续拥塞与突发负载下更具韧性, 进一步改善网络活性。 在我们的基准测试中,结合栈内其他性能改进,TPS 已超过 2000, 而 lib-p2p 是促成这一结果的关键解锁项之一。

传输与对等节点 ID 的差异

lib-p2p 使用自己的 peer ID 格式, 这与 comet-p2p 不同,二者格式不兼容。
# comet-p2p peer ID format
[email protected]:26656

# lib-p2p peer ID format
{ host = "10.186.73.3:26656", id = "12D3KooWRuTppVZGE7qhanfsHfmzkWUZnnRbTxbgWYvKibij9niy" }
要通过 CLI 打印节点的 lib-p2p peer ID:
cometbft show-node-id --libp2p
# e.g. 12D3KooWJwoqHMXukQGFg425582Jr2Cq9VLE6MtbRt21hRrudjqM
lib-p2p 使用 QUIC 而不是 TCP,请确保防火墙允许 UDP 通信。

配置

在 config.toml 的 p2p.libp2p 部分配置 lib-p2p。 除 external_address 和 laddr 之外,其他所有 p2p 设置都会被忽略。 默认情况下,节点监听 UDP 端口 26656。
要验证配置是否成功,请检查日志中是否出现:
“EXPERIMENTAL: go-libp2p transport is enabled.”
[p2p.libp2p]

# Enabled set true to use go-libp2p for networking instead of CometBFT's p2p.
enabled = true

# Bootstrap peers to connect to
# format: { host, id, private (opt), persistent (opt), unconditional (opt) }
# DNS resolution is also supported (e.g. "example.com:26656")
bootstrap_peers = [
  { host = "10.186.73.3:26656", id = "12D3KooWRuTppVZGE7qhanfsHfmzkWUZnnRbTxbgWYvKibij9niy", persistent = true },
  { host = "10.186.73.5:26656", id = "12D3KooWHjC8SJFVpAvY3qpM5PPeXSpQZvLxcZb7Tjr1kHMLEFtS", persistent = true },
  { host = "10.186.73.6:26656", id = "12D3KooWJFbLcqdPpNP7E1EXC4tDiPtxEGDM6K7RXpDsdWmVnjSu", persistent = true },
]

# Options for scaling concurrent p2p message queues.
[p2p.libp2p.scaler]
min_workers = 4
max_workers = 32

# downscale concurrency if P90 latency of message processing
# is longer than the threshold
threshold_latency = "100ms"

## Optional per-reactor override.
# [[p2p.libp2p.scaler.overrides]]
# reactor = "MEMPOOL"
# min_workers = 8
# max_workers = 512
# threshold_latency = "500ms"

# Resource limits mode:
# - disabled: no limits (unsafe on untrusted/public networks)
# - default: lib-p2p defaults
# - custom: enforce explicit peer/stream caps
[p2p.libp2p.limits]
mode = "default"

# Used only in custom mode.
# max_peers = 200
# max_peer_streams = 16
每个 bootstrap peer 支持以下选项:
  • persistent:确保始终与该对等节点保持(重新)连接。
  • unconditional:不受最大对等节点数量限制影响。
  • private:不会将该对等节点传播给其他对等节点。

队列伸缩器

队列伸缩器通过吞吐量/延迟反馈回路控制 reactor 的接收并发度。
  • min_workers、max_workers:每个 reactor 的工作线程下限/上限。
  • threshold_latency:目标处理延迟阈值。
  • overrides:针对每个 reactor 的配置值(reactor 名称不区分大小写)。
在大多数部署中,默认值已经足够,应该优先使用。 只有当指标显示队列持续增长、接收延迟升高或吞吐量不佳时,再进行调优。

资源管理器

资源管理器模式决定连接和流的限制方式:
  • default:使用 libp2p 自动伸缩的限制以及内置协议的合理上限。
  • custom:禁用大多数 cometbft p2p 限制,但强制执行显式的 max_peers 和 max_peer_streams 上限。
  • disabled:不做任何限制,适合受控基准测试和本地测试。
如果默认值不够,推荐按以下流程调优:
  1. 从 mode = "default" 开始,在具有代表性的负载下观察指标。
  2. 如果限制边界仍不清晰,可短时间使用 mode = "disabled" 进行受控测试,以找出所需余量。
  3. 切换到 mode = "custom",并基于测量结果设置保守的 max_peers / max_peer_streams 上限。
  4. 重新测试并保留安全余量;避免在公共网络中长期使用 disabled 模式。
你可以在这里找到关于 lib-p2p 资源管理器的更多细节:

实现细节

从 CometBFT actor 模型的视角看,API 保持不变: Reactor、Peer、PeerSet、Switch 以及 envelope 流程仍然兼容, 因此现有 reactor 无需在协议层面重写即可运行。 在连接层,lib-p2p 用其原生的身份机制和安全握手机制 取代了 CometBFT 的 secret connection。 这意味着,对等会话建立、加密协商和远端身份识别都由 lib-p2p 传输栈处理。 CometBFT 的通道流量会映射到 lib-p2p 协议处理器:
  • 每个 CometBFT 通道都会暴露在一个 lib-p2p protocol.ID 命名空间下(例如 /p2p/cometbft/1.0.0/...)。
  • 消息通过绑定到这些协议处理器的 lib-p2p 流进行交换。
  • 入站处理支持并发,结合优先级 FIFO 队列和工作池,在负载下并行处理 reactor 流量。
工作池由 autopool 自动伸缩:
  • 它会跟踪逐消息处理时长,并基于吞吐量 EWMA、队列压力和延迟分位数(P90)做出决策。
  • 吞吐量快速增长或队列压力升高时会增加工作线程;当 P90 延迟高于配置阈值时会缩减规模,以避免过载。
  • 默认限制是每个 reactor 4 到 32 个工作线程;mempool 使用更大的范围(8 到 512)以吸收突发交易流量。
  • 在分发前会保持优先级顺序(Receive() 按优先级推入,然后由工作线程并行消费)。

对比与限制

当前版本不包含 peer exchange(PEX)。 节点必须使用显式 bootstrap peers/静态拓扑;PEX 将在未来版本中加入。
区域comet-p2plib-p2p
传输TCPQUIC
对等身份Comet peer IDs(<hex>@host:port)lib-p2p peer IDs(12D3Koo...)
连接握手Comet secret connectionlib-p2p identity and secure handshake
对等交换PEX + address book flow此版本无 PEX
由于对等节点标识格式不同,你不能运行混合 comet-p2p / lib-p2p 的网络。

指标

用于 lib-p2p 队列伸缩器和资源调优的关键指标:
cometbft_p2p_message_reactor_queue_concurrency
cometbft_p2p_messages_reactor_in_flight
cometbft_p2p_messages_reactor_pending_duration
cometbft_p2p_message_reactor_receive_duration
cometbft_p2p_messages_received
cometbft_p2p_peer_receive_bytes_total
cometbft_p2p_peer_send_bytes_total
cometbft_p2p_message_receive_bytes_total
cometbft_p2p_message_send_bytes_total
cometbft_p2p_peer_send_queue_size
cometbft_p2p_peers

This is an experimental feature. It has been tested under a range of network conditions and perturbations, but you should validate it for your specific workload before enabling it on a production mainnet chain.
Use only alongside AdaptiveSync
This is an experimental networking layer based on go-libp2p. It adds a new transport and connection-management layer for peer-to-peer communication, while keeping the reactor-facing CometBFT API unchanged. Actors still use the same core p2p concepts (Switch, Peer, PeerSet, Reactor, Envelope, …). The transport implementation under those abstractions is lib-p2p instead of comet-p2p. lib-p2p is a widely used networking stack with production-ready peer-to-peer features, and implementations across many languages and transport protocols (TCP, QUIC, WebSockets, and more). You can refer to the implementation in the CometBFT codebase here:

Performance and Liveness

In high-load conditions, legacy comet-p2p can become a networking bottleneck for modern blockchain workloads:
  • It is more prone to congestion under concurrent message pressure.
  • Stream/message handling is less effective at scaling with traffic spikes.
  • This limits end-to-end throughput when the rest of the stack is optimized.
The lib-p2p integration addresses this with native stream-oriented transport, concurrent receive pipelines, and autoscaled worker pools per reactor, which helps reduce queue pressure and improve message flow under load. Beyond raw throughput, this also improves network liveness by making peer communication and block propagation more resilient under sustained congestion and sudden load spikes. In our benchmarks, together with additional performance improvements across the stack, we reached over 2000 TPS, and lib-p2p has been one of the key unblockers enabling that result.

Differences in Transport and Peer IDs

lib-p2p uses its own peer ID format, which is different from comet-p2p. The two formats are not compatible.
# comet-p2p peer ID format
[email protected]:26656

# lib-p2p peer ID format
{ host = "10.186.73.3:26656", id = "12D3KooWRuTppVZGE7qhanfsHfmzkWUZnnRbTxbgWYvKibij9niy" }
To print your node’s lib-p2p peer ID from the CLI:
cometbft show-node-id --libp2p
# e.g. 12D3KooWJwoqHMXukQGFg425582Jr2Cq9VLE6MtbRt21hRrudjqM
lib-p2p uses QUIC instead of TCP, ensure UDP communication is allowed in your firewall.

Configuration

Configure lib-p2p in the p2p.libp2p section of config.toml. All other p2p settings are ignored except external_address and laddr. By default, the node listens on UDP port 26656.
To validate successful configuration, check logs for:
“EXPERIMENTAL: go-libp2p transport is enabled.”
[p2p.libp2p]

# Enabled set true to use go-libp2p for networking instead of CometBFT's p2p.
enabled = true

# Bootstrap peers to connect to
# format: { host, id, private (opt), persistent (opt), unconditional (opt) }
# DNS resolution is also supported (e.g. "example.com:26656")
bootstrap_peers = [
  { host = "10.186.73.3:26656", id = "12D3KooWRuTppVZGE7qhanfsHfmzkWUZnnRbTxbgWYvKibij9niy", persistent = true },
  { host = "10.186.73.5:26656", id = "12D3KooWHjC8SJFVpAvY3qpM5PPeXSpQZvLxcZb7Tjr1kHMLEFtS", persistent = true },
  { host = "10.186.73.6:26656", id = "12D3KooWJFbLcqdPpNP7E1EXC4tDiPtxEGDM6K7RXpDsdWmVnjSu", persistent = true },
]

# Options for scaling concurrent p2p message queues.
[p2p.libp2p.scaler]
min_workers = 4
max_workers = 32

# downscale concurrency if P90 latency of message processing
# is longer than the threshold
threshold_latency = "100ms"

## Optional per-reactor override.
# [[p2p.libp2p.scaler.overrides]]
# reactor = "MEMPOOL"
# min_workers = 8
# max_workers = 512
# threshold_latency = "500ms"

# Resource limits mode:
# - disabled: no limits (unsafe on untrusted/public networks)
# - default: lib-p2p defaults
# - custom: enforce explicit peer/stream caps
[p2p.libp2p.limits]
mode = "default"

# Used only in custom mode.
# max_peers = 200
# max_peer_streams = 16
Each bootstrap peer supports these options:
  • persistent: ensures the peer is always (re)connected.
  • unconditional: not affected by the max number of peers limit.
  • private: peer is not gossiped to other peers.

Queue Scaler

The queue scaler controls reactor receive concurrency using a throughput/latency feedback loop.
  • min_workers, max_workers: lower/upper worker bounds per reactor.
  • threshold_latency: target processing-latency threshold.
  • overrides: per-reactor values (case-insensitive reactor name).
In most deployments, the defaults are enough and should be used first. Tune only when metrics show persistent queue growth, elevated receive latency, or poor throughput.

Resource Manager

Resource manager mode determines connection and stream limits:
  • default: uses libp2p autoscaled limits and sane built-in protocol caps.
  • custom: disables most cometbft p2p limits but enforces explicit max_peers and max_peer_streams caps.
  • disabled: no limits, useful for controlled benchmarking and local testing.
Recommended tuning flow if defaults are not enough:
  1. Start with mode = "default" and observe metrics under representative load.
  2. If limits are still unclear, run short, controlled tests with mode = "disabled" to discover required headroom.
  3. Move to mode = "custom" and set conservative max_peers / max_peer_streams caps based on measurements.
  4. Re-test and keep safety margin; avoid running public networks long-term in disabled mode.
You can find more details about lib-p2p resource manager here:

Implementation Details

From the CometBFT actor-model perspective, the API stays the same: Reactor, Peer, PeerSet, Switch, and envelope flow remain compatible, so existing reactors can run without protocol-level rewrites. At the connection layer, lib-p2p replaces CometBFT secret connection with lib-p2p native identity and secure handshake mechanisms. This means peer session establishment, encryption negotiation, and remote identification are handled by the lib-p2p transport stack. CometBFT channel traffic is mapped to lib-p2p protocol handlers:
  • Each CometBFT channel is exposed under a lib-p2p protocol.ID namespace (for example /p2p/cometbft/1.0.0/...).
  • Messages are exchanged over lib-p2p streams bound to those protocol handlers.
  • Inbound handling is concurrent, with a priority FIFO queue and worker pool to process reactor traffic in parallel under load.
The worker pool is autoscaled by autopool:
  • It tracks per-message processing durations and computes decisions from throughput EWMA, queue pressure, and latency percentile (P90).
  • High throughput growth or queue pressure scales workers up; high P90 latency above the configured threshold triggers shrink to avoid overload.
  • Default limits are 4-32 workers per reactor; mempool uses a wider range (8-512) to absorb bursty transaction traffic.
  • Priority ordering is preserved before dispatch (Receive() pushes by priority, then workers consume in parallel).

Comparison and Limitations

The current release does not include peer exchange (PEX). Nodes must use explicit bootstrap peers/static topology; PEX will be added in a future release.
Areacomet-p2plib-p2p
TransportTCPQUIC
Peer identityComet peer IDs (<hex>@host:port)lib-p2p peer IDs (12D3Koo...)
Connection handshakeComet secret connectionlib-p2p identity and secure handshake
Peer exchangePEX + address book flowNo PEX in this release
Because peer identification formats differ, you cannot run a mixed comet-p2p / lib-p2p network.

Metrics

Key metrics for lib-p2p queue-scaler and resource tuning:
cometbft_p2p_message_reactor_queue_concurrency
cometbft_p2p_messages_reactor_in_flight
cometbft_p2p_messages_reactor_pending_duration
cometbft_p2p_message_reactor_receive_duration
cometbft_p2p_messages_received
cometbft_p2p_peer_receive_bytes_total
cometbft_p2p_peer_send_bytes_total
cometbft_p2p_message_receive_bytes_total
cometbft_p2p_message_send_bytes_total
cometbft_p2p_peer_send_queue_size
cometbft_p2p_peers