midnight-p2p-networking
Skill18 starsChanged 18 days agoMITView on GitHub
Midnight P2P networking — Polkadot SDK libp2p, peer discovery (bootstrap, mDNS, Kademlia DHT), transport (TCP/WebSocket/DNS), Noise encryption, Yamux multiplexing, and substream protocols. Use when configuring nodes, debugging connectivity, or explaining how validators exchange blocks and gossip.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- 1am-walletSkill
- android-example-votingSkill
- ankr-midnightSkill
- compactSkill
- dynamic-midnight-walletSkill
- example-counterSkill
- example-hello-worldSkill
- example-leaderboard-dappSkill
- example-locker-dappSkill
- example-passport-dappSkill
- example-payment-dappSkill
- example-private-party-dappSkill
- example-private-reserve-auction-dappSkill
- example-zk-loan-applicationSkill
- gsap-coreSkill
- gsap-utilsSkill
- indexerSkill
- midnight-consensusSkill
- midnight-cryptographySkill
- midnight-environment-setupSkill
- midnight-jsSkill
- midnight-onchain-logicSkill
- midnight-passportSkill
- midnight-rpcSkill
- midnightskillSkill
- midnight-storageSkill
- midnight-transactionsSkill
- multinetworkSkill
- nftSkill
- react-wallet-connectorSkill
- midnight-securitySkill
- testingSkill
- token-transfersSkill
- why-midnightSkill
- zk-vs-fhe-vs-mpcSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 92
When node A (Alice) connects to node B (Bob):
- Distinctive: line 104
After the base transport connects, peers upgrade via negotiated protocols:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
P2P Networking
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.
Stack overview
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
- 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.
mDNS (multicast DNS)
- Discovers peers on the same LAN via UDP broadcast.
- Useful for development, testnets, or co-located deployments.
- Enable/disable via network settings.
Kademlia DHT (random walk)
- Once connected to at least one peer, the node performs a Kademlia-based random walk on each configured chain's DHT.
- Sends
FIND_NODEqueries to discover more peers. - Builds a resilient, expanding view of the network over time.
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.
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 |
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 |
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 |
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 midnight-cryptography/ for Ed25519 usage in libp2p vs GRANDPA.
Related skills
midnight-consensus/— what validators gossip (blocks, finality)midnight-cryptography/— Noise, Ed25519 peer identitymidnight-rpc/— external client access (complements P2P sync)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

