From 02853067a14068b6f3b076da5a72f64658883307 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Tue, 21 Jul 2020 10:08:24 +0000 Subject: [PATCH] bitcoind: postStart wait until bitcoind can receive rpc calls --- modules/bitcoind.nix | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index fd15040..433fc70 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -260,8 +260,8 @@ in { default = cfg.cli-nonetns-exec; description = "Binary to connect with the bitcoind instance."; }; - # Needed because bitcoind-import-banlist already executes inside - # nb-bitcoind, hence it doesn't need netns-exec prefixed. + # Needed because bitcoin-cli commands executed through systemd already + # run inside nb-bitcoind, hence they don't need netns-exec prefixed. cli-nonetns-exec = mkOption { readOnly = true; type = types.package; @@ -303,10 +303,11 @@ in { install -o '${cfg.user}' -g '${cfg.group}' -m 640 <(echo "$cfg") $confFile fi ''; - # Wait until RPC port is open. This usually takes just a few ms. postStart = '' - while ! { exec 3>/dev/tcp/127.0.0.1/${toString cfg.rpc.port}; } &>/dev/null; do - sleep 0.05 + cd ${cfg.cli-nonetns-exec}/bin + # Poll until bitcoind accepts commands. This can take a long time. + while ! ./bitcoin-cli getnetworkinfo &> /dev/null; do + sleep 1 done ''; serviceConfig = nix-bitcoin-services.defaultHardening // { @@ -331,10 +332,6 @@ in { after = [ "bitcoind.service" ]; script = '' cd ${cfg.cli-nonetns-exec}/bin - # Poll until bitcoind accepts commands. This can take a long time. - while ! ./bitcoin-cli getnetworkinfo &> /dev/null; do - sleep 1 - done echo "Importing node banlist..." cat ${./banlist.cli.txt} | while read line; do if ! err=$(eval "$line" 2>&1) && [[ $err != *already\ banned* ]]; then