The Lightning Network — Technology Behind Bitcoin’s Scaling Solution.

Wheatstones
Coinmonks
13 min readJul 7, 2022

--

Flickr

Introduction

It’s no secret that Bitcoin can only process around 7 transactions per second. To put that into a context, VISA routinely processes around 1,700 transactions per second, a figure it rarely exceeds, but could theoretically handle up to 65,000 transactions per second.

At 1,700 transactions per second, Visa is significantly faster than Bitcoin and this presents a problem for Bitcoin’s speed and scalability.

This is where the Lightning Network comes in.

The Overview — What is The Lightning Network?

The Lightning Network is a payment protocol that operates on top of the Bitcoin’s blockchain. It’s a network of decentralized nodes that allows for sending of huge number of transactions (up to a million per second) extremely fast for a negligible fee. The Lightning Network takes the transactions off the main blockchain and makes them highly scalable and ultra cheap, bringing it head to head with likes of VISA, MasterCard and Amex.

Lightning Network achieves that by establishing payment channels between pairs of users through which the parties can make or receive payments from each other.

New to trading? Try crypto trading bots or copy trading

As oppose to the main Bitcoin network, where every transaction has to be validated, in the Lightning Network the two parties can send and receive funds endlessly between themselves, and only the opening and closing of such payment channels are ever recorded on the main blockchain.

Wheatstones

Practical Example

Alice buys coffee from Bob’s coffee shop every morning on her way to work. Since Bob’s coffee shop accepts Bitcoin, Alice has the option to make a small transaction everyday for each coffee in Bitcoin, but she has to wait from 10 minutes to over an hour for her transaction to be validated and pay a high fee. Since Alice is very busy, instead she uses Lightning Network. She opens a payment channel with Bob’s coffee shop and deposits $50 worth of BTC, and Bob’s coffee shop creates an invoice, represented as a QR code.

Now, anytime Alice wants to pay for her coffee she simply scans QR code with her lightning wallet, making her transaction instant at a fraction of a cost (considerably lower than any traditional payment rail). At this stage Alice and Bob’s coffee shop are transacting with each other off-chain and at any point either one of them can easily terminate this arrangement by closing the payment channel.

In the background, Lightning Network creates a ‘smart contract’ between Alice and Bob’s coffee shop.

Furthermore, in order to transact, Lightning Network does not need to create payment channels between each and every user. For example, Alice’s buddy Dan arrives into her neighbourhood and already has a payment channel with her. Alice, who frequents Bob’s coffee shop, recommends it to Dan. Dan can now come to the coffee shop and buy coffee on a daily basis by sending BTC freely via Alice to Bob’s coffee shop, without needing to establish a payment channel with Bob directly.

Wheatstones

Six Degrees Of Separation — imagine this multiplied and expanded to millions of merchants worldwide with billions of payment channels. You can visit a new country and go shopping, and Lightning Network will find a way to connect you to a merchant through several channels. The idea is that, similar to the concept of “six degrees of separation,” all Lightning Network users will be able to pay all other Lightning Network users directly or through one or more forwarding users.

History

Back in 2014, Tadge Dryja, research scientist at the MIT Digital Initiative and Joseph Poon, a long-time Bitcoin developer, who also co-authored Plasma whitepaper with Ethereum Co-Founder Vitalik Buterin, began brainstorming ideas on how to scale Bitcoin.

The pair first proposed the Lightning Network in 2015. Their writings were based on previous discussions of payment channels made by Satoshi Nakamoto, the anonymous creator of Bitcoin.

In 2016, Dryja and Poon founded Lightning Labs, which raised $2.5 million and a beta version of the Lightning Network was launched in March 2018.

Privacy

The Lightning Network enhances privacy, because the blockchain will only ever have a record of the funding and closing transactions not any of the transactions in between.

The Lightning Network Under the Hood

Lightning Network is not a blockchain but rather a network which is maintained by nodes that route transactions via payment channels. Nodes are run by everyday people and corporations, running program on their desktops and laptops.

A payment channel is a two person multi signature address. This means it takes two signatures to move money out of it — similar to a joint bank account. In the above example, two users, Alice and Bob, would need to establish an initial channel between themselves in order to transact.

To Open a Channel — Alice & Bob’s Coffee Shop

Wheatstones

Alice sends money into the Alice-Bob multi-sig address by broadcasting a funding transaction onto the Bitcoin’s blockchain. After that they both keep a track of balances internally.

Initially Alice has 100,000 sats and Bob 0 sats. To buy coffee from Bob for 10,000 sats, Alice will initiate a commitment transaction that sources funding transactions as the input, pays her 90,000 and Bob 10,000. Alice and Bob both sign this transaction and keep a copy each — but this specific transaction is not broadcasted on Bitcoin’s blockchain.

Wheatstones

When Alice buys a second coffee next day, she creates another transaction replacing the first, sending her 80,000 and Bob 20,000. If Bob needs to make a refund for a coffee the numbers adjust in Alice’s favour, adding 10,000 back onto Alice’s total. None of these transactions ever interact with the blockchain, but are still secured by the blockchain.

