The Bitcoin community has come up with a new technique called the Lightning Network to help solve the scalability issues. The idea is that those small and everyday transactions don’t have to be stored on the main blockchain. This new idea allows for more than 7 transactions per second and introduces the concept of Off-Chain transactions.
The lightning network is a protocol or set of rules, that sits on top of the Bitcoin blockchain. The intention of the Lightning Network is to provide a way to facilitate micro-transactions using Bitcoin. The concept was originally introduced in 2015 and has been in development ever since.
To understand the Lightning Network, let’s take a look at a real-life example. Every morning on his way to work, Alex stops at Jimmy’s Juice Stand for a cold-pressed organic juice. Creating a transaction on the main blockchain for this micro transaction is unnecessary. Alex will likely double the cost of his juice with the added transaction fees. However, with the Lightning Network, Alex could set up a Payment Channel with the Juice Stand.
To accomplish this, both Alex and Jimmy’s Juice Stand deposit a specific amount of Bitcoin into a Multi-signature address. For this example, we will assume that Alex deposits 0.01 BTC and Jimmy’s Juice Stand deposits 0 BTC (because they don’t accept refunds). The multi-signature address works similarly to a safe that can only open when both parties agree.
When the payment channel is opened, a balance sheet is also created that specifies how the funds should be distributed. At the time of opening the payment channel, the balance sheet would say that Alex would receive 0.01 BTC and Jimmy’s Juice would receive 0 BTC.
Opening the payment channel occurs on the main blockchain, this ensures that there is full transparency. Jimmy can see that Alex has deposited 0.01 BTC, and he can feel safe that he will receive whatever money Alex spends once the channel closes.
Now that the payment channel is open, Alex can order his morning juice from Jimmy. Let’s assume that one of Jimmy’s Juices cost 0.001 BTC (you know Jimmy uses all organic ingredients). To pay for this, Alex simply changes the totals of the balance sheet. He subtracts the cost of the juice from his balance and adds it to the balance of Jimmy’s Juice Stand. After one transaction the new balance sheet says that Alex will receive 0.009 BTC and the Juice Stand will receive 0.001 BTC.
The updated balance sheet is then signed by both Alex and Jimmy’s Juice Stand using their private keys. After the balance sheet is signed, each party gets a copy to hold on to. Alex can keep ordering juices for as long as he has money in the payment channel. There is no limit to the amount of transaction that can happen within the channel because it is all happening off of the main blockchain.
The payment channel can be closed at any time by either Alex or Jimmy’s Juice. All that is needed to close the channel is to take their copy of the latest balance sheet, signed by both parties, and broadcast it to the Bitcoin network. Miners then validate the digital signatures on the balance sheet. If everything looks correct, the funds are released according to the balance sheet. This creates a single transaction on the Bitcoin blockchain.
You can think of this like starting a tab at the bar. If you are going to sit at the bar and have a few drinks, they don’t want to charge your card for each drink. Rather they write down all your drinks and then charge the card 1 time once the order is complete.
The lightning network significantly reduces the load on the main blockchain. It only requires 2 transactions on the blockchain. The first transaction opens the channel, and the second transaction closes it out.
The lightning network also helps increase the security of the network. The system ensures that only the latest balance sheet can unlock the money. Since both parties have a signed copy of the balance sheet, they can release the funds at any time, regardless if the other party is non-cooperative. For example, Alex cannot hold the money hostage and refuse to pay Jimmy for the juices he has already served.
Additionally, if any party engages in any malicious activity, the entire balance sheet is given to the victim of fraud. These types of harsh penalties are in place to discourage cheating.
Another added benefit of the lightning network is that you don’t need to open a direct payment channel with everyone that you want to transact with. You can use the lightning network to help move your money in the most efficient way possible.
To help explain this point, we will look at another example. Let’s bring in Becky. Becky is a friend of Alex, and they have exchanged money on the lighting network previously and have an active payment channel. Now let’s assume that Becky has heard Alex raving about Jimmy’s Juice, and wants to try it herself. Instead of Becky opening her own payment channel with Jimmy’s Juice Stand, she can simply ‘transfer’ the money to Alex, who then ‘transfers’ to the Juice Stand.
This means that there is no need to create a channel with every person and business that you want to do business with. Using the lightning network, the payment tries to find the most efficient route from Sender to Receiver. This ability further reduces the strain on the main blockchain, but it does require that the intermediaries have enough money in their payment channels.
Implemented in Bitcoin 0.1 were features such as transaction replacement, input sequence numbers (nSequence), and nLockTime that would allow two or more parties to repeatedly update the state of an unconfirmed transaction prior to it becoming confirmed.
Satoshi Nakamoto described the technique to a Bitcoin developer in a personal email on April 17, 2013:
An unrecorded open transaction can keep being replaced until nLockTime. It may contain payments by multiple parties. Each input owner signs their input. For a new version to be written, each must sign a higher sequence number (see IsNewerThan). By signing, an input owner says “I agree to put my money in, if everyone puts their money in and the outputs are this.” There are other options in SignatureHash such as SIGHASH_SINGLE which means “I agree, as long as this one output (i.e. mine) is what I want, I don’t care what you do with the other outputs.”. If that’s written with a high nSequenceNumber, the party can bow out of the negotiation except for that one stipulation, or sign SIGHASH_NONE and bow out completely. The parties could create a pre-agreed default option by creating a higher nSequenceNumber tx using OP_CHECKMULTISIG that requires a subset of parties to sign to complete the signature. The parties hold this tx in reserve and if need be, pass it around until it has enough signatures. One use of nLockTime is high frequency trades between a set of parties. They can keep updating a tx by unanimous agreement. The party giving money would be the first to sign the next version. If one party stops agreeing to changes, then the last state will be recorded at nLockTime. If desired, a default transaction can be prepared after each version so n-1 parties can push an unresponsive party out. Intermediate transactions do not need to be broadcast. Only the final outcome gets recorded by the network. Just before nLockTime, the parties and a few witness nodes broadcast the highest sequence tx they saw.
At the time that this email was sent in 2013, the concept of the Lightning Network was 2 years away from being realized. However, in reading this quote from Satoshi’s email, it was clear he had the idea of the Lightning Network long before it was officially conceived.
There is no doubt that the Lightning Network addresses some of the largest concerns surrounding the Bitcoin blockchain. Only time will tell when it becomes available for everyday use, but it is definitely the reason you see companies like Starbucks lining up to accept the digital currency.
The main focus of this article was clearly the Bitcoin Lightning Network. In order to fully understand the benefits of the lightning network. It is important to have a full understanding of the consensus algorithm Proof of Work. For a Deep Dive into the Byzantine Generals Problem and Proof of Work, I recommend you review this article.