- Reminder of the channel lifecycle
- The three types of channel closure
- The Good: the cooperative closure
- The Bad: the forced closure
- The cheat: cheating
In this chapter, we will discuss closing a channel on the Lightning Network, which is done through a Bitcoin transaction, just like opening a channel. After seeing how transactions within a channel work, it is now time to see how to close a channel and recover the funds on the Bitcoin blockchain.
Reminder of the channel lifecycle
The lifecycle of a channel begins with its opening, which is initiated via a Bitcoin transaction. Then, Lightning transactions are made within it. Finally, when the parties wish to recover their funds, the channel is closed through a second Bitcoin transaction. The intermediate transactions made on Lightning are represented by unpublished commitment transactions.
The three types of channel closure
There are three main ways to close this channel, which can be called the good, the brute, and the truant (inspired by Andreas Antonopoulos in Mastering the Lightning Network):
- The Good: the cooperative closure, where Alice and Bob agree to close the channel.
- The Bad: the forced closure, where one of the parties decides to close the channel honestly, but without the other's agreement.
- The Ugly: the closure with cheating, where one of the parties attempts to steal funds by publishing an old commitment transaction (any but not the last one, which reflects the actual and fair distribution of funds).
Let's take an example:
- Alice owns 100,000 satoshis and Bob 30,000 satoshis.
- This distribution is reflected in 2 commitment transactions (one per user) that are not published, but could be in the event of channel closure.
The Good: the cooperative closure
In a cooperative closure, Alice and Bob agree to close the channel. Here's how it goes:
- Alice sends a message to Bob via the Lightning communication protocol to propose closing the channel.
- Bob agrees, and the two parties make no further transactions in the channel.
- Alice and Bob negotiate together the fees of the closing transaction. These fees are generally calculated based on the Bitcoin fee market at the time of closure. It is essential to note that it is always the person who opened the channel (in our example, Alice) who pays the closing fees.
- They construct a new closing transaction. This transaction resembles a commitment transaction, but without timelocks or revocation mechanisms, since both parties are cooperating and there is no risk of cheating. This cooperative closing transaction is therefore different from commitment transactions.
For example, if Alice owns 100,000 satoshis and Bob owns 30,000 satoshis, the closing transaction will send 100,000 satoshis to Alice's address and 30,000 satoshis to Bob's address, without timelock constraints. Once this transaction is signed by both parties, it is published by Alice. Once the transaction is confirmed on the Bitcoin blockchain, the Lightning channel will be officially closed.
The cooperative closure is the preferred method of closing because it is fast (no timelock) and the transaction fees are adjusted according to the current Bitcoin market conditions. This avoids paying too little, which could risk blocking the transaction in the mempools, or overpaying unnecessarily, resulting in unnecessary financial loss for the participants.
The Bad: the forced closure
When Alice's node sends a message to Bob's asking for a cooperative closure, if he does not respond (for example, due to an internet outage or a technical problem), Alice can proceed with a forced closure by publishing the last signed commitment transaction.
In this case, Alice will simply publish the last commitment transaction, which reflects the state of the channel at the time the last Lightning transaction took place, with the correct distribution of funds.
This transaction includes a timelock for Alice's funds, making the closure slower.
Additionally, the fees associated with the commitment transaction may be unsuitable at the time of closure, as they were set when the transaction was created, often several months prior. Generally, Lightning clients tend to overestimate fees to avoid future problems, but this can lead to excessive fees or, conversely, too low fees.
In summary, forced closure is a last resort option when the peer no longer responds. It is slower and less economical than a cooperative closure. Therefore, it should be avoided whenever possible.
The cheat: cheating
Finally, a closure with cheating occurs when one of the parties attempts to publish an old commitment transaction, often when they held more funds than they were entitled to. For example, Alice might publish an old transaction where she owned 120,000 satoshis, while she actually owns only 100,000 now.
Bob, to prevent this cheating, monitors the Bitcoin blockchain and its mempool to ensure Alice does not publish an old transaction. If Bob detects a cheating attempt, he can use the revocation key to recover Alice's funds and punish her by taking the entire funds of the channel. Since Alice is blocked by the timelock on her output, Bob has time to spend it without a timelock on his side, allowing him to recover the whole sum on an address he owns.
Obviously, cheating can potentially succeed if Bob does not act within the time imposed by the time lock on Alice's output. In this case, Alice's output is unlocked, allowing her to consume it to create a new output to an address she controls.
What should you take away from this chapter?
There are three ways to close a channel:
- Cooperative Closure: Fast and less expensive, where both parties agree to close the channel and publish a tailored closing transaction.
- Forced Closure: Less desirable, as it relies on publishing a commitment transaction, with potentially unsuitable fees and a timelock, which slows down the closure.
- Cheating: If one of the parties tries to steal funds by publishing an old transaction, the other can use the revocation key to punish this cheating.
In the upcoming chapters, we will explore the Lightning Network from a broader perspective, focusing on its operation as a network.
Quiz
Quiz1/5
lnp2013.4
In what situation is a forced closure of a channel used?