Analyzing Lightning Network Payment Channels with Memgraph
In our latest Memgraph Community Call, Vincent, a Senior Data Scientist from Amboss Technologies, shared his insights on using Memgraph to analyze the Lightning Network. This use case is interesting because it covers real-time analysis and optimization of payment networks in the blockchain and cryptocurrency industry. We’ve already uploaded the video onto our Memgraph YouTube channel.
Talking Point 1: Introduction to the Lightning Network
Vincent begins by explaining the Lightning Network, a layer 2 payment protocol built on top of the Bitcoin blockchain. He detailed how this network operates off-chain to facilitate faster and cheaper transactions, emphasizing its role as a scalability solution for Bitcoin.
Talking Point 2: Why Memgraph?
The discussion moves onto the reasons behind choosing Memgraph. The primary factor was Memgraph’s in-memory capabilities, which provide the sub-second latency required for efficient pathfinding queries, making it a superior choice over other graph databases.
Vincent mentions several positive aspects of Memgraph:
- Support: He appreciates the great support, stating he can jump on the Discord and get answers to his questions quickly.
- Performance: He highlights the low-latency responses and the speed of performing queries, which are crucial for his project.
- Features: He values the extensive graph algorithms that Memgraph provides out of the box.
- Visualization: He likes the visualization capabilities and mentions using query collections as a nice touch.
Talking Point 3: LN Stream and Loading Data into Memgraph
Vincent's personal project is LN Stream, which loads data from a snapshot of the Lightning Network into Memgraph. This tool also streams graph updates from the network, enabling a real-time view based on network gossip.
Talking Point 4: Running Queries on Memgraph
Demoing various queries to extract meaningful insights from the Lightning Network data. These queries included identifying zero-degree nodes, calculating node capacities, examining betweenness centrality, and analyzing fee ratios to understand the flow of funds within the network.
Talking Point 5: Visualizing the Lightning Network
He showcases the visualizations created using Memgraph Lab, highlighting how different styles can reveal important network characteristics, such as node capacity, fee ratios, and payment paths.
Talking Point 6: Demo
Vincent walks through a live demo of setting up LN Stream, running queries, and interpreting the results.
Q&A
We’ve compiled the questions and answers from the community call Q&A session. Note that we’ve paraphrased them slightly for brevity. For complete details, watch the entire video.
1. Did you put a lot of work into the visualizations? Can you share your experiences with graph and lab?
- Vincent: There was a lot of helpful example code in the Memgraph tutorials, especially for normalization. It was then up to me to decide how to use it, for example by focusing on total capacity, betweenness centrality, or fee ratio. The process of exploring the graph and exporting queries was enjoyable and helped with iteration. These visualizations are useful for technical analysis and for presenting insights to those unfamiliar with Cypher or other technical details.
2. Which Memgraph feature is the most valuable for your project? Which queries did you run the most?
- Vincent: The most valuable features were the lambda expressions and conditional expansion in Memgraph, which greatly simplified pathfinding. For example, accurately calculating path costs involves working backwards from the destination, and these features made the process more efficient without needing to write custom modules.
3. Do you have advice for someone just starting to use Memgraph?
- Vincent: My advice is to automate repetitive tasks. When developing the LN Stream project, I found it helpful to create buttons for processes I repeated often. This included resetting the graph to a specific state and making an API to streamline these tasks. Automating such processes can save a lot of time and effort.
4. What is the future of the project? What are you working on now?
- Vincent: Currently, we're focused on pathfinding and running benchmarks to predict channel balances based on channel policies and public information. We have models that seem useful, and we are iterating on them to improve accuracy. Additionally, we're looking for a machine learning intern for simulation-based tasks, including research on max flow to develop network-level SLAs. This research is ongoing, and we are seeking more hands to help with it.
Conclusion
Vincent’s presentation was a deep dive into how Memgraph can be utilized to explore and analyze the Lightning Network. This use case highlights the power of Memgraph as an in-memory graph database in handling large-scale, dynamic datasets with speed and efficiency. The demo showcased practical applications in the fintech industry, particularly in blockchain and cryptocurrency research, demonstrating the value Memgraph brings to real-time data analysis and visualization.