Lightning 101: Routing

Torkel Rogstad
Oppdatert 05,mars 2019

As mentioned in our last blog post, the Lightning Network would be no fun (or practical) if you needed to connect to every single node you wanted to either send to or receive from. One of the core features and innovations when the Lightning Network was initially conceived, was that payment channels (described in further details in our last post) would be stitched together, enabling payments to be made without all participants having to be directly connected.

Let’s illustrate this with an example. In our little town of Lightningville lives Alice, Bob and Carol. Bob is the local town store-owner. Alice and Carol shop at his store several times a week, so they have opened a channel with him. However, they don’t pay each other very often, so it wouldn’t be efficient for them to have a channel directly. What should they do when that need arises? They route payments through Bob:

  1. Alice makes an invoice, requesting 1000 satoshis from Carol
  2. Carol accepts the invoice in her wallet
  3. Because she isn’t directly connected to Alice, her Lightning node checks if any of her connections have a channel she can use
  4. Her node finds a route through Bob that connects to Alice
  5. Carol sends money to Bob
  6. Bob send the same money (minus a small fee) to Alice

This is of course all done automatically by the involved Lightning nodes, enabling it to happen in the blink of an eye. Carol has now paid Alice 1000 satoshis without being connected to her. This is what we mean by routing on the Lightning Network.

Now you may think that this sounds scary. What if we couldn’t route through honest Bob but had to use malicious Mallory instead? Could Mallory steal our money? In short: no.

Warning: The next paragraph is a bit technical, so don’t panic if it doesn’t make sense at first.

All payments on the Lightning Network requires the recipient (Alice) to generate a random secret. All transactions on the Lightning Network are set up in such a way that if the secret is revealed, money is being transferred. In our example, Carol wants to route 1000 satoshis through Bob to Alice. Alice generates a secret. Carol tells Bob that if he can tell her that secretshe will pay him 1001 satoshis. Bob then goes to Alice, buying the secret from her for 1000 satoshis. He reveals the secret to Carol, gaining him 1001 satoshis. He has successfully been a middleman between Alice and Carol, and also made a profit of 1 satoshi.

Keep in mind that everything that’s described in the above paragraph is done automatically by Lightning nodes creating, executing and verifying smart contracts. This ensure that all actors along the way must act according to the established rules. If anyone tries to steal money along the way, the smart contracts have built in punishment mechanics, as mentioned in our blog post on Lightning Channels.

For routing to work properly on the Lightning Network, it’s necessary that we find channels with enough liquidity. What’s meant by this? Going back to our example: If Carol wants to pay Alice through Bob, it’s obviously a requirement that Carol has enough money in her wallet. Something that’s less obvious is that Bob also has to have a certain amount of money, in this case in his channel with Alice. To be specific: Bob has to have some money on his side of the channel with Alice. If he didn’t, he wouldn’t be able to forward the payment to Alice. All transactions on the Lightning Network need paths of channels with enough money in them to complete the payment.

As compensation for providing liquidity, nodes can require a fee for routing payments. These fees are typically very small, on the order of single digit satoshis. Recall that 1 bitcoin is divided into 100 million satoshis. So if a node requires a 5 satoshi routing fee, that’s less than 0.02 cents. However, if a node is well connected and routes a lot of payments, the node operator can potentially earn some money on hosting a node. This is something we will cover in more detail in a later blog post, as it is a very interesting topic.

Routing is really one of the core features of the Lightning Network. The concept of payment channels had been around for a long while, but being able to route through multiple parties in a decentralized and safe manner is a breakthrough compared to previous technological iterations.

If you’re interested in chatting more about Lightning Network technology or crypto tech in general, you can find us on Twitter @Suredbits or join our Suredbits Slack community.

In December of last year Suredbits released the first ever cryptocurrency market data API where you could stream data and pay for it on the Lightning Network.

Here’s some additional reading on that topic you may find interesting:

Cryptocurrency Exchange API Release
Today we are excited to announce the release of our cryptocurrency exchange market data api that is monetized with the…

Crypto Exchange API Demo
We are making significant progress in building our Cryptocurrency Exchange API using the Lightning Network. We put…

Crypto Exchange API Demo: “Refunds”
Last week we shared a demo of how “Refills” work as part of our Cryptocurrency Exchange Service. The week prior, we…

Originally posted on Suredbits Medium page.