From 22c5a2e43f134e84633e7ec10a2f362e98d9796a Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 7 Jun 2024 11:48:56 +0200 Subject: [PATCH 1/5] Update lightningd to v24.05 --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b9a8c66..4030da7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: ipv4_address: 172.30.1.3 cln1: - image: elementsproject/lightningd:v24.02 + image: elementsproject/lightningd:v24.05 restart: unless-stopped depends_on: - bitcoind @@ -96,7 +96,7 @@ services: ipv4_address: 172.30.2.2 cln2: - image: elementsproject/lightningd:v24.02 + image: elementsproject/lightningd:v24.05 restart: unless-stopped depends_on: - bitcoind @@ -125,7 +125,7 @@ services: - "./conf/eclair/logback-custom.xml:/data/logback-custom.xml" cln3: - image: elementsproject/lightningd:v24.02 + image: elementsproject/lightningd:v24.05 restart: unless-stopped depends_on: - bitcoind From 56434716c6ca9a7598f16150dc792d1ee2abb4c9 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 7 Jun 2024 11:54:41 +0200 Subject: [PATCH 2/5] Update lnd to v0.18.0-beta.1 --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4030da7..6d04d92 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: - "./conf/bitcoind/bitcoin.conf:/data/.bitcoin/bitcoin.conf" lnd1: - build: ./docker/lnd + image: lightninglabs/lnd:v0.18.0-beta.1 restart: unless-stopped depends_on: - bitcoind @@ -68,7 +68,7 @@ services: - "./conf/eclair/logback-custom.xml:/data/logback-custom.xml" lnd2: - build: ./docker/lnd + image: lightninglabs/lnd:v0.18.0-beta.1 restart: unless-stopped depends_on: - bitcoind From 345bbc5ed73731b345f4c29c4396dc5ef5d4f318 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 7 Jun 2024 11:55:07 +0200 Subject: [PATCH 3/5] Update lnzap/eclair to v0.10.0.strike.2 --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6d04d92..5155a83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,7 +53,7 @@ services: - "./conf/cln/config:/root/.lightning/config" eclair1: - build: ./docker/eclair + image: lnzap/eclair:v0.10.0.strike.2 restart: unless-stopped depends_on: - bitcoind @@ -110,7 +110,7 @@ services: - "./conf/cln/config:/root/.lightning/config" eclair2: - build: ./docker/eclair + image: lnzap/eclair:v0.10.0.strike.2 restart: unless-stopped depends_on: - bitcoind @@ -139,7 +139,7 @@ services: - "./conf/cln/config:/root/.lightning/config" eclair3: - build: ./docker/eclair + image: lnzap/eclair:v0.10.0.strike.2 restart: unless-stopped depends_on: - bitcoind From d720afd3e681fb55b0cf6d56756ace35f95a3a76 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 7 Jun 2024 13:05:44 +0200 Subject: [PATCH 4/5] Resolve bitcoind/cln startup race condition --- docker-compose.yml | 46 +++++++++++++++++++-------------- docker/cln/wait-for-bitcoind.sh | 16 ++++++++++++ scripts/init.sh | 16 +++++++++--- 3 files changed, 54 insertions(+), 24 deletions(-) create mode 100755 docker/cln/wait-for-bitcoind.sh diff --git a/docker-compose.yml b/docker-compose.yml index 5155a83..8442af0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,8 +32,8 @@ services: environment: - RUST_BACKTRACE=1 volumes: - - "lnd1:/root/.lnd" - "lndk1:/root/.lndk" + - "lnd1:/root/.lnd:ro" networks: testing_net: ipv4_address: 172.30.1.3 @@ -46,14 +46,16 @@ services: networks: testing_net: ipv4_address: 172.30.1.30 - command: --network=regtest --addr=0.0.0.0:9735 --announce-addr=172.30.1.30:9735 --developer --dev-fast-gossip --dev-bitcoind-poll=2 --alias=cln1 --rgb=FF0000 + entrypoint: ["/wait-for-bitcoind.sh"] + command: --network=regtest --addr=0.0.0.0:9735 --announce-addr=172.30.1.30:9735 --bitcoin-retry-timeout=180 --developer --dev-fast-gossip --dev-bitcoind-poll=2 --alias=cln1 --rgb=FF0000 volumes: - "cln1:/root/.lightning" - - "bitcoind:/root/.lightning/bitcoin" + - "bitcoind:/root/.lightning/bitcoin:ro" - "./conf/cln/config:/root/.lightning/config" + - "./docker/cln/wait-for-bitcoind.sh:/wait-for-bitcoind.sh" eclair1: - image: lnzap/eclair:v0.10.0.strike.2 + image: lnzap/eclair:0.10.0.strike.2 restart: unless-stopped depends_on: - bitcoind @@ -61,11 +63,11 @@ services: testing_net: ipv4_address: 172.30.1.31 environment: - - JAVA_OPTS=-Declair.printToConsole -Dakka.loglevel=DEBUG -Dlogback.configurationFile=/data/logback-custom.xml + - JAVA_OPTS=-Declair.printToConsole -Dakka.loglevel=DEBUG -Dlogback.configurationFile=/eclair/logback-custom.xml volumes: - "eclair1:/data" - - "./conf/eclair/eclair1.conf:/data/eclair.conf" - - "./conf/eclair/logback-custom.xml:/data/logback-custom.xml" + - "./conf/eclair/eclair1.conf:/eclair/eclair.conf" + - "./conf/eclair/logback-custom.xml:/eclair/logback-custom.xml" lnd2: image: lightninglabs/lnd:v0.18.0-beta.1 @@ -89,8 +91,8 @@ services: environment: - RUST_BACKTRACE=1 volumes: - - "lnd2:/root/.lnd" - "lndk2:/root/.lndk" + - "lnd2:/root/.lnd:ro" networks: testing_net: ipv4_address: 172.30.2.2 @@ -103,14 +105,16 @@ services: networks: testing_net: ipv4_address: 172.30.2.30 - command: --network=regtest --addr=0.0.0.0:9735 --announce-addr=172.30.2.30:9735 --developer --dev-fast-gossip --dev-bitcoind-poll=2 --alias=cln2 --rgb=FF0000 + entrypoint: ["/wait-for-bitcoind.sh"] + command: --network=regtest --addr=0.0.0.0:9735 --announce-addr=172.30.2.30:9735 --bitcoin-retry-timeout=180 --developer --dev-fast-gossip --dev-bitcoind-poll=2 --alias=cln2 --rgb=FF0000 volumes: - "cln2:/root/.lightning" - - "bitcoind:/root/.lightning/bitcoin" + - "bitcoind:/root/.lightning/bitcoin:ro" - "./conf/cln/config:/root/.lightning/config" + - "./docker/cln/wait-for-bitcoind.sh:/wait-for-bitcoind.sh" eclair2: - image: lnzap/eclair:v0.10.0.strike.2 + image: lnzap/eclair:0.10.0.strike.2 restart: unless-stopped depends_on: - bitcoind @@ -118,11 +122,11 @@ services: testing_net: ipv4_address: 172.30.2.31 environment: - - JAVA_OPTS=-Declair.printToConsole -Dakka.loglevel=DEBUG -Dlogback.configurationFile=/data/logback-custom.xml + - JAVA_OPTS=-Declair.printToConsole -Dakka.loglevel=DEBUG -Dlogback.configurationFile=/eclair/logback-custom.xml volumes: - "eclair2:/data" - - "./conf/eclair/eclair2.conf:/data/eclair.conf" - - "./conf/eclair/logback-custom.xml:/data/logback-custom.xml" + - "./conf/eclair/eclair2.conf:/eclair/eclair.conf" + - "./conf/eclair/logback-custom.xml:/eclair/logback-custom.xml" cln3: image: elementsproject/lightningd:v24.05 @@ -132,14 +136,16 @@ services: networks: testing_net: ipv4_address: 172.30.3.30 - command: --network=regtest --addr=0.0.0.0:9735 --announce-addr=172.30.3.30:9735 --developer --dev-fast-gossip --dev-bitcoind-poll=2 --alias=cln3 --rgb=FF0000 + entrypoint: ["/wait-for-bitcoind.sh"] + command: --network=regtest --addr=0.0.0.0:9735 --announce-addr=172.30.3.30:9735 --bitcoin-retry-timeout=180 --developer --dev-fast-gossip --dev-bitcoind-poll=2 --alias=cln3 --rgb=FF0000 volumes: - "cln3:/root/.lightning" - - "bitcoind:/root/.lightning/bitcoin" + - "bitcoind:/root/.lightning/bitcoin:ro" - "./conf/cln/config:/root/.lightning/config" + - "./docker/cln/wait-for-bitcoind.sh:/wait-for-bitcoind.sh" eclair3: - image: lnzap/eclair:v0.10.0.strike.2 + image: lnzap/eclair:0.10.0.strike.2 restart: unless-stopped depends_on: - bitcoind @@ -147,11 +153,11 @@ services: testing_net: ipv4_address: 172.30.3.31 environment: - - JAVA_OPTS=-Declair.printToConsole -Dakka.loglevel=DEBUG -Dlogback.configurationFile=/data/logback-custom.xml + - JAVA_OPTS=-Declair.printToConsole -Dakka.loglevel=DEBUG -Dlogback.configurationFile=/eclair/logback-custom.xml volumes: - "eclair3:/data" - - "./conf/eclair/eclair3.conf:/data/eclair.conf" - - "./conf/eclair/logback-custom.xml:/data/logback-custom.xml" + - "./conf/eclair/eclair3.conf:/eclair/eclair.conf" + - "./conf/eclair/logback-custom.xml:/eclair/logback-custom.xml" blockgen: build: ./docker/blockgen diff --git a/docker/cln/wait-for-bitcoind.sh b/docker/cln/wait-for-bitcoind.sh new file mode 100755 index 0000000..1f32acf --- /dev/null +++ b/docker/cln/wait-for-bitcoind.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Function to check if bitcoind is ready +is_bitcoind_ready() { + bitcoin-cli -rpcconnect=bitcoind -rpcport=43782 -rpcuser=user -rpcpassword=pass -conf=/root/.lightning/bitcoin/bitcoin.conf getblockchaininfo &> /dev/null + return $? +} + +# Wait for bitcoind to be ready +until is_bitcoind_ready; do + echo "Waiting for bitcoind to be ready..." + sleep 5 +done + +# Start cln +exec lightningd "$@" \ No newline at end of file diff --git a/scripts/init.sh b/scripts/init.sh index 5b5c879..77bc5cb 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -69,10 +69,12 @@ initBitcoinChain() { mineBlocks $BITCOIN_ADDRESS 103 } -generateAddresses() { +generateBitcoinAddress() { BITCOIN_ADDRESS=$(bitcoind getnewaddress) echo BITCOIN_ADDRESS: $BITCOIN_ADDRESS +} +generateNodeAddresses() { LND1_ADDRESS=$(lnd1 newaddress p2wkh | jq -r .address) echo LND1_ADDRESS: $LND1_ADDRESS @@ -239,9 +241,13 @@ openChannel() { mineBlocks $BITCOIN_ADDRESS 10 } -waitForNodes() { + +waitBitcoind() { waitFor bitcoind getnetworkinfo +} + +waitForNodes() { waitFor lnd1 getinfo waitFor cln1 getinfo waitFor eclair1 getinfo @@ -255,11 +261,13 @@ waitForNodes() { } main() { + waitBitcoind createBitcoindWallet + generateBitcoinAddress + initBitcoinChain waitForNodes - generateAddresses + generateNodeAddresses getNodeInfo - initBitcoinChain fundNodes openChannel } From 04b166a00907e2dba20b3bb5a7abdc7e5d39668a Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 7 Jun 2024 13:09:22 +0200 Subject: [PATCH 5/5] Add node about startup sequence --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c30c356..ac91e79 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ docker compose up This script sets up a network of nodes and channels for the Lightning Network. The nodes are instances of different Lightning Network implementations, including LND, c-lightning (CLN), and Eclair. +***NOTE: the init script must be run no later than 60 seconds after starting the nodes, otherwise nodes may crash due to an uninitialised blockchain*** + ### Nodes The script sets up eight nodes: