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:
| Layer | What it does | Lessons | BOLTs |
|---|---|---|---|
| Network connection | Encrypted, authenticated links between nodes | 14 | 8 |
| Messaging | The format of every message on the wire | 13 | 1 |
| Peer-to-peer | Channel announcements and updates, the gossip | 11 | 7 |
| Routing | Finding a path and sending it in layers, by onion routing | 10, 12 | 4 |
| Payment channels | Funding, commitments, HTLCs, closing | 7, 8, 9 | 2, 3, 5 |
| Payments | What users see: an invoice, an amount, a receipt | 15 | 11 |
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.
- Which layer would you change to make payments more private, and which to make them cheaper?
- Why does it help that each layer is specified separately?
Check yourself
Further reading
Adapted from Mastering the Lightning Network. Andreas M. Antonopoulos, Olaoluwa Osuntokun and René Pickhardt. Licence: CC BY-SA 4.0.