Problem with bitcoin –
As we see exponential growth in the usage of bitcoin, the bitcoin transactions take a relatively long time to be settled than they used to be in the initial years. In the case of bitcoin, every transaction has to be broadcasted to every node. The bitcoin blocks are 1 MB each and are created every 10 minutes, restricting it from carrying out more than 7 transactions per second. On the other hand, we have VISA which can carry out as high as 65000 transactions per second. So in order to compete with the existing payment methods, a change was required which later led to the invention of the lightning network.
Proposed solution for the scalability problem –
Increasing block size– In 2017, the proposed solution was to increase the block size, this was met with a lot of criticism in the bitcoin community. Finally Bitcoin Cash (BCH) was developed with the main motive of making transactions faster by increasing the block size from 1 MB to 8 MB . But the problem with having a high block size is that it discourages the mining part. Large block size leads to the requirement of large storage which many miners won’t be able to afford, thereby making the network more vulnerable and less decentralized.
This led to the introduction of lightning network.
Introduction to lightning network-
Lightning network is a layer 2 protocol built on top of bitcoin which facilitates ultra-fast transactions. It was developed by Joseph Poon and Thaddeus Dryja. The whitepaper for the lightning network can be found here.
A lightning network is a network of decentralized nodes that can send/receive a large number of transactions in few seconds and for a very low fee. It supports micropayments too.
To understand how the lightning network makes transactions fast is by taking an example of a man who visits a bar and orders a drink and then pays for it, after this, he orders a drink again and then pays for it again. This is the old way of settling each transaction on the blockchain which makes the transaction quite slow. But if we take the lightning network into consideration, in this case, the man orders the drinks and every subsequent drink is noted on a tab and finally, after enjoying all the drinks, the man pays for all the drinks in one go.
So we see that in the case of the lightning network, not every transaction is settled on the blockchain. When a payment channel is set up, only two transactions are mined or broadcasted to the blockchain that is the opening and the settlement transactions. Other transactions between the peers are not recorded on the blockchain hence the transactions are very fast. This off-chain layer 2 payment solution thus makes the lightning network a very scalable means for transactions.
Payment channels are said to be the building blocks of a lightning network. They are usually set up between peers who transact frequently. In order to open a new payment channel, the two peers need to commit some funds to a multi-signature address. This initial sending of some amount to the multi-signature address is known as a funding transaction which is broadcasted to the blockchain.
The total amount sent as a funding transaction represents the total capacity of the channel. After the funding transaction is done, a channel is created between the two peers who can now send the required amount to and fro, without any fees. The transactions done through the channel are not broadcasted to the blockchain, thereby providing the solution of scalability. Finally, when the payment channel is closed, it is broadcasted to the blockchain. Therefore we simply have just two transactions on the blockchain, making this a very viable way for transactions to take place.
Payment to people with whom a direct channel isn’t set up-
In the above section, we found out how the transactions are carried out when a channel is set up between two peers, but what happens when we need to transact with someone, with whom we don’t have a direct channel set up?
In this case, a route is found between the peers with whom I already have a channel and with whom I want to transact. The route in the network is selected in such a way that it is the shortest route possible, thereby minimizing routing fees and facilitating fast transactions.
So let’s see how the payment is actually carried out through the lightning network channels
Here we have the case where Alice wants to send some amount to Eric but both of them don’t have a direct channel with each other. But we see that Alice does have a channel with Bob who in turn has a channel with Carol, now Carol has a channel with Diana, and finally, we find that Diana has a channel with Eric. So this is the path that would be used to carry out the payment from Alice to Eric.
Steps for payment from Alice to Eric without a direct channel
Step 1 – Eric generates a secret (R) and then creates a hash (HASH(R)) of the secret which is an invoice when he sends it to Alice and the hash contains the information on how to construct the payment. The secret R is used for redeeming the payment and is only available to Eric for now.
Step 2– Since Alice now has the info regarding the payment construct, she directs Bob that if he pays forward the specified amount, he will be paid the given amount by her when he has the secret(R).
Step 3– Bob now directs Carol that if she forwards the given amount, he will pay her the amount when she has the Secret (R).
Step 4– The same goes for Carol- Diana and Diana-Eric payment channels.
Step 5– As soon as Eric finds out from Diana that he will be paid the amount if he reveals the secret R to her, he does so and manages to redeem the amount, the balances are updated in the payment channels between Eric and Diana, where Eric now has the given amount and Diana has deficit of the same value and at the same time she also has the secret (R).
Step 6– Since Diana has the secret(R) now, she can now redeem the amount promised by Carol to her if she reveals the secret(R) to her. The balances are updated in their respective payment channels.
Step 7– The above step is continued till Alice pays Bob when he(Bob) reveals the secret(R) to Alice. Thus Alice has managed to pay Eric through the lightning network without having a direct channel.
In the above image we see that in every successive payment channel the amount goes lower than the previous one(Alice sends 1.003 BTC but Eric receives 1.0 BTC). This is because of the routing fees which needs to be paid to the participants of the intermediate payment channels. This is the reason why the shortest path is chosen so as to minimize routing fees.
All the transactions are carried out using an encrypted onion route thereby enabling privacy, so the participants don’t know where is the source of the payment and where is it heading to. The participants also don’t know their position in the network.
Other possible applications of lightning network-
Creating a streaming service where user doesn’t have to pay a monthly or subscription fees instead they can pay for the number of minutes or even seconds they want to use the service. This will open up a whole new category of money-time based applications.
As Lightning network saw a huge growth , there was a need to set up a standard for the same, hence BOLT(Basics of Lightning Technology) was introduced.
BOLT specifies certain standard specifications for the implementation of the Lightning network. Some of the implementation based on the BOLT are LND, Eclair and C-Lightning
Lightning network is still in its early stages and is undergoing rigorous developments to revolutionize the payment methods between peers. It has also gained a lot of popularity in the twitter community where it was used in a campaign known as Satoshi Torch in which a certain amount of Sats was sent to a trusted individual using the lightning network and then he/she would add some more Sats to the already existing amount and send it further. This enthusiasm shown for lightning network reveals that it’s one of the most interesting technologies of this era, although it still has a long way to go it will certainly have a big impact on the way we carry out transactions.