The lightning network has earned a reputation of being one of the most potent solutions to the scaling problems faced by cryptocurrencies and Bitcoin in particular. Effectively, the Lightning Network acts as a second layer on top of the bitcoin blockchain. We use this layer to transact Bitcoin and some other cryptocurrencies much faster and cheaper than normal transactions.
Lightning Network For Dummies
In essence, there are 2 main parts to this second layer payment network that can be explained separately. 1 being the payment channels, then the lightning network itself.
Imagine your coffee shop begins accepting Bitcoin (BTC). Fees start to accumulate once people come back once and even twice a day for their coffee.
Opening a Channel
- Create a multi-sig wallet. The act of spending from that wallet will require more than one cryptographic signature. In the case above, this would be you and the coffee shop.
- You then agree on how much will be deposited into the wallet. (in the case of the coffee shop, if you deposit 1 BTC, the shop deposits 0 BTC agreed-upon. This is because they are not expecting to be sending you any payments as a customer.
- Next, you create half-signed ‘spending transactions’ from that wallet for the agreed amount of BTC and swap them. Either person involved in a transaction can add their signature to the other’s half-signed TX before sending it back to the network at any point. This would allow them to receive the agreed-upon balance.
— Vijay Boyapati (@real_vijay) February 25, 2019
- Let’s say you’re buying a Pizza for 0.1 BTC. You swap new half-signed transactions in which you will receive 0.9 BTC and the coffee shop will receive 0.1 BTC. For this to work, nothing needs to be sent to the network, just swap any bytes that represent transactions over.
(you don’t need to touch the blockchain to trust that these transactions represent money claimable at any time).
- You can repeat this as many times as you require or until the channel needs to be rebalanced. (for example, your side is now 0.00 BTC and you can’t subtract any more. Thus, you’d need to deposit more funds with an on-chain transaction.)
Closing Your Bitcoin Lightning Channel
So you’ve switched jobs and signed and broadcast the most recent transaction. You’re probably thinking ‘why the latest transaction?’
This is because for this whole time, to update the balances you have technically been giving that coffee shop answers to puzzles that could have potentially allowed them to take your money in the vent you try to sign and broadcast one of the older transactions.
They don’t have the answer to the most recent puzzle because each time you make a transaction, you swap answers for the previous TX. As a result, it’s always in your best interest to use the correct one. Trying to be smart and attempting to send the transactions where you still had a balance of 1 BTC will end with it being taken from you. You will not receive any outstanding funds that you may have previously owned. Thus, you lose the entire contents of the channel if you sign and broadcast an old TX.
So the main problem we have here is the introduction of a random retailer. What would happen if it wasn’t just you and the coffee shop? What if instead, it was you and a random e-commerce site where you were only trying to purchase a single item? Technically, opening and closing your channel would cost you more than a simple on-chain transaction.
Summary of the Lightning Network
- You open your channel to a payment hub
- The retailer will have open channels that go to other payment hubs
- After a certain number of hops, someone finally has a channel to the webshop you’re aiming for.
- Along the way, everyone swaps their half-signed transactions in the fashion explained above. In essence, this shifts the balance from you, all the way to the webshop, inevitably paying them.
- The system constructs the puzzles in a way that counteracts any bad players. Anyone attempting to do anything fraudulent, will not negatively impact the other participants. The most that will happen at this moment in time is some simple re-routing.
Have you used the lightning network yet? If so, what did you use it for? Let us know your thoughts in the comments below!