The Lightning Network (or just Lightning for short) is a Layer 2 protocol built on top of Bitcoin that enables instant, off-chain transactions with very low fees.
The Lightning Network is a system of smart contracts that enables micro-transactions and takes the load off the main Bitcoin blockchain. Created by Joseph Poon and Thaddeus Dryja, the Lightning whitepaper was released in January 2016.
Lightning is also compatible with coins that are based on Bitcoin’s code base (such as Litecoin and Dogecoin) and enables atomic cross-chain trading between different coins.
How Does the Lightning Network Work?
As a hub and spoke model, the Lightning Network works similar to Internet routing. To use Lightning, two or more parties create a payment channel so that bitcoins can be sent without being recorded on the Bitcoin blockchain. However, a multi-signature transaction is required to open the payment channel, which is recorded on the blockchain and takes on average ten minutes.
Any funds locked up in a payment channel can only be spent if both individuals agree on the new balance and works like a bar tab. To make a payment, each party would have to sign an exit transaction spending from the payment channel address. These payments do not require confirmations from miners, are processed near instantly and can be as small as one satoshi (~$0.000083). Therefore, Lightning payments are unconfirmed transactions.
Until the tab is settled, payments remain off-chain (meaning that transfer of ownership is no longer recorded on the blockchain). Once two parties want to settle the tab, they close the payment channel and it is then recorded on the Bitcoin blockchain. Consequently, the Lightning Network has the potential to reduce fees since fees are only paid to miners twice (to open and close a channel), but hundreds or even thousands of transactions may have taken place in between opening and closing a channel.
Payment channels can be set up between more than two people. In fact, Lightning is a network of payment channels where each user can be a node. One party can transact with another by forwarding payments to another node, travelling along different payment channels until it reaches the intended recipient. Nodes are like miners in the main Bitcoin chain and receive a small fee for forwarding transactions. If they cannot find a path, the user will receive their bitcoins back.
A payment channel can be closed by one participant if the other participant ever goes offline, ensuring that users never lose access to their funds. To prevent breaches of the smart contracts, users must continually monitor the Bitcoin blockchain, which can be done by running a full node (known as a ‘watcher node’ in Lightning). The watcher node, which broadcasts a penalty transaction when needed, can be outsourced but requires the user to trust the external server.
Lightning Network Example
Suppose that Alice and Bob open a payment channel and both deposit 0.2 BTC; they can transact as many times as they want. If Alice sends Bob 0.1 BTC, the tab is updated to show that Alice has 0.1 BTC and Bob has 0.3 BTC. Once they have finished transacting, either party can close the channel between them and the final balance will be published to the Bitcoin blockchain.
What if Alice wants to pay another person Carol? If we assume Bob and Carol have a channel open, then Alice can send funds directly to Carol by ‘hopping’ through Bob’s channel. What actually happens is that Bob pays Carol first, then receives the money back from Alice.
Bitcoin’s smart contract functionality ensures that there is no counterparty risk, and that the network works in a decentralised fashion. The cryptography used by the Lightning protocol ensures that Carol receives the funds through Bob (or Alice is refunded).
But what if one of the parties is offline?
This is where Hashed Timelock Contracts (HTLCs) come into play. HTLCs can create transactions that are only valid for a particular time period. The time value on the contract specifies how long one party can claim their money back if the other party is offline.
If Alice tries to claim her funds back by broadcasting an older transaction and attempts to close the channel with a state it was previously in, Bob’s software will pick up the transaction and Alice will lose all of her funds to Bob. Therefore, users are discouraged to cheat by submitting old, invalid states through this punishment mechanism.
How Can I Use the Lightning Network?
Several wallets and merchants have already enabled Lightning. There are three main implementations including lnd by Lightning Labs, eclair by ACINQ and lightning-d by Blockstream.
To get started with Lightning, guides are available online for building your own Lightning node. Alternatively, you can buy a plug and play node such as Casa or Nodl. To make payments on the Lightning Network, you can use mobile wallets such as Breez, Eclair, BlueWallet, and Zap or desktop wallets such as Lightning App, Spark and Peach.
Room77 in Berlin was the first merchant in the world to accept Lightning payments. To find other places to spend bitcoin through the Lightning Network, check out Accept Lightning or Lightning Network Stores.
Limitations of the Lightning Network
In its current form, the Lightning Network is still a work in progress and not yet ready for wide roll-out. Some limitations are listed below:
- You will have to guess how much money you will need at any given time and lock these funds up for a certain time period. Suppose you have a channel open with $25 on deposit, you will not be able to send $30 through this channel. Instead, you’d have to open a new payment channel for $30.
- Because of the liquidity problem described above, it is likely that large businesses will provide most of the liquidity for Lightning, centralising the network around a few key players.
- For any individual or business providing a substantial amount of liquidity or acting as an intermediary for large transfers are likely to be labelled as money transmitters and may be required to adhere to KYC/AML regulations.
- Hot wallets are used to transfer bitcoins through the Lightning Network. If Lightning gains mass adoption, then these hot wallets will become targets for hackers.
- Lightning requires users to be online all the time. Users who are offline cannot be paid with Lightning and if one of the peers is unresponsive, an alternative route must be found to pay the recipient.