Note: This tutorial is made available free to the Umbrel community. If you’d like to tip me for my work in publishing this article, please consider purchasing it on Y’alls.
I’m happy to report that thanks to generous help from Carsten Otto, I now have rebalance-lnd working smoothly on Umbrel, in a way that won’t get erased every time I update the OS (though not in a docker, for now).
I wanted to create another guide (like my guide for charge-lnd) for all of you who are non-technical (like me), so that you can simply follow along with the steps and get automatic, profit-calculated rebalancing working on your node. As you probably know, Umbrel is notoriously finicky about you playing with it’s core files, so my main objective here was to install all files either on the SSD, to prevent you from losing your configurations during updates, so that no core system functionality or apps are disturbed
0. What is Rebalance-LND, and why do you need it?
As you likely already know, rebalancing through Thunderhub or RTL is time consuming, and doesn’t work half the time. You have to try 20 different channels, at different prices, and different amounts, to get 1 rebalance to work.
There are lots of rebalancing scripts that will “probe” and try different routes for you, including Balance of Satoshis. But as far as I know, they don’t consider profitability!
Rebalance-LND is smarter. It takes into consideration both how much you’ll earn if the sats are re-routed, as well as how much you’re giving up in routing fees by sending the sats from another channel.
(Note the 2X profit rate on the route, within 1 hour)
This is a pretty big deal… it saves a ton of time, plus, it makes sure that you never rebalance in a way that would lose you money:
Alright, let’s begin:
1. Log in to your Umbrel’s ssh via a command line tool on your computer (Terminal on Mac, for example):
ssh -t umbrel@Umbrel.local
You’ll need your admin password, which is the one you set on the back end.
2. Create a directory on the SSD for the plugin files (so it doesn’t get erased upon updates or SD card reflashes)
sudo mkdir -p /mnt/data/upgrades/rebalance-lnd
3. Clone the Github Directory (The Files) into your new folder
cd /mnt/data/upgrades/rebalance-lnd && git clone https://github.com/C-Otto/rebalance-lnd.git
4. Install Python 3
pip3 install -r requirements.txt
(This may take a long time. Be patient)
5. Check that it’s working by listing your channels:
Run this command:
(-c is for listing channels)
It should list out all of your channels, in order of which ones need the most balancing.
6. Try a 100,000 sat rebalance
Take one of your channel ID’s that you’re sure will route a lot of sats at the price you currently have set. Copy/paste the long number on the left column:
Then, in the command line, type:
/mnt/data/upgrades/rebalance-lnd/rebalance.py -t [PASTE NUMBER HERE] -a 100000
- -t tells the script which channel you want the sats to go to
- -a tells it the amount. It’s good to try 100k or less - bigger rebalances are harder.
Hit “enter” and watch the script work:
Immediately, you will see it start trying routes, including calculating the profit or loss from each of the attempted routes. Brilliant!
If successful, you will see a lot of blue text which will tell you how much you rebalanced, and for how much, and through which route.
(By the way, you can also use --fee-factor to adjust the rate up or down. For a full list of commands/parameters/limits, check out the Github page where it’s all explained and pretty easy to understand.
Don’t use this script to rebalance funds into channels that are dynamically repriced using charge-lnd. As you put more sats there, the price will go lower automatically, and you’ll end up charging less than you paid to rebalance. Carsten suggests disabling automatic fee policies for channels you use this script with, though you could also use “–fee-factor” and lower the fee so that the profit calculation is correct or at least wrong in your favor
Also, Carsten does not recommend you rebalance OUT of channels, b/c the profit calculation can’t possibly know which channel is going to use that new inbound capacity you’ve created, and that could mean losses.
Finally, as I said before, only use this on channels you know will route at the current price you’ve set. If a channel hasn’t “proven” it will route at that price, the script will calculate profit the wrong way, and you’ll lose money. Alternatively, once again, use --fee-factor of 0.5 or whatever to lower the price artificially so you don’t get screwed, for example if you want to rebalance a new channel that you don’t have any history for.
Other than that, keep it basic. Let the script do the heavy lifting.
7. Now, Automate it (Optional)
Once you’re happy with everything, you can optionally set up a “cron job” to automatically run this command every few hours.
First, structure the rebalance you want, with the right fees, the right “destination, etc… for example:
/mnt/data/upgrades/reblance-lnd/rebalance.py -t [CHANNEL-ID—HERE] -a 100000 --min-remote 2000000
Copy/paste that formatted command.
Then, from the command line, type:
The system will create a new crontab file, if none exists - or open your existing one if you’re created one.
In this file, you can put the following, all on one line:
30 */3 * * * /mnt/data/upgrades/reblance-lnd/rebalance.py -t [CHANNEL-ID—HERE] -a 100000 --min-remote 2000000
This will run your rebalance-lnd script once every 3 hours, at the 30 minute mark (I did this because some of you might be resetting fee policies on the 0 minute, and we want to stagger things). This is the maximum recommended frequency by Carsten. (It might take a long time to find routes, so you probably shouldn’t run it more than every 3 hours or so).
If you wish to run it more/less frequently, or change the timing, or add additional ones to go at different times (stagger them by the minute or by the hour), that’s up to you, and you can find the instructions for changing the 0 * * * * part of the command above here: https://crontab.guru
If you’ve followed the steps above correctly, everything should work just fine, and you should see rebalance transactions come through every 3 hours, assuming they are successful.
This guide was created with the help and support of a LOT of people MUCH smarter than me - and of course, it leverages the awesome (and free) script written by Carsten - so make sure to support their work.
Tip Carsten for building this script: firstname.lastname@example.org:9735 (keysend)
Tip The Lorax for writing this tutorial:
- email@example.com:9735 (keysend)
Thanks for reading, I hope you enjoyed this guide.