Lightning for Builders Inside Lightning

Payment channels

Look inside a real channel: find its funding transaction on-chain and see how commitment transactions and revocation keep both sides honest.

40 minIntermediate7 / 17

Draft: this lesson is still waiting for review.

What you'll learn

  • Find a channel's funding transaction from its channel point
  • Explain how commitment transactions record each new balance
  • Explain how revocation punishes publishing an old balance

Key terms

commitment transaction (muamala wa ahadi)
A signed transaction holding a channel's current balances; every payment makes a new one.
multisig
A setup where several signatures are needed to spend bitcoin, for example 2 of 3.
transaction (muamala)
A signed message that moves bitcoin from old outputs to new owners.
UTXO
Unspent transaction output: a piece of bitcoin you can spend.

A channel is a UTXO: one output on the blockchain, locked so that only Alice and Bob together can spend it. Everything else about the channel is a set of unpublished, signed transactions.

The funding transaction

LND names a channel by its channel point, txid:index: the funding transaction and which of its outputs holds the channel. That output is a 2-of-2 multisig, wrapped in a pay-to-witness-script-hash (P2WSH) script, or a Taproot output for newer channel types.

Find the funding transaction

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

The output value matches the channel's capacity. Nothing on-chain shows who owns how much of it; that lives only in the two nodes.

Commitment transactions

Each side holds a commitment transaction that spends the funding output and pays out the current balances. Alice's copy is signed by Bob, so she can publish it whenever she wants, and Bob's copy is signed by Alice.

With each payment they sign a new pair and throw away the old one. But a thrown-away transaction is still valid Bitcoin, so what stops Alice from publishing an old one where she had more?

Revocation

When they move to a new state, Alice hands Bob a revocation secret for her previous commitment. If she ever publishes that old commitment:

  • her own output is time-locked (for example 144 blocks, about a day), and
  • during that time Bob can use the revocation secret to take all the channel's funds.

So cheating risks everything for nothing. This is why your node, or a watchtower, must keep watching the chain.

Practise this concept

Reflect

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

  1. Why does each side hold a different version of the commitment transaction?
  2. What would Bob need to do, and how fast, if Alice published an old balance?

Check yourself

Question 1 of 4What is a channel point?

Further reading

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