Merge #249: Add regtest support

9951f10e74 test: add scenario 'regtest' (Erik Arvstedt)
1f96ca67c5 electrs test: make service shutdown optional (Erik Arvstedt)
eb42fc8e06 test: extract test 'joinmarket-yieldgenerator' (Erik Arvstedt)
06b2ec5b02 joinmarket: add regtest support (Erik Arvstedt)
975b30c90e joinmarket: don't hardcode bitcoind rpc port (Erik Arvstedt)
031df4231f joinmarket: move comment out of config file (Erik Arvstedt)
848c4c6eda joinmarket: add variable 'bitcoind' (Erik Arvstedt)
96b08f5d60 btcpayserver: add regtest support (Erik Arvstedt)
bd2145dc77 btcpayserver: add 'port' option (Erik Arvstedt)
001f8fe8d3 btcpayserver: use option bitcoind.rpc.port (Erik Arvstedt)
6f4715ac2a electrs: add regtest support (Erik Arvstedt)
46efd141a1 lightning-loop: add regtest support (Erik Arvstedt)
75ec85bea2 lnd: add regtest support (Erik Arvstedt)
1935c252ec lnd: remove redundant option 'bitcoind-host' (Erik Arvstedt)
b1a8629223 lnd: add variable 'bitcoind' (Erik Arvstedt)
937aee0062 spark-wallet: add regtest support (Erik Arvstedt)
47d611b5ef spark-wallet: use tor rate provider only when enforceTor (Erik Arvstedt)
127b186c3c spark-wallet: simplify start script (Erik Arvstedt)
0f32f3c99e clightning: add regtest support (Erik Arvstedt)
c24ac5d363 clightning: remove redundant option 'bitcoin-rpcconnect' (Erik Arvstedt)
abd32cde30 clightning: enable config file read access for group (Erik Arvstedt)
ddadaed3da clightning: always use bind-addr in config (Erik Arvstedt)
9e928e2097 bitcoind: add regtest support (Erik Arvstedt)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 9951f10e74

Tree-SHA512: 42e2d95755a16b59044e400bc4c9d891bfc22eb73b920fdcf29e607f7df88de599bec99677cf49be7c275c0113a2224a45b1f47f40c029878421eae1a44f3254
This commit is contained in:
Jonas Nick 2020-10-17 13:04:18 +00:00
commit 06cba7b519
No known key found for this signature in database
GPG Key ID: 4861DBF262123605
12 changed files with 165 additions and 78 deletions

View File

