midnight-p2p-networking
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseP2P Networking
P2P 网络
The peer-to-peer (P2P) layer connects Midnight nodes and enables data exchange across the decentralized network. Midnight uses the default Polkadot SDK Rust libp2p implementation.
点对点(P2P)层连接Midnight节点,实现去中心化网络中的数据交换。Midnight采用默认的Polkadot SDK Rust libp2p实现。
Stack overview
技术栈概览
mermaid
flowchart TB
subgraph Discovery["Peer discovery"]
BS["Bootstrap nodes"]
MDNS["mDNS (LAN)"]
KDHT["Kademlia DHT random walk"]
end
subgraph Transport["Connection"]
TCP["TCP/IP"]
WS["WebSockets"]
DNS["DNS resolution"]
end
subgraph Security["Upgrade"]
Noise["Noise Protocol — encryption"]
Yamux["Yamux — multiplexing"]
MS["Multistream-Select negotiation"]
end
subgraph Protocols["Substream protocols"]
Ping["Ping — liveness"]
RR["Request-Response — block/tx queries"]
Notif["Notifications — gossip, finality, sync"]
end
Discovery --> Transport
Transport --> Security
Security --> Protocolsmermaid
flowchart TB
subgraph Discovery["Peer discovery"]
BS["Bootstrap nodes"]
MDNS["mDNS (LAN)"]
KDHT["Kademlia DHT random walk"]
end
subgraph Transport["Connection"]
TCP["TCP/IP"]
WS["WebSockets"]
DNS["DNS resolution"]
end
subgraph Security["Upgrade"]
Noise["Noise Protocol — encryption"]
Yamux["Yamux — multiplexing"]
MS["Multistream-Select negotiation"]
end
subgraph Protocols["Substream protocols"]
Ping["Ping — liveness"]
RR["Request-Response — block/tx queries"]
Notif["Notifications — gossip, finality, sync"]
end
Discovery --> Transport
Transport --> Security
Security --> ProtocolsDiscovery mechanisms
节点发现机制
To join the network, a node must discover and connect to peers.
要加入网络,节点必须发现并连接到其他节点。
Bootstrap nodes
Bootstrap节点
- Predefined trusted peers in network configuration (hard-coded identities + addresses).
- On startup, the node connects to bootstrap peers to join the network and learn about additional peers.
- 网络配置中预定义的可信节点(硬编码身份+地址)。
- 启动时,节点连接到Bootstrap节点以加入网络,并了解更多节点信息。
mDNS (multicast DNS)
mDNS(多播DNS)
- Discovers peers on the same LAN via UDP broadcast.
- Useful for development, testnets, or co-located deployments.
- Enable/disable via network settings.
- 通过UDP广播发现**同一局域网(LAN)**内的节点。
- 适用于开发、测试网或同址部署场景。
- 可通过网络设置启用/禁用。
Kademlia DHT (random walk)
Kademlia DHT(随机游走)
- Once connected to at least one peer, the node performs a Kademlia-based random walk on each configured chain's DHT.
- Sends queries to discover more peers.
FIND_NODE - Builds a resilient, expanding view of the network over time.
mermaid
flowchart LR
Start["Node starts"] --> Boot["Connect to bootstrap"]
Boot --> Learn["Learn peer addresses"]
Learn --> Walk["Kademlia random walk"]
Walk --> More["More peers discovered"]
More --> Walk
MDNS["mDNS on LAN"] -.-> Learn- 连接到至少一个节点后,节点会在每条配置链的DHT上执行基于Kademlia的随机游走。
- 发送查询以发现更多节点。
FIND_NODE - 随时间推移构建一个弹性扩展的网络视图。
mermaid
flowchart LR
Start["Node starts"] --> Boot["Connect to bootstrap"]
Boot --> Learn["Learn peer addresses"]
Learn --> Walk["Kademlia random walk"]
Walk --> More["More peers discovered"]
More --> Walk
MDNS["mDNS on LAN"] -.-> LearnConnection establishment
连接建立
After discovery, peers:
- Establish direct connections.
- Negotiate shared protocol capabilities (transport, security, multiplexing).
This foundation supports higher-level sync and gossip protocols.
发现节点后,节点会:
- 建立直接连接。
- 协商共享协议能力(传输层、安全层、多路复用)。
这一基础支持更高层级的同步和gossip协议。
Transport layer
传输层
When node A (Alice) connects to node B (Bob):
| Transport | Description |
|---|---|
| TCP/IP | Traditional IPv4/IPv6 sockets |
| WebSockets | TCP + WebSocket framing (browser/proxy friendly) |
| DNS | Domain names resolved to IPs during connection |
当节点A(Alice)连接到节点B(Bob)时:
| 传输协议 | 描述 |
|---|---|
| TCP/IP | 传统IPv4/IPv6套接字 |
| WebSockets | TCP + WebSocket帧格式(适配浏览器/代理) |
| DNS | 连接过程中将域名解析为IP地址 |
Encryption and multiplexing
加密与多路复用
After the base transport connects, peers upgrade via negotiated protocols:
| Protocol | Purpose |
|---|---|
| Noise | End-to-end confidentiality and integrity |
| Yamux | Multiple logical streams over one physical connection |
| Multistream-Select | Choose compatible encryption and multiplexing options |
mermaid
sequenceDiagram
participant A as Alice
participant B as Bob
A->>B: TCP / WebSocket connect
A->>B: Multistream-Select (Noise)
Note over A,B: Encrypted channel
A->>B: Multistream-Select (Yamux)
Note over A,B: Multiplexed substreams
A->>B: Open Ping / Request-Response / Notifications基础传输连接建立后,节点会通过协商协议进行升级:
| 协议 | 用途 |
|---|---|
| Noise | 端到端机密性与完整性保障 |
| Yamux | 在一条物理连接上承载多个逻辑流 |
| Multistream-Select | 选择兼容的加密与多路复用方案 |
mermaid
sequenceDiagram
participant A as Alice
participant B as Bob
A->>B: TCP / WebSocket connect
A->>B: Multistream-Select (Noise)
Note over A,B: Encrypted channel
A->>B: Multistream-Select (Yamux)
Note over A,B: Multiplexed substreams
A->>B: Open Ping / Request-Response / NotificationsSubstream protocols
子流协议
Each substream runs a dedicated application-level protocol:
| Protocol | Purpose |
|---|---|
| Ping | Liveness checks and latency measurement |
| Request-Response | Structured exchange (block queries, transaction queries) |
| Notifications | Broadcast: new transactions, block announcements, finality updates, light-client state sync |
每个子流运行一个专用的应用层协议:
| 协议 | 用途 |
|---|---|
| Ping | 存活状态检查与延迟测量 |
| Request-Response | 结构化数据交换(区块查询、交易查询) |
| Notifications | 广播:新交易、区块公告、最终性更新、轻客户端状态同步 |
Peer identification
节点标识
- Each node has a unique Ed25519 public key for P2P identity.
- This keypair is separate from consensus message signing keys.
- Exchanged during handshake; used to authenticate peers for the session.
See for Ed25519 usage in libp2p vs GRANDPA.
midnight-cryptography/- 每个节点拥有唯一的Ed25519公钥作为P2P身份标识。
- 该密钥对与共识消息签名密钥相互独立。
- 在握手阶段交换;用于会话中的节点身份验证。
查看了解libp2p与GRANDPA中Ed25519的使用方式。
midnight-cryptography/Related skills
相关技能
- — what validators gossip (blocks, finality)
midnight-consensus/ - — Noise, Ed25519 peer identity
midnight-cryptography/ - — external client access (complements P2P sync)
midnight-rpc/
- —— 验证节点 gossip 的内容(区块、最终性信息)
midnight-consensus/ - —— Noise加密、Ed25519节点身份
midnight-cryptography/ - —— 外部客户端访问(补充P2P同步)
midnight-rpc/