Bitcoin Lightning Network: Micro Payment Channel

The lightning network is based on the micro-payment channel. To understand that the lightning network must first understand the micro-payment channel.

Let's discuss the process of establishing a micropayment channel.

Consider the following scenario: A is the user, B is a data provider, and B needs to send a 100G big data file to A with a value of 100 yuan.

In order to reduce the risk, A does not want to give 100 yuan to B once, but every time I receive 1G of data, I pay 1 yuan to B.

Then you need 100 transactions. Now take a look at how the micropayment channel solves this problem:

  1. Generated but not initiated Funding Transaction User A generates 1 margin transaction and 100 Yuan to the address of the multi-signature controlled by A and B. This money requires A and B 2 individuals to issue a private key at the same time to take the money out.
  2. Generate and Save Refund Transaction User A generates a refund transaction with the margin transaction entered, then sends the transaction to B for signature and returns the signature to A. After User A verifies that the margin transaction content is correct, submit the first step to generate the margin transaction .

    About margin trading

1. The nLockTime of the margin trading is a value of >0 , that is, the transaction is Hold there and will not take effect immediately.

2. There are 2 outputs of margin trading: A, 100 yuan; B, 0 yuan.

3. The purpose of the margin trading is to ensure that the margin trading generated in the first step will not be locked by the B user .

  • Continue to initiate a commitment transaction user A to copy a refund transaction, and adjust the output to: A, 99 yuan; B, 1 yuan, signed and sent to B. B keeps this transaction and does not broadcast it to the network. The purpose of this transaction is to give the user B a dollar. B After receiving the user's promised transaction, send the 1G file to A; after A receives the 1G file of B, re-adjust the output to become: A, 98; B, 2 yuan. A, B re-sign, A then sends this transaction to B.
  • Repeat this until the end, these transactions will not be broadcast to the network, only between A, B.

  • A Settlement Transaction is initiated in A to receive the last G file and initiate a clearing transaction. The transaction output is: A, 0 yuan, B, 100 yuan. Its nLockTime = 0 , B receives this transaction, broadcasts to the network, the transaction takes effect immediately, and B receives 100 yuan.
  • The ingenuity of the micropayment channel

    1. Throughout the process, only the first step of the margin trading and the final step of the clearing transaction will be broadcast to the network, and the intermediate transactions will not be broadcast.
    2. How to avoid B running, A's money is always locked in the public account? This is guaranteed by sending a margin transaction after confirming that the refund transaction is correct.
    3. How to avoid A running, B can't get his own money? Each promised transaction has a common signature of A and B. If A runs, B will broadcast the latest transaction to the network, the transaction will be executed, and B will get the latest money. There is a characteristic of the promised transaction. The nLockTime each transaction is gradually reduced. Therefore, after B broadcasts the latest transaction to the network, it will be packaged first and executed first. Previous other transactions will not be executed.
    4. How to avoid A, B tampering with trading content? In any 1 transaction, B is signed first, then returned to A, A is re-signed, and then sent to B. In each transaction, there is a double signature of A and B. B changes the transaction content, and A's signature is not correct. In turn, A changes the transaction content, and it is not compatible with B's signature. Therefore, it is impossible for A and B to change the tampering transaction content! !
    5. How to prevent A double spending this money? In the second step, A got the refund transaction. A broadcasted the transaction to the Internet, took back the 100 yuan, and spent it elsewhere. Can't do it. Because the refund transaction has nLockTime , it is locked. And this nLockTime > 后面的任何1笔承诺交易的值 .

    Insufficient micropayment channel

    1. It is one-way and can only be used to transfer funds to A. If the other way around, you need to create another channel from B to A.
    2. The limit of nLockTime . Assuming that B is running, A will wait until the nLockTime refund transaction expires before he can get his money back. Similarly, if A nLockTime , B will wait until the nLockTime promised transaction expires and get his own. Money.

    We will continue to update Blocking; if you have any questions or suggestions, please contact us!

    Share:

    Was this article helpful?

    93 out of 132 found this helpful

    Related articles

      Discover more