header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

Understand the Lightning network: Settle and close the payment channel

Read this article in 10 Minutes
At present, Alice and Bob have opened a two-way payment channel and stored 5BTC into the channel respectively.
原文标题:《 UNDERSTANDING THE LIGHTNING NETWORK, PART 3: COMPLETING THE PUZZLE AND CLOSING THE CHANNEL 》
原文作者: AARON VAN WIRDUM
原文编译: 闵敏 & 阿剑,以太坊爱好者


图片


Lightning network


At present, Alice and Bob have opened a two-way payment channel and stored 5BTC into the channel respectively. They have completed two transactions back and forth. In the current channel state, Alice and Bob can each retrieve 5BTC through the termination channel.


Now, they want to put a hash time lock contract (HTLC) in the channel to ensure that Bob can retrieve 1BTC from Alice after exchanging 1BTC for Carol's secret value.


As in the previous step (see Part 1), Alice and Bob each create a new commitment transaction. These two promise transactions are similar to the one created earlier, consisting of a normal output, a multi-sign address output with a CSV time lock (relative time lock), and a special hash lock. Then, as in the previous step, Alice and Bob swap the previous secret values to invalidate the previous channel state. Once the secret values have been exchanged, Alice and Bob can sign their respective promise transactions and send them to the blockchain at any time.


These steps are basically the same as before, except for one thing. The newly created commitment transaction by Alice and Bob contains a new output with a value of 1BTC. (Therefore, the BTC balance in the payment channel becomes Alice: 4; Bob: 5; New output: 1.)


This new output is essentially a hash time lock contract, and it's more interesting than the other outputs because there are three ways to unlock it.


The first is that the new output (contained within Alice and Bob's promise transaction) only releases the BTC if the subsequent transaction contains Bob's signature and secret value. Whether Or not Alice or Bob signs and broadcasts the promise transaction, only Bob can unlock the output -- as long as he includes the secret value in the subsequent transaction. However, there is a slight difference between the two promised transactions: if Bob terminates the channel, it is constrained by the CSV time lock. At this point, Bob must wait 1000 blocks before he can retrieve his BTC. (If Alice terminates the channel, Bob can immediately retrieve his BTC.)


Why does Bob need to wait for 1000 blocks? The reason is similar to what we explained earlier: If Bob tries to sign and broadcast an expired channel state, Alice can take 1 BTC. This is the second way to unlock the output. If Alice provides Bob's (latest) secret value, it can "steal" the funds in the channel.


Alice and Bob can play a game where if Alice tries to broadcast an expired channel state, Bob can use Alice's secret value to take that 1 BTC (without even having to provide the secret value).


Third, like other hash time-lock contracts, these two promise transactions also include the common CLTV time-lock (absolute time-lock) time-back mechanism, that is, if Bob does not include the secret value in the subsequent transaction within a time limit (say, two weeks), Alice can get back her 1BTC. In this case, it doesn't matter whether Alice or Bob terminates the channel.


So, how does it work?


Alice and Bob each hold partially valid commitment transactions. If Alice sends a promised transaction that she holds (and that Bob sent to her) to the blockchain, it immediately sends 5BTC to Bob. Alice has to wait 1000 blocks before she can get her 4BTC back. In addition, Bob has two weeks to provide the secret value to unlock 1 BTC corresponding to the "hash time lock contract output". (If he does not provide the secret value within two weeks, Alice can retrieve the 1BTC.)


Meanwhile, Bob can link his commitment transaction at any time and immediately send the 4BTC to Alice. He then has to wait for 1000 blocks before he can take 5 BTC from an address, and if he provides the secret value within that time, he can unlock 1 BTC of the "hash time lock contract output". (If he does not provide the secret value within two weeks, Alice can retrieve the 1BTC.)


Of course, if Either Alice or Bob tries to do evil at any point in the future, sign and broadcast the expired channel state, the other party can stop the evil party and steal all the BTCS in the channel.


图片


Settlement status


At this point, Bob must receive 1BTC in exchange for his secret value (if he has one). All he has to do is sign and broadcast the promise transaction he gets from Alice, include the secret value in a post-order transaction, and then sign and broadcast the post-order transaction.


Alice knows this. There is no way she can trick Bob out of his BTC, even if she gets the secret value by other means.


Therefore, Alice and Bob might as well "settle" out of the payment channel. Bob can give the secret value to Alice, and Alice can agree to update the channel state, so that hash time-lock contracts and deadlines are not required.


Assuming that Both Alice and Bob want to keep the channel open, this is perfectly normal: it's a lot less trouble than terminating the channel on the chain.


图片


Close the channel

 

And finally, where the Lightning network is really powerful:


Almost nothing in this series needs to actually use the Bitcoin blockchain.


If Alice and Bob want to peacefully close the channel, they can create a transaction that completely overwrites all transactions after the channel transaction is opened. They can close the channel transaction to send their due BTC balance to themselves based on the BTC balance ascription as shown in the latest channel status.


Specifically, this means that if Alice wants to close the channel, she can create a transaction that pays herself 4BTC and Bob 6BTC, and then have Bob sign and broadcast the transaction. Bob has no reason not to grant this request, and he will most likely cooperate with Alice to close the channel.


In the end, only two transactions are broadcast to the Bitcoin network and packaged into blocks: open channel transactions and close channel transactions. Even if there were a million transactions between Alice and Bob, this would be the result, thus greatly reducing the burden on the blockchain.


图片


A special thanks to Rusty Russell and JosephPoon for their information and additional feedback.


The original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit