Lightning network evolved from micropayment channel, and creatively designed two kinds of transaction contracts: RSMC (Revocable Serial Expiration Contract) and HTLC (Hash Time Lock Contract).
RSMC solves the problem of one-way currency flow in the channel, while HTLC solves the problem of cross-node currency transfer. These two types of transactions combine to form a lightning network.
RSMC creation
Let's first create a revocable contract with continuous expiration (RSMC). Alice and Bob are partners and often communicate with each other in Bitcoin, so they decided to put 0.5BTC in each channel to facilitate business communication.
RSMC transaction structure diagram
1. The two sides each took out 0.5BTC to establish the funding Tx, and the output was 2/2 times the signature of Alice and Bob. At this time, the funding for Tx is not signed, let alone broadcast. 2.Alice constructs commitments TX: C 1A and RD 1a, and gives them to Bob for signature. The first output of C 1a is the multi-signature address, Alice's other private key Alice 2, Bob's 2/2 multi-signature, and the second output is Bob 0.5btc.3. RD 1a is the first fee transaction output by C 1a, which is 0.5BTC output to Alice. However, this type of transaction has an order to prevent the current transaction from freezing, and it can only be frozen when the forward transaction has an order confirmation. 4.Bob constructs promises TX: C 1B and RD 1b, and gives them to Alice for signature. The structure is symmetrical with C 1a and rd1a. 5. Bob signs C 1a and RD 1a and gives them to Alice; Similarly, Alice signs C 1b and RD 1b, and gives them to Bob when finished. At this time, since the contribution Tx has not been signed, neither party can do evil and neither party will lose anything. 6. After the two parties sign and exchange the letter of commitment, they will sign and exchange the sponsorship respectively. At this point, funding Tx is a complete transaction, broadcast it.
The description of the above process and structure diagram is the whole process of creating RSMC.
Two transactions, C 1a and C 1b+0B, consume the same output, so only one transaction can enter the block. If Alice broadcasts C 1a, Bob immediately gets 0.5 BTC (the second output of c 1A), and Alice needs to wait for C1a to get 1000 acknowledgments before she can get 0.5 BTC through the output of RD1a. On the other hand, if Bob broadcasts C 1b, Alice will get 0.5BTC immediately, Bob will wait for C 1b to get 1000 acknowledgements, and then get 0.5BTC through RD1b. In other words, the party who unilaterally terminates the contract will delay getting the money, while the other party will get the money immediately.