Author: Hu Feitong
Lightning Network is the most mature second-layer solution for Bitcoin. Its theory It has been nearly 10 years of exploration and engineering construction. Although there are still many weaknesses, compared to other innovative second-layer solutions for Bitcoin, the Lightning Network is not only the most complete and mature, but may also be the most complete and mature. A foundation for other two-tier solutions. This article gives a brief introduction to the technology of Lightning Network, hoping to play a role in popularizing science.
Introduction
In the current sudden prosperity of the Bitcoin ecosystem, various innovations and projects have sprung up. It seems a bit outdated to talk about Lightning Network when it emerges like this. But if you carefully analyze the various innovations in the Bitcoin ecosystem, you have to admit that the Lightning Network is the most complete in terms of design and engineering practice. The concept of Lightning Network was proposed in 2015, and the white paper was completed and released in early 2016. In 2018, Lightning Network was born and implemented, and realized your off-chain transfer payment of 1 BTC. By the end of 2023, the number of Lightning Network nodes will reach more than 14,000, and the capacity will reach about 5,000 BTC.
In view of Bitcoin's low TPS, long confirmation time, and network congestion, the Lightning Network hopes to be able to conduct off-chain transactions and leverage Bitcoin To solve these three major problems with the security of your own network, that is, to achieve:
Immediacy of transactions;
High-throughput transactions;
Reduce transaction fees
Of course, for some other solutions to the current Bitcoin Layer 2, It also hopes to solve another important problem of the Bitcoin network - Turing complete contracts. This in itself is not a big problem for blockchain technology, because it is already a mature technology. The key lies in how to achieve decentralized transfer and confirmation of Bitcoin assets and rely on the security of the Bitcoin network. From this aspect, there is no perfect solution that can replace the Lightning Network (state channel).
Some technical points of the Lightning Network
The Lightning Network is built on the Bitcoin blockchain Create a payment channel network to achieve the three goals mentioned above. It mainly includes the following technical points:
Payment Channels: Payment Channels are the core concept of the Lightning Network. It allows two users to conduct multiple transactions without having to initiate a transaction on the main Bitcoin chain each time. Users first create a multi-signature wallet on the Bitcoin blockchain, which requires the private keys of two users to transfer funds. They then deposit a certain amount of Bitcoin into this wallet, and this deposit transaction is confirmed on the blockchain.
Off-Chain Transactions: Once the payment channel is opened, both parties can conduct transactions without interacting with the main chain. An unlimited number of off-chain transactions can be performed under certain conditions. These transactions update the allocation of funds within the channel by signing new transactions. These transaction records represent how funds should be distributed when the channel is closed, but these transactions are not broadcast to the Bitcoin network while the channel is open.
Channel Closing: When either party wants to withdraw the funds in the channel, they can close it Payment channel. This is accomplished by broadcasting the final state of the transaction on the Bitcoin blockchain. Once the transaction is confirmed, the funds in the channel will be distributed between the two parties based on the status of the last off-chain transaction.
Routing and Multi-hop Payments: Users can pay through other users in the network Payment channels send payments even if they don't have a direct payment channel connection. This is achieved by routing payments through one or more intermediate nodes. Each intermediate node charges a small fee as compensation for providing liquidity.
Hash Time-Locked Contracts (HTLCs, Hash Time Locks): For secure multi-hop payments, the Lightning Network HTLCs were used. This allows the creation of conditional payments that can only be completed if the recipient provides proof of a payment preimage (a hash of a random number generated by the sender). This ensures that each node along the way will only forward a payment if it is sure it will receive it.
Network capacity and liquidity: While the Lightning Network can significantly reduce transaction fees and increase speed, its performance also depends on on the capacity and liquidity of the network. The funding capacity of each channel limits the maximum amount of payments that can be sent through that channel. Additionally, funds must be properly distributed across the network so payments can find efficient paths.
Security and Privacy: The Lightning Network improves privacy because all transactions do not need to be recorded on a public blockchain. However, it also brings new security considerations, such as requiring users to be online regularly to respond to potential fraud attempts.
Basic process of Lightning Network payment
Payment channel It is the most critical component of the Lightning Network, allowing two participants to conduct multiple transactions without having to broadcast to the Bitcoin main chain each time. The process of multiple transactions between two parties through the Lightning Network can be divided into three steps: 1) opening the payment channel; 2) multiple off-chain transactions; 3) closing the channel. The following is a detailed explanation of payment channels and related concepts from a technical perspective:
The establishment of payment channels is based on a multi-signature wallet, which requires multiple private key signatures A special type of wallet that can only be used for transactions. In the Lightning Network, usually two parties each hold a private key and jointly control the wallet. Multi-signature wallets ensure that no one party can move funds alone and transactions can only occur when both parties agree.
Open payment channel:
Fund deposit: Participate Participants jointly create a multi-signature wallet and send Bitcoins to this multi-signature wallet from their regular wallets. This transaction is broadcast and confirmed on the main Bitcoin chain, indicating that they jointly have control over the funds.
Transaction record: Each party keeps a transaction record to record the current allocation of funds. This transaction is not broadcast to the Bitcoin network and is only shared between the two parties.
Off-chain transactions:Once the channel is established, participate Users can conduct unlimited off-chain transactions.
Transaction update: Every time an off-chain transaction is performed, both parties update the latest transaction records they save. This record represents the final distribution of funds when the channel is closed. Way.
Privacy and speed: These transactions are only between two parties and do not require confirmation from the Bitcoin network, so they are nearly instant and remain private.
Close channel:
Broadcast final status: when any When a party wants to exit the channel, they can broadcast the last transaction they agreed to to the Bitcoin network.
Settlement funds: Once this transaction is confirmed by the network, the funds in the multi-signature wallet will be distributed to the two parties based on the last transaction record.
Payment channels and off-chain transactions are key technologies for the Lightning Network to improve the speed and scalability of Bitcoin transactions. In this way, transactions only need to be confirmed on the Bitcoin main chain when the channel is established and closed, and once the channel is opened, participants can conduct an unlimited number of fast, low-cost transactions.
So everyone can naturally think, how to ensure the safety of funds? Because funds will only return to their respective wallets when the channel is closed, if one party closes the channel in advance, or a party is unwilling to close the channel, an expected settlement process cannot be achieved.
The security of user funds in the Lightning Network is mainly guaranteed by the following two mechanisms:
Timelock: To prevent fraud (e.g., one party trying to broadcast an outdated transaction to obtain more funds), payment channels often include a timelock mechanism. If one party attempts to broadcast an old transaction, the other party has time to react and broadcast the latest status.
Monitoring: Participants need to regularly monitor the network to ensure that the other party is not trying to broadcast old transactions.
Basic process examples and settlement security
We use Let’s take an example to illustrate this basic process. In this example, users A and B want to conduct multiple transactions through the Lightning Network.
Step 1 - Establish a payment channel: Both parties to the transaction (for example, Alice and Bob) jointly create a multi-signature (multisig) address and deposit to this address Initial funds (for example, Alice deposits 5 BTC and Bob deposits 3 BTC). This initial transaction is confirmed on the Bitcoin main chain, marking the establishment of the payment channel.
Second step - Both parties conduct off-chain transactions: Once the payment channel is established, both parties can start an unlimited number of off-chain transactions without having to go to the chain every time. Recorded on the Bitcoin main chain. For each off-chain transaction, both parties update a jointly maintained balance sheet to reflect the current allocation of funds. For example, three transactions occurred: 1) A transferred 1.0 BTC to B; 2) B transferred 0.5 BTC to A; 3) A transferred 0.2 BTC to B again.
After these transactions, according to the balance sheet, A transferred a total of 0.7BTC to B, that is, A: 4.3BTC, B: 3.7BTC
Step 3: Either A or B can send this last result. A transfers 0.7 BTC to B to close the channel;
Step 4: Wait for the time lock to end; before the time lock ends, either A or B can send a later transaction result signed by both parties to prevent either party from obtaining the final transaction result without sending it. Pro;
Step 5: The time lock ends and the channel is closed. The multisig address handles the final transaction and returns funds to A and B; in this example, A will receive 4.3BTC and B will receive 3.7BTC.
To prevent dishonest parties from submitting old states, the Lightning Network encourages users to stay online or entrust third-party monitoring services (such as "monitoring towers") to monitor the network dishonest behavior. If B discovers that A is trying to submit an old state, B can use the latest state he holds containing A's signature as evidence and submit it to the network to correct and punish A's dishonest behavior.
If A submits a non-latest state, and B can prove that there is an updated state, then the Lightning Network protocol allows B to not only recover his own funds, but also potentially obtain Part or all of A’s funds as punishment. This mechanism greatly increases the cost of attempted fraud, thereby protecting the network's honest behavior.
Routing and multi-hop payment
As discussed earlier, the two parties pass the payment channel (state channel ) to improve efficiency and throughput through off-chain payments and establish the process of transaction fees. We know that it is impossible for all users with transactions to establish payment channels. The Lightning Network can solve this problem through routing and multi-hop payments. This is similar to our current network system. Each end user only needs a few service providers (equivalent to gateways) recognized by themselves to establish status channels, and these service providers then establish status channels between them, thus forming a network. Multi-hop payment enables any interaction and transfer between users in the entire Lightning Network.
Let's illustrate how routing and multi-hop payments work in the Lightning Network with a simple example: Assume there are four users on the Lightning Network: Alice (A), Bob (B), Carol (C) and Dave (D). Alice has a payment channel directly connected to Bob, Bob has a channel connected to Carol, and Carol has a channel connected to Dave. Now, Alice wants to send a payment to Dave, but there is no direct payment channel between her and Dave.
Step 1: Find the route
Alice's client Use the Lightning Network's routing algorithm to find a path to Dave. In this example, the simplest path is Alice -> Bob -> Carol -> Dave.
Step 2: Create payment
Alice decides to send 0.01 BTC to Dave. Her client creates a payment request that contains the payment details and a special number - the hash of the payment preimage (a random number created by Dave).
Step 3: Use HTLCs
To do it safely For multi-hop payments, each intermediate node (Bob and Carol) creates an HTLC. HTLC allows intermediate nodes to forward payments, but can only ultimately receive funds if they know the payment pre-image. This ensures that the payment is only finally unlocked when it has fully reached Dave.
Step 4: Forward payment
Alice first sends the payment to Bob, locked in an HTLC.
Bob sees that this payment is going to be forwarded to Carol, so he creates a new HTLC and sends it to Carol.
Carol does the same thing, creates an HTLC and sends it to Dave.
At each step, the payment is locked in a new HTLC, and each node only knows the payment preimage These funds will be unlocked at a later date.
Step 5: Unlock payment
Once Dave receives the payment, he will provide the payment pre-image to Carol, unlocking her HTLC there and obtaining the funds.
Carol uses this payment pre-image to unlock the HTLC sent to her by Bob, and sends the payment pre-image to Bob to unlock her should obtained funds.
Bob finally uses the payment pre-image to unlock the HTLC given to him by Alice, completing the entire payment process.
Step 6: Confirm and Close
< p style="text-align: left;">Once the entire payment chain is completed, all intermediate HTLCs are unlocked and everyone receives their due funds. The payment is confirmed and all participating nodes update their payment channel status.
Analysis of the advantages, disadvantages and development prospects of the Lightning Network
According to the previous introduction, we can It is said that the Lightning Network technically solves some problems of the Bitcoin network and has the following advantages: instant transactions, low transaction fees, high scalability and high transaction frequency, better privacy protection and support for micropayments. Because of this, through technological innovations such as the Lightning Network, it is possible for Bitcoin to become true electronic cash, rather than just a stored value currency.
But at the same time, we also see the technical complexity of the Lightning Network. At the same time, the construction of a network is not only a technical factor, but also user recognition and adoption rate are also very critical. Although Bitcoin has received wider recognition of its value, the overall capacity of the Lightning Network is not high. In its development process, the following weaknesses will be obstacles:
Online requirement: In order to receive payments, the user's device needs to remain online in order to respond in real time to possible payment requests or fraud attempts.
Fund lock: The funds in the payment channel will be locked before the channel is closed, which means that the funds cannot be Free to use.
Complexity and user experience: Setting up and managing payment channels can be complex for the average user, especially when it comes to channels Issues such as money management and routing.
Network liquidity and routing challenges: Although in theory the Lightning Network can handle a large number of transactions, in practice its efficiency is highly dependent on The distribution of payment channels and financial liquidity in the network. Finding efficient payment routes can sometimes be a challenge.
Centralization risk: Although the Lightning Network is designed to be decentralized, there may be large nodes or centralized service providers The risk of controlling larger traffic volumes, which could lead to some degree of centralization of the network.
With the development of the Bitcoin ecosystem, although various BTC Layer2 solutions have been introduced, at the same time, the overall development has also Bringing unprecedented opportunities to the Lightning Network. If the designers of the Lightning Network make major breakthroughs in user experience, network scale, and integration with other technologies, I believe that the Lightning Network will usher in a spring.