Onchain interaction with your node.
The Lightning Network relies on the Bitcoin protocol to operate, so it is important to understand how your Lightning Node interacts with it. The Bitcoin network is often called “Layer one” and the Lightning Network, “Layer two.” Your Lightning Node has an on-chain wallet built into it. This wallet allows you to send and receive bitcoin as you normally would. The channels that you will inevitably open are funded by this on-chain wallet. When your channels close, this wallet is also where the funds on your side of the closed channel will appear after confirmation. This wallet is a hot wallet, as well, meaning the keys are stored on an online accessible device. Take your security seriously if you are running your node at home. Have passwords, configurations, etc.. set up and stored safely.
For LND, there is no coin control for your on-chain wallet. You cannot pick and choose which UTXOs are combined when opening channels. For privacy-conscious users, this means you will have to be very careful if you are trying to avoid combining UTXOs during channel opens. If opening from coinjoin, it may be wise to send the exact amount of funds to the Lightning node on-chain wallet that you plan to open a channel with, rather than a large sum, to avoid combining UTXOs. If there is a change output after a channel opens, consider sending it to an address you control that allows coin control before opening a new channel.
Your node’s seed phrase that you wrote down during your node’s initial setup will help you recover these on-chain funds should your node fail. The seed phrase provided to you from your LND node cannot be recovered on any other wallet such as electrum or Blockstream green. Any failed LND node funds must be recovered on another LND instance.
What happens on-chain when a channel is opened or closed
The Bitcoin Lightning Network is often described as a layer two technology, with the traditional bitcoin layer below it. In order to use the Lightning Network in a sovereign way (running your own node), interaction with the base bitcoin network is required. Your Lightning node has a built-in regular (layer one) bitcoin wallet. This wallet is used to allocate funds to opening channels. And anytime you close a channel, the funds on your local/outbound side of the closed channel are then moved to your layer one bitcoin wallet built into your node.
The Lightning Network uses the base bitcoin layer for security and authentication. Each Lightning Channel uses what is known as a multi-sig transaction with a time lock to secure your funds and allow payments through the channel. Keep in mind also that your on-chain UTXOs cannot be chosen, so if privacy is a concern please be careful with combining UTXOs when opening channels. Every time funds move through a lightning network channel, an on-chain transaction is updated and signed by both parties. Each peer now has access to a broadcastable transaction with updated balances. This is to ensure that if the channel closes, the correct amount of funds will be returned to each party on-chain.
Cooperative vs. Unilateral Channel Closure
Your lightning channel is a 2 of 2 multi-sig smart contract. Each peer has the option to close a channel at any time because both parties have access to the fully signed, but unbroadcasted close transaction at all times. To close a channel means to allocate the funds in a channel back to the bitcoin base layer. These funds that you own (or would be considered your ‘outbound’ or ‘local’ funds) will then be deposited into your LND on-chain wallet.
Every time the balance of a channel changes, each peer signs an on-chain transaction updating the contract. Each peer then stores the signed 2 of 2 transaction if a closure is requested by either peer.
In the event of a cooperative close, one would broadcast the signed transaction, also known as a commitment transaction, to the bitcoin network. They would choose the fee rate and the channel would close and each peer would receive what they had on their side of the channel on-chain.
In the event of a unilateral close, this transaction enters a time lock state which will allow the other peer to contest the close if it is representing a channel state with a timestamp before the timestamp of the other peer. An uncooperative close also allocates more funds for the on-chain fee to be absolutely sure the transaction will confirm on-chain. An uncooperative close is usually initiated by a node runner whose peer has been offline for a long amount of time and is unlikely to return. If a node attempts to broadcast a channel state that is not the most current one, and the other peer comes back online, they will detect the attempted cheat and the network will allow the cheated peer to have the total amount of funds in the channel.
Another way to protect your node should your node go offline is to have another node on the network watch your node. These are called watchtower nodes and are completely invisible on the network. Because of this, node runners are incentivized to not cheat their peers because the punishment is grave and there is no way of knowing if their peer has a watchtower active.
If you have any questions or comments either email us at firstname.lastname@example.org, use our live on-site chat, or join us in Discord.