banner
CKB 中文

CKB 中文

CKB 是理想的比特币 Layer 2

How does the Lightning Network work? (1)

In the previous article “Why We Need the Lightning Network”, we explored 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, serving as the foundation for our 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 constitutes 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, serving as collateral for establishing the channel. This transaction, known as the "Funding Transaction" or "Anchor Transaction," needs to be broadcast to the network and recorded on the Bitcoin blockchain to indicate the official 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. Starting Transactions: The Art of Off-Chain Transactions#

Once the channel is opened, subsequent transactions between the parties will all take place off the Bitcoin blockchain, achieving efficient off-chain settlement. Let's assume Alice and Bob conducted the following three transactions:

  1. Alice transfers 10,000 sats to Bob, at which point Alice has 90,000 sats, and Bob has 110,000 sats.
  2. Alice continues to transfer 20,000 sats to Bob, at which point Alice has 70,000 sats, and Bob has 130,000 sats.
  3. Bob transfers 10,000 sats to Alice, at which point Alice has 80,000 sats, and Bob has 120,000 sats.

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

Each time Alice and Bob transact, both parties 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 keep 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: one is by mutual agreement to close, sending a settlement transaction to the Bitcoin network; the other is by unilateral decision to close, sending the last commitment transaction to the Bitcoin network. The latter design is to prevent a situation where one party going offline locks the other party's balance in the channel 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 (similarly, 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, a channel can be closed by mutual agreement or by unilateral decision. So, in a bidirectional payment channel, how can we prevent one party from committing fraud? For example, in the above case, 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 clearly seems very 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 drawbacks; in addition to its own complexity, it creates a storage burden — users must keep records of every past update to the channel state, and some rare scenarios may lead to unintended penalties for honest users.

To overcome these shortcomings, as early as 2018, the Bitcoin community proposed a solution called "eltoo" 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 help the victim execute penalty transactions upon detecting malicious behavior, 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 the cleverly designed payment channel system. Through the three stages of opening a channel, off-chain transactions, and closing a 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, low-cost micro-payments.

📖 Recommended Reading

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