⚡️ Lightning for dummies

Luis Miguel Louzao
5 min readMay 28, 2019

--

Hi there! This is a tutorial for dummies in which you will learn all the basics about this fantastic technology and how this solutions solves the scalability problems that currently constraint the Bitcoin network. Ready?

I am Lightning Network. I am inevitable.

Lightning is a second layer solution, that means that you don’t work directly with the Bitcoin network. Instead, you work with a second layer on top of the blockchain. As a consequence, the blockchain is relieved from traffic and the increased transaction fees that come with it. By using Lightning, you can save your satoshis from those evil miners 😇

Basic concepts

These are all the concepts that you need to know about LN to start:

  • Lightning Node: process connected to the Bitcoin Blockchain that allows you to connect to the Lightning Network.
  • Channel: peer-to-peer connection between nodes which share a specific amount of Bitcoin via scripting (HTLC).
  • HTLC (HashTime Lock Contract): contract in which a lifetime is specified for the channel. When this time is over, funds are returned to the counterparties.

How it works

Lightning works as a peer-to-peer network in which all nodes are connected to a distributed layer, where you can spend your (crypto)currency through this network. Sound this familiar? YES! It’s Bitcoin!

However, Lightning works as a second layer solution over the original Bitcoin Blockchain. Why? Because on-chain payments are slow, expensive and they leave a trace on the Blockchain. Can you imagine instant micropayments, without fees and non traceable? That’s why LN was created.

What’s the trick of LN? Transactions between counterparties are made offchain, without hitting the Blockchain. Think of channels as a vault in which you deposit your bitcoins. This vault contains a ledger in which assignments between the counterparties are modified in intermediate payments. In the end you obtain a balance that you can redeem when you close your channel.

Vault storing Alice and Bob Bitcoins

Channels by definition are a multisigned account in which these funds are stored. Keeping this in mind, think about of the channels as a continous flow of bitcoin transactions changing the state of the ledger.

Important: channels are bound by their capacity. Capacity is defined as the sum of both parties’ funds. What does this mean? If a channel has a capacity of 2 bitcoins, you can’t use this channel to make a payment with a higher value.

There are 3 types of transactions in Lightning:

  • Funding tx: onchain transaction that costs an amount of btc to be sent to the network and opens a channel with another node of the network.
  • Commitment tx: offchain transaction in which the balance between 2 nodes (channel) is updated. No communication with the blockchain, no fees.
  • Settlement tx: onchain transaction used for closing the channel. The funds are redeemed with the final balance.

What makes Lightning so interesting? The capability of making instant payments through multiple nodes in a multihop payment! That means that you can use third-party nodes to find a path to your destination and settle your payment.

Multihop payment from Alice yo Eric

LN works different than Bitcoin. Someone (the person who wants to receive your money) must emit an invoice like in retail commerce. This can be easily generated in a Lightning Node. This invoice can be sent as a hash that looks like this:

This is an invoice generated on Starblocks website

All payments starts with the ln preffix. This hash also encodes an optional “description” text field on your payment with a description of the payment. Something like this, just check the field:

Payment decoded

With a Lightning wallet you can make payments with this technology. You will see that they are made instantly!

How secure is LN?

May you wonder how secure is making payments through this cutting-edge technology. We have to consider two important scenarios:

  • What if a counterparty dissapear? In this sceneario, your funds can be retained in the channel. Fortunately, channels work with HTLC contracts that ensure that funds will be returned to the counterparties once a timelock expires (usually 3 days).
  • What if a counterparty tries to cheat on the final balance? To work with HTLC ensures the capacity of redeem the counterparty funds in case of fraud. If he/she tries to send you an old balance or force a channel to close with an old state, you have the capability of claim his funds.

HTLC are a good tool to ensure this system. However, LN is still in beta version. It’s recommended not to put too much money on your node in order to avoid a node failure from causing you to lose your funds.

Which is the benefit of running a Lightning Node?

I previously mentioned that Lightning Network is a fee free network. That’s actually a lie, as you do have to pay a fee for each transaction. However fees are close to 0 satoshis.

When you open a channel, more and more transactions flow through your node, which implies that your node can obtain a fee for this service. In this new paradigm, you can collect satoshis simply by routing payments. As a result, the more your node lives, the more you gain. Channels can remain alive as long as you want.

There are no miners, now there are routers 💻

The future of LN

LN is intended to introduce new business models, as for example, power supply streaming. What if you can pay only for the energy that you consume at home?

Another great example is paying with Bitcoin in retail stores without having to wait all 6 confirmations (1 hour to pay for a t-shirt??). Imagine paying a t-shirt which costs 7$ and paying another 7$ (like December 2017) of fees. With LN these fees are 0.00$.

Conclusions

A lot of work has been done on Lightning, but there is still a lot of room for it to grow. Lightning has already overcome all payment rails, but wallets are not so easy to use and custodial solutions are not optimal.

When a payment channel is opened, you fix the amount of money that can be transacted over this channel. At the moment, many companies, e.g. BlockStream, are working on solutions to overcome this restriction. If you want to learn more about these new solutions, just look up the “Lightning Loop”.

The future of Lightning seems to be as bright as a light! ⚡️

In next article(s), I’m going to describe how to deploy a Lightning Node in a few steps. Stay tuned! 🚀

--

--