How Does the LN Protocol Work?
How Does the LN Protocol Work?
The Lightning Network runs on a peer-to-peer (P2P) level where all transactions occur on an off-chain network built on top of the Bitcoin blockchain. For this reason, the protocol is considered a Layer 2 solution, with the blockchain itself being Layer 1.
Rather than record each individual payment onto the blockchain, the two parties (typically a buyer and seller) open bi-directional payment channels via the Lightning Network. To create a bi-directional channel, the participants must decide to open a payment channel where they can transact funds back and forth from each other's wallets. To set it up, both parties need to fund the creation of the channel with an on-chain Bitcoin transaction. The total amount of the payment channel is the maximum amount of funds that can be transacted, thus protecting both parties from losing more funds than necessary. These transactions do not require a confirmation from the Bitcoin network since they occur off-chain on the second layer. As a result, they occur almost instantaneously through a smart contract, providing much lower fees and much higher throughput.
The most common example of how LN works is with the Alice & Bob Model. To get started, Alice and Bob need to fund a payment channel using a multi-signature wallet. With the funds in the payment channel, it can act as a smart contract, and the multi-signature wallet can act like a safe holding all of the funds being transacted. While the payment channel remains open, Alice and Bob can continue to make as many transactions with each other as they choose.
These transactions are kept on a “balance sheet” localized in the channel between Alice and Bob. After every transaction, they sign and update their copies of the balance sheet to record the amount of Bitcoin each one of them has. When they are finished, they can both agree to close the payment channel and broadcast their final balances to the Bitcoin blockchain. Both parties will receive their Bitcoin according to the latest version of the balance sheet submitted due to the rules of the Lightning Network smart contract.
Hashed time-locked contracts powered by the Lightning Network are designed to protect both parties and always require the approval from both parties for any funds to be moved. Anytime one party acts maliciously and attempts to remove funds from the payment channel without the other's consent, they are penalized and must forfeit their funds to the other party in the channel.