Lightning for Builders The network

Gossip and the channel graph

How every node learns the map of the network from its peers, and what that map contains. Read Alice's graph in Python.

35 minIntermediate11 / 17

Draft: this lesson is still waiting for review.

What you'll learn

  • Name the three gossip messages and what each announces
  • Explain why channels are announced only after they are confirmed
  • Read the channel graph from a node and count its nodes and channels

Key terms

gossip
Messages nodes pass on about existing channels and nodes, so each can build a map of the network.
channel (chaneli)
A payment link between two Lightning nodes, locked by a Bitcoin transaction.
node (nodi)
A computer running Bitcoin or Lightning software that checks every rule for itself.

To find a route to Dina, Alice needs a map: which nodes exist and which channels connect them. Nobody publishes that map. Every node builds its own from gossip, messages it hears from its peers and passes on.

Three gossip messages

MessageAnnouncesSigned by
channel_announcementA channel exists between two nodes, with proof it is funded on-chainBoth nodes and both funding keys
node_announcementA node's alias, colour, addresses and featuresThe node
channel_updateOne direction's fee policy, time lock and whether it is enabledThe node on that side

A channel is announced only after its funding transaction has six confirmations. That stops nodes from spamming the map with channels that don't exist: anyone can check the funding output on the blockchain.

Capacity, not balance

The graph shows each channel's capacity, the funding amount, but never how it's split between the two sides. Balances change with every payment and would reveal who paid whom. This is why senders sometimes try a route and fail: the map says the channel is big enough, but the balance on the needed side isn't.

Read Alice's map

Read the channel graph

These exercises need a laptop with the lab running. You can read the lesson on your phone.

Your counts should match the scenario: four nodes and three channels in a line. The book's lngraph.py does the same thing on the real network, where the graph holds many thousands of nodes.

Reflect

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

  1. The graph shows capacities but not balances. Why does Lightning keep balances private?
  2. What could a node learn about you from the public graph alone?

Check yourself

Question 1 of 4Which message announces one direction's fee policy?

Further reading

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