If needed, Bob or Alice could broadcast the latest transaction at any time in order to cash out of payment channel on Bitcoin’s blockchain, which would send each of them their share of funds.

What If One Party Disappears?

Imagine this case, Bob disappears immediately after Alice commits funds to the payment channel, trapping her funds in multi signature address that requires both signatures to move funds out of it.

In order to address this issue, in Lightning Network Alice would get Bob to pre-sign a transaction sending all money back to Alice before she broadcasted the initial funding transaction to the main network. So, even if Bob disappears, Alice would simply broadcast Bob’s pre-signed refund transaction to get her money out.

What If One Party Cheats?

But what prevents Alice from broadcasting a previous transaction? These are still valid, fully signed transactions, whereby a previous transaction can direct 90k to Alice instead of 80k after Bob gave her a coffee?

To get around this lightning network includes a clever way to punish either one of them if they do broadcast an older transaction via revocation key. Every time Alice buys coffee from Bob, she and Bob create a new transaction and they each exchange revocation key to the previous state transactions and sign the latest version. Now, if one of them post ‘revoked’ transaction the other one can claim the cheaters share and the claimant will have 24 hours to do so, since it’s time locked.

In order to avoid for Bob or Alice to keep monitoring the state of blockchain in case the other one cheats, there are “watchtowers” in Lightning Network. The watchtower functionality is a mechanism for connecting to another friendly node, which monitors your lightning channels for you and prevents a dishonest counterparty from stealing your funds, even when you are offline.

Paying Via Other Channels

Aside from individual payment channels, such as the one between Alice and Bob, as discussed in our practical example, lightning network is able to send Bitcoin through multiple channels.

This is where Lightning Protocol shines, as you don’t have to set up a payment channel with every new person you want to transact with, but rather you can use the network to route your payments. Remember Alice’s buddy, Dan, from the previous example, who comes into the neighborhood, visits the coffee shop, but has no account with Bob?

Let’s walk through that example in more detail.

Wheatstones

We have Dan, Alice and Bob’s Coffee Shop. Dan wishes to pay for coffee to Bob via Alice, with whom he has previously established a payment channel.

Wheatstones

Bob creates a ‘secret’ (byte combination) and a hash of that secret and shares it with Dan as a QR code on a lightning invoice.

Wheatstones

Dan then sets up a new contract with Alice deducting some funds from her main total. Then Alice sets up a similar contract with Bob.

Wheatstones

Once everyone signed these new transactions and revoked earlier ones, Bob reveals secret to Alice and removes the temporary contract, moving the balance from that temporary total to Bob’s main total. Alice then passes the secret along to Dan, creating a news transaction that removes the temporary contract and moves the balance to Alice’s new total.

Contracts were set up from left to right, locking up funds temporarily and then funds were unlocked right to left to complete the payment via second round of transactions. What if Bob disappears and never reveals the secret, wouldn’t everybody funds be stuck?

Hash Time-lock Contract (HTLC)

HTLC is a centerpiece of any Lightning transaction. It’s a time out that is added to all the transactions returning funds to the original owner if secret isn’t revealed by a deadline. There is no risk, since either everyone gets paid or nobody does.

Privacy in Multiple Payment Channels

The multiple channel architecture of the Lightning Network maintains transaction privacy. This is because participants are not aware beyond the channel before and after them. They wouldn’t know if they were in a 5, 10 or 50 person chain.

Challenges of The Lightning Network

Centralized Hubs

Using the Lightning Network’s micropayment channels, Bitcoin could scale to billions of transactions per day, however, this can only be accomplished by using large, centralized “banking” hubs (for now). In its current format Lightning Network will not be entirely peer to peer.

flickr; Paul Baran (Network Topologies, 1964)

There are three types of networks that can be applied to capital markets

(A) Centralized — representing legacy capital markets. These are major exchanges, like NASDAQ and large banks, such as BlackRock.

(B) Decentralized with Hubs — smaller entities, such as online exchanges and local/regional banks.

(C) Distributed — representing Bitcoin’s main blockchain. A fully distributed network, with no middlemen, no gatekeepers.

The Lightning Network, will most likely fall into category (B) if it has any real chance of scaling to billions of users, rather than it being truly peer-to-peer. The reason for that is when you send BTC transaction across multiple payment channels on the lightning network every single one of the multi-sig wallets on the way must have a BTC balance that is larger than or equal to the amount being sent, which makes larger transactions harder to do.

Furthermore, there are not many incentives for an individual to keep a payment channel open on the Lightning Network. Fees rarely exceed handful of satoshis worth fractions of a penny which are paid to any intermediaries when BTC moves between payment channels. It’s safe to assume that the average user will not have a substantial amount of BTC locked up and it’ll be unlikely for an average user to keep their BTC locked up on a lightning network for pennies in profit.

Moreover, if the price of Bitcoin were to increase or crash, we could see a lot of payment channels close as multi-sig participants sell their BTC for profit or due to panic, shrinking the size of the network.

Because of all of the above, channels will most likely be set up by payment apps, crypto exchanges and tech companies working on Bitcoin, thus creating a “hub and spoke model”.

