Content
To build a two-way channel, in layman's terms, Bob and Alice each produce some btc, such as 5btc, and store it in a 2-2 multi-signature address controlled by both of them. However, Alice and Bob do not trust each other. Bob is afraid that after he transfers btc, Alice does not transfer btc and does not provide a private key to help Bob unlock the coins, making the funds fall into an endless loop. Then, we need to build a two-way transaction channel without mutual trust. The construction method is as follows:
Build a two-way trading channel
Alice uses the public key A1 and Bob uses the public key B1 to generate two 2-2 multi-signature addresses: A1B1, B1A1
Alice constructs a transaction and transfers it to B1A1 address 5btc. The transaction is not signed or broadcast.
Alice constructs another transaction 1, the originating address is B1A1, and the destination address is Bitcoin address A1. If this transaction is broadcast, it needs to go through 1000 blocks before it can be packaged
Alice sends transaction 1 to Bob separately, and asks Bob to sign the transaction. Bob discovers that this transaction is just that Alice transfers his coins back to him, which has no effect on Bob. Bob will sign and send transaction 1 back to Alice.
Alice receives transaction 1 signed by Bob and uses A1 signature to test the transaction signed with the B1 public key. The test is successful
At this time, Alice can safely broadcast the transaction of step 2. Even if Bob does not cooperate, Alice can get her coins back. After this step is completed, the B1A1 address receives the 5btc recharged by Alice
Bob also uses the same operation to recharge 5btc to the B1A1 address, and keeps the transaction 2 signed by A1, so he can redeem his coins at any time
Although the B1A1 address has received their respective money, Bob and Alice still have transaction 1 and transaction 2 on their hands, and there is a risk of breaking the contract at any time. Therefore, the last step requires Bob and Ailce to jointly initiate a transaction to transfer the 10btc in the B1A1 address to the A1B1 address, thus completing the construction of the two-way channel of the Lightning Network