Once again, working with LN Capital under Summer of Bitcoin 2022 program, we were able to produce interesting visualizations for selecting potential paths for a payment in the Lightning Network (LN).
Recall that the LN is a payment channel network (PCN) built on top of Bitcoin. If you have a LN node, then you can send, receive, and forward payments through the network. Here, we are going to focus on sending payments.
When you send a payment to another node, data gets back to you when the payment rather succeeds or fails. You are able to see the route of the payment, the fees in each channel, and in which channel, if any, the payment failed.
You can also send a payment to yourself for rebalancing purposes. Rebalancing is needed when the inbound and outbound capacities of a channel become unbalanced. One way to rebalance your channels is creating a circular route, i.e. sending a payment from your node back to your node.
It would be great to have a tool that helps node owners visualize potential paths to rebalance their channels. With it, they could select which paths to probe by filtering and sorting the data of the different possible routes.
Visualization tool
This time, we decided the best way to easily visualize this was with interactive tables, where you can filter, sort, and select data to display the full route you're interested in.
The tool consists of 4 tables. The first one is for selecting a node you want to include in the rebalancing (central node), and the channel you want to send the payment from. The second table is for selecting a route that starts from the channel you selected before, and ends in the central node. Third one is for selecting the channel where you want to receive the payment. Finally, the fourth table is for selecting a route from the central node to your node, ending in the channel you selected right before.
For this task, the 3 main libraries used were networkx
, pandas
, and dash
. network
was used for computing the simple paths from one node to the rest in the network. pandas
was used for creating the suitable dataframes, that later were converted into interactive tables using dash
.
First table
This table has 3 columns:
- source: to choose your node
- central_node: to choose a certain node you want to include in the rebalancing path
- Channel_out: to choose the channel you want to send the payment from.
Second table
This table is more interesting. All columns support filtering and sorting. It's an easy way to see which routes are cheaper, which take fewer hops, and which have a higher overall capacity.
Here is part of the code to build this table:
@app.callback(
Output('secondtable-container', 'children'),
Input('first-table', 'selected_row_ids'),
)
def make_second_table(selected_rows):
if selected_rows is None:
source_central, channel_out = [], []
else:
rows = [row.split(' -> ') for row in selected_rows]
source_central = [row[0] for row in rows]
channel_out = [row[1] for row in rows]
masks = (grouped_routes.peers.isin(source_central) & grouped_routes.channel_out.isin(channel_out))
second_dff = grouped_routes[masks]
return html.Div([
dash_table.DataTable(
id='second-table',
columns=[
{'name': i, 'id': i, 'deletable': True} for i in second_dff.columns
if i != 'id' and i != 'channel_out'
],
data=second_dff.to_dict('records'),
editable=False, # cells are not editable
filter_action='native', # filter by entering text in the input box
sort_action='native',
sort_mode='multi',
row_selectable='single',
page_action='native',
page_current=0,
page_size=10,
),
html.Div(id='thirdtable-container'),
])
Third table
The third table is similar to the first one. It's only purpose is showing the channels you have, in order to select the one where you want to receive the payment, hence completing the circular path.
Fourth table
The final table is this one, similar to the second one but for selecting an appropriate route, based on your criteria, to complete the rebalancing path.
After selecting a row, a new container displays the whole information of the circular path, like this:
Here is a full demonstration of the tables functionality:
The value of having a tool like this is being tested. Feel free to leave in the comments whether this would help you in some way with your lightning node.
Top comments (3)
Hi Leonardo,
I found your post very interseting. I would like to know more about this topic if you do not mind. Is there such a tool as this and if so does it work in the wild? We have been running our Lightning Node for about a year and a half now but have still not found a way to automate our channel rebalancing. We are currently using RTL and it works quite well but does not currently have a way to automate rebalancing and that is the only program that we have manage to get to work. LNDG did not as well as LNDBOSS (BOS App). Sorry to drone on to you about all of this but being a developer we thought you would be the right person to ask.
Thank you for any assistance you can offer us. :)
Orange
Hi Orange,
Sorry for the late reply. You can take a look at Torq here. Depending on your Node size, it can be a great free tool to manage your lightning node (it automates a lot of things). Here's also their Twitter account if you want to approach them :)
Hi Leonardo,, Thanks for your reply. Do you use the Torq app at all? We have tried it and after modifying the settings a few times then waitng we still could not get it to perform any automatic rebalancing? We have contacted their dev team but were unable to receive any information as to why it failed to work? Do you operate a lightning node? If so maybe you could enlighten us on how we can get our node to route sats in and out without rebalancing as we find it cost a lot more to rebalance than we make on routing fees? We have an idea that if we can better adjust our fee rates and have enough channels with good peers as well as having peers open channels with us that should give us plenty of inbound liquidity to then help our node be more useful to the lightning community. Thanks you for your help. Warm regards, Orange