How does the Lighting Network work (1)?

robot
Abstract generation in progress

Source: Nervos CKB

As a P2P network built on the BTC blockchain, the Lighting Network not only effectively solves the problem of BTC being ‘slow and expensive’, but also has unparalleled advantages in the field of encryption payments compared to other solutions. It is the foundation of our P2P economy and an important part of the Web5 world we aspire to.

In today’s article, we will continue to introduce the Lighting Network, explaining the operating principles and related technologies of the Lighting Network.

The cornerstone of Lighting Network: payment channels

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

1. Open Channel: Building a Trusted Bridge

The so-called opening of the channel is essentially the creation of a multi-signature Wallet jointly controlled by the participating parties, and the injection of funds into the Wallet. The total amount of funds received by this Wallet is the balance of this channel.

We assume that Alice and Bob each hold 100,000 Satoshi BTC. First, they need to transfer their respective 100,000 Satoshi to a multi-signature WalletAddress jointly controlled by the two, as a deposit 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 BTC Block on-chain to indicate the formal opening of the channel. In this example, the payment channel connecting Alice and Bob is essentially a regular 2-of-2 multi-signature Wallet containing a balance of 200,000 Satoshi (for simplicity, we temporarily do not consider the gas fee required to open the channel).

2. Start Trading: The Art of Off-chain Transactions

After the channel is opened, all subsequent transactions between the two parties will be conducted off the Bit coin blockchain, achieving efficient off-chain Settlement. Let’s assume that Alice and Bob have had the following 3 transactions:

  1. Alice transfers 10,000 Satoshi to Bob. At this time, Alice has 90,000 Satoshi and Bob has 110,000 Satoshi.
  2. Alice continues to transfer 20,000 Satoshi to Bob. At this time, Alice has 70,000 Satoshi, and Bob has 130,000 Satoshi.
  3. Bob transfers 10,000 Satoshi to Alice. At this point, Alice has 80,000 Satoshi and Bob has 120,000 Satoshi.

From the above example, we can see that no matter how many times Alice and Bob transfer money to each other, the initial balance of their channel remains unchanged at 200,000 satoshis.

Every time Alice and Bob make a transaction, both parties need to update their respective balances in the channel and exchange signed ‘Commitment Transactions.’ These transactions are valid in themselves and can be sent to the BTC network at any time, but both parties typically save them without broadcasting unless they intend to close the channel. As a result, the balance status of Alice and Bob in the channel can change tens or hundreds of times within a second, and the speed of updates is only limited by the speed at which both parties create, sign, and send commitment transactions to each other.

3、Close the channel: The moment of final Settlement

There are two ways to close a channel: one is to close it with the unanimous agreement of both parties by sending a Settlement Transaction to the BTC network; the other is to unilaterally decide to close it by sending the last Commitment Transaction to the BTC network. The latter is designed to prevent one party from being offline and causing the balance of the other party in the channel to be locked.

In the example of Alice and Bob, they decided to close the channel after conducting three transactions. After the channel was closed, Alice retrieved 80,000 Satoshi, and Bob retrieved 120,000 Satoshi. (Similarly, to simplify the explanation, we do not consider the gas fee generated when closing the channel).

Security guarantee of bidirectional payment channel: From LN-Penalty to eltoo to Daric

As mentioned above, the channel can be closed with the unanimous consent of both parties, or it can be unilaterally decided to be closed. So, in a bidirectional payment channel, how can one prevent one party from cheating? For example, in the above example, how can one prevent Bob from using the second rather than the third promised transaction to close the channel? If the channel is closed using the second promised transaction, Bob can repudiate the payment of 10,000 satoshis to Alice, which obviously seems very tempting.

BTCLighting Network introduces the LN-Penalty mechanism to prevent one party from closing the channel on-chain with an outdated but beneficial state to themselves. LN-Penalty uses complex technologies such as ‘asymmetric commitment transactions’ and ‘revoke Secret Keys’ to ensure that if Bob attempts to close the channel using an outdated commitment transaction, Alice will have the right to claim all funds in the channel - 200,000 satoshis. This penalty mechanism effectively curbs potential fraudulent behavior.

However, LN-Penalty also has some shortcomings. In addition to its own complexity, it also creates storage burden - users must save the data every time the channel status is updated in the past, and there are some rare situations that may accidentally penalize honest users.

To overcome these drawbacks, as early as 2018, the BTC community proposed a solution called eltoo to eliminate the burden of storage and the risk of accidental 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 BTC and the introduction of a new signature hash type —— SIGHASH_ANYPREVOUT.

The Lighting Network Fiber Network launched by Nervos CKB has chosen the Daric scheme proposed in 2022. Based on eltoo, Daric effectively solves the cost and security issues of Watchtower. The Watchtower is a Lighting Network Node running on an independent machine and network, monitoring payment channels and assisting the victim in executing slashing transactions when malicious behavior is detected, thereby protecting user funds. Node operators typically run their own Watchtower to protect their Node.

Conclusion

The Lighting Network, as a scaling solution for Bitcoin, is based on a cleverly designed payment channel system. Through the three stages of opening channels, off-chain transactions, and closing channels, the Lighting Network greatly improves transaction speed and reduces costs.

To ensure the security of the two-way payment channel, the Lighting Network has adopted the LN-Penalty mechanism, and the BTC community has also proposed more secure mechanisms such as eltoo and Daric to effectively prevent potential fraudulent behavior.

These innovations have significantly improved the performance of the BTC network while ensuring security, paving the way for fast and low-cost small payments through the Lighting Network.

CKB-0,8%
BTC-0,61%
ALICE-1,42%
View Original
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • Comment
  • Repost
  • Share
Comment
0/400
No comments
Trade Crypto Anywhere Anytime
qrCode
Scan to download Gate App
Community
  • 简体中文
  • English
  • Tiếng Việt
  • 繁體中文
  • Español
  • Русский
  • Français (Afrique)
  • Português (Portugal)
  • Bahasa Indonesia
  • 日本語
  • بالعربية
  • Українська
  • Português (Brasil)