@ -11,7 +11,10 @@ let
# We're already logging via journald # We're already logging via journald
nodebuglogfile=1 nodebuglogfile=1
${optionalString cfg.testnet "testnet=1"} ${optionalString cfg.regtest ''
regtest=1
[regtest]
''}
${optionalString (cfg.dbCache != null) "dbcache=${toString cfg.dbCache}"} ${optionalString (cfg.dbCache != null) "dbcache=${toString cfg.dbCache}"}
prune=${toString cfg.prune} prune=${toString cfg.prune}
${optionalString (cfg.sysperms != null) "sysperms=${if cfg.sysperms then "1" else "0"}"} ${optionalString (cfg.sysperms != null) "sysperms=${if cfg.sysperms then "1" else "0"}"}
@ -159,10 +162,18 @@ in {
Allow JSON-RPC connections from specified source. Allow JSON-RPC connections from specified source.
''; '';
}; };
testnet = mkOption { regtest = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = "Whether to use the test chain."; description = "Enable regtest mode.";
};
network = mkOption {
readOnly = true;
default = if cfg.regtest then "regtest" else "mainnet";
};
makeNetworkName = mkOption {
readOnly = true;
default = mainnet: regtest: if cfg.regtest then regtest else mainnet;
}; };
port = mkOption { port = mkOption {
type = types.nullOr types.port; type = types.nullOr types.port;

View File

@ -34,6 +34,11 @@ in {
default = "127.0.0.1"; default = "127.0.0.1";
description = "The address on which to bind."; description = "The address on which to bind.";
}; };
port = mkOption {
type = types.port;
default = 24444;
description = "Port on which to bind.";
};
enable = mkOption { enable = mkOption {
# This option is only used by netns-isolation # This option is only used by netns-isolation
internal = true; internal = true;
@ -70,6 +75,11 @@ in {
default = "127.0.0.1"; default = "127.0.0.1";
description = "The address on which to bind."; description = "The address on which to bind.";
}; };
port = mkOption {
type = types.port;
default = 23000;
description = "Port on which to bind.";
};
lightningBackend = mkOption { lightningBackend = mkOption {
type = types.nullOr (types.enum [ "clightning" "lnd" ]); type = types.nullOr (types.enum [ "clightning" "lnd" ]);
default = null; default = null;
@ -104,11 +114,12 @@ in {
systemd.services.nbxplorer = let systemd.services.nbxplorer = let
configFile = builtins.toFile "config" '' configFile = builtins.toFile "config" ''
network=mainnet network=${config.services.bitcoind.network}
btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name} btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name}
btcrpcurl=http://${builtins.elemAt config.services.bitcoind.rpcbind 0}:8332 btcrpcurl=http://${builtins.elemAt config.services.bitcoind.rpcbind 0}:${toString cfg.bitcoind.rpc.port}
btcnodeendpoint=${config.services.bitcoind.bind}:8333 btcnodeendpoint=${config.services.bitcoind.bind}:8333
bind=${cfg.nbxplorer.bind} bind=${cfg.nbxplorer.bind}
port=${toString cfg.nbxplorer.port}
''; '';
in { in {
description = "Run nbxplorer"; description = "Run nbxplorer";
@ -138,12 +149,13 @@ in {
systemd.services.btcpayserver = let systemd.services.btcpayserver = let
configFile = builtins.toFile "config" ('' configFile = builtins.toFile "config" (''
network=mainnet network=${config.services.bitcoind.network}
postgres=User ID=${cfg.btcpayserver.user};Host=/run/postgresql;Database=btcpaydb postgres=User ID=${cfg.btcpayserver.user};Host=/run/postgresql;Database=btcpaydb
socksendpoint=${cfg.tor.client.socksListenAddress} socksendpoint=${cfg.tor.client.socksListenAddress}
btcexplorerurl=http://${cfg.nbxplorer.bind}:24444/ btcexplorerurl=http://${cfg.nbxplorer.bind}:${toString cfg.nbxplorer.port}/
btcexplorercookiefile=${cfg.nbxplorer.dataDir}/Main/.cookie btcexplorercookiefile=${cfg.nbxplorer.dataDir}/${config.services.bitcoind.makeNetworkName "Main" "RegTest"}/.cookie
bind=${cfg.btcpayserver.bind} bind=${cfg.btcpayserver.bind}
port=${toString cfg.btcpayserver.port}
'' + optionalString (cfg.btcpayserver.lightningBackend == "clightning") '' '' + optionalString (cfg.btcpayserver.lightningBackend == "clightning") ''
btclightning=type=clightning;server=unix:///${cfg.clightning.dataDir}/bitcoin/lightning-rpc btclightning=type=clightning;server=unix:///${cfg.clightning.dataDir}/bitcoin/lightning-rpc
''); '');

View File

@ -6,13 +6,15 @@ let
cfg = config.services.clightning; cfg = config.services.clightning;
inherit (config) nix-bitcoin-services; inherit (config) nix-bitcoin-services;
onion-chef-service = (if cfg.announce-tor then [ "onion-chef.service" ] else []); onion-chef-service = (if cfg.announce-tor then [ "onion-chef.service" ] else []);
network = config.services.bitcoind.makeNetworkName "bitcoin" "regtest";
configFile = pkgs.writeText "config" '' configFile = pkgs.writeText "config" ''
network=bitcoin network=${network}
bitcoin-datadir=${config.services.bitcoind.dataDir} bitcoin-datadir=${config.services.bitcoind.dataDir}
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
always-use-proxy=${if cfg.always-use-proxy then "true" else "false"} always-use-proxy=${if cfg.always-use-proxy then "true" else "false"}
${optionalString (cfg.bind-addr != null) "bind-addr=${cfg.bind-addr}:${toString cfg.bindport}"} bind-addr=${cfg.bind-addr}:${toString cfg.bindport}
${optionalString (cfg.bitcoin-rpcconnect != null) "bitcoin-rpcconnect=${cfg.bitcoin-rpcconnect}"} bitcoin-rpcconnect=${builtins.elemAt config.services.bitcoind.rpcbind 0}
bitcoin-rpcport=${toString config.services.bitcoind.rpc.port}
bitcoin-rpcuser=${config.services.bitcoind.rpc.users.public.name} bitcoin-rpcuser=${config.services.bitcoind.rpc.users.public.name}
rpc-file-mode=0660 rpc-file-mode=0660
${cfg.extraConfig} ${cfg.extraConfig}
@ -61,16 +63,16 @@ in {
default = false; default = false;
description = "Announce clightning Tor Hidden Service"; description = "Announce clightning Tor Hidden Service";
}; };
bitcoin-rpcconnect = mkOption {
type = types.nullOr types.str;
default = null;
description = "The bitcoind RPC host to connect to.";
};
dataDir = mkOption { dataDir = mkOption {
type = types.path; type = types.path;
default = "/var/lib/clightning"; default = "/var/lib/clightning";
description = "The data directory for clightning."; description = "The data directory for clightning.";
}; };
networkDir = mkOption {
readOnly = true;
default = "${cfg.dataDir}/${network}";
description = "The network data directory.";
};
extraConfig = mkOption { extraConfig = mkOption {
type = types.lines; type = types.lines;
default = ""; default = "";
@ -122,8 +124,8 @@ in {
cp ${configFile} ${cfg.dataDir}/config cp ${configFile} ${cfg.dataDir}/config
chown -R '${cfg.user}:${cfg.group}' '${cfg.dataDir}' chown -R '${cfg.user}:${cfg.group}' '${cfg.dataDir}'
# The RPC socket has to be removed otherwise we might have stale sockets # The RPC socket has to be removed otherwise we might have stale sockets
rm -f ${cfg.dataDir}/bitcoin/lightning-rpc rm -f ${cfg.networkDir}/lightning-rpc
chmod 600 ${cfg.dataDir}/config chmod 640 ${cfg.dataDir}/config
echo "bitcoin-rpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/bitcoin-rpcpassword-public)" >> '${cfg.dataDir}/config' echo "bitcoin-rpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/bitcoin-rpcpassword-public)" >> '${cfg.dataDir}/config'
${optionalString cfg.announce-tor "echo announce-addr=$(cat /var/lib/onion-chef/clightning/clightning) >> '${cfg.dataDir}/config'"} ${optionalString cfg.announce-tor "echo announce-addr=$(cat /var/lib/onion-chef/clightning/clightning) >> '${cfg.dataDir}/config'"}
''; '';
@ -139,11 +141,11 @@ in {
); );
# Wait until the rpc socket appears # Wait until the rpc socket appears
postStart = '' postStart = ''
while [[ ! -e ${cfg.dataDir}/bitcoin/lightning-rpc ]]; do while [[ ! -e ${cfg.networkDir}/lightning-rpc ]]; do
sleep 0.1 sleep 0.1
done done
# Needed to enable lightning-cli for users with group 'clightning' # Needed to enable lightning-cli for users with group 'clightning'
chmod g+x ${cfg.dataDir}/bitcoin chmod g+x ${cfg.networkDir}
''; '';
}; };
}; };

View File

@ -90,6 +90,7 @@ in {
else else
"--jsonrpc-import --index-batch-size=10" "--jsonrpc-import --index-batch-size=10"
} \ } \
--network=${bitcoind.makeNetworkName "bitcoin" "regtest"} \
--db-dir='${cfg.dataDir}' \ --db-dir='${cfg.dataDir}' \
--daemon-dir='${bitcoind.dataDir}' \ --daemon-dir='${bitcoind.dataDir}' \
--electrum-rpc-addr=${cfg.address}:${toString cfg.port} \ --electrum-rpc-addr=${cfg.address}:${toString cfg.port} \

View File

@ -7,9 +7,10 @@ let
inherit (config) nix-bitcoin-services; inherit (config) nix-bitcoin-services;
secretsDir = config.nix-bitcoin.secretsDir; secretsDir = config.nix-bitcoin.secretsDir;
inherit (config.services) bitcoind;
torAddress = builtins.head (builtins.split ":" config.services.tor.client.socksListenAddress); torAddress = builtins.head (builtins.split ":" config.services.tor.client.socksListenAddress);
# Based on https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/jmclient/jmclient/configure.py
configFile = builtins.toFile "config" '' configFile = builtins.toFile "config" ''
# Based on https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/jmclient/jmclient/configure.py
[DAEMON] [DAEMON]
no_daemon = 0 no_daemon = 0
daemon_port = 27183 daemon_port = 27183
@ -18,10 +19,10 @@ let
[BLOCKCHAIN] [BLOCKCHAIN]
blockchain_source = bitcoin-rpc blockchain_source = bitcoin-rpc
network = mainnet network = ${bitcoind.network}
rpc_host = ${builtins.elemAt config.services.bitcoind.rpcbind 0} rpc_host = ${builtins.elemAt bitcoind.rpcbind 0}
rpc_port = 8332 rpc_port = ${toString bitcoind.rpc.port}
rpc_user = ${config.services.bitcoind.rpc.users.privileged.name} rpc_user = ${bitcoind.rpc.users.privileged.name}
@@RPC_PASSWORD@@ @@RPC_PASSWORD@@
[MESSAGING:server1] [MESSAGING:server1]
@ -155,7 +156,8 @@ in {
"s|@@RPC_PASSWORD@@|rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-privileged)|" \ "s|@@RPC_PASSWORD@@|rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-privileged)|" \
'${cfg.dataDir}/joinmarket.cfg' '${cfg.dataDir}/joinmarket.cfg'
''; '';
ExecStartPost = nix-bitcoin-services.privileged '' # Generating wallets (jmclient/wallet.py) is only supported for mainnet or testnet
ExecStartPost = mkIf (bitcoind.network == "mainnet") (nix-bitcoin-services.privileged ''
walletname=wallet.jmdat walletname=wallet.jmdat
pw=$(cat "${secretsDir}"/jm-wallet-password) pw=$(cat "${secretsDir}"/jm-wallet-password)
mnemonic=${secretsDir}/jm-wallet-seed mnemonic=${secretsDir}/jm-wallet-seed
@ -170,7 +172,7 @@ in {
recoveryseed=$(echo "$out" | grep 'recovery_seed') recoveryseed=$(echo "$out" | grep 'recovery_seed')
echo "$recoveryseed" | cut -d ':' -f2 > $mnemonic echo "$recoveryseed" | cut -d ':' -f2 > $mnemonic
fi fi
''; '');
ExecStart = "${pkgs.nix-bitcoin.joinmarket}/bin/joinmarketd"; ExecStart = "${pkgs.nix-bitcoin.joinmarket}/bin/joinmarketd";
WorkingDirectory = "${cfg.dataDir}"; # The service creates 'commitmentlist' in the working dir WorkingDirectory = "${cfg.dataDir}"; # The service creates 'commitmentlist' in the working dir
User = "${cfg.user}"; User = "${cfg.user}";

View File

@ -8,12 +8,13 @@ let
secretsDir = config.nix-bitcoin.secretsDir; secretsDir = config.nix-bitcoin.secretsDir;
configFile = builtins.toFile "loop.conf" '' configFile = builtins.toFile "loop.conf" ''
datadir=${cfg.dataDir} datadir=${cfg.dataDir}
network=${config.services.bitcoind.network}
logdir=${cfg.dataDir}/logs logdir=${cfg.dataDir}/logs
tlscertpath=${secretsDir}/loop-cert tlscertpath=${secretsDir}/loop-cert
tlskeypath=${secretsDir}/loop-key tlskeypath=${secretsDir}/loop-key
lnd.host=${builtins.elemAt config.services.lnd.rpclisten 0}:${toString config.services.lnd.rpcPort} lnd.host=${builtins.elemAt config.services.lnd.rpclisten 0}:${toString config.services.lnd.rpcPort}
lnd.macaroondir=${config.services.lnd.dataDir}/chain/bitcoin/mainnet lnd.macaroondir=${config.services.lnd.networkDir}
lnd.tlspath=${secretsDir}/lnd-cert lnd.tlspath=${secretsDir}/lnd-cert
${optionalString (cfg.proxy != null) "server.proxy=${cfg.proxy}"} ${optionalString (cfg.proxy != null) "server.proxy=${cfg.proxy}"}

View File

@ -5,13 +5,15 @@ with lib;
let let
cfg = config.services.lnd; cfg = config.services.lnd;
inherit (config) nix-bitcoin-services; inherit (config) nix-bitcoin-services;
onion-chef-service = (if cfg.announce-tor then [ "onion-chef.service" ] else []);
secretsDir = config.nix-bitcoin.secretsDir; secretsDir = config.nix-bitcoin.secretsDir;
mainnetDir = "${cfg.dataDir}/chain/bitcoin/mainnet";
bitcoind = config.services.bitcoind;
bitcoindRpcAddress = builtins.elemAt bitcoind.rpcbind 0;
onion-chef-service = (if cfg.announce-tor then [ "onion-chef.service" ] else []);
networkDir = "${cfg.dataDir}/chain/bitcoin/${bitcoind.network}";
configFile = pkgs.writeText "lnd.conf" '' configFile = pkgs.writeText "lnd.conf" ''
datadir=${cfg.dataDir} datadir=${cfg.dataDir}
logdir=${cfg.dataDir}/logs logdir=${cfg.dataDir}/logs
bitcoin.mainnet=1
tlscertpath=${secretsDir}/lnd-cert tlscertpath=${secretsDir}/lnd-cert
tlskeypath=${secretsDir}/lnd-key tlskeypath=${secretsDir}/lnd-key
@ -19,16 +21,17 @@ let
${lib.concatMapStrings (rpclisten: "rpclisten=${rpclisten}:${toString cfg.rpcPort}\n") cfg.rpclisten} ${lib.concatMapStrings (rpclisten: "rpclisten=${rpclisten}:${toString cfg.rpcPort}\n") cfg.rpclisten}
${lib.concatMapStrings (restlisten: "restlisten=${restlisten}:${toString cfg.restPort}\n") cfg.restlisten} ${lib.concatMapStrings (restlisten: "restlisten=${restlisten}:${toString cfg.restPort}\n") cfg.restlisten}
bitcoin.${bitcoind.network}=1
bitcoin.active=1 bitcoin.active=1
bitcoin.node=bitcoind bitcoin.node=bitcoind
tor.active=true 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=${cfg.bitcoind-host} bitcoind.rpchost=${bitcoindRpcAddress}:${toString bitcoind.rpc.port}
bitcoind.rpcuser=${config.services.bitcoind.rpc.users.public.name} bitcoind.rpcuser=${bitcoind.rpc.users.public.name}
bitcoind.zmqpubrawblock=${config.services.bitcoind.zmqpubrawblock} bitcoind.zmqpubrawblock=${bitcoind.zmqpubrawblock}
bitcoind.zmqpubrawtx=${config.services.bitcoind.zmqpubrawtx} bitcoind.zmqpubrawtx=${bitcoind.zmqpubrawtx}
${cfg.extraConfig} ${cfg.extraConfig}
''; '';
@ -47,6 +50,11 @@ in {
default = "/var/lib/lnd"; default = "/var/lib/lnd";
description = "The data directory for LND."; description = "The data directory for LND.";
}; };
networkDir = mkOption {
readOnly = true;
default = networkDir;
description = "The network data directory.";
};
listen = mkOption { listen = mkOption {
type = pkgs.nix-bitcoin.lib.ipv4Address; type = pkgs.nix-bitcoin.lib.ipv4Address;
default = "localhost"; default = "localhost";
@ -81,13 +89,6 @@ in {
default = 8080; default = 8080;
description = "Port on which to listen for REST connections."; description = "Port on which to listen for REST connections.";
}; };
bitcoind-host = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
The host that your local bitcoind daemon is listening on.
'';
};
tor-socks = mkOption { tor-socks = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
@ -138,7 +139,7 @@ in {
# Switch user because lnd makes datadir contents readable by user only # Switch user because lnd makes datadir contents readable by user only
'' ''
${cfg.cliExec} sudo -u lnd ${cfg.package}/bin/lncli --tlscertpath ${secretsDir}/lnd-cert \ ${cfg.cliExec} sudo -u lnd ${cfg.package}/bin/lncli --tlscertpath ${secretsDir}/lnd-cert \
--macaroonpath '${cfg.dataDir}/chain/bitcoin/mainnet/admin.macaroon' "$@" --macaroonpath '${networkDir}/admin.macaroon' "$@"
''; '';
description = "Binary to connect with the lnd instance."; description = "Binary to connect with the lnd instance.";
}; };
@ -148,7 +149,7 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [ assertions = [
{ assertion = config.services.bitcoind.prune == 0; { assertion = bitcoind.prune == 0;
message = "lnd does not support bitcoind pruning."; message = "lnd does not support bitcoind pruning.";
} }
]; ];
@ -160,8 +161,8 @@ in {
]; ];
services.bitcoind = { services.bitcoind = {
zmqpubrawblock = "tcp://${cfg.bitcoind-host}:28332"; zmqpubrawblock = "tcp://${bitcoindRpcAddress}:28332";
zmqpubrawtx = "tcp://${cfg.bitcoind-host}:28333"; zmqpubrawtx = "tcp://${bitcoindRpcAddress}:28333";
}; };
services.onion-chef.access.lnd = if cfg.announce-tor then [ "lnd" ] else []; services.onion-chef.access.lnd = if cfg.announce-tor then [ "lnd" ] else [];
@ -206,7 +207,7 @@ in {
chown lnd: "$mnemonic" chown lnd: "$mnemonic"
''}" ''}"
"${nix-bitcoin-services.script '' "${nix-bitcoin-services.script ''
if [[ ! -f ${mainnetDir}/wallet.db ]]; then if [[ ! -f ${networkDir}/wallet.db ]]; then
echo Create lnd wallet echo Create lnd wallet
${pkgs.curl}/bin/curl -s --output /dev/null --show-error \ ${pkgs.curl}/bin/curl -s --output /dev/null --show-error \
@ -217,14 +218,14 @@ in {
# Guarantees that RPC calls with cfg.cli succeed after the service is started # Guarantees that RPC calls with cfg.cli succeed after the service is started
echo Wait until wallet is created echo Wait until wallet is created
while [[ ! -f ${mainnetDir}/admin.macaroon ]]; do while [[ ! -f ${networkDir}/admin.macaroon ]]; do
sleep 0.1 sleep 0.1
done done
else else
echo Unlock lnd wallet echo Unlock lnd wallet
${pkgs.curl}/bin/curl -s \ ${pkgs.curl}/bin/curl -s \
-H "Grpc-Metadata-macaroon: $(${pkgs.xxd}/bin/xxd -ps -u -c 99999 '${mainnetDir}/admin.macaroon')" \ -H "Grpc-Metadata-macaroon: $(${pkgs.xxd}/bin/xxd -ps -u -c 99999 '${networkDir}/admin.macaroon')" \
--cacert ${secretsDir}/lnd-cert \ --cacert ${secretsDir}/lnd-cert \
-X POST \ -X POST \
-d "{\"wallet_password\": \"$(cat ${secretsDir}/lnd-wallet-password | tr -d '\n' | base64 -w0)\"}" \ -d "{\"wallet_password\": \"$(cat ${secretsDir}/lnd-wallet-password | tr -d '\n' | base64 -w0)\"}" \
@ -244,7 +245,7 @@ in {
echo "Create custom macaroon ${macaroon}" echo "Create custom macaroon ${macaroon}"
macaroonPath="$RUNTIME_DIRECTORY/${macaroon}.macaroon" macaroonPath="$RUNTIME_DIRECTORY/${macaroon}.macaroon"
${pkgs.curl}/bin/curl -s \ ${pkgs.curl}/bin/curl -s \
-H "Grpc-Metadata-macaroon: $(${pkgs.xxd}/bin/xxd -ps -u -c 99999 '${mainnetDir}/admin.macaroon')" \ -H "Grpc-Metadata-macaroon: $(${pkgs.xxd}/bin/xxd -ps -u -c 99999 '${networkDir}/admin.macaroon')" \
--cacert ${secretsDir}/lnd-cert \ --cacert ${secretsDir}/lnd-cert \
-X POST \ -X POST \
-d '{"permissions":[${cfg.macaroons.${macaroon}.permissions}]}' \ -d '{"permissions":[${cfg.macaroons.${macaroon}.permissions}]}' \

View File

@ -267,10 +267,7 @@ in {
}; };
systemd.services.bitcoind-import-banlist.serviceConfig.NetworkNamespacePath = "/var/run/netns/nb-bitcoind"; systemd.services.bitcoind-import-banlist.serviceConfig.NetworkNamespacePath = "/var/run/netns/nb-bitcoind";
services.clightning = { services.clightning.bind-addr = netns.clightning.address;
bitcoin-rpcconnect = netns.bitcoind.address;
bind-addr = netns.clightning.address;
};
services.lnd = { services.lnd = {
listen = netns.lnd.address; listen = netns.lnd.address;
@ -282,7 +279,6 @@ in {
"${netns.lnd.address}" "${netns.lnd.address}"
"127.0.0.1" "127.0.0.1"
]; ];
bitcoind-host = netns.bitcoind.address;
cliExec = mkCliExec "lnd"; cliExec = mkCliExec "lnd";
}; };

View File

@ -6,19 +6,21 @@ let
cfg = config.services.spark-wallet; cfg = config.services.spark-wallet;
inherit (config) nix-bitcoin-services; inherit (config) nix-bitcoin-services;
onion-chef-service = (if cfg.onion-service then [ "onion-chef.service" ] else []); onion-chef-service = (if cfg.onion-service then [ "onion-chef.service" ] else []);
run-spark-wallet = pkgs.writeScript "run-spark-wallet" ''
CMD="${pkgs.nix-bitcoin.spark-wallet}/bin/spark-wallet --ln-path ${cfg.ln-path} --host ${cfg.host} -Q -k -c ${config.nix-bitcoin.secretsDir}/spark-wallet-login ${cfg.extraArgs}" # Use wasabi rate provider because the default (bitstamp) doesn't accept
${optionalString cfg.onion-service # connections through Tor
'' torRateProvider = "--rate-provider wasabi --proxy socks5h://${config.services.tor.client.socksListenAddress}";
echo Getting onion hostname startScript = ''
CMD="$CMD --public-url http://$(cat /var/lib/onion-chef/spark-wallet/spark-wallet)" ${optionalString cfg.onion-service ''
'' publicURL="--public-url http://$(cat /var/lib/onion-chef/spark-wallet/spark-wallet)"
} ''}
# Use rate provide wasabi because default (bitstamp) doesn't accept exec ${pkgs.nix-bitcoin.spark-wallet}/bin/spark-wallet \
# connections through Tor and add proxy for rate lookup. --ln-path '${config.services.clightning.networkDir}' \
CMD="$CMD --rate-provider wasabi --proxy socks5h://${config.services.tor.client.socksListenAddress}" --host ${cfg.host} \
echo Running $CMD --config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \
$CMD ${optionalString cfg.enforceTor torRateProvider} \
$publicURL \
--pairing-qr --print-key ${cfg.extraArgs}
''; '';
in { in {
options.services.spark-wallet = { options.services.spark-wallet = {
@ -34,13 +36,6 @@ in {
default = "localhost"; default = "localhost";
description = "http(s) server listen address."; description = "http(s) server listen address.";
}; };
ln-path = mkOption {
type = types.path;
default = "${config.services.clightning.dataDir}/bitcoin";
description = ''
"The path of the clightning network data directory.";
'';
};
onion-service = mkOption { onion-service = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
@ -84,8 +79,8 @@ in {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
requires = [ "clightning.service" ] ++ onion-chef-service; requires = [ "clightning.service" ] ++ onion-chef-service;
after = [ "clightning.service" ] ++ onion-chef-service; after = [ "clightning.service" ] ++ onion-chef-service;
script = startScript;
serviceConfig = nix-bitcoin-services.defaultHardening // { serviceConfig = nix-bitcoin-services.defaultHardening // {
ExecStart = "${pkgs.bash}/bin/bash ${run-spark-wallet}";
User = "spark-wallet"; User = "spark-wallet";
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "10s"; RestartSec = "10s";

View File

@ -181,6 +181,7 @@ all() {
scenario=default buildTest "$@" scenario=default buildTest "$@"
scenario=netns buildTest "$@" scenario=netns buildTest "$@"
scenario=full buildTest "$@" scenario=full buildTest "$@"
scenario=regtest buildTest "$@"
} }
build() { build() {

View File

@ -52,6 +52,7 @@ let testEnv = rec {
environment.systemPackages = mkIfTest "btcpayserver" (with pkgs; [ openssl xxd ]); environment.systemPackages = mkIfTest "btcpayserver" (with pkgs; [ openssl xxd ]);
tests.joinmarket = cfg.joinmarket.enable; tests.joinmarket = cfg.joinmarket.enable;
tests.joinmarket-yieldgenerator = cfg.joinmarket.yieldgenerator.enable;
services.joinmarket.yieldgenerator = { services.joinmarket.yieldgenerator = {
enable = config.services.joinmarket.enable; enable = config.services.joinmarket.enable;
customParameters = '' customParameters = ''
@ -104,6 +105,9 @@ let testEnv = rec {
services.nix-bitcoin-webindex.enable = true; services.nix-bitcoin-webindex.enable = true;
tests.secure-node = true; tests.secure-node = true;
tests.banlist-and-restart = true; tests.banlist-and-restart = true;
# Stop electrs from spamming the test log with 'WARN - wait until IBD is over' messages
tests.stop-electrs = true;
}; };
netns = { netns = {
@ -116,6 +120,38 @@ let testEnv = rec {
tests.backups = mkForce false; tests.backups = mkForce false;
}; };
# All regtest-enabled services
regtest = {
imports = [ scenarios.regtestBase ];
services.clightning.enable = true;
services.spark-wallet.enable = true;
services.lnd.enable = true;
services.lightning-loop.enable = true;
services.electrs.enable = true;
services.btcpayserver.enable = true;
services.joinmarket.enable = true;
};
regtestBase = {
tests.regtest = true;
services.bitcoind.regtest = true;
systemd.services.bitcoind.postStart = mkAfter ''
cli=${config.services.bitcoind.cli}/bin/bitcoin-cli
address=$($cli getnewaddress)
$cli generatetoaddress 10 $address
'';
# lightning-loop contains no builtin swap server for regtest.
# Add a dummy definition.
services.lightning-loop.extraConfig = ''
server.host=localhost
'';
# Needs wallet support which is unavailable for regtest
services.joinmarket.yieldgenerator.enable = mkForce false;
};
## Examples / debug helper ## Examples / debug helper
# Run a selection of tests in scenario 'netns' # Run a selection of tests in scenario 'netns'

View File

@ -111,14 +111,18 @@ def _():
) )
# Impure: Stops electrs
@test("electrs") @test("electrs")
def _(): def _():
assert_running("electrs") assert_running("electrs")
wait_for_open_port(ip("electrs"), 4224) # prometeus metrics provider wait_for_open_port(ip("electrs"), 4224) # prometeus metrics provider
# Check RPC connection to bitcoind # Check RPC connection to bitcoind
machine.wait_until_succeeds(log_has_string("electrs", "NetworkInfo")) machine.wait_until_succeeds(log_has_string("electrs", "NetworkInfo"))
# Stop electrs from spamming the test log with 'wait for bitcoind sync' messages
# Impure: Stops electrs
# Stop electrs from spamming the test log with 'WARN - wait until IBD is over' messages
@test("stop-electrs")
def _():
succeed("systemctl stop electrs") succeed("systemctl stop electrs")
@ -206,6 +210,10 @@ def _():
machine.wait_until_succeeds( machine.wait_until_succeeds(
log_has_string("joinmarket", "P2EPDaemonServerProtocolFactory starting on 27184") log_has_string("joinmarket", "P2EPDaemonServerProtocolFactory starting on 27184")
) )
@test("joinmarket-yieldgenerator")
def _():
machine.wait_until_succeeds( machine.wait_until_succeeds(
log_has_string("joinmarket-yieldgenerator", "Failure to get blockheight",) log_has_string("joinmarket-yieldgenerator", "Failure to get blockheight",)
) )
@ -318,6 +326,27 @@ def _():
assert_no_failure("bitcoind-import-banlist") assert_no_failure("bitcoind-import-banlist")
@test("regtest")
def _():
if "electrs" in enabled_tests:
machine.wait_until_succeeds(log_has_string("electrs", "BlockchainInfo"))
get_block_height_cmd = (
"""echo '{"method": "blockchain.headers.subscribe", "id": 0, "params": []}'"""
f" | nc -N {ip('electrs')} 50001 | jq -M .result.height"
)
assert_full_match(get_block_height_cmd, "10\n")
if "clightning" in enabled_tests:
machine.wait_until_succeeds(
"[[ $(sudo -u operator lightning-cli getinfo | jq -M .blockheight) == 10 ]]"
)
if "lnd" in enabled_tests:
machine.wait_until_succeeds(
"[[ $(sudo -u operator lncli getinfo | jq -M .block_height) == 10 ]]"
)
if "lightning-loop" in enabled_tests:
machine.wait_until_succeeds(log_has_string("lightning-loop", "Connected to lnd node"))
if "netns-isolation" in enabled_tests: if "netns-isolation" in enabled_tests:
def ip(name): def ip(name):