Channel Balance Interpolation in the Lightning Network via Machine Learning

Extracted source text · arXiv 2405.12087

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
% The preceding line is only needed to identify funding in the first footnote. If that is unneeded, please comment it out.
\usepackage{xurl}
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{float}
\usepackage{dirtytalk}
\usepackage{algorithm}
\usepackage{subfigure}
% \usepackage{algpseudocode}
\usepackage{hyperref}
\usepackage{amsmath}
% \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
%     T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}




\begin{document}
\title{Channel Balance Interpolation in the Lightning Network via Machine Learning\\
\thanks{* Jointly supervised }
}

\author{\IEEEauthorblockN{ Vincent}
\IEEEauthorblockA{
\textit{Amboss Technologies}\\
Nashville, USA \\
v@amboss.tech}
\and
\IEEEauthorblockN{ Emanuele Rossi*}
\IEEEauthorblockA{\textit{Amboss Technologies} and \textit{VantAI} \\
Barcelona, Spain \\
emanuele.rossi1909@gmail.com}
\and
\IEEEauthorblockN{ Vikash Singh*}
\IEEEauthorblockA{\textit{Stillmark} \\
San Francisco, USA \\
vikash@stillmark.com}
}

\maketitle


\begin{abstract}
The Bitcoin Lightning Network is a Layer 2 payment protocol that addresses Bitcoin's scalability by facilitating quick and cost-effective transactions through payment channels. This research explores the feasibility of using machine learning models to interpolate channel balances within the network, which can be used for optimizing the network's pathfinding algorithms. While there has been much exploration in balance probing and multipath payment protocols, predicting channel balances using solely node and channel features remains an uncharted area. This paper evaluates the performance of several machine learning models against two heuristic baselines and investigates the predictive capabilities of various features. Our model performs favorably in experimental evaluation, outperforming by 10\% against an equal split baseline where both edges are assigned half of the channel capacity.
\end{abstract}

\begin{IEEEkeywords}
Bitcoin, Lightning Network, Pathfinding, Machine Learning, Payment Channel Network
\end{IEEEkeywords}

\section{Introduction}
The Lightning Network is a layer-2 protocol on the Bitcoin blockchain that enables rapid and cost-effective payments. Central to optimizing its efficiency is the accurate estimation of channel balances, which directly informs pathfinding strategies. Effective pathfinding circumvents the need for a cumbersome trial-and-error process in identifying viable payment routes, thereby streamlining operations within the network. While there have been advances in understanding balance generation\cite{pickhardt2021security}, along with the exploration of reinforcement learning (RL) for pathfinding\cite{valko2023increasing} and the development of multipath payment protocols\cite{pickhardt2021optimally}, the prediction of channel balances is less explored territory.

This gap in the literature motivates the current study, which seeks to determine whether it is feasible to interpolate the balances of channels within the Lightning Network accurately. It further aims to identify the most predictive features for balance interpolation, questioning whether these predictions can rely solely on node features, channel features, or a combination of both, and possibly enhanced by topological information of the network. To tackle these questions, the study evaluates the performance of two baseline methods against six machine learning (ML) models, each with a varying subset of features.

The investigation reveals that ML models are indeed capable of predicting channel balances with a better degree of accuracy than heuristic methods like the equal split assumption. This outcome suggests that the predictive power of machine learning models could be leveraged to refine pathfinding algorithms. This study sheds light on the potential of specific features and how machine learning can enhance the network's pathfinding efficiency.

The remainder of this paper is organized as follows. \hyperref[sec:background]{Section II} provides background information on Bitcoin and the Lightning Network. \hyperref[sec:motivation]{Section III} elaborates on the specific problem and the motivation for improved channel balance interpolation. \hyperref[sec:relatedwork]{Section IV} reviews related work in areas such as pathfinding algorithms and multipath payment protocols for the Lightning Network. Sections \hyperref[sec:problem]{V},\hyperref[sec:data]{VI}, and \hyperref[sec:mlmodels]{VII} formally define the problem statement, the data collection and preprocessing steps, and the machine learning models and features evaluated. \hyperref[sec:evaluation]{Section VIII} outlines the methodology and metrics. Sections \hyperref[sec:results]{IX} and \hyperref[sec:futurework]{X} present and analyze the performance of the various models. Finally, \hyperref[sec:discussion]{Section XI} explores potential future work, such as implementing an enhanced pathfinding algorithm that leverages the balance interpolation model and directions for further improving model performance.