Block Size — Onboarding The World Onto LN Would Take Over 100 Years?

flickr — stevendepolo

Bitcoin was originally designed as peer to peer cash that would scale with block size increases, however block size has been a subject of controversy. Many have argued that the protocol’s block size cap is a crucial protection parameter, and increasing the block size will threaten decentralization, as eventually only a handful of computers will be able to store the full history of BTC transactions, as it would be too large for most to handle.

According to the Lightning Network whitepaper, in order for the Lightning Network to scale to billions of people, the Bitcoin block size has to be increased. See the Lightning Network’s original whitepaper published by J. Poon and T. Dryja on page 55, stating:

Lightning Network whitepaper

At present with the current block size, the average rate of transactions being typically 3 to 4 tps, the creation of a single Lightning Network channel for every person in the world, with the entire Bitcoin network dedicated entirely to that, would take roughly 140 years.

Why? First, you need to get Bitcoin — transaction one. Then, to create a Lightning channel requires a second Bitcoin transaction, and settling the channel afterwards requires a third one. That is 3 transactions per person on Bitcoin’s blockchain.

Since Bitcoin’s maximum average transactions per day are about 350,000, this would mean just over 116,000 people per day can be onboarded to the lightning network (350,000 tpd / 3txs for LN) — assuming that the network did nothing else, no regular BTC transactions. Now if we were to attempt to onboard 6 billion people (world’s adult population), then at the rate of 116K per day, it would take around 140 years to get the global adult population onboard the lightning network.

However, in practical sense, it would require only a single transaction, as users could convert their fiat and send it strait away via the lightning network using intermediary, such as Kraken, which has 746 direct channels open — i.e. decentralized with hubs model.

Leaving the lightning network isn’t necessary. Lightning is intended to be used to spend money that you would regularly spend with merchants, not your life savings. The best-case scenario for lightning is for a user to join up and then stick with it. The only real reason to leave the lightning network would be if anything went wrong and users needed to safely secure their funds back on the blockchain.

This brings us onto one transaction per person, or put in another way, around 47 years to onboard 6 billion people onto Lightning Network — considering the blockchain is effectively shut off to all else besides onboarding people to Lightning.

In order to address this issue, the lightning developers came up with a concept called Lightning Channel Factories, which will make channel management more efficient by reducing the eventual number of on-chain transactions.

themoneymongers.com

In essence, channel factories are simply an extension of 2-of-2 payment channels. So in channel factories, instead of doing 2-of-2 multi-sig, you can do 5-of-5 or 10-of-10 multi-sig where the funds are allocated by multiple parties.

The concept of channel factories will allow to onboard multiple users at a time onto the lightning network in one transaction. For a group of 20 users with 100 intra-group channels, the cost of the blockchain transactions is reduced by 90%. This means that the time frame to onboard 6 billion people will be reduced to under 3–4 years.

Thinking Fourth Dimensionally

Bitcoin is not a static technology, bur rather a constantly evolving suite of protocols. It evolves with time, while protecting its fundamental monetary properties as well as its ethos of decentralization, where no single party can direct how Bitcoin evolves.

Consider the evolution that brough about the Lightning Network itself. In 2017 Segregated Witness (SegWit) upgrade was implemented in Bitcoin Core which enabled the launch of the Lightning Network as a second layer on top of the Bitcoin’s blockchain. Until SegWit was activated, the Lightning Network was unworkable because it relied heavily on unconfirmed bitcoin transactions and was thus susceptible to attack so long as transaction malleability was possible.

SegWit improved several aspects of Bitcoin and opened the door to future upgrades, including a major one, known as Taproot. The Taproot upgrade, which went live in Nov 2021 provided workarounds and removed limits in Bitcoin’s code to increase the network’s real-world use cases. For instance, after Taproot, the Bitcoin Network shifted to use Schnorr signatures to sign transactions, which reduced on-chain transaction size, validated transactions faster and improved privacy.

Taproot has resulted in drastic scalability and privacy improvements to Bitcoin’s Lightning Networks for a number of technical reasons (mainly, the switch to use point-time locked contracts and batched validation, both made possible through Schnorr signatures). After Taproot, Bitcoin Lightning Networks should become more intuitive and cost-effective for users.

Changes to the Bitcoin protocol are like stones thrown into a lake, leading to ripple effects. Just as the Segwit upgrade solved the urgent issue of block space while also enabling the launch of the Lightning Network by solving transaction malleability, Taproot’s changes to the Bitcoin protocol will have immediate repercussions while setting the groundwork for future developments.

The Lightning Network is just the beginning.

DISCLAIMER: The information contained in this article is for educational purposes only and does not constitute any form of advice or recommendation by Wheatstones, and is not intended to be relied upon by users in making (or refraining from making) any investment decisions.

--

--

Coinmonks
Coinmonks

Published in Coinmonks

Coinmonks is a non-profit Crypto Educational Publication.

Wheatstones
Wheatstones

Written by Wheatstones

Digital Asset Management | Cryptocurrency & Blockchain | Cayman — London

Responses (1)