Lightning for Builders Inside Lightning

Lightning Network architecture

A map of the whole protocol, layer by layer, so every later lesson has a place to fit.

20 minIntermediate6 / 17

Draft: this lesson is still waiting for review.

What you'll learn

  • Name the layers of the Lightning protocol from the network up to payments
  • Place channels, routing, gossip, onions and invoices on that map
  • Find the BOLT that specifies each part

Key terms

onion routing (upitishaji wa kitunguu)
Wrapping payment instructions in layers of encryption so each node only learns the next hop.
gossip
Messages nodes pass on about existing channels and nodes, so each can build a map of the network.
invoice (ankara)
A Lightning payment request, often shown as a QR code, with an amount and an expiry time.

The book draws Lightning as a stack. Each layer relies only on the one below it, like the floors of a building. Read it from the bottom up:

LayerWhat it doesLessonsBOLTs
Network connectionEncrypted, authenticated links between nodes148
MessagingThe format of every message on the wire131
Peer-to-peerChannel announcements and updates, the gossip117
RoutingFinding a path and sending it in layers, by onion routing10, 124
Payment channelsFunding, commitments, HTLCs, closing7, 8, 92, 3, 5
PaymentsWhat users see: an invoice, an amount, a receipt1511

Underneath it all sits Bitcoin, which enforces the channels.

Why layers

Layers let developers improve one part without rewriting the rest. A new invoice format (like BOLT 12 offers) doesn't change how channels are funded. A faster pathfinding algorithm doesn't change the wire format.

They also make debugging possible. When a payment fails, you ask: was it the connection, gossip (the sender didn't know a channel), routing (no path with enough liquidity), or the channel itself?

How to use this map

Keep this table open as you go. From here on, each lesson zooms into one row. There is no lab in this chapter; it is the map for the next ten.

Reflect

Write your answer down, or talk it over with a friend or your chama.

  1. Which layer would you change to make payments more private, and which to make them cheaper?
  2. Why does it help that each layer is specified separately?

Check yourself

Question 1 of 4Which layer encrypts connections between nodes?

Further reading

Adapted from Mastering the Lightning Network. Andreas M. Antonopoulos, Olaoluwa Osuntokun and René Pickhardt. Licence: CC BY-SA 4.0.