\section{Background}
\label{sec:background}
\subsection{Bitcoin}
Bitcoin is a peer-to-peer electronic cash system invented in 2008 by a pseudonymous person or group under the name Satoshi Nakamoto \cite{Satoshi}. The purpose of Bitcoin is to provide a trustless way to transfer value. The features which allow this trustless transfer of value are Bitcoin's distributed ledger, Proof-of-Work consensus model, and fixed supply. The Bitcoin network operates without relying on a central server. New transactions are added to the decentralized ledger through a process known as mining. Bitcoin nodes which participate in this mining process collect transactions and add them to to an \say{ongoing chain of hash-based proof-of-work} \cite{Satoshi}, by solving a computationally difficult problem. The chain which demonstrates the most computational effort is regarded as the authentic record of transactions. Proof-of-Work adds a real world cost to attempting to invalidate past transactions, also known as a block re-organization.  

Transaction fees in Bitcoin are determined by the amount of data consumed on-chain rather than the value being transferred. All else equal, this pricing dynamic makes smaller payments more expensive relative to larger payments. Additionally, the Bitcoin blockchain's transaction throughput is intentionally constrained. With a fixed block size and block time, the network is designed to process an average of one 4MB block every ten minutes, translating to a maximum of seven transactions per second \cite{scaling}. While this design choice ensures accessible storage and bandwidth requirements for Bitcoin, it also hampers the scalability of its blockchain as a peer-to-peer electronic cash system. Considering the time, fees, and energy expended, common use cases like micropayments, subscriptions, and streaming payments are prohibitively expensive to execute on the base layer of the Bitcoin blockchain.

\subsection{Lightning Network}
The Lightning Network is a Layer 2 payment protocol built on top of the Bitcoin blockchain \cite{Poon2016}. LN emerged in 2017 as a potential solution to Bitcoin's scalability challenge that preserves its trustless nature. In LN, value is transferred by way of payment channels between peers in the network. A payment channel is established by depositing funds into a 2-of-2 multisig address jointly controlled by both peers. This deposit is known as the funding transaction. The funding transaction establishes the initial balance of funds between both parties. 

In contrast, the current balance of the channel is contained in the commitment transaction. Both peers maintain a copy of this transaction, but defer its broadcast until they want to close the channel. When payments are made via this channel, the peers jointly update the commitment transaction. Because the peers defer broadcasting the commitment transaction, payments on the Lightning Network are not subject to the 10 minute average blocktime on Layer 1 (the Bitcoin blockchain). Furthermore, the pricing dynamic of LN is fundamentally different than on L1. While transactions on L1 compete for blockspace by paying higher fees to miners, routing nodes on LN compete with each other to relay payments by offering lower fees.

Of course there are tradeoffs to using LN over L1. Single path payments can only be relayed if there exists a path with sufficient liquidity from source to destination. In other words, one cannot forward a payment if they have an insufficient balance on their side of the channel. However, only the nodes incident to a channel know the balance of that channel. Thus payment pathfinding in the Lightning Network is a trial-and-error process. 
\begin{figure}
    \begin{subfigure}
    \centering
    \includegraphics[width=0.95\linewidth]{liquidity.png}
    \caption{Single path payments can only occur if there is sufficient liquidity. In this network state, Bob can relay a payment from Alice to Charlie, but he cannot relay a payment from Charlie to Alice.}
    \label{fig:enter-label}
\end{subfigure}
% \\
% \vspace{10}
\begin{subfigure}
    \centering
    \includegraphics[width=0.95\linewidth]{unknown_balances.png}
    \caption{Alice only knows the balances of channels she owns. She may learn information about intermediate channels after attempting payments.}
    \label{fig:enter-label}
\end{subfigure}
\end{figure}


\section{Motivation}
\label{sec:motivation}
Topological analysis from other works have shown that the Lightning Network topology is consistent with small-world architecture\cite{seres2020topological}. These graphs exhibit a robustness because of their high local clustering coefficient and low average path length. However, in the Lightning Network, this abundance of short paths comes with the downside of not knowing which ones have sufficient liquidity to relay the payment. For example, River is a Bitcoin-only exchange that operates two of the largest nodes in the Lightning Network\cite{RF1, RF2}. In a research report River released in 2023, they cited timeout during pathfinding as the leading cause of payment failure for their nodes\cite{riverfinancial}. The goal of this work is to investigate ways of evaluating paths \textit{before} trying them. Our key focus is on whether the balance of intermediate channels can be interpolated from channel policies and node metrics. This would enable the prioritization of paths in the trial-and-error process, and thus save time searching for a viable path. 

\section{Related Work}
\label{sec:relatedwork}

\textit{LightningNetworkDaemon}, the majority implementation present on the Lightning Network \cite{zabka2022empirical} has two models for estimating the success probabilities of paths: \textit{apriori} and \textit{bimodal}. The \textit{apriori} model assumes a constant probability on untested channels also taking into account capacity of the channel and payment size\cite{lightningnetworkdaemon}.
The \textit{bimodal} model  is an outcome of Pickhardt et al.'s work\cite{pickhardt2021security} whereby they sampled balances in the Lightning Network and found that portions of channels followed different distributions. They observed that about 30\% of channels balances were concentrated on one side while the rest of the channel balances made up a uniform distribution. The assumption of a bimodal distribution is a configurable path estimator option in LND as of version v0.16.

