Keep Your Node Up to Date with LNsync
By Christian Decker
Today, we announced the launch of LNsync, a server-assisted gossip synchronization mechanism for the Lightning Network. 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.
We’ve provided a high-level summary of the launch on the main Blockstream blog, so you may want to read that first before continuing below.
Server-Assisted Gossip Sync
As the name suggests, LNsync is a web server that allows nodes to query for changes from a specific point of time in the past. It consists of three parts:
- Data collection: Using the historian plugin, we collect, deduplicate, and store all the gossip messages received by our c-lightning nodes. The information is stored in a database and indexed for fast retrieval.
- Web server: The web server exposes a simple API that allows querying for changes since the last time a node was online, delivering the minimal set of gossip messages required to catch up with the rest of the network. This set of gossip messages is called a delta.
- Injector: The injector “injects” the retrieved gossip messages into the node so it can process the information. This is done over a peer-to-peer connection and works with any Lightning implementation.
Augmenting the Gossip Protocol
The server-assisted gossip sync does not replace the existing gossip protocol. Rather, it augments it by providing an additional method to retrieve topology information that is optimized for the quick 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. In addition, it skips any updates that were later overwritten, further reducing the download size.
As an example, retrieving a delta of two hours results in about 500KB of uncompressed data, delivered in just over a second, while a delta of 24 hours results in about 5700KB of data and requires approximately 2.5 seconds. This is significantly faster than a full sync using the gossip protocol and can take place in the background while the user opens their wallet and scans an invoice.
How to Use LNsync
Blockstream operates an instance of the collection as well as the web server. As a user, you just need to download your required delta and inject the messages into your node.
If you are using c-lightning and have the historian code checked out, you can sync all changes from the previous two hours using the below commands:
# curl command is all one linecurl -s https://LNsync.blockstream.com/gossip/delta/$(date +%s — date=”2 hours ago”) > /tmp/delta.gsp./historian-cli snapshot load /tmp/delta.gsp
The commands will launch the c-lightning RPC interface and retrieve your node’s ID and listening port, then use that information to open a peer-to-peer connection and inject the messages. If you are running a different implementation, the tool still works; however, it cannot automatically detect the necessary information. In that case, you need to provide said information manually through the following commands:
# curl command is all one linecurl -s https://LNsync.blockstream.com/gossip/delta/$(date +%s — date=”2 hours ago”) > /tmp/delta.gsp./historian-cli snapshot load /tmp/delta.gsp [nodeid]@localhost:9375
That’s it! Your node should now be synchronized with the rest of the network, increasing your chances of a successful payment.
We hope that LNsync will help make Lightning payments more reliable, especially for mobile wallets. We’re also working on a number of additions and enhancements:
- Further reduction in size: Delta currently includes both the most recent channel updates and the channel announcements, as well as the node announcements for the endpoints. If we are able to conclude that the user already has that information, we can omit it, thereby reducing the size of the delta.
- Pruning of closed channels: Relying solely on gossip messages means that we don’t notice when channels close. The web server currently implements passive pruning of channels that haven’t seen an update within the previous two weeks. In addition, however, we can watch the blockchain for closes and omit messages referring to those closed channels, which helps to further reduce the size of the delta.
Get Started on LNsync
To get started with building on LNsync, visit our GitHub repo containing all the required tools, including the Historian plugin. For an API reference, head to the c-lightning docs.