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.
- If Bitcoin can achieve all the plans, is it necessary for most of the competition coins to exist?
- Bitcoin riots in the early morning! More than 9% in an hour, breaking through $8,700 to hit a new high
- 10% of net worth bets on BTC, ETH makes a net profit of 1.5 billion, Wall Street giant Mike's road to crypto kingdom?
- Perspectives | Analysts: "Perfect Storm" Has Formed, Bitcoin Has Become Key Global Asset
- Who is the biggest bitcoin holder: Nakamoto, Winklevoss brothers or "King of encryption" Barry Sylbert?
- Switzerland promotes cryptocurrency payments, 65,000 merchants will accept bitcoin
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:
- 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.
- 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
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 .
Repeat this until the end, these transactions will not be broadcast to the network, only between A, B.
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
- 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.
- 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.
- 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
nLockTimeeach 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.
- 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! !
- 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
- 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.
- The limit of
nLockTime. Assuming that B is running, A will wait until the
nLockTimerefund transaction expires before he can get his money back. Similarly, if A
nLockTime, B will wait until the
nLockTimepromised transaction expires and get his own. Money.