The next majority implementation present on the Lightning Network is \textit{core-lightning}. In the default pathfinding behavior, paths are weighted using a fee and risk factor. This weight takes into consideration the risk of locking up liquidity for some number of blocks, with bias to larger capacity channels. The \textit{core-lightning} implementation also includes a plugin architecture to extend and customize its functionality. One such plugin, altpay, implements pickhardt payments with probability scoring. This payment algorithm is the result of work by Pickhardt and Richter to generalize payments as a minimum cost flow problem\cite{pickhardt2021optimally}. Here, the cost considers both the fee and reliability of a path. The reliability of the path is estimated using an uncertainty network.  The uncertainty network is updated in a similar fashion to the trial-and-error approach in a single path payment. However, multipath payments explore multiple paths, are split into smaller amounts, and are not constrained by the liquidity of a single route. In their work, these authors observed that multipath payments can more reliably move funds across the network as compared to single path payments. 


Other works include Valko and Kudenko's work on using reinforcement learning for path planning in the Lightning Network\cite{valko2023increasing}. In this technique, an agent learns to predict paths in the Lightning Network that have low total cost and are close to the shortest path calculated by Dijkstra's algorithm. This approach has a nearly constant execution time regardless of the number of nodes considered, however, it also requires limited retraining ($<$100 epochs) when the network updates. 



\section{Problem Formulation}
\label{sec:problem}
The Lightning Network can be modeled as a directed graph \( G = (V, E) \), where \( V \) represents the set of nodes and \( E \) represents the set of edges. Each node \( u \) and each edge \( (u, v) \) have associated features, denoted by \( \mathbf{x}_u \in \mathbb{R}^k \) for nodes and \( \mathbf{e}_{(u, v)} \) for edges, which contain specific information about those nodes and edges. Additionally, each edge \( (u, v) \) has a scalar value \( y_{(u, v)} \geq 0 \), representing the pre-allocated balance for transactions from \( u \) to \( v \).

Graph \( G \) has the constraint that if an edge exists in one direction, it must also exist in the opposite direction, i.e., \( (u, v) \in E \iff (v, u) \in E \). The set of two edges between any two nodes is called a channel, denoted as \( \{(u, v), (v, u)\} \). For simplicity, we represent a channel by the set of its two nodes: \( \{u, v\} \). The total capacity of the channel \( \{u, v\} \) is defined as \( c_{\{u, v\}} = y_{(u, v)} + y_{(v, u)} \).

We are provided with the total channel capacities \( c_{\{u, v\}} \) for all channels in the graph, but we only know the individual values \( y_{(u, v)} \) for a subset of edges. Note that knowing \( y_{(u, v)} \) allows us to determine \( y_{(v, u)} \), since \( y_{(v, u)} = c_{\{u, v\}} - y_{(u, v)} \). Therefore, we can focus on predicting \( y_{(u, v)} \).

Moreover, since we are given \( c_{\{u,v\}} \) for all edges, and we know \( 0 \leq y_{(u, v)} \leq c_{\{u,v\}} \), we also have that \( y_{(u, v)} = p_{(u,v)}c_{\{u,v\}} \), where \( 0 \leq p_{(u,v)} \leq 1 \). Intuitively, \( p_{(u,v)} \) is the proportion of the channel capacity which belongs to the \( (u,v) \) direction. From this, we see that we focus on predicting \( p_{(u,v)} \), and then use it to obtain \( y_{(u, v)} \).

Therefore, our primary task is to predict \( p_{(u,v)} \) for all edges where it is unobserved.


\section{Data Collection and Preprocessing}
\label{sec:data}
The data used in this experiment is a combination of publicly available information from the Lightning Network and crowdsourced information from nodes in the network. 
A snapshot of the network from December 15, 2023 is used in this experiment. The snapshot was collected from a lightning node on the network operated by Amboss Technologies. Further information is derived from the network snapshot. This information includes aggregated channel capacities, giving the capacity of each node and the network. Other relevant information includes the fee ratios of each node which is found by dividing average incoming fee rates by average outgoing fee rates. In other works\cite{bitmex}, this ratio is referred to as drain. Balance data is crowdsourced from nodes in the Lightning Network. Node operators may opt to share balance with Amboss Technologies in order to receive liquidity notifications, automatically purchase channels, or to maintain a historical account.  
\subsection{Preprocessing Steps}
Balance information for each node is represented by its local balance, recorded at one-minute intervals over the preceding hour. This data is converted into a probability density function (PDF) through kernel density estimation. Subsequently, a balance value is sampled from each PDF, serving as the representative local balance for the corresponding channel within the dataset. 



