The Lightning Network (Part 2)

 

 

Part 1   Part 3

In Part 1, we talked about multisig addresses and how you can have Open Channel Payments and Closed Channel Payments. These are the building blocks of the Lightning Network (LN). Now let’s look at how the LN would work between 2 people: Alice the Boss and Carol the Graphic Designer.

The Lightning Network between 2 People

Let’s say Alice hires Carol as a Graphic Designer and Alice intends to pay Carol 0.1 LTC for every project she completes. Alice would rather avoid paying a transaction fee for every payment so she and Carol agree to use the Lightning Network(LN). The LN will allow Alice to pay Carol multiple times for only opening and closing payment channel fees.

In order to use the LN, Alice and Carol create a multisig address where there must be 2 signatures in order for LTC to be sent (i.e to close the payment channel). This is called a 2 of 2 multisig address: 2 people, 2 signatures.

 Both Alice's and Carol's personal LTC addresses are connected to the multisig address.

Both Alice's and Carol's personal LTC addresses are connected to the multisig address.

In order to set up the Lightning Network, Alice first sends 1 LTC into the multisig address. Alice creates an open payment channel through a Hash Time Locked Contract that states it will return to her in 30 days which requires a small fee to open; a fee less than the normal Litecoin transaction fee.  This fee will only be broadcast to the network once the channel closes.

1_HD_wMXwDNVVeZHTwTxLqsA.png

Ok So Let’s Review:

  • Alice pays a small fee to open the payment channel for the Lightning Network through a Hash Time Locked Contract.
  • Once the initial payment channel is open, several other payments can be initiated and exist at the same time. 
  • One way the channel can be closed and the LTC sent in a 2 of 2 multisig address is when both Alice and Carol sign one of the payment offers in the open payment channel.
  • When a payment channel closes, the rest of the payment offers disappear.

Now let’s flush out how this might look like with Alice and Carol.

Alice Pays Carol for 1 Project

Carol finishes 1 project and so Alice decides to pay Carol 0.1 LTC. Alice goes into the multisig address to propose a payment of 0.1 LTC to Carol from the 1 LTC that is locked up in the multisig address. She does this by initiating a payment and then signs the transaction. Carol is notified by the multisig address that 0.1 LTC is trying to be sent and asks for her signature. If Carol accepts the offer, she signs this transaction closing the payment channel. This means that 0.9 LTC will stay in the multisig address and 0.1 LTC will go into Carol’s address. The transaction will also be recorded on the blockchain and a transaction fee will be sent to the miners.

1_30delgGSTCqfv13q62DFJw.png

BUT! Carol decides not to sign this proposed payment of 0.1 LTC and leaves the offer “on the table.” So the 0.1 LTC is unspent and stays as an open payment channel. The reason for this is because Carol has 9 other projects to finish for Alice.

Alice pays Carol for 2 Projects

Carol finishes her 2nd project and so Alice decides to pay Carol for two jobs. Alice goes back into the multisig address and offers her 0.2 LTC for 2 jobs because you can not combine or sign two offers. Once Carol signs one payment channel, all the other offers will disappear.

Carol is notified that 0.2 LTC is trying to be spent and requests her signature. Carol can only sign the most recent transaction due to something called "Relative Time Locks."  Should Carol try to cash out on a previous state (0.1 LTC), then a punishing contract is broadcast sending everything in the wallet to Alice.  This is particularly important if a previous offer (0.3 LTC) is greater than the most recent one (0.2 LTC).  

Carol decides to do nothing because she decides to keep working on the 8 other projects for Alice.

1_udcGatKpFVTR5Ez9uBDwzQ.png

Relative Time Locks

Now would be a good time to talk about Relative Time Locks. Relative Time locks help ensure that the most recent offer is the one that gets recorded on the blockchain. Here’s a scenario to explain why this is important:

  1. Alice offers 0.1 LTC to Carol for 1 job. Carol ignores it.
  2. Alice offers 0.2 LTC to Carol for 2 jobs. Carol ignores it.
  3. Alice offers 0.15 LTC because Carol broke Alice’s stapler and is taking a 0.05 LTC deduction from the 0.2 LTC payment.
  4. Carol still has the option to sign off on the 0.2 LTC offer because all 3 offers are still on the table.
  5. Relative Time Locks recognize the 0.15 LTC as the most recent offer. It then delays all previous offers a significant amount of time (which you as a wallet owner could determine) should it be chosen to be broadcasted. If Carol tries to cheat Alice, the conditions have been set for Alice to broadcast a “punishing contract.”
  6. This allows Alice to go back into the multisig and broadcast a “punishing contract” to take the whole LTC from Carol.

Closing the Payment Channel

Carol continues to work for Alice and ignores every offer Alice signs in the open payment channel until all 10 projects have been completed. Alice finally signs the 10th transaction to Carol for 1 whole LTC.

*Side note: Up to this point, not a single transaction has been recorded on the LTC blockchain and no fee charged because none of the payment channels have closed. This is what it means to have “offchain” transactions. None of the offers have been recorded on the blockchain and a fee has not yet been sent to miners.

Carol is notified of Alice’s proposal of sending 1 LTC and she immediately accepts the offer by signing the transaction. This closes the payment channel and the 1 LTC is sent from the multisig address into Carol’s personal address. A small fee is also assessed to close the channel. The transaction is finally recorded on the blockchain and both the opening and closing fee, totaling one regular Litecoin transaction fee, is sent to a miner.

Through the Lightning Network, only 1 fee out of 10 was paid. Also, only 1 transaction out of 10 was recorded on the blockchain which also saved blockspace in the Litecoin blockchain.

Carol Can Initiate Payments Too

One last point to mention is that Carol can propose payments too because she controls the multisig wallet as well. However just like before, the transaction can only be completed if there are two signatures. So Alice must sign Carol’s transaction for the LTC to be sent.

Summary

Alice offered 10 payments which increased by 0.1 LTC each time to Carol through the Lightning Network. Carol accepted the offer of 1 LTC by signing off on it. Of the 10 proposed transactions, only 1 was recorded on the blockchain and there was only one transaction fee.

Alright now that we have the basics down, you can now move on to Part3: The Full Picture of the Lightning Network.

Sources:

https://lightning.network/

https://www.youtube.com/watch?v=8zVzw912wPo

https://streams.lykke.com/Project/ProjectDetails/b134b15b54e745559f26c217bef5a2f8

Donation Addresses:

LTC: LgGHRsbYHs93gKttBMehLzth3xDAU3tCSZ

BTC: 36Nc4cJxcwp5Xn6wfo1W9UuC5SRQKXHmYy (Segwit address. Legacy and Segwit chains accepted)