Umbrel: Neutrino 馃攣 Bitcoin Node Automatic Switching

Created on 2 May 2020  路  13Comments  路  Source: getumbrel/umbrel

Issue

  • The user cannot start using his lightning or bitcoin wallet until bitcoind has fully synchronized. This adds a lot of friction due to the long delay, creating a very frustrating experience.

  • If bitcoind lags behind for some reason, such as when the user had his node turned off for a few days/weeks, the same problem reoccurs.

Solution

Neutrino filters can solve this problem. We need an automatic, recurring way to switch lnd's bitcoin mode to neutrino from bitcoind as soon as bitcoind lags behind by a certain number of blocks from its best header.

Ideas

Perhaps it's a good idea to create a new service that runs 24x7 via a container called lnd-switch that uses the following environment variables:

BITCOIN_HOST: "0.0.0.0"
BITCOIN_RPC_PORT: "8332"
BITCOIN_RPC_USER: "umbrel"
BITCOIN_RPC_PASSWORD: "1234567890"
LND_CONFIG_FILE: "/home/umbrel/lnd/lnd.conf"
SWITCH_TO_NEUTRINO: "144" (switch to neutrino when bitcoind is *at least* 144 blocks behind)
SWITCH_TO_BITCOIND: "3" (switch to bitcoind when bitcoind is *at max* 3 blocks behind)

Considering the above example variables, lnd-switch will update the bitcoin node in LND_CONFIG_FILE from bitcoin.node=bitcoind to bitcoin.node=neutrino as soon as bitcoind's headers - blocks >= 144 and update it from bitcoin.node=neutrino to bitcoin.node=bitcoind as soon as bitcoind's headers - blocks <= 3. It also needs a way to restart the lnd container after every config file change.

I'm not sure if this is the right approach or not. If it is, then lnd-switch can be a tiny FOSS project on its own that (I think) many more people will find useful.

cc @nolim1t @meeDamian

Most helpful comment

Will attempt to do this. Probably a bash looping service similar to the unlock script

All 13 comments

Instead of creating a new docker service, perhaps this should be handled by https://github.com/getumbrel/umbrel-manager

lets make it $HOST/lnd/lnd.conf or /mnt/data/lnd/lnd.conf

can be a docker service for sure and restart: on-error

lets make it $HOST/lnd/lnd.conf or /mnt/data/lnd/lnd.conf

I didn't fully understand that.. can you please elaborate a bit?

Also, since $HOST/lnd/lnd.conf is symlinked to /mnt/data/lnd/lnd.conf, the lnd-switch can make changes directly to $HOST/lnd/lnd.conf

Concept ACK.

Would love to see this, it's a feature that I hear a lot of people talk about but AFAIK no one has implemented yet, would be great if Umbrel was the first.

lets make it $HOST/lnd/lnd.conf or /mnt/data/lnd/lnd.conf

I didn't fully understand that.. can you please elaborate a bit?

Also, since $HOST/lnd/lnd.conf is symlinked to /mnt/data/lnd/lnd.conf, the lnd-switch can make changes directly to $HOST/lnd/lnd.conf

${HOME}

it would need to keep running too and be able to switch back and forth too.

Say bitcoind is corrupted it should switch back and forth

Will attempt to do this. Probably a bash looping service similar to the unlock script

Awesome! Looking forward. It really is one of the last few missing pieces before we can launch.

going to have a stab at this now.. it will need a lot of testing

sample code which can do it

#!/bin/bash -e

PASSWORD=`cat $PWD/secrets/rpcpass.txt`

INFO=`curl --user lncm:$PASSWORD --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' http://10.254.2.2:18332 2>/dev/null`

HEADERS=`echo $INFO | jq .result.headers`
BLOCKS=`echo $INFO | jq .result.blocks`

if [ $HEADERS -eq $BLOCKS ]; then
    echo "Switching over from bitcoind to neutrino"
    sed 's/bitcoin.node\=neutrino/bitcoin.node\=bitcoind/g; ' lnd/lnd.conf
fi

Looking good

Was this page helpful?
0 / 5 - 0 ratings