\subsection{Preliminary Analysis}

The following section is a statistical overview of the Lightning Network, including various tables and metrics that detail the distribution of channel capacities and the ratio of channel balances to their capacities. The analysis of channel capacities illustrate the range and distribution of liquidity across the network. This data serves as a reference for understanding the current state and structural characteristics of the Lightning Network.






\begin{figure*}
    \begin{subfigure}
        \centering
        \includegraphics[width=0.32\linewidth]{distribution_of_channel_capacities.png}
        \label{fig:dist-channels}
    \end{subfigure}
    \begin{subfigure}
        \centering
        \includegraphics[width=0.32\linewidth]{figures/distribution_of_edge_balances.png}
        \label{fig:dist-edges}
    \end{subfigure}
    \begin{subfigure}
        \centering
        \includegraphics[width=0.32\linewidth]{figures/distribution_of_edge_balances_scaled.png}
        \label{fig:bimodal}
    \end{subfigure}
\caption{Distribution of channel capacities, crowdsourced edge balances, and normalized edge balances in the Lightning Network. }
\end{figure*}




The leftmost histogram in \autoref{fig:bimodal} displays the frequency of channel capacities in the Bitcoin network. Capacities range between 0 and 10 BTC, with the highest frequency observed at the lowest capacity interval. The frequencies diminish significantly for higher capacities, although there are several notable peaks, suggesting capacity values around round numbers are more common. The overall distribution suggests that smaller channel capacities are much more typical within this network, with occasional larger-capacity channels appearing less frequently. 

The middle histogram in \autoref{fig:bimodal} depicts the distribution of edge balances in Bitcoin (BTC). This data also shows a left-skewed distribution, indicating a prevalence of smaller balances over larger ones. 

The rightmost histogram in \autoref{fig:bimodal} illustrates the distribution of edge balances as a percentage of their respective capacities within a network. The distribution shows two prominent peaks indicating a high frequency of channels with balances that are either very low (close to empty) or very high (close to full capacity) relative to their channel capacities. There is a notable scarcity of channels with intermediate balances. This pattern could be indicative of a "bimodal" distribution, suggesting that channels within this network are typically either mostly unused or nearly fully utilized, with fewer channels maintaining a balance around the mid-range. This distribution aligns with findings reported in the study by Pickhardt et al \cite{pickhardt2021security}.




\subsection{Feature Analysis}

To assess the relationship between each feature and the target variable, channel balance, a correlation analysis was conducted. Presented below in \autoref{fig:correlation-table} is a table showcasing those features which demonstrated any notable correlation, in this case, having a correlation coefficient beyond the range of $- 0.1$ to $+0.1$. The feature Max HTLC msat represents the maximum size of an outgoing payment a node will handle. Feature flag \#19 acts as a binary flag that signifies whether the node permits the creation of channels with capacities exceeding approximately 16.7 million satoshis, which is generally referred to as the 'wumbo channel' threshold in the Lightning Network.

\begin{figure}[H]
    \begin{table}[H]
        \centering

% \resizebox{0.5\linewidth}{!}{%
\begin{tabular}{ll}
Feature                & Correlation \\ \hline
local\_feat\_19.is\_known    & 0.1523   \\ 
remote\_feat\_19.is\_known    & 0.1603    \\ 
local\_max\_htlc\_msat  & 0.6246    \\ 
remote\_max\_htlc\_msat  & 0.6165    \\ 
\end{tabular}%
% }
\end{table}
    \caption{Table of features and their correlations to the target variable.}
    \label{fig:correlation-table}
\end{figure}



Both Max HTLC msat and Feature 19 have a positive correlation with the target variable, as indicated by the positive values of the correlation coefficients. The features local\_max\_htlc\_msat and remote\_max\_htlc\_msat, show a notably strong positive correlation. In contrast, the features local\_19.is\_known and remote\_19.is\_known exhibit a modest but still significant positive correlation.


\section{Methodology}
\label{sec:mlmodels}
\subsection{Modeling}
 We will predict $p_{(u,v)}$ by learning a parametric function:
 \[
\hat p_{(u,v)}= f_{\Theta}(u, v, G, \mathbf{x}_u, \mathbf{x}_v, \mathbf{e}_{(u, v)}, c_{\{u, v\}})
 \]
where $\Theta$ are learnable weights, $\mathbf{x}_u$, $\mathbf{x}_v$ and  $\mathbf{e}_{(u, v)}$ are the node and edge features respectively, while $c_{\{u, v\}}$ is the capacity of the channel.
While several choices are possible for $f_{\Theta}$, such as multi-layer perceptrons or Graph Neural Networks, we focus on Random Forests for this work given their simplicity and efficacy. In particular, our Random Forest (RF) model operates on the concatenation of the features of the source and destination nodes as well as the edge features:
\[
\hat p_{(u,v)}=\mathrm{RF}(x_u || z_u || x_v|| z_v || e_{(u,v)})
\]


