In this tutorial we tell you how the Lightning Network will improve blockchain.
Blockchain technology in itself is slow and expensive. When you send some bitcoins (Bitcoin) to someone, they will receive them only in a few hours, and the commission for the transaction will be quite high. How, then, does blockchain plan to conquer the world?
The main problem with blockchain is its non-scalability issue and one of the solutions for it could be the Lightning Network. Before we move on to discussing this idea, let's take a deeper look at the problem.
Why is Blockchain slow?
Blockchain is a kind of register that contains multiple pages or blocks, and on each page there are several transactions recorded. Once the page is filled in, it must be added to the register (chain), and only then start recording transactions on the next page.
Prior to adding a block to the chain, you need to perform a special operation to make sure that everyone agrees with the content of the page, and this operation takes about 10 minutes for each block (in the case of bitcoin).
Let’s imagine that you are sending 1 bitcoin (BTC) to your friend- Joe. This is how it would look like.
The transaction also contains information about the sender, the recipient, the amount and the transaction fee.
Hold on, what transaction fee?
Mhm, the transaction costs money. It’s in your best interest to incentivize miners so that they can include your transaction in the block. There is no preset price, you decide how much you are willing to pay to speed this process up, because the higher the fee, the faster your transaction will pass.
Miners must decide which of the available transactions should be included in the current block, and they simply look at the one which will bring more money, so that transactions with a high commission are processed first.
If you did not offer the highest commission, your transaction will be queued, and the waiting can last from several minutes to several days. And the more you pay, the faster your transaction goes.
Now you understand why blockchain is slow and expensive. Theoretically, with the adoption of blockchain, the number of transactions will grow, but this will slow down the network, and, therefore, hinder its further spread.
That’s when the Lightning Network (LN) comes in.
What is Lightning Network?
The concept of LN is that not all transactions should be recorded on the register.
Here is a situation: you and your friend transact several times among each other. In this case, you don’t have to register transactions in the blockchain.
To simplify, you and your friend can open a payment channel between you two and record its opening. Now you can make transactions on this channel, and it can remain open for several days or even years. But when you decide to close this channel, you would need a blockchain again as you will record the final result of all the transactions that have passed through the channel.
Based on this idea, we can create a network of payment channels, and recording transactions on the blockchain won’t be needed as much. We have Xan, Yelena and Zeke.
Supposedly Xan and Yelena have opened one payment channel, and Yelena and Zeke have another payment channel, then Xan can send money to Zeke through Yelena.
If Xan wants to send Zeke 2 BTC, in this case, Yelena will transfer 2 BTC to Zeke, and Xan will reimburse her 2 BTC.
That’s the idea of LN. As you can see, we almost don’t use blockchain, which means that all transactions occur very quickly. But, as you've guessed, the most important thing happens in the payment channels.
What is a payment channel?
It's like a safe deposit in which two people put in equal amounts, and then lock it.
The act of depositing equal amounts is recorded on the blockchain as an opening transaction - after that the payment channel is opened.
The whole idea is that no participant can spend money without the other, so this money is used only for transactions between these two figures.
So, let's imagine that Xan and Yelena deposited 10 BTC in their safe box. And what should Xan do if he wants to send Yelena 2 BTC?
He transfers a promise of ownership of 2 BTCs, after which, if the box is unlocked, Xan will be able to take only 8 BTC from it, and Yelena can already claim 12 BTC.
However, they will not open the safe deposit, because they plan to transfer money to each other in the future.
Imagine if the next day Yelena decides to send 1 BTC to Xan, she will do the same thing - give him the right to own one of her bitcoins. If they open the safe now, after two transactions, Xan will be able to claim 9 BTC, and Yelena - 11 BTC.
This is how it looks like:
The payment channel is simply a combination of several transactions, while any of the participants can close the channel.
Closure of the channel means that the participants open their "piggy bank" and take their own funds, and the result is permanently recorded on the blockchain.
This is how payment channels are arranged. But we do not yet see their true potential. They become a truly powerful tool when two or more such channels work together, forming a network - the Lightning Network.
How does Lightning Network work?
LN does not move actual bitcoins from one person to another, but the promise of the ownership of the bitcoins.
This is a very important difference - we'll look at it in an example. Imagine our trio: Xan, Yelena and Zeke, with one payment channel open between Xan and Yelena, and the second - between Yelena and Zeke. Please note that there is no payment channel between Xan and Zeke.
In this case, if Xan transfers 2 BTC to Zeke, he can do it with the help of the channel between Yelena and Zeke. How does it work?
Xan will request Yelena to pass a promise of 2 BTC to Zeke via the payment channel between Yelena and Zeke, and then reimburse Yelena with 2 BTC via the Xan-Yelena channel.
With the help of Lightning Network, a huge part of transactions are not recorded on the blockchain, thus not overloading the network and reducing the costs.