diff --git a/dev/bin/init-lightning.sh b/dev/bin/init-lightning.sh index ef9e85cb3a..5750cefc3c 100755 --- a/dev/bin/init-lightning.sh +++ b/dev/bin/init-lightning.sh @@ -24,6 +24,25 @@ retry() { false } +run_with_lnd() { + local func_name="$1" + shift # This will shift away the function name, so $1 becomes the next argument + + if [[ "$func_name" == "lnd_cli" ]]; then + lnd_cli "$@" + elif [[ "$func_name" == "lnd_outside_cli" ]]; then + lnd_outside_cli "$@" + else + echo "Invalid function name passed!" && return 1 + fi +} + +lnd_is_ready() { + run_with_lnd "$1" getinfo + return "$?" +} + + mempool_not_empty() { echo "Waiting for txn to show up in mempool..." local txid="$(bitcoin_cli getrawmempool | jq -r ".[0]")" @@ -66,9 +85,11 @@ echo "Funded with txid: ${funded_txid}" # Open channel from lndoutside1 -> lnd1 echo "Opening channel: lndoutside1 -> lnd1..." +retry 30 1 lnd_is_ready lnd_cli pubkey_lnd1="$(lnd_cli getinfo | jq -r '.identity_pubkey')" endpoint_lnd1="${COMPOSE_PROJECT_NAME}-lnd1-1:9735" -lnd_outside_cli connect "${pubkey_lnd1}@${endpoint_lnd1}" > /dev/null 2>&1 || true +echo "CONNECTING 1..." +lnd_outside_cli connect "${pubkey_lnd1}@${endpoint_lnd1}" || true retry 30 1 synced_to_graph funding_txid=$(lnd_outside_cli openchannel \ --node_key "$pubkey_lnd1" \ @@ -89,7 +110,8 @@ echo "Channel ${funding_txid} confirmed" echo "Opening balanced channel: lndoutside1 -> lndoutside2..." pubkey_lnd_outside_2="$(lnd_outside_2_cli getinfo | jq -r '.identity_pubkey')" endpoint_lnd_outside_2="${COMPOSE_PROJECT_NAME}-lnd-outside-2-1:9735" -lnd_outside_cli connect "${pubkey_lnd_outside_2}@${endpoint_lnd_outside_2}" > /dev/null 2>&1 || true +echo "CONNECTING 2..." +lnd_outside_cli connect "${pubkey_lnd_outside_2}@${endpoint_lnd_outside_2}" || true retry 30 1 synced_to_graph funding_txid=$(lnd_outside_cli openchannel \ --node_key "$pubkey_lnd_outside_2" \