Last active
November 15, 2021 03:48
-
-
Save xanoni/430ead6d11e9caaed8b020b11bc3a75c to your computer and use it in GitHub Desktop.
lnd: rebalance channel autopilot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
PCT_INIT=100 | |
PCT_MIN=25 | |
PCT_DROP=25 | |
MIN_AMOUNT=10000 # don't rebalance below this amount (def: 10k) | |
MIN_LOCAL=1000000 # min outbound sats per chan (def: 1M) | |
MIN_REMOTE=1000000 # min inbound sats per chan (def: 1M) | |
FEE_FACTOR=0.95 # (def: 1.0) | |
# channels to be rebalanced per run/cycle | |
CHANS_PER_ITER_TO=30 | |
CHANS_PER_ITER_FROM=50 | |
# `nice` process value (+19 = lowest prio) | |
NICENESS='+19' | |
# time to sleep between runs/cycles, in minutes (picked randomly) | |
SLEEP_MIN=20 | |
SLEEP_MAX=60 | |
# workaround for 32-Bit Raspbian Bullseye | |
LD_PRELOAD="/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0" | |
cd "${HOME}/rebalance-lnd" || exit 1 | |
PCT_CUR="${PCT_INIT}" | |
while true; do | |
echo -en "\nStarting cycle with PCT_CUR=${PCT_CUR} ...\n\n" | |
for _ in $(seq 1 "${CHANS_PER_ITER_TO}"); do | |
# increase outbound capacity | |
LD_PRELOAD="${LD_PRELOAD}" nice -n"${NICENESS}" ./rebalance.py \ | |
--to="-1" \ | |
--min-amount="${MIN_AMOUNT}" \ | |
--min-local="${MIN_LOCAL}" \ | |
--percentage="${PCT_CUR}" \ | |
--fee-factor="${FEE_FACTOR}" | |
done | |
for _ in $(seq 1 "${CHANS_PER_ITER_FROM}"); do | |
# increase inbound capacity | |
LD_PRELOAD="${LD_PRELOAD}" nice -n"${NICENESS}" ./rebalance.py \ | |
--from="-1" \ | |
--min-amount="${MIN_AMOUNT}" \ | |
--min-remote="${MIN_REMOTE}" \ | |
--percentage="${PCT_CUR}" \ | |
--fee-factor="${FEE_FACTOR}" | |
done | |
# pick random timeframe from interval and sleep | |
SLEEP_MINS=$((SLEEP_MIN + RANDOM % (SLEEP_MAX-SLEEP_MIN))) | |
echo -en "\n\nSleeping for ${SLEEP_MINS} minutes ...\n" && sleep "$((60 * SLEEP_MINS))" | |
# modify "--percentage" parameter before next run/cycle | |
if [ "${PCT_CUR}" -gt "${PCT_MIN}" ]; then | |
PCT_CUR="$((PCT_CUR * (100-PCT_DROP) / 100))" | |
else | |
PCT_CUR="${PCT_INIT}" # reset to start | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment