about 2 years ago ·
9 min read
The Lightning Network (LN) is a second-layer scalability solution which enables peer-to-peer off-chain transactions by routing payments through a network of payment channels. This sentence might seem a little complicated at first but don’t worry, in this article we will break it down and explain what each piece means. First, we will explain what words like second-layer and off-chain transactions mean and why they are key elements of the LN protocol. Then, we will describe how the protocol works conceptually and what lightning payment channels are. By the end of this article, you will know what the lightning network is, how it works and why it is a viable solution to Bitcoin’s scalability issues.
Second-layer (or Layer 2) solutions refer to the solutions (protocols) that extend the base (or Layer 1) protocol rather than making changes to it. The lightning network is a second-layer solution because it extends the protocol of blockchain-based cryptocurrencies (such as Bitcoin’s). A lesser known fact is that LN is not a Bitcoin specific solution, the protocol can be adapted to work with other blockchains and already has support for Litecoin.
Now you might understand why the transactions that occur on the lightning network are also called off-chain transactions. Those transactions do not occur on the base blockchain. A clear benefit of that is scalability. Off-chain transactions do not need as many resources to validate and therefore don’t suffer from the same confirmation times as the first layer. Indeed, on the first layer, the 10-minute block time and the 1Mb block limit greatly impact the maximum transaction throughput of the network, with an estimated maximum of 4.6 transactions per second. The Lightning Network lifts this bottleneck and offers a theoretical unlimited throughput. As the network matures, we should get a better idea of the real capabilities of LN with some already very promising results.
However, that increase in scalability comes at some cost as the off-chain transactions do not benefit from the full security offered by the base blockchain. In the Lightning Network, the security comes very close to the base-layer while still having a near unlimited scalability potential. Let’s see how exactly that is possible and how transactions work on LN.
The lightning protocol is fairly simple: when two people (say Alice and Bob) wish to transact with one another, they can open a so called payment channel between them. A payment channel is essentially a smart contract to which both Alice and Bob commit a certain amount of funds. For the sake of our example, we will say they each commit 5 BTC into the contract. This commitment is called the funding transaction and needs to be broadcasted and validated on the Bitcoin blockchain. This is one of the only two transactions that need to be validated on the base blockchain, the second one being the closing transaction. Once the transaction is confirmed on the blockchain, Alice and Bob have a payment channel between them with a total capacity of 10 BTC, in which Alice owns 5 BTC and Bob owns another 5 BTC. This is the initial state as pictured in Figure 1.
Figure 1: Payment channel between Alice and Bob with a total capacity of 10 BTC
Now, Alice and Bob can transact as many times as they wish without the need to broadcast each transaction to the first-layer. Instead, they simply need to update the contract to update their balance. For example, say Alice wants to send 1 BTC to Bob through their payment channel. In that situation, the contract would be updated to show that Alice now has 4 BTC and Bob has 6 BTC, as seen in Figure 2.
Figure 2: Updated payment channel between Alice and Bob after Alice sent Bob 1 BTC
This can go on forever, until one of the two (or both) parties decide they no longer want to have an open payment channel with the other. Let’s say after sending 1 BTC to Bob, Alice decides to close the channel. In this case, she would need to broadcast the closing transaction which would contain their respective balances as defined in the latest state of the contract. In this example, Alice and Bob only transacted once so it wouldn’t make much sense to go over the hassle of opening and closing a channel. However, there are many situations where you would want to keep your channel open and transact several times. Imagine having recurring payments for a service you use (monthly, weekly, daily), opening a channel with your favourite bar and buying your beer/coffee through LN every night after work. Perhaps you need to pay a few satoshis for every API call you make to get the latest market price of a cryptocurrency by using a service such as Suredbits. Or you are a high frequency trader making use of Bitfinex’s latest lightning withdrawals. Well, you get the picture!
Ok, so Alice can open a channel with Bob and transact with him - great. Does that mean she needs to open a channel with every single person she wishes to transact with? Fortunately, no. Here comes the magic part. Let’s take our initial state from Figure 1 and add a third user called Carol. Carol has a channel open with Bob and they have each committed 2 BTC in it.
Figure 3: Showing the additional channel between Bob and Carol with a total capacity of 4 BTC
Now, let’s say Alice wants to buy some art piece made by Carol for the price of 1BTC. She doesn’t have a channel open with Carol but Bob does! So instead of opening a channel with Carol, Alice can route her payment through Bob. In such a setting, two contracts would get updated. First the contract between Alice and Bob, specifying that Alice has sent 1 BTC to Bob. Alice would be left with 4 BTC, while Bob would then have 6 BTC (in that channel). After updating that contract, the second contract would be updated with Bob sending 1 BTC to Carol. The final result is practically the same as if Alice had a direct channel with Carol: she has 1 BTC less while Carol has 1 BTC more 1 BTC more.
Figure 4: Showing the final state of the channels after Alice sent out 1 BTC to Carol
Here, Bob is filling the role of a routing node. Since he is offering a service to Alice by relaying her transaction he is allowed to charge a small routing fee to her. For simplicity’s sake, he didn’t charge any fee in our example. If he had, then Alice would have paid a little more than 1 BTC and Bob would have kept that extra amount when routing the transaction. In reality the fees charged by routing nodes in the Lightning Network are extremely low, sometimes a few satoshis (1 satoshi equals 0.00008306 € at current prices) , sometimes less than a satoshi (and sometimes even none!).
Moreover, the concept of routing payments is absolutely not limited to three people, you can extend this to as many people as necessary! Usually, you can reach (ie: pay) any node in the network in about 4 hops. However, that can change depending on the current topology of the network and on the node you are trying to reach.
What stops Alice from broadcasting an older contract state to the base layer where she owned more BTC? Or what stops Bob from not relaying the transaction? Well it’s a mixture of cryptographic ingenuity and well-aligned incentives that keep the nodes honest and the network secure.
The smart contracts I mentioned above, lock funds by using mainly the same cryptographic principles as in the first-layer (public/private keys, time locks, etc…). Also, remember that the initial state of the contract is broadcasted and secured on the first-layer, therefore making the contract as secure as the blockchain used to create it in the first place (so as secure as Bitcoin in our example).
The updates made to those contracts are made in a way that if any of the two parties were to try to cheat the other by broadcasting an older state, they would be penalised by having all their funds given to the other party. In our example, imagine if, after paying Bob 1 BTC, Alice decided to close the channel by broadcasting the old state where she still had 5 BTC. Then she would be cheating and all her funds would be given to Bob when closing the channel. She would be left with nothing while Bob would keep all his funds and win Alice’s. It would therefore be very risky to attempt such a cheat and Alice is better off staying honest.
Just like Bitcoin, there is no centralised server running the software and handling the transactions. The Lightning Network is a peer-to-peer protocol that follows the Basis Of Lightning Technology (or BOLT) specifications and can be run on practically any device. Anyone can implement their own version of lightning in their favourite programming language by following these specifications. Fortunately, you don’t have to as some very smart developers have already implemented this protocol and are constantly working on improving it. The most notable open-source implementation include c-lightning (in C ), LND (in Go) and Eclair (in Scala) with some very minor differences in each.
This really depends on your technical skills, your security profile and on the time you are willing to invest in the set up before you can start using the Lightning Network. In short, there are two “extremes”:
You aren’t very technical and would rather leave that up to the experts, you just want to get started using this amazing tech to transact bitcoin cheaply across the world
We hear you! It can be a little overwhelming to set everything up when you are not familiar with the technology involved. For you, the best way to start is to download one of the many custodial wallets available for both Android and iOS. Some options are BlueWallet, Phoenix and Wallet Of Satoshi. They all offer a seamless experience with little to no setup. Just download their app, send some funds to your wallet and start paying with bitcoin over the lightning network!
You want full control over the custody of your funds, you are tech savvy and have a few hours to spare to set up your Lightning wallet
If this is you, then well done for wanting to take control of your financial sovereignty! To get there, you will need to setup a bitcoin full node and a lightning node on your device (or on a server) to which you will connect your wallet. This will give you full control over your funds. However, like they say, with great power comes great responsibility. You are responsible for your funds and for your funds’ security. Setting things up correctly is not particularly difficult but it will require some time and there are a number of steps to follow. I added a short collection of links below to get you started on your journey.
Once you have completed all the steps and feel confident to try out a lightning wallet by spending some of your precious satoshis, check out Zap, a simple non-custodial wallet with a slick UI and many functionalities such as channel management, LNDConnect to easily connect to you node, and more!
The Lightning Network and the lightning protocol are simple at their core but can be difficult to grasp at first. So don’t worry if you didn’t understand everything, it’s normal. And if you did, that’s great! You might want to keep updated for our next LN article to learn more about the tech and how to use it. Although the Lightning Network is still experimental, there are many ways you can already interact with it and many wallets (like the ones mentioned above) take away most of the complexity for you to let you use fast, cheap and secure bitcoin transactions right now. If you want to learn more about those wallets and how to use them, make sure to keep an eye on our blog!
Some links to get setup: Full guide to setup LND: https://veriphi.io/en/blog/lnd-tutorial Full guide to setup C-Lightning: https://veriphi.io/en/blog/tutorial-from-scratch-to-a-c-lightning-transaction Backup your channels: https://medium.com/p/how-to-backup-your-lightning-network-channels-170c995c157b Activate the watchtowers: https://github.com/lightningnetwork/lnd/blob/master/docs/watchtower.md
about 2 years ago ·
9 min read
We are a multi-faceted team of crypto enthusiasts based in Berlin.
© 2021 cryptotesters UG
Crypto wallet guide
Crypto savings accounts
Defi lending rates
Exclusive crypto deals