The model is trained using a Mean Squared Error loss. Moreover, we know that $p_{(u,v)}=1-p_{(v,u)}$. Therefore, we would like to design our model such that $f_{\Theta}(u, v, G, x, c)=1-f_{\Theta}(v, u, G, x, c)$. We can obtain this approximately through data augmentation: make sure that both directions of an edge are present in the data so that the model is trained to predict both that $f_{\Theta}(u, v, G, x, c)=p_{(u,v)}$ and that $f_{\Theta}(v, u, G, x, c)=1-p_{(v,u)}$.

\subsection{Node Features}

\begin{itemize}
    \item \textbf{Node Feature Flags}\\
0-1 vector indicating which of the features each node supports. For example, feature flag \#19, the wumbo flag.
    \item \textbf{Capacity Centrality}\\
The node's capacity divided by the network's capacity. This indicates how much of the network’s capacity is incident to a node.
    \item \textbf{Fee Ratio}\\
Ratio of the mean cost of a nodes outgoing fees to the mean cost of its incoming fees. 
\end{itemize}

\subsection{Edge Features}
\begin{itemize}
    \item \textbf{Time Lock Delta} 
The number of blocks a relayed payment is locked into an HTLC.
    \item \textbf{Min HTLC} 
The minimum amount this edge will route. (denominated in millisats)
    \item \textbf{Max HTLC msat} 
The maximum amount this edge will route. (denominated in millisats)
    \item \textbf{Fee Rate millimsat} 
Proportional fee to route a payment along an edge. (denominated in millimillisats)
    \item \textbf{Fee Base msat} 
Fixed fee to route a payment along an edge. (denominated in millisats)
\end{itemize}

\subsection{Positional Encodings}
Positional encoding is essential for capturing the structural context of nodes, as graphs lack inherent sequential order. Utilizing eigenvectors of the graph Laplacian matrix as positional encodings provides a robust solution to this challenge. These eigenvectors highlight key structural patterns, enriching node features with information about the overall topology of the graph\cite{vijay}. By integrating these spectral properties, machine learning models can effectively recognize and utilize global characteristics, enhancing performance in tasks like node classification and community detection.




\section{Model Evaluation}
\label{sec:evaluation}
We set aside $10\%$ of the observed $y_{(u,v)}$ as our test set and $10\%$ as our validation set. 
We use Mean Absolute Error (MAE) to evaluate how well our predictions match the test set. In particular, we consider two MAE metrics,
$MAE_y$ which is computed on the raw channel balance, and $MAE_p$, computed on the channel proportion on capacity.
\[
MAE_y=MAE(y, \hat y)=\sum_{(u,v) \in test} \left| y_{(u,v)}-\hat y_{(u,v)} \right| \]
\[
MAE_p=MAE(p, \hat p)=\sum_{(u,v)\in test} \left|p_{(u,v)}-\hat p_{(u,v)}\right| 
\]

\subsection{Baselines}
\subsubsection{Equal Split}
Split the capacity equally in the two channels: 
\[
\hat p_{(u,v)}= \hat p_{(v,u)}=0.5
\].

\subsubsection{Local Max HTLC}
Use the max HTLC amount from the local channel policy as the balance:
\[
\hat p_{(u,v)}= \mathrm{max\_htlc\_msat}(e_{(u,v)})
\]
Note that this value is normalized by the channel's capacity. It is also not subject to the constraint that $\hat p_{(u,v)} + \hat p_{(v,u)} = 1$.

\subsection{ML Models}

\subsubsection{Edge-Wise Random Features Prediction}
Assign random features $r_{(u,v)}$ from an isotropic Normal distribution to each edge.
Train a model which predicts $p_{(u,v)}$ only as a function of the random features of the edge $(u,v)$:
\[
\hat p_{(u,v)}=\mathrm{RF}(r_{(u,v)})
\]
\subsubsection{Node-Wise Prediction}
A model which predicts $p_{(u,v)}$ only as a function of the features of source node $u$:
\[
\hat p_{(u,v)}=\mathrm{RF}(x_u)
\]

\subsubsection{Edge-Wise Prediction}
A model which predicts $p_{(u,v)}$ only as a function of the features of the edge $(u,v)$:
\[
\hat p_{(u,v)}=\mathrm{RF}(e_{(u, v)})
\]

