lnd: add neutrino backend support
Add option to use neutrino instead of bitcoind for fetching blockchain data. This allows running LND as a lightweight client that connects to remote Bitcoin full nodes via P2P protocol. New options: - services.lnd.backend: choose between "bitcoind" (default) or "neutrino" - services.lnd.neutrino.addpeers: list of Bitcoin node peers to connect to 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4f4cb34837
commit
b0076a2e1d
1 changed files with 39 additions and 10 deletions
|
|
@ -144,6 +144,22 @@ let
|
||||||
description = "LND TLS certificate path.";
|
description = "LND TLS certificate path.";
|
||||||
};
|
};
|
||||||
tor = nbLib.tor;
|
tor = nbLib.tor;
|
||||||
|
backend = mkOption {
|
||||||
|
type = types.enum [ "bitcoind" "neutrino" ];
|
||||||
|
default = "bitcoind";
|
||||||
|
description = "The backend to use for fetching blockchain data.";
|
||||||
|
};
|
||||||
|
neutrino = {
|
||||||
|
addpeers = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
example = [ "192.168.1.1:8333" "btcd.example.com:8333" ];
|
||||||
|
description = ''
|
||||||
|
List of Bitcoin full node peers to connect to via neutrino.addpeer.
|
||||||
|
Multiple peers provide redundancy for maximum uptime.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
cfg = config.services.lnd;
|
cfg = config.services.lnd;
|
||||||
|
|
@ -170,15 +186,20 @@ let
|
||||||
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
||||||
|
|
||||||
bitcoin.${bitcoind.network}=1
|
bitcoin.${bitcoind.network}=1
|
||||||
bitcoin.node=bitcoind
|
|
||||||
|
|
||||||
${optionalString (cfg.tor.proxy) "tor.active=true"}
|
${optionalString (cfg.tor.proxy) "tor.active=true"}
|
||||||
${optionalString (cfg.tor-socks != null) "tor.socks=${cfg.tor-socks}"}
|
${optionalString (cfg.tor-socks != null) "tor.socks=${cfg.tor-socks}"}
|
||||||
|
|
||||||
bitcoind.rpchost=${bitcoindRpcAddress}:${toString bitcoind.rpc.port}
|
${if cfg.backend == "bitcoind" then ''
|
||||||
bitcoind.rpcuser=${bitcoind.rpc.users.public.name}
|
bitcoin.node=bitcoind
|
||||||
bitcoind.zmqpubrawblock=${zmqHandleSpecialAddress bitcoind.zmqpubrawblock}
|
bitcoind.rpchost=${bitcoindRpcAddress}:${toString bitcoind.rpc.port}
|
||||||
bitcoind.zmqpubrawtx=${zmqHandleSpecialAddress bitcoind.zmqpubrawtx}
|
bitcoind.rpcuser=${bitcoind.rpc.users.public.name}
|
||||||
|
bitcoind.zmqpubrawblock=${zmqHandleSpecialAddress bitcoind.zmqpubrawblock}
|
||||||
|
bitcoind.zmqpubrawtx=${zmqHandleSpecialAddress bitcoind.zmqpubrawtx}
|
||||||
|
'' else ''
|
||||||
|
bitcoin.node=neutrino
|
||||||
|
${lib.concatMapStringsSep "\n" (peer: "neutrino.addpeer=${peer}") cfg.neutrino.addpeers}
|
||||||
|
''}
|
||||||
|
|
||||||
wallet-unlock-password-file=${secretsDir}/lnd-wallet-password
|
wallet-unlock-password-file=${secretsDir}/lnd-wallet-password
|
||||||
|
|
||||||
|
|
@ -202,9 +223,15 @@ in {
|
||||||
services.lnd.port to a port other than 9735.
|
services.lnd.port to a port other than 9735.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
{ assertion = cfg.backend != "neutrino" || cfg.neutrino.addpeers != [];
|
||||||
|
message = ''
|
||||||
|
When using neutrino backend, you must configure at least one peer
|
||||||
|
in services.lnd.neutrino.addpeers.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
services.bitcoind = {
|
services.bitcoind = mkIf (cfg.backend == "bitcoind") {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
# Increase rpc thread count due to reports that lightning implementations fail
|
# Increase rpc thread count due to reports that lightning implementations fail
|
||||||
|
|
@ -225,12 +252,14 @@ in {
|
||||||
|
|
||||||
systemd.services.lnd = {
|
systemd.services.lnd = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
requires = [ "bitcoind.service" ];
|
requires = optional (cfg.backend == "bitcoind") "bitcoind.service";
|
||||||
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ];
|
after = optional (cfg.backend == "bitcoind") "bitcoind.service" ++ [ "nix-bitcoin-secrets.target" ];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
install -m600 ${configFile} '${cfg.dataDir}/lnd.conf'
|
install -m600 ${configFile} '${cfg.dataDir}/lnd.conf'
|
||||||
{
|
{
|
||||||
echo "bitcoind.rpcpass=$(cat ${secretsDir}/bitcoin-rpcpassword-public)"
|
${optionalString (cfg.backend == "bitcoind") ''
|
||||||
|
echo "bitcoind.rpcpass=$(cat ${secretsDir}/bitcoin-rpcpassword-public)"
|
||||||
|
''}
|
||||||
${optionalString (cfg.getPublicAddressCmd != "") ''
|
${optionalString (cfg.getPublicAddressCmd != "") ''
|
||||||
echo "externalip=$(${cfg.getPublicAddressCmd})"
|
echo "externalip=$(${cfg.getPublicAddressCmd})"
|
||||||
''}
|
''}
|
||||||
|
|
@ -288,7 +317,7 @@ in {
|
||||||
users.users.${cfg.user} = {
|
users.users.${cfg.user} = {
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
group = cfg.group;
|
group = cfg.group;
|
||||||
extraGroups = [ "bitcoinrpc-public" ];
|
extraGroups = optional (cfg.backend == "bitcoind") "bitcoinrpc-public";
|
||||||
home = cfg.dataDir; # lnd creates .lnd dir in HOME
|
home = cfg.dataDir; # lnd creates .lnd dir in HOME
|
||||||
};
|
};
|
||||||
users.groups.${cfg.group} = {};
|
users.groups.${cfg.group} = {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue