The closing transaction is how two parties end a payment channel. This transaction spends the funding output and splits funds within the channel based on the final channel state which is agreed on by both parties in the channel. The closing transaction is one of two Lightning Network transactions that occur on the Bitcoin blockchain; the other being the funding transaction.
In other words, the closing transaction essentially overrides everything that has happened within the channel and allocates the funds each party is owed as one transaction less any fees, dust, and sub-satoshis. If Bob and Alice transact 100 times over the channel, they will only show up as one transaction on the Bitcoin blockchain, with the value equal to the final channel state.
The incentives for closing channels are mutually beneficial. Let’s say Bob and Alice have a channel where Bob is owed 3 Bitcoin and Alice 7. If either Bob or Alice requests to close the channel, the other will likely agree because it just means that they will get their funds. There is no reason not to – it’s not like anyone is getting the short end of the stick!
Each node signing a closing transaction:
- MUST round each output down to a whole satoshi
- MUST subtract the fees from the output to the funder
- MUST remove any output below its own dust limit
- MAY eliminate itself as an output.