\subsubsection{Concatenated Prediction}
A model which predicts $p_{(u,v)}$ as a function of the concatenation of the features of the source and destination nodes as well as edge features:
\[
\hat p_{(u,v)}=\mathrm{RF}(x_u || x_v || e_{(u,v)})
\]
\subsubsection{Shallow Graph Prediction}
Compute graph positional encodings (an embedding for each node representing its position in the graph) as graph laplacian eigenvectors. Let’s represent such positional encodings for node $u$ by $z_u$. Train a model that predicts $p_{(u,v)}$ as a function of the concatenation of the positional encodings of the source and destination nodes:
\[
\hat p_{(u,v)}=\mathrm{RF}(z_u || z_v)
\]

\subsection{Methodology}
Each model was evaluated using a train-test split method. The performance of each model was reported in a table using four metrics:
\begin{itemize}
    \item $MAE_y$: Mean Absolute Error between the actual edge balances and the predictions.
    \item $MAE_p$: Mean Absolute Error in the predictions of edge balances.
    \item $R$: The correlation coefficient, indicating how closely the predictions align with the actual values.
    \item $R^2$: The coefficient of determination, showing the percentage of the variance in the actual edge balances that is explained by the model.

\end{itemize}

The model could be any kind of machine learning model. In this study, we used a Random Forest regression model. 

This table allows for a straightforward comparison of model performance, focusing on accuracy (MAE) and the strength of the relationship between predicted and actual values (R and R²). The goal being to identify the model that offers the best balance between minimizing prediction errors and maximizing explanatory power for edge balances. 

Additionally, the Mean Decrease Impurity (MDI) feature importance was plotted, illustrating the contribution of each feature to model effectiveness.


\section{Results}
\label{sec:results}
The results are recorded in a table in \autoref{fig:performance-summary}. Note that MAE$_y$ is denoted in millions of satoshis.
\begin{figure}[H]
\begin{table}[H]
\resizebox{\linewidth}{!}{%
\begin{tabular}{lllll}
Model          & MAE$_p$($\downarrow$) & MAE$_y$($\downarrow$) & R ($\uparrow$)     & $R^{2}$ ($\uparrow$) \\ \hline
Equal Split    & $0.358$  & $1.60$   & $-$     & $-0.001$              \\
Local Max HTLC & $0.479$  & $2.16$   & $0.034$ & $0.001$                \\
Random Edge Features         & $0.362$  & $1.67$   & $-0.06$ & $-0.03$       \\
Nodes          & $0.313$  & $1.31$   & $0.355$ & $0.097$                \\
Edges          & $0.316$  & $1.39$   & $0.350$ & $0.115$                \\
Concatenated   & $0.265$  & $1.09$   & $0.601$ & $0.351$                \\
Shallow        & $0.285$  & $1.20$   & $0.530$ & $0.275$                \\
$\textbf{Joint}$          & $\textbf{0.259}$  & $\textbf{1.08}$   & $\textbf{0.612}$ & $\textbf{0.365}$               
\end{tabular}%
}
\end{table}
    \caption{Performance summary of all models and heuristics.}
    \label{fig:performance-summary}
\end{figure}




The heuristics Equal Split and Local Max HTLC provide initial reference points for comparing performance. The Equal Split and Local Max HTLC models demonstrate negligible predictive power, explaining virtually none of the variance in the dependent variable. The Node-wise and Edge-wise models show some predictive ability but still limited effectiveness. Moderate improvements are seen in the Concatenated and Shallow Graph models. The Joint model, which considers node, edge, and positional encoding features, has the greatest predictive power. 


The inclusion of positional encodings in the Random Forest model resulted in improved performance compared to the models without positional encodings. This suggests that positional encodings enhance the model's ability to capture the underlying data structure. Additionally, it is noteworthy that the Shallow Graph model outperformed the Equal Split heuristic, indicating that positional information alone is predictive of channel balances. 


\begin{figure*}[]
    \begin{subfigure}
        \centering
        \includegraphics[width=0.32\linewidth]{figures/y_p_histogram.png}
        \label{fig:pistogram}
    \end{subfigure}
    \begin{subfigure}
        \centering
        \includegraphics[width=0.32\linewidth]{figures/y_p_scatterplot.png}
        \label{fig:pscatterplot}
    \end{subfigure}
    \begin{subfigure}
        \centering
        \includegraphics[width=0.32\linewidth]{figures/confusion_matrix.png}
    \label{fig:pconfusion}
    \end{subfigure}
    \caption{Histogram of errors, a scatterplot of the actual vs. predicted values, and a confusion matrix of the best performing model.}
\end{figure*}


The histogram in \autoref{fig:pistogram} presents the error distribution for the top-performing model from the analysis. Errors are binned between -1 and 1, and the y-axis is the frequency of each errors. The model's errors presents a distribution that peaks around the central value, zero. As the histogram tapers off on both sides, so does the frequency of larger errors. The symmetry of the data indicates that the model does not consistently overpredict or underpredict. 


The scatterplot in \autoref{fig:pscatterplot} presents a comparison between actual and predicted balance percentages. The best fit line for this scatterplot has a positive slope indicating that the predicted values tend to increase as the actual values increase, although this is clearly not a tight correlation. 


