Read this blog in हिंदी, 中文, Türkçe, Indonesian, Russian, ΕΛΛΗΝΙΚΑ, and Vietnamese.
The Lightning Network is the most prominent Bitcoin Layer 2 network in existence today, and it has long been hailed as a key building block for the scalability of the world’s most valuable blockchain.
While not a solution to every problem facing bitcoin, the Lightning Network can tweak the cryptocurrency network’s scaling equation from transactions per second to new users per second without sacrificing too much in terms of decentralization and censorship resistance. Additionally, it may be an important technology for tying together a large number of different Bitcoin L2s that could develop in the coming years.
But what is the Lightning Network, and how does it work? Let’s take a deep dive into this Bitcoin L2 focused on payments.
The Problem Of Scaling Bitcoin
While bitcoin was originally launched as a peer-to-peer digital cash system with cheap, blockchain-based payments, the reality is that this system was never going to scale to a large user base while publishing all transactions on the base blockchain. In the past, bitcoin has peaked at processing just under nine on-chain transactions per second. Although on-chain transactions were basically free for the early years of the network’s development, the limitations of the system were hit in 2016 when the capacity limit of one megabyte per block was reached for the first time.
As the network grew in popularity, scarce block space on the network filled up, and there was eventually a crisis where on-chain transactions became both historically expensive and unpredictable in terms of when they would be confirmed in a block.
This situation was the crux of the blocksize war, in which various proposals for dealing with bitcoin’s capacity limits and long-term scalability were debated by users. Some saw a simple increase to bitcoin’s block size limit as the most straightforward option over the near term, but the problem was many of the most prominent proposals related to this method of scaling used a hard fork — a type of change that would effectively require all users to move over to a new, backwards-incompatible bitcoin network. This made finding consensus on such a change quite difficult.
Additionally, various contributors to the bitcoin protocol up to that point preferred a multi-layer scaling approach where the limited amount of block space available on the blockchain could be used more efficiently. It was thought that simply increasing the amount of data that could be held by the blockchain would also increase the cost of operating a full node, which would further centralize the network and put into question the properties that make bitcoin valuable in the first place. By allowing users to opt into Bitcoin L2s, smaller payments, such as a purchase of a cup of coffee, could be made off of the base blockchain while still retaining a high degree of decentralization. There were also a number of changes large, centralized entities could make to use block space more efficiently such as transaction batching.
Eventually, the upgrade that was chosen via consensus as the best path forward was a soft-forking (backwards compatible) change known as Segregated Witness (SegWit). This change enabled both a block size increase and a fix to the transaction malleability issue, which would enable more efficient and secure off-chain scaling mechanisms for bitcoin payments, such as the Lightning Network.
What Is The Lightning Network At A High Level?
The Lightning Network is effectively a network of smart IOUs where different parties can send off-chain payments to each other in an extremely low-trust manner. Instead of making an on-chain transaction for each transfer, users send signed cryptographic proofs of payment to each other without broadcasting them to the larger bitcoin network. After a large number of payments have been made, those connected to the Lightning Network can eventually cash out to the base bitcoin blockchain whenever they’d like.
The key innovation here is that an on-chain imprint is not needed for every payment. Instead, users can take advantage of the blockchain in situations where someone tries to lie about the history of payments that have taken place on the Lightning Network. In such a scenario, the victim of the theft attempt simply publishes a cryptographic proof to the blockchain regarding the history of off-chain payments that were made.
In a way, the Lightning Network alters the scaling equation for bitcoin from payments per second to user onramps and offramps per second. Once a user has joined the Lightning Network via an on-chain transaction, they can send an unlimited number of payments, assuming sufficient liquidity.
How Does The Lightning Network Technically Work?
Payment Channels
From a technical perspective, the Lightning Network is a network of payment channels. A payment channel is created when two bitcoin users obtain collaborative custody over some amount of bitcoin via a 2-of-2 multisig address (i.e., requiring each party to sign the transaction). These two users can then send bitcoin back and forth to each other without touching the bitcoin blockchain. This is accomplished by having the users sign transactions that allow the users to withdraw the bitcoin back to their own addresses without broadcasting the transaction to the network to be mined.
For example, Alice and Bob could each send 2 bitcoin to a 2-of-2 multisig address for a total of 4 bitcoin. If Alice wants to send 1 bitcoin to Bob, she and Bob will collaborate on signing two transactions from the 2-of-2 multisig address without broadcasting them to the network. The first transaction sends 3 of the 4 bitcoin to Bob’s personal address, while the second one sends 1 bitcoin to Alice’s personal address. Despite nothing occurring on the blockchain, both parties now have the ability to publish these transactions whenever they feel like it. So, in effect, Alice now has ownership over 1 bitcoin in the 2-of-2 multisig address, while Bob has ownership over 3 bitcoin.
Payment channels are a powerful tool in themselves, but the innovation with the Lightning Network is to generalize this concept to connect many more parties. Extending the above example with Alice and Bob, we can imagine there is another bitcoin user named Carol who also has a payment channel open with Bob. With the Lightning Network, Alice can send bitcoin to Carol without having to open a channel with her directly because they both have channels open with Bob.
For a further technical overview of how the Lightning Network works, let’s go through the process of opening a channel, sending a payment, and closing a channel.
Opening A Lightning Network Channel
Opening a Lightning Network channel is similar to the traditional payment channel process described above. A user will need to create a 2-of-2 multisig address with another party — hopefully one that is already well-connected to many other Lightning Network users — to get started. The two users will then fund the multisig address and create their commitment transactions in order to establish the opening of the Lightning channel. Notably, the commitment transactions must be signed prior to the broadcasting of the transactions funding the 2-of-2 multisig address.
Sending A Lightning Network Transaction
Sending a payment via the Lightning Network when two parties have a channel opened directly with each other is essentially just the updating of commitment transactions. The commitment transactions are what allow each user to withdraw the bitcoin they own based on the current state of the Lightning channel. They are updated with each payment made via the Lightning channel; however, they are only broadcast to the blockchain in a situation where dispute resolution is needed via the blockchain.
These commitment transactions also use OP_CHECKSEQUENCEVERIFY (CSV) to ensure that the outputs associated with them cannot be spent until the other party has had time to dispute. Lightning users also share revocation keys with each other after updating their commitment transactions, which can be used to prove that an outdated state of the Lightning channel has been published.
Routing Lightning Network Transactions With HTLCs
Of course, the key innovation with the Lightning Network is that it allows a network of payment channels to interact with each other. This is made possible through the use of hashed timelock contracts (HTLCs). An HTLC is a type of bitcoin smart contract that locks funds based on a secret known only by the original creator of the contract. Additionally, a timelock, via the OP_CHECKLOCKTIMEVERIFY (CLTV) opcode, is involved so the original creator of the contract can reclaim the funds after a certain period of time in a situation where the recipient does not accept the payment.
Let’s say Alice wants to send a 1 bitcoin Lightning payment to Carol through Bob. For simplicity, we will say that each of these channels have 2 bitcoin in them, with ownership of the 2 bitcoin being evenly split between the two parties.
Alice will create an HTLC for 1 bitcoin and send it to Bob. Alice’s new commitment transaction for her channel with Bob will set the amount she can withdraw from the channel to 0 bitcoin. However, instead of simply increasing Bob’s commitment transaction to 2 bitcoin, he receives the HTLC. Bob will then go through the same process Alice just went through, creating an HTLC and lowering the balance in his channel with Carol to 0 bitcoin.
Upon receiving the HTLC from Bob, Carol is able to use a secret provided to her by Alice to unlock the funds in the HTLC. During this process, Carol also reveals the secret to Bob. Bob is then also able to use the same secret to unlock the bitcoin in the HTLC sent to him by Alice as well. The end result is that Alice sent 1 bitcoin to Bob and Bob sent 1 bitcoin to Carol.
This entire process happens atomically, meaning either all payments happen or none of them happen. Once the HTLCs are dealt with, each channel’s commitment transactions are updated to reflect the outcome of the successful payment.
Closing A Lightning Network Channel
When a user wants to close a Lightning channel, they can ask their counterparty to do so in a collaborative manner. In such a situation, the process is no different from creating any other normal 2-of-2 multisig transaction where a new transaction is created with sufficient fees and the proper amounts are returned to each users’ respective personal address.
Closing A Channel When Something Goes Wrong
While cooperative channel closures are the norm on the Lightning Network, there are a variety of situations where one party may become uncooperative. For example, if the other party is offline or otherwise uncommunicative, a user will not be able to organize a collaborative channel closure. This is where the publication of the aforementioned commitment transactions comes into play.
When a commitment transaction is published, the user will not have access to their funds instantly. This is due to the use of CSV on the commitment transactions. The other party will be given a predetermined period of time (measured in blocks) to dispute the outcome of the commitment transaction. These transactions can be disputed by revealing a revocation key, used to prove there is a more recent state of the Lightning channel ignored by the published commitment transaction. When the revocation process is found to be valid, the revocating user is able to instantly withdraw all of the funds held in the channel.
The Future Of The Lightning Network
It’s no secret that the Lightning Network is far from perfect as it exists today, but it’s also already providing a powerful scaling tool for the network. Some have made the claim that the Lightning Network has failed, but that’s nowhere near the truth. The Lightning Network is definitely a useful tool for specific situations, and that will become clearer over time.
Even if it’s difficult for users to operate their own Lightning nodes right now — and it can be expensive to open and close channels at times — the fact that users can send and receive bitcoin between exchanges instantly at no cost (and without any on-chain footprint) should be seen as a victory for scaling, especially when considering the amount of overall bitcoin activity that is still centralized around these entities. Additionally, there is the potential for stablecoins issued on the Lightning Network — via protocols such as Taproot Assets and RGB — to eventually become the preferred medium of exchange for that particular type of digital asset.
It’s also worth noting that it’s unclear how the Lightning Network will ultimately evolve, as it is currently used in a mostly custodial way due to the usability benefits such a setup can provide. Some people envision a future where individual users are operating their own Lightning nodes at home and connecting to them from their mobile phones, while others see a situation where the Lightning Network acts more of a connecting glue between a variety of other Bitcoin L2s. Indeed, it’s clear that the Lightning Network will be the most effective option for swapping between Bitcoin L2s because it enables instant and low-cost atomic swaps.
The Lightning Network’s evolution will partly depend on how improvements can be made to it over time. There are a number of theoretical alterations that could be made to the protocol to improve how channel liquidity is managed and how often the base blockchain needs to be touched, but many of these proposals would necessitate the addition of a covenants mechanism to bitcoin via a soft fork. One of the most notable potential changes for Lightning — enabled by covenants — is Eltoo, which would provide for better mechanisms for Lightning wallet backups and enable more than two parties to open a single channel with each other. There’s also Ark, which is a separate Bitcoin L2 system that could end up being a replacement for the Lightning Network with many similar goals.
That said, it’s still early days for the development of the Lightning Network, and it will only evolve to fill in the gaps and use cases where it makes the most sense. Additionally, off-chain bitcoin transactions can take place via a variety of other upper-layer protocols, and each of these Bitcoin L2s can offer something different that isn’t found in their alternatives. For example, the Lightning Network was launched with a focus on payments, while Lorenzo App Chain and a variety of other Bitcoin L2s have focused on bringing some of the more expressive smart contracting functionality found in Ethereum back to bitcoin.
The Lightning Network has proven to be a powerful addition to the base bitcoin network, but at the end of the day, it is only one of many tools in the toolbox for scaling bitcoin by using the base blockchain as efficiently as possible.