What is Lightning Network — A clear explanation of how Lightning Network works and its further applications

Lightning Network is a lightweight solution to solve the Bitcoin and other cryptocurrencies scalability problem, which shortens several intermediary transactions into only two transactions.

Quang Nhat Dao
Vibentec-IT

--

For those who own and trade cryptocurrencies, have you ever suffered from:

· Extremely long transaction time
· Extortionate transaction fee

One transaction might be a little itchy waiting here and there, imaging you have to transfer your crypto ten or even hundreds of times, not to mention correct your false deals. Waiting for hours and spending a great deal are surely the last things you want to do with them. Then, my friends, Lightning network might suit you the best.

What is Lightning Network?

According to Lightning Network’s official website, Lightning is a decentralized network using smart contract functionality in the blockchain to enable instant payments across a network of participants. In other words, if two parties wish to perform several transactions using Lightning Network, they should follow these steps below:

1. Make a Funding Transaction
2. Establish Payment Channel
3. Update the channel through Hash and Pre-image (this is the step, where they make so-called “virtual” transactions within the channel)
4. Settle the final balance through Commitment Transaction

The upsides of Lightning Network

To make the long story short, we jump directly into the upsides of Lightning Network, so you can decide right now if Lightning Network is really for you.

  • It is instant and does not require any fee for the transaction. To address the situation, let’s compare Bitcoin’s 7 transactions per second (tps) to Visa’s average of 24,000, and its peak capacity of around 50,000 tpc. The Lightning Network is said to be able to take the transactions per second figure of Bitcoin and other cryptocurrencies to unprecedented heights of at least 1 million transactions per second.
Visa, Bitcoin, and Bitcoin with Lightning Network’s scalability
  • It is secured and one can use it for micropayments. When it comes to the Lightning Network, most of the transactions occur off the main blockchain, making them almost impossible to trace.
  • Cross-chain atomic swaps. As long as the two blockchains have the same cryptographic hash function, the users will be able to send money from one chain to another without any third-party intermediary.

In the following subsections, we will reveal the frequently asked questions around this means of cryptocurrencies transaction, including:

· Special terms for the sack of clarification
· How Lightning Network works
· A bonus example of Lightning Network transaction in normal situation and fraud-detected situation
· Further application from Lightning Network
· Cryptocurrencies that Lightning Network supports

Terms you’d better know

Transaction

Transaction denotes a transaction named β (beta), broadcastable by party X, indicating that the channel has been updated j times, and having an optional Relative Lock Time of λ (lambda). Moreover, X only needs a signature of itself to broadcast this transaction. In its variation, however, the transaction requires X to have both parties’ signatures to broadcast.

Revocation

Revocation hash denotes a hash that X sends to the other party to signal a j-th update of the state of the channel.

Pre-image

Pre-image plays a vital role in the revocation mechanism and in issuing a penalty to the party that broadcasted a revoked state of the channel. For a revocation hash h, a pre-image S is a value for which H(S) = h with H is a hash function. It is sent by X to revoke a Commitment Transaction in the previous j-th update.

Signature

The signature can be used by X to broadcast its own set of transactions. It is worth noting that both parties may have to cooperate to exchange their signatures because some transactions require both signatures to be broadcasted.

Relative Lock Time

Relative Lock Time makes sure that a child transaction can only be able to spend its parent transaction’s output if the parent transaction has achieved a depth of λ in the Blockchain. In other words, after the block containing the parent transaction was committed into the Blockchain, λ more blocks have been committed as well.

How Lightning Network works

Funding Transaction is to be signed by both parties and broadcasted by either of them to establish a payment channel.

Commitment Transaction represents the state of the channel after j updates and is edited by the party that does not broadcast it. It has an input requiring both parties’ signatures and two outputs designating the addresses to which fund’s bitcoins will be sent. The first output sends bitcoins to the broadcaster, but they are only spendable after a Relative Lock Time of λ. This provides the other party enough time to issue a penalty if it detects that the broadcasted Commitment Transaction has already been revoked. In that case, the number of bitcoins in the first output will be redirected to the other party. The second output, due to no λ attached, sends bitcoins to the other party immediately.

Revocable Delivery Transaction: After a time of λ has passed since a Commitment Transaction has been broadcasted, its broadcaster can claim the bitcoins of its first output by broadcasting a Revocable Delivery Transaction.

Delivery Transaction can be broadcasted by the party that did not broadcast the Commitment Transaction to immediately claim the bitcoins of the Commitment Transaction’s second output.

Breach Remedy Transaction: A party can claim all the fund’s bitcoins by broadcasting this transaction if the other party broadcasted an already revoked Commitment Transaction and the transaction has been committed into the Blockchain.

The illustration of the relationships between the type of transactions and their input(s) and output(s)

Still don’t have any idea how Lightning Network actually functions? Don’t worry, the following example might give you a clearer idea of how it works.

Examples: For your better knowing of Lightning Network

Bob — The pizza owner

This is Bob. He owns a pizza shop with delicious pizza and a business mind. Accepting paying with Bitcoin (BTC) gives his business a boost, yet along with a lot of headaches. Mostly, the problems come from:

  • Unwanted transferring wait time
  • Pricey transaction fee
Bob — The pizza owner

Alice — The pizza lover

Meet Alice. She loves pizza. Sometimes, she eats one, the other times she eats two. She also suffers from long transaction duration and costly fees.

Alice — The pizza lover

