banner
CKB 中文

CKB 中文

CKB 是理想的比特币 Layer 2

How does the Lightning Network work? (1)

In the previous article “Why We Need the Lightning Network,” we discussed the necessity and importance of the Lightning Network. As a P2P network built on the Bitcoin blockchain, the Lightning Network not only effectively addresses the "slow and expensive" issues of Bitcoin but also has unparalleled advantages in the field of cryptocurrency payments compared to other solutions. It is the foundation for realizing a P2P economy and an important component of the Web5 world we envision.

In today’s article, we will continue to introduce the Lightning Network, clarifying its operating principles and related technologies.

The Cornerstone of the Lightning Network: Payment Channels#

The Lightning Network is essentially a well-designed payment channel system. Taking the transaction between Alice and Bob as an example, when they settle using the Lightning Network, they go through the following three key stages: opening a channel, conducting transactions, and closing the channel.

1. Opening a Channel: Building a Bridge of Trust#

Opening a channel essentially involves creating a multi-signature wallet jointly controlled by both parties and injecting funds into that wallet. The total amount of funds received by this wallet is the balance of the channel.

Let’s assume Alice and Bob each hold 100,000 satoshis (sats) of BTC. First, they need to transfer their respective 100,000 sats into a multi-signature wallet address controlled by both, as collateral for establishing the channel. This transaction, known as a “Funding Transaction” or “Anchor Transaction,” needs to be broadcast to the network and recorded on the Bitcoin blockchain to indicate the formal opening of the channel. In this example, the payment channel connecting Alice and Bob is essentially a standard 2-of-2 multi-signature wallet containing a balance of 200,000 sats (for simplicity, we will not consider the miner fees incurred when opening the channel).

2. Conducting Transactions: The Art of Off-Chain Transactions#

Once the channel is opened, subsequent transactions between the two parties will occur entirely off the Bitcoin blockchain, achieving efficient off-chain settlement. Let’s assume Alice and Bob conduct the following three transactions:

  1. Alice transfers 10,000 sats to Bob, leaving Alice with 90,000 sats and Bob with 110,000 sats.
  2. Alice continues to transfer 20,000 sats to Bob, leaving Alice with 70,000 sats and Bob with 130,000 sats.
  3. Bob transfers 10,000 sats to Alice, leaving Alice with 80,000 sats and Bob with 120,000 sats.

From the above example, we can see that no matter how many transfers occur between Alice and Bob, the channel balance between them remains unchanged at 200,000 sats.

Each time Alice and Bob conduct a transaction, they need to update their respective balances in the channel and exchange signed “Commitment Transactions.” These transactions themselves are valid and can be sent to the Bitcoin network at any time, but both parties typically save them without broadcasting unless they intend to close the channel. This way, the balance states of Alice and Bob within the channel can change dozens or even hundreds of times in a second, with the update speed only limited by how quickly both parties create, sign, and send the commitment transactions to each other.

3. Closing the Channel: The Moment of Final Settlement#

Closing the channel can be done in two ways: either both parties agree to close it and send a settlement transaction to the Bitcoin network, or one party decides to close it unilaterally by sending the last commitment transaction to the Bitcoin network. The latter design is to prevent one party from going offline and causing the other party's balance in the channel to remain locked indefinitely.

In the case of Alice and Bob, after conducting three transactions, they decide to close the channel. After closing, Alice retrieves 80,000 sats, and Bob retrieves 120,000 sats (again, for simplicity, we will not consider the miner fees incurred when closing the channel).

Security Assurance of Bidirectional Payment Channels: From LN-Penalty to eltoo to Daric#

As mentioned above, closing the channel can be done by mutual agreement or unilaterally. So, in a bidirectional payment channel, how can we prevent one party from committing fraud? For instance, in the example above, how can we prevent Bob from using the second commitment transaction instead of the third to close the channel? If Bob uses the second commitment transaction to close the channel, he could deny the last payment of 10,000 sats made to Alice, which is clearly tempting.

The Bitcoin Lightning Network introduces the LN-Penalty mechanism to prevent one party from sending an outdated but favorable state on-chain to close the channel. LN-Penalty uses complex techniques such as “asymmetric commitment transactions” and “revocation keys” to ensure that if Bob attempts to close the channel using an outdated commitment transaction, Alice will have the right to claim all the funds in the channel — 200,000 sats. This penalty mechanism effectively curbs potential fraudulent behavior.

However, LN-Penalty also has some shortcomings. Besides its inherent complexity, it creates a storage burden — users must keep records of every past channel state update, and some rare scenarios may lead to unintended penalties for honest users.

To overcome these drawbacks, the Bitcoin community proposed a solution called “eltoo” back in 2018 to eliminate storage burdens and the risk of unintended penalties. In this solution, users only need to keep the latest commitment transaction and its settlement transaction. However, the eltoo solution is still not available because its implementation requires a soft fork of Bitcoin to introduce a new signature hash type — SIGHASH_ANYPREVOUT.

The Lightning Network Fiber Network launched by Nervos CKB chose the Daric solution proposed in 2022. Daric effectively addresses the cost and security issues of Watchtowers, which are Lightning Network nodes running on independent machines and networks that monitor payment channels and assist the victim in executing penalty transactions when malicious behavior is detected, thereby protecting users' funds. Node operators typically run their own Watchtowers to protect their nodes.

Conclusion#

As a scaling solution for Bitcoin, the Lightning Network's core lies in its cleverly designed payment channel system. Through the three stages of opening a channel, conducting off-chain transactions, and closing the channel, the Lightning Network significantly enhances transaction speed and reduces costs.

To ensure the security of bidirectional payment channels, the Lightning Network employs the LN-Penalty mechanism, and the Bitcoin community has proposed better security mechanisms such as eltoo and Daric to effectively prevent potential fraudulent behavior.

These innovations have significantly improved the performance of the Bitcoin network while ensuring security, paving the way for fast and low-cost micropayments.

📖 Recommended Reading

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.