From the confusion matrix in \autoref{fig:pconfusion}, it is apparent that the model is able to identify which side a majority of the liquidity is present. For example, of the channels in the test data that have less local liquidity than remote, the model predicted a $\hat{p}\leq0.5$ 72\% of the time. 

\subsection{Feature Importance}

Feature importance analysis using Mean Decrease in Impurity (MDI) provides a clear comparison of the predictive ability of each feature in the Random Forest model. 

\begin{figure}[H]
    \centering
    \includegraphics[width=\linewidth]{figures/Feature_Importance.png}
\end{figure}

Notably, Positional Encoding emerges as the most influential feature, suggesting that the model heavily weighs the structural positioning of nodes within the network. Other network features like Capacity Centrality highlight the strategic importance of controlling capacity within the network's topology.

While the economic features, Fee Rate, Remote Fee, Fee Ratio, and Local Fee have lower MDI values compared to the network features, they still depict how the cost dynamics affect the model's decision-making process. The feature Max HTLC (\%), despite its lower ranking, indicates that constraint on payment size is useful in predicting channel balances. These economic features reveal how the fee structures and transactional ceilings set by the channels incentivize certain flow patterns and impact the distribution of funds across the network. 

The economic features and network features each hold approximately half of the importance. This suggests a balanced reliance on both economic and network attributes. Together, these network and economic features enhance the model's ability to provide a nuanced prediction of channel balances.







\section{Discussion}
\label{sec:discussion}

This study was conducted to explore the utility of machine learning models in predicting channel balances within the Lightning Network. A novel aspect to this method is the incorporation of graph features into the machine learning models. This approach leverages the inherent structure of the network, utilizing the relational and topological data that characterizes the connections between nodes and channels. The results suggest that machine learning techniques, such as regression algorithms and neural networks, can indeed provide accurate predictions of channel balances. This indicates a promising direction for further research and potential practical application in enhancing the efficiency of network operations. 




Probing techniques to estimate channel balances, while useful, often incur significant overhead and can potentially compromise user privacy due to the frequent and sometimes intrusive nature of probes. In contrast, our balance interpolation approach uses only crowdsourced data and reduces the need for frequent probing by providing a probabilistic estimation of balances that can be updated as new transaction data becomes available. This method not only diminishes the operational overhead associated with probing but also enhances user privacy by reducing the frequency of direct channel queries.


%  This ties into Pickhardt probabilistic pathfinding framework well. 

% Highlight that tomography and or probing is not efficient or tractable at scale and why even though balances can be theoretically obtained by probing, this is more efficient 





\section{Future Work}
\label{sec:futurework}
A natural follow up to this experiment is to implement an enhanced pathfinding algorithm that integrates the predictive model into a Lightning Node's routing decisions. The Enhanced Pathfinding Algorithm aims to find the most reliable path from a source node to a destination node. It utilizes a three-step process: first, predict the balance of each edge in the network; second, assign a cost to each edge according to its predicted balance; and finally, use Djikstras algorithm to find the cheapest path. The cost function used is the negative logarithm which has been shown in other works to be useful for optimizing pathfinding for reliability\cite{pickhardt2021optimally}. 





\begin{algorithm}
\caption{Enhanced Pathfinding Using Predictive Model}
\label{alg:PredictiveDijkstraSimplified}
\begin{algorithmic}[1]
\REQUIRE $G(V, E)$, a graph where $V$ are nodes and $E$ are edges.
\REQUIRE $src$, the source node.
\REQUIRE $dest$, the destination node.
\REQUIRE $amt$, the payment amount.
\REQUIRE M, a model that predicts the balance of each channel.
\ENSURE The most reliable path from $s$ to $d$ based on model predictions.

\STATE $\mathcal{C} \gets$ empty map \COMMENT{Store the cost for each edge}
\FORALL{edge $(u, v) \in E$}
    \STATE $feats \gets$ ExtractFeatures($(u, v)$) 
    \STATE $\hat{p} \gets$ M.predict($(u, v)$,$feats$) 
    \IF{ EffectiveBalance($(u, v)$, $\hat{p}$) $< amt$}
        \STATE $\mathcal{C}[(u, v)] \gets \infty$ 
    \ELSE
        \STATE $\mathcal{C}[(u, v)] \gets -\log(\hat{p})$ 
        \COMMENT{Convert balance to cost}
    \ENDIF
\ENDFOR
\STATE $path \gets Dijkstra({G, src, dest, \mathcal{C}})$
\RETURN $path$
\end{algorithmic}
\end{algorithm}





