Cooperative Channel Closing on the Lightning Network
What happens when we close a Lightning channel?
Closing a channel
A good and wisely open channel seldom needs to be closed. By “good channel” we mean a channel open with an interconnected and well managed partner, with good capacity and efficient flow of transactions. By the way sometimes we need to close a channel, in order to terminate the financial relationship between our node and the remote one, and we can do that cooperatively.
Cooperatively closing a Lightning Network channel is the preferred method for ending a channel partnership. This method involves a series of steps designed to ensure both parties receive their respective balances without delays or excessive fees.
What happens when a channel is closed? When a Lightning Network channel is closed, the funds that were held within the channel's 2-of-2 multisignature address are settled on the Bitcoin blockchain, and the channel is no longer available for transacting or routing payments. So the current balance of both parties is returned to each owner on-chain.
How the procedure looks like?
1. Initiating the Closure:
shutdown Message: One channel partner (e.g., Alice) initiates the closing process by sending a shutdown message to the other partner (Bob). This message includes:
channel_id: The unique identifier of the channel to be closed.
scriptpubkey: A Bitcoin script specifying the address where Alice wants to receive her funds. This could be any standard Bitcoin address. Just for recap: normally, referring to an on-chain transaction, a scriptPubKey is a locking script that is placed on a transaction output, specifying the conditions that must be met to spend that output in the future.
Acknowledgement: Bob responds with his own shutdown message, indicating his agreement to close the channel and providing the scriptpubkey for his chosen receiving address.
2. Negotiating Closing Fees:
closing_signed Message (Alice): Alice, as the channel funder, initiates the fee negotiation by sending a closing_signed message to Bob. This message proposes a transaction fee for the on-chain closing transaction and includes Alice's signature for the transaction.
closing_signed Message (Bob): Bob can either:
Accept: If Bob agrees with the proposed fee, he responds with a closing_signed message echoing the same fee and his own signature for the transaction.
Propose a Different Fee: If Bob disagrees, he responds with a closing_signed message containing a different fee_satoshis value.
Fee Negotiation: This back-and-forth exchange of closing_signed messages continues until both parties agree on a suitable fee for the closing transaction.
3. Constructing and Broadcasting the Closing Transaction:
Final Agreement: Once Alice receives a closing_signed message from Bob with the same fee she proposed, the negotiation concludes.
Transaction Construction: Both nodes construct the final closing transaction, which is similar to a commitment transaction but without timelocks or penalty mechanisms. The outputs of this transaction directly pay Alice and Bob their respective balances at the specified addresses.
Transaction Broadcast: Alice, as the initiator, broadcasts the signed closing transaction to the Bitcoin network.
4. Channel Closure Confirmation:
Transaction Confirmation: The closing transaction is confirmed on the Bitcoin blockchain, effectively closing the channel.
Fund Availability: Alice and Bob can now spend their received funds as desired.
What is important to remember:
Cooperative Nature: Both channel partners actively participate in the closing process, agreeing on the final balance distribution and the transaction fee. They both need to be online during the whole closing process.
On-Chain Fees: Closing a channel incurs on-chain transaction fees, which are paid by the channel funder.
Efficiency: A cooperative close generally results in lower fees and faster fund availability compared to a unilateral force close. This is because the parties agrees on all the aspects of the closing process.
Finality: The confirmed closing transaction provides a definitive record of the final channel balance on the Bitcoin blockchain and terminates the channel existence.
Up-Front Shutdown Script (Optional): An optional feature where parties can pre-specify a "delivery address" for their funds during the channel opening. This enhances security by restricting the destination of funds upon closure, mitigating risks in case of a compromise.
I hope you enjoyed this value added article. If you did, please share it and subscribe to my other social channels as Youtube, Instagram, Tiktok for even more contents.
Massimo's posts are always a good education. direct and clear me explanations