That is when Bob suggests a brilliant idea:

To document all the BTC Alice owns Bob, so Alice can pay Bob the balance at the end of the month.

In other words, they decide to use Lightning Network

Channel establishment
The first trade
The second trade

Normal channel settling

Normal channel settling

Channel settling when fraud detected

What happens if Alice tends to be wicked and broadcasts the old commitment transaction in other to pay less than she is supposed to?

  • Will Bob lose his Bitcoins for nothing?
  • Is there any security within the Lightning system?

Thanks to Hash and Pre-image, there will be no way for a party to cheating the other, at least by broadcasting a revoked Commitment. Within the λ of time after Alice’s commitment broadcasting, if Bob finds out that she broadcasted the old (revoked) commitment (the one where Alice owns 2 BTCs while Bob owns 1 BTC), he can broadcast the Pre-image (S)from Alice’s revoked commitment (h).

If H(S)=h, Alice will lose all the Bitcoins in the Funding to Bob.

Further application: Payment Over Multiple Hops

The following scenario is assumed. Bob is a merchant who wants to sell his merchandise and to be therefore paid with bitcoins on Lightning Network. In case that Bob has a lot of customers, it would be a nuisance for him to create a payment channel for each customer. One solution for this problem is to reuse the already established payment channels.

To further exploit the potential of the Lightning Network, the users need to be able to exchange bitcoins indirectly via an array of already established payment channels between them. Hashed Time-Locked Contract (HTLC) provides an adequate implementation for this issue and will be explained as follows.

Hashed Time-Locked Contract

Hashed Time-Locked Contract solves the problem of crypto transactions across payment channels.

As the concept of Lightning Network has previously been explained, the involved parties and the intermediary hops do not have to settle their payment channels after the preimage has been revealed but can update their channels instead.

Lightning Channels With HTLC

Now you understand HTLC and Lightning Network, let combine them all.

Before we jump into the explanation, meet Caroline. She is Alice’s bestie and Bob’s customer.

Caroline

Alice wants to send Caroline some cryptos, but establishing a new transaction channel seems to cost them lots of time. What should they do? Luckily, they know about HTLC and they have Bob, as their bridge.

So this is what will happen

It is important that the sender (Alice) and the receiver (Caroline) have to make sure to broadcast the Commitment Transaction before k - λ time so that they can claim the refund or the payment at the right time. Moreover, the λ in each hop may vary, so the sender must calculate k carefully. In case of not settling but updating the payment channels, more efforts for synchronization are required.

The challenges of Lightning Network

Now we know Lightning Network can help us save a lot of time and money in crypto transferring. But is Lightning Network the perfect solution? No, the reasons are

  • Lack of offline capacity
  • Interactive protocol requirement
  • Problem with transferring a large amount of crypto
  • Inability to solve the scalability thoroughly

Lack of offline capacity

To conduct transactions on Lightning Network, nodes must remain online at all times. This, however, dissuades many people from partaking, who favor the storing of their bitcoins on hardware wallets like Trezor or Coldcard due to their provision of better security. Nonetheless, an offline Lightning Network vision can somewhat be realized with the support of hardware for Lightning Network.

Interactive Protocol

The involved parties have to communicate with each other to set up the payment channels or HTLC, if they are to transact on Lightning Network. However, on the Bitcoin Blockchain level, one can simply transfer bitcoins to others without them knowing about it.

Transferring Large Amount Of Bitcoins

In the case of payment over multiple hops, if the sender sends too large an amount of bitcoins, some intermediary payment channels may not have big enough funds to send the bitcoins further to the receiver. For this reason, Lightning Network is for now more suitable for small transactions.

Not Solving The Scalability Problem Completely

Many have doubts that Lightning Network could actually solve the scalability problem of bitcoins. Their argumentation is that the transaction fee, which Lightning Network claims to be able to reduce, depends on Bitcoin’s congestion level or the rising difficulty of mining and the routing fee charged by nodes on Lightning Network. This fee can rise heftily as the number of users on Lightning Network increases.

Which cryptocurrencies does Lightning support?

  • Bitcoin
  • Litecoin
  • Ripple
  • Monero
  • Stella

Besides, there are other cryptos using solutions with the same technique as Lightning

  • Ethereum with Raiden
  • Zcash with BOLT
  • NEO with Trinity

The future of the Lightning network

Although Lightning network still has its restriction in boosting the scalability and simultaneously lowing the transaction cost, its development team promises several new features incorporated in the network in 2021, such as

Larger payment via Lightning Network

The limit of 0.1677 BTC per channel was lifted in 2020 to increase the usage and utility for both customers and businesses.

Cryptocurrencies exchange

In December of 2020, the Kraken exchange announced that it would begin supporting Lightning Network in 2021. At first, users can only withdraw due to the system acclimation, but payment channels may become possible so that Lightning transactions can be done directly with the exchange.

Watchover

Watchtowers are third parties that run on nodes to prevent fraud within Lightning Network.

Taking the example from Alice and Bob. If Bob has fraud intention and logs off the system before he delivers his pizza, Alice could broadcast the initial state, meaning they both get their initial deposits back as if no transactions were done.

In a nutshell, the Lightning network has proven its significant role in the evolution of cryptocurrencies’ transactions, despite the fact that it might not provide the ultimate solution to all the scalability problems all cryptocurrencies are facing. With the fast developing pace of technology and the network itself, there will be potentially new problems and opportunities.

--

--