Another future direction of work is to conduct analysis via simulation to determine how the number of payment retries changes when using this machine learning model versus existing pathfinding methods. This can be directly translated to time saved in waiting for payment confirmation, a critical aspect of Lightning wallet user experience (UX). This quantified pathfinding efficiency gain is expected to go up as interpolation models improve. 

By adding more features or more diverse historical data, the model can potentially uncover more intricate patterns and improve its predictions. For example, adding data related to transaction frequencies, channel opening and closing times, or network congestion might provide deeper insights into balance dynamics. Incorporating time series analysis could help capture trends and seasonal variations in channel balances. This approach could make predictions more dynamic by considering how balances change, not just the static state of balances at a single point in time.

In addition to supervised learning, the probabilistic learning of distributions would be useful for conducting simulations so balances can be repeatedly sampled to generate robust confidence intervals. Robust confidence intervals, derived from well-modeled probabilistic distributions, can give network operators and users more reliable information for path planning. By addressing these areas, the model not only becomes more accurate in its predictions but also more useful for planning and operational decisions within the Lightning Network. This enhancement could lead to more efficient routing decisions, reduced transaction costs, and improved overall network stability.









% \begin{thebibliography}{00}
% \bibitem{b1}
% \end{thebibliography}
\bibliographystyle{ieeetr} % We choose the "plain" reference style
\bibliography{bibliography} % Entries are in the refs.bib file
\end{document}

\begin{thebibliography}{10}

\bibitem{pickhardt2021security}
R.~Pickhardt, S.~Tikhomirov, A.~Biryukov, and M.~Nowostawski, ``Security and privacy of lightning network payments with uncertain channel balances,'' 2021.

\bibitem{valko2023increasing}
D.~Valko and D.~Kudenko, ``Increasing energy efficiency of bitcoin infrastructure with reinforcement learning and one-shot path planning for the lightning network,'' in {\em Proc. of the Adaptive and Learning Agents Workshop (ALA 2023) At AAMAS 2023, May 29-30}, Cruz, Hayes, Wang, Yates (eds.) London, UK, 2023.

\bibitem{pickhardt2021optimally}
R.~Pickhardt and S.~Richter, ``Optimally reliable \& cheap payment flows on the lightning network,'' 2021.

\bibitem{Satoshi}
S.~Nakamoto, ``Bitcoin: A peer-to-peer electronic cash system,'' 2008.

\bibitem{scaling}
C.~Li, P.~Li, W.~Xu, F.~Long, and A.~C. Yao, ``Scaling nakamoto consensus to thousands of transactions per second,'' {\em CoRR}, vol.~abs/1805.03870, 2018.

\bibitem{Poon2016}
J.~Poon and T.~Dryja, ``The bitcoin lightning network: Scalable off-chain instant payments,'' 2016.

\bibitem{seres2020topological}
I.~A. Seres, L.~Guly{\'a}s, D.~A. Nagy, and P.~Burcsi, ``Topological analysis of bitcoin’s lightning network,'' in {\em Mathematical Research for Blockchain Economy: 1st International Conference MARBLE 2019, Santorini, Greece}, pp.~1--12, Springer, 2020.

\bibitem{RF1}
``{River Financial 2}.'' \url{https://amboss.space/node/03037dc08e9ac63b82581f79b662a4d0ceca8a8ca162b1af3551595b8f2d97b70a}.
\newblock Accessed: 2024-03-26.

\bibitem{RF2}
``{River Financial 1}.'' \url{https://amboss.space/node/03aab7e9327716ee946b8fbfae039b0db85356549e72c5cca113ea67893d0821e5}.
\newblock Accessed: 2024-03-26.

\bibitem{riverfinancial}
{River Financial}, ``The lightning network grew by 1212\% in 2 years: Why it's time to pay attention,'' Oct 2023.

\bibitem{zabka2022empirical}
P.~Zabka, K.-T. Foerster, S.~Schmid, and C.~Decker, ``Empirical evaluation of nodes and channels of the lightning network,'' {\em Pervasive and Mobile Computing}, vol.~83, p.~101584, 2022.

\bibitem{lightningnetworkdaemon}
``{lightningnetworkdaemon/lnd}.'' \url{https://github.com/lightningnetwork/lnd}.
\newblock Accessed: 2024-03-26.

\bibitem{bitmex}
``The power of valves for better flow control, improved reliability \& lower expected payment failure rates on the lightning network.'' \url{https://blog.bitmex.com/the-power-of-htlc_maximum_msat-as-a-control-valve-for-better-flow-control-improved-reliability-and-lower-expected-payment-failure-rates-on-the-lightning-network/}.
\newblock Accessed: 2024-05-16.

\bibitem{vijay}
V.~P. Dwivedi, C.~K. Joshi, T.~Laurent, Y.~Bengio, and X.~Bresson, ``Benchmarking graph neural networks,'' {\em CoRR}, vol.~abs/2003.00982, 2020.

\end{thebibliography}