⚡Lightning network: how to explore the topology

Simonluca Landi
Coinmonks
5 min readOct 28, 2018

--

Extracting topology data from LND

In previous story, I described how I installed a bitcoin lightning network node at home, running LND on a cheap Raspberry Pi3.

lncli provides a useful command to export the the network topology. We can simply run:

to obtain a json that contains the topology of the lightning network as seen from the current lnd node.

The format of describegraph.json is pretty simple and self-explanatory:

We can then quickly count the number of nodes and channel:

Import topology data in Neo4j

Installing Neo4jDesktop

What’s better than a Graph Database to explore a network topology? Let’s download Neo4jDesktop from https://neo4j.com/product/ and spin a database to import our describegraph.json

We can now create a new Graph in Neo4jDesktop, just click on Add Graph → Create a Local Graph, set the graph name, the password and click Create.

Then we need to install the APOC library (“ Awesome Procedures On Cypher”), in Neo4j Desktop: go to the Manage screen and the Plugins tab. Now click on the Install button in the APOC box and you’re done.

Because we need to import a local file, we need to change the default configuration: go to the Manage screen and the Settings tab and add this line:

Now click on Open Browser and be ready to start or exploration of the lightning network.

Import the network data

It’s now time to import the describegraph file in our Graph database. We can use the procedure load.json provided by the APOC library to load the json file and then iterate over the edges, creating 2 Node objects for each edge we found in the list, connected by a relationship LINKED. Then we can add a field alias to each Node object to better identify them.

Finally we can add an index on the field alias to speed up the queries.

Exploring the topology

We are now ready to use the powerful query engine of Neo4j to discover some interesting facts about the network.

Number of Nodes and Channel

First, let’s see how many nodes and channels we know about. This is an easy query, we need to count all the Nodes objects and then count all the relationships LINKED present in the graph:

The numbers obtained by those queries match the number obtained from the “grep” that we previously executed directly on the describegraph.json file, we we can be pretty confident that the import procedure run smooth.

According to https://1ml.com/, at the moment we have more that 3,000 nodes and more than 12,000 channels in the lightning network. So, even after almost 6 weeks of operation, my node knows about less that 1/3 of the nodes and less than 1/4 of the channels that exist in the network.

This is not surprising: mesh routing is unsolved problem in Computer Science yet.

The longest shortest path

The longest shortest path in the network in defined as the max distance between nodes, or network diameter. Neo4j is a Graph oriented DB, so it provides a shortestpath function out of the box. We can easily find all the shortest paths and get the longest:

The longest shortest path, according to the topology of the Lightning network as seen from my node.

So, according to my view of the network, the most distant nodes are 8 hops away.

The most distant nodes

We can also find the most distant nodes from a given node, for instance here are the 5 most distant nodes from my at home node, aliased SLL.

The shortest paths to the 5 most distant nodes from mine

The top 10 Hubs

Let’s find the nodes with most directly connected nodes (not channels…)

The winner is the node tady je slushovo, with 169 nodes directly linked.

Triangle Counting

An interesting query that we can run is the count of Triangles that each node is part of:

clustering coefficient is the likelihood that its neighbors are also connected. You can find more detail in the wikipedia page https://en.wikipedia.org/wiki/Clustering_coefficient , but simply speaking: a node a has clustering coefficient 1 if every neighbor connected to it is also connected to every other node within the neighborhood, and 0 if no node that is connected to it connects to any other node that is connected to it.

The top 10 nodes by number of triangles seam to have a local clustering coefficient lesser than 10%

In a perfect tia

We can also calculate the network average clustering coefficient.

So, my node knows about a total of 877 nodes in the network, meshed in 2045 triangles, and the average of the local clustering coefficient is about 0.123.

Conclusions

I hope you had fun discovering some interesting facts the lightning network topology.

Feel free to suggest more interesting queries to run :)

Read Next: Why ⚡Lightning Network⚡ makes no sense 😱

Get Best Software Deals Directly In Your Inbox

--

--

Simonluca Landi
Coinmonks

80% of problems can be solved by marketing. I’m actually doing the things to solve the other 20%