Skip to content

Instantly share code, notes, and snippets.

@jorijn
Last active February 19, 2022 13:31
Show Gist options
  • Save jorijn/dc39f8b6340e4c6f73ad04c60a931708 to your computer and use it in GitHub Desktop.
Save jorijn/dc39f8b6340e4c6f73ad04c60a931708 to your computer and use it in GitHub Desktop.
Attempt at automatic rebalancing for LND with rebalance-lnd, although it could fit any script... πŸ€·β€β™‚οΈ
420183667455285923,rompert.comguy,20,20
590034546445293500,otherpeeralias,20,20
#!/usr/bin/env bash
#####
# Attempt at automatic rebalancing for LND with rebalance-lnd, although it could
# fit any script... πŸ€·β€β™‚οΈ The config file can't contain comments, format is
# <channel id>,<some label>,<trigger if funds on local side are less than N%>,<trigger if funds on remote side are less than N%>
# The script will order the rebalancing to stop if it's still going after 600 seconds
# and kill if it's not stopped 30 seconds after that. Oh, and spaces in the config breaks stuff.
#####
REBALANCE="/path/to/rebalance.py"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
SOFT_TIMEOUT=600
KILL_TIMEOUT=30
cd $DIR
for line in $(cat ${DIR}/auto_rebalance.conf)
do
channel_id=$(echo $line|cut -d, -f1)
peer_alias=$(echo $line|cut -d, -f2)
local_threshold=$(echo $line|cut -d, -f3)
remote_threshold=$(echo $line|cut -d, -f4)
echo "βš–οΈ Checking ${peer_alias} (${channel_id}), will rebalance if less than ${local_threshold}% of funds are on the local side or less than ${remote_threshold}% are on the remote side."
if $REBALANCE -l -r "$local_threshold" -i |grep "$channel_id" &>/dev/null; then
echo "πŸ€– Moving funds to ${peer_alias}.."
timeout -v -k $KILL_TIMEOUT $SOFT_TIMEOUT $REBALANCE -t "$channel_id"
fi
if $REBALANCE -l -r "$remote_threshold" -o |grep "$channel_id" &>/dev/null; then
echo "πŸ€– Moving funds from ${peer_alias}.."
timeout -v -k $KILL_TIMEOUT $SOFT_TIMEOUT $REBALANCE -f "$channel_id"
fi
done
@C-Otto
Copy link

C-Otto commented Jul 21, 2021

I suggest to use --econ-fee, the default fee configuration most likely isn't successful. I also don't think rebalancing to 50/50 is the best idea, maybe just send 100k sats (repeatedly) until you've meet your threshold?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment