LNsync: Getting Your Lightning Node Quickly Up to Speed
Lightning Network

LNsync: Getting Your Lightning Node Quickly Up to Speed

Christian Decker
Christian Decker

We’re excited to announce the release of a new piece of Bitcoin infrastructure that simplifies payment routing for Lightning app developers: LNsync, a server-assisted gossip synchronization mechanism.

You can think of LNsync like a Google Maps for Lightning, providing Lightning nodes with a comprehensive “map” of the network so that they can quickly find the optimal route for each payment without having to grind through the gossip data to build a map from scratch.

By providing Lightning apps with an efficient method to keep in sync with the rest of the network, LNsync should represent a major step in improving the usability of Lightning for all Bitcoin users.

Addressing a Common Problem

LNsync addresses a problem many Lightning users have encountered before. Imagine you are looking to pay for a purchase using your mobile Lightning wallet. You open the app on your phone, scan the QR code, press send, and… it fails. You try again a few seconds later, and this time it works. But what went wrong the first time around?

During startup, your mobile application reconnects with its peers and re-establishes the channels that were created during previous sessions. At this point, your app can technically send and receive payments. But an often overlooked requirement when transacting over Lightning is that the sender needs a good enough view of the network topology in order to be able to route a payment to its destination.

For this purpose, Lightning includes the so-called gossip protocol, which allows nodes to exchange metadata, or gossip, about other nodes and channels on the network. This protocol, however, is not very efficient: it can take anywhere from a couple of seconds to several minutes to catch up with the latest gossip, which may also result in your mobile app retrieving duplicate information from different peers.

Sync Fast

LNsync collects changes on the network since your node was last online and makes that information available to your node in a compact format—currently allowing for a significantly accelerated synchronization process. This is done in a procedure called the server-assisted gossip sync, explained in more detail in our Engineering Blog.

Applications can query changes from a specific point of time through a simple API that delivers the minimal set of gossip messages required to catch up with the rest of the network. For example, catching up two hours results in about 500KB of uncompressed data, delivered in just over a second, while catching up on 24 hours results in about 6MB of data and requires approximately 2.5 seconds. This is significantly faster than a full sync using the gossip protocol.

A Complement to the Gossip Protocol

LNsync does not replace the existing gossip protocol. Rather, it augments gossip by providing an additional method to retrieve topology information for fast synchronization with the rest of the network.

The web server returns only announcements and updates from nodes and channels that changed during the queried interval. And once your node has completed it’s sync through LNsync, the gossip protocol takes over again, keeping your node up to date while it is online.

The computation of the route is always performed on your device. No information about the payment is leaked to the LNsync servers, which only provide the data required for your node to perform its route computation.

Add LNsync to Your Lightning Apps

We hope that LNsync will help make Lightning payments more reliable, especially for mobile wallets. For a deep dive on the mechanics of LNsync and a how to guide, check out our article on the Engineering Blog. You can also find an API reference and a guide to the Historian plugin that powers LNsync on the c-lightning technical docs.

If you have specific preferences, please, mark the topic(s) you would like to read: