Lightning for Builders Inside Lightning
Routing on a network of payment channels
How Alice pays Dina through two strangers without trusting either: hash time-locked contracts, step by step, then a real two-hop payment.
45 minIntermediate8 / 17
Draft: this lesson is still waiting for review.
What you'll learn
- Explain how an HTLC makes a payment conditional on a secret
- Explain why time locks decrease along the route
- Pay across two intermediate nodes and verify the preimage
Key terms
Alice wants to pay Dina 21,000 sats. They have no channel, but Alice → Bob → Chan → Dina is a path. Why would Bob and Chan, strangers to Alice, pass the money on honestly?
The promise: an HTLC
- Dina picks a random secret, the preimage, and puts its hash in her invoice.
- Alice offers Bob an HTLC: "21,002 sats are yours if you show me the secret behind this hash before block height H."
- Bob offers Chan the same deal for 21,001 sats, with an earlier deadline. Chan offers Dina 21,000 sats, earlier still.
- Dina knows the secret, so she reveals it to Chan and claims her 21,000. Chan now knows it and claims from Bob; Bob claims from Alice.
Each hop keeps 1 sat as its fee. Nobody can claim without the secret, and the secret only travels backwards once Dina has been paid. If anything fails, the deadlines pass and every HTLC is cancelled: the whole payment happens, or none of it does.
Why the deadlines shrink
Bob must have time to claim from Alice after Chan claims from him. So each hop's time lock is shorter than the one before it, by that node's time_lock_delta (you saw 80 blocks for LND in lesson 5).
Step 1: Pay through two hops
Pay through Bob and Chan
These exercises need a laptop with the lab running. You can read the lesson on your phone.
The route table lists Bob and Chan, each taking a small fee.
Step 2: The preimage is the receipt
Alice now holds the preimage. Hash it, and you get exactly the payment hash in Dina's invoice. That is proof she was paid, which Dina can't deny.
Check the preimage
These exercises need a laptop with the lab running. You can read the lesson on your phone.
Reflect
Write your answer down, or talk it over with a friend or your chama.
- Why can't Bob take Alice's payment and keep it?
- What would go wrong if every hop had the same time lock?
Check yourself
Further reading
Adapted from Mastering the Lightning Network. Andreas M. Antonopoulos, Olaoluwa Osuntokun and René Pickhardt. Licence: CC BY-SA 4.0.