Lightning for Builders Inside Lightning

Channel operation and payment forwarding

Two ways to end a channel: a cooperative close that settles at once, and a force close where the time lock makes you wait. Do both.

40 minIntermediate9 / 17

Draft: this lesson is still waiting for review.

What you'll learn

  • Explain the difference between a cooperative and a force close
  • Close Alice's channel with Bob cooperatively
  • Force-close Dina's channel with Chan and watch the time lock

Key terms

force close (kufunga kwa nguvu)
Closing a channel alone by publishing a commitment transaction; your funds wait for a timelock.
commitment transaction (muamala wa ahadi)
A signed transaction holding a channel's current balances; every payment makes a new one.
HTLC
Hash time-locked contract: a payment that unlocks only with the right secret before a deadline.

While a channel is open, the two nodes keep adding and removing HTLCs and signing new commitments: that is payment forwarding. Sooner or later, a channel ends.

Cooperative close

Both nodes agree on the final balance and sign one new closing transaction that pays each side directly. There are no time locks, the fee is small and agreed, and both get their money as soon as it confirms. This is how a channel should end.

Close a channel cooperatively

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

Force close

If the other side is offline, unresponsive or misbehaving, a node can force close: it publishes its latest commitment transaction on its own. Then:

  • the other side is paid immediately,
  • the publisher's own output waits behind its time lock (blocks_til_maturity), and
  • any HTLCs still in flight are settled on-chain, each with its own deadline.

Force-close and watch the timelock

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

Dina's funds now show as limbo_balance with a count of blocks to go. On regtest you can mine them away; on mainnet that wait could be a day or more.

Reflect

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

  1. When would a node have no choice but to force close?
  2. Why do force closes cost more in fees than cooperative ones?

Check yourself

Question 1 of 4Does a cooperative close have a time lock?

Further reading

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