Back to Browse

Use with your AI agent

  1. Install — run npx skills add Kali-Decoder/Midnight-skills --skill midnight-p2p-networking for this skill, or npx skills add Kali-Decoder/Midnight-skills for all
  2. Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
  3. Build — the agent loads this skill and scaffolds your Midnight work

P2P Networking

FoundationIntermediateReviewedUnchanged since v1.0.7v1.0.0

Agent picks this when: Configure or debug Midnight P2P networking and peer discovery

libp2p peer discovery, TCP/WebSocket transport, Noise encryption, Yamux multiplexing, and gossip protocols.

Good for

  • Bootstrap, mDNS, and Kademlia DHT discovery strategies.
  • Noise + Yamux upgrades; Ping, Request-Response, and Notification substreams.

Preview in agent

Suggested prompts

Configure or debug Midnight P2P networking and peer discovery. Use the "midnight-p2p-networking" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Loaded skill midnight-p2p-networking

What the skill guides the agent to do:

  1. Bootstrap, mDNS, and Kademlia DHT discovery strategies.
  2. Noise + Yamux upgrades; Ping, Request-Response, and Notification substreams.

Illustrative — based on the skill's description, not recorded agent output.

Try it without installing: npx skills use Kali-Decoder/Midnight-skills@midnight-p2p-networking

What changed in v1.0.16

All registry changes

No changes in v1.0.16 or the releases before it that we track.

On this page · 11 sections
SKILL.md

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 --> Protocols

Discovery 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_NODE queries 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"] -.-> Learn

Connection establishment

After discovery, peers:

  1. Establish direct connections.
  2. 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):

TransportDescription
TCP/IPTraditional IPv4/IPv6 sockets
WebSocketsTCP + WebSocket framing (browser/proxy friendly)
DNSDomain names resolved to IPs during connection

Encryption and multiplexing

After the base transport connects, peers upgrade via negotiated protocols:

ProtocolPurpose
NoiseEnd-to-end confidentiality and integrity
YamuxMultiple logical streams over one physical connection
Multistream-SelectChoose 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 / Notifications

Substream protocols

Each substream runs a dedicated application-level protocol:

ProtocolPurpose
PingLiveness checks and latency measurement
Request-ResponseStructured exchange (block queries, transaction queries)
NotificationsBroadcast: 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.


  • midnight-consensus/ — what validators gossip (blocks, finality)
  • midnight-cryptography/ — Noise, Ed25519 peer identity
  • midnight-rpc/ — external client access (complements P2P sync)

Start in 2 steps

  1. 1. Install — one skill or the full set
  2. 2. Prompt — paste the example into your agent

Install all skills (recommended)

npx skills add Kali-Decoder/Midnight-skills

One command adds every Midnight skill to Cursor, Claude Code, and similar agents.

Install this skill only

npx skills add Kali-Decoder/Midnight-skills --skill midnight-p2p-networking

Installs only "midnight-p2p-networking" into every detected agent (Cursor, Claude Code, Codex, …).

Example agent prompt

Configure or debug Midnight P2P networking and peer discovery. Use the "midnight-p2p-networking" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Paste into Cursor, Claude Code, or Codex after installing.

Author
Kali-Decoder
Category
Foundation
Difficulty
intermediate
Version
v1.0.0

Tags

P2Plibp2pNetworkingDiscovery

Files included

SKILL.md
Create Social CardLive HackathonsGallery
Mock Demo
P2P Networking