Featured Post

Monday, October 30, 2023

My current understanding of the need for, and functioning of, LN

Limitations of the blockchain:

The Bitcoin (BTC) blockchain, also called "layer 1," is secure but relatively slow.  It can handle about 3 - 7 transactions per second.  By comparison, Visa and MC can handle thousands of transactions per second.  When BTCs layer 1 has many transactions pending, the costs to entice a miner to record your transaction can become expensive.  As I write this, I see that some transactions are costing $12, $17, or even more.  Others, though they might have lower fees, can take hours to process.

"You can't buy a cup of coffee with Bitcoin":

So, the two problems that keep people from buying a cup of coffee with BTC are:  (1) the fee could cost several times more than the purchase and (2) if the fee is lower, your transaction might not clear for tens of minutes or even an hour or more.  To save money, people aren't going to sit in the coffee shop for half an hour waiting on the cheaper transaction to record before the barista gives them their coffee.

So, the common complaint about BTC is that it is a store of value more than a currency to use day-to-day.  "Nobody is going to buy a coffee with Bitcoin" is a common saying.

A potential solution in layer 2, or the Lightning Network:

Lightning Network (LN) offers a solution to both of the numbered problems above.  (1), regarding fees, LN transactions are often fractions of a penny.  (2), regarding speed, LN transactions usually take only a few seconds.  I myself bought a Panda Express gift card using LN.  It was free (because I bought it through my own node) and took about one second between the time I authorized the payment from my phone and the time that the website registered that I had successfully paid for the gift card.

LN also seems to solve the problem with BTC's limited number of transactions per second by allowing this to scale up with the number of nodes and channels on the network.

How Lightning Network works:

At the most basic description, LN is a network or web of nodes and the channels between them.  If I have 1,000,000 sats (0.01 BTC) unused on my node, for example, I can make a channel of that size or two of half that size, and so on.  The creation of that channel is a transaction that must be recorded on the blockchain.  So, the fee and speed limitations are potential problems with only the opening of the channel.

Once the channel is in place, it can remain open indefinitely, processing transactions "off-chain" in its own layer, layer 2, the network of nodes and channels that make up LN.

A good way to a channel is as one row on an abacus.

In the image above, imagine that the abacus represents five channels (red, orange, yellow, green, and blue).  When your node opens a channel, all the beads are on your side of the channel; all the sats are yours.  The on-chain transaction basically tells the blockchain that such a row of beads exists between your node and the other node, the remote or inbound side.

A node ideally has many channels that have the potential to route inbound and outbound traffic.  If each bead above was 100,000 sats, the red and blue channels can route 700,000 sats of payments from your node to the other side.  After such a thing happened, all the beads would be on the remote side, ready to come back to you of a payment were routed from that remote node back to yours.

Similarly, the green channel could route 200,000 sats to your node or 800,000 sats from your node.

In such a manner, any one channel might route millions, tens of millions, or more sats over its lifetime.  Your node earns sats only on forwarding transactions (that is, sending them to the other node from yours).

If both nodes are happy with the channel, each may choose to never close it.

Once a channel is closed, the opener pays the on-chain fee for the blockchain to see the current state of the abacus/channel, record it on the chain, and distribute it to the two nodes.

If the yellow channel were closed, for example, your node would get 500,000 sats, and so would the remote node.  Whoever opened the channel would pay the on-chain fee from those 500,000 sats.

May write more later, but wanted to publish this for now.

No comments:

Post a Comment