diff --git a/README.md b/README.md index 54d10df..006529b 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,40 @@ docker volume create lightning_data docker compose up --build ``` +## Using Bitcoin Chains + +We have three possible overrides over the default `testnet` configuration in `docker-compose.yml`: +- `docker-compose.testnet.yml` +- `docker-compose.regtest.yml` +- `docker-compose.mainnet.yml` + +To use override we have to pass it down both the config using `-f` flag: +``` +docker compose -f docker-compose.yml -f up --build +``` + +__Note__: Even while using `testnet` running using the override is recommended as that will expose the `P2P` port for `bitcoind` and `P2P` port for `lightningd` on the host. + +## Additional Regtest Commands + +We have to run these commands after bitcoind is up and running. + +Create Wallet: +``` +docker container exec -it bitcoind bitcoin-cli createwallet default +``` + +Generate Address for node: +``` +docker container exec -it bitcoind bitcoin-cli getnewaddress +``` + +Generate Blocks +``` +docker container exec -it bitcoind bitcoin-cli generatetoaddress 50 $NODE_ADDRESS + +``` + ### References - [bitcoind](https://github.com/ruimarinho/docker-bitcoin-core/blob/master/23/alpine/Dockerfile) by @ruimarinho diff --git a/assets/bitcoin.conf b/assets/bitcoin.conf index f4aa604..0a3978c 100644 --- a/assets/bitcoin.conf +++ b/assets/bitcoin.conf @@ -2,15 +2,29 @@ ## bitcoin.conf configuration file. Lines beginning with # are comments. ## -[test] server=1 +rpcallowip=0.0.0.0/0 +whitelist=0.0.0.0/0 +txindex=1 +blockfilterindex=1 + +[main] +rpcbind=0.0.0.0 +rpcuser=rpcuser +rpcpassword=VLSsigner1 +rpcport=8332 +port=8333 + +[test] +rpcbind=0.0.0.0 rpcuser=rpcuser rpcpassword=VLSsigner1 rpcport=18332 +port=18333 + +[regtest] rpcbind=0.0.0.0 -rpcallowip=0.0.0.0/0 -whitelist=0.0.0.0/0 -zmqpubrawblock=tcp://bitcoind:38332 -zmqpubrawtx=tcp://bitcoind:38333 -txindex=1 -blockfilterindex=1 \ No newline at end of file +rpcuser=rpcuser +rpcpassword=VLSsigner1 +rpcport=38332 +port=38333 \ No newline at end of file diff --git a/assets/main-config b/assets/main-config new file mode 100644 index 0000000..95d6daa --- /dev/null +++ b/assets/main-config @@ -0,0 +1,9 @@ +network=regtest +bitcoin-rpcuser=rpcuser +bitcoin-rpcpassword=VLSsigner1 +bitcoin-rpcport=8332 +log-level=info +max-locktime-blocks=288 +important-plugin=/usr/bin/clboss +clboss-auto-close=true +bind-addr=0.0.0.0:9735 \ No newline at end of file diff --git a/assets/main-env b/assets/main-env new file mode 100644 index 0000000..bad59e7 --- /dev/null +++ b/assets/main-env @@ -0,0 +1,4 @@ +VLS_PORT=17701 +VLS_NETWORK=regtest +BITCOIND_RPC_URL=http://rpcuser:VLSsigner1@bitcoind:8332 +RUST_LOG=info \ No newline at end of file diff --git a/assets/regtest-config b/assets/regtest-config new file mode 100644 index 0000000..545c024 --- /dev/null +++ b/assets/regtest-config @@ -0,0 +1,9 @@ +network=regtest +bitcoin-rpcuser=rpcuser +bitcoin-rpcpassword=VLSsigner1 +bitcoin-rpcport=38332 +log-level=info +max-locktime-blocks=288 +important-plugin=/usr/bin/clboss +clboss-auto-close=true +bind-addr=0.0.0.0:19846 \ No newline at end of file diff --git a/assets/regtest-env b/assets/regtest-env new file mode 100644 index 0000000..a21ee38 --- /dev/null +++ b/assets/regtest-env @@ -0,0 +1,4 @@ +VLS_PORT=17701 +VLS_NETWORK=regtest +BITCOIND_RPC_URL=http://rpcuser:VLSsigner1@bitcoind:38332 +RUST_LOG=info \ No newline at end of file diff --git a/assets/testnet-config b/assets/testnet-config index 3980616..06f71f8 100644 --- a/assets/testnet-config +++ b/assets/testnet-config @@ -5,4 +5,5 @@ bitcoin-rpcport=18332 log-level=info max-locktime-blocks=288 important-plugin=/usr/bin/clboss -clboss-auto-close=true \ No newline at end of file +clboss-auto-close=true +bind-addr=0.0.0.0:19735 \ No newline at end of file diff --git a/bitcoind/Dockerfile b/bitcoind/Dockerfile index d0753d3..feb830d 100644 --- a/bitcoind/Dockerfile +++ b/bitcoind/Dockerfile @@ -46,8 +46,8 @@ RUN set -ex \ done && \ wget -O- https://raw.githubusercontent.com/Kvaciral/kvaciral/main/kvaciral.asc | gpg --import -ENV BITCOIN_VERSION=23.0 -ENV BITCOIN_PREFIX=/opt/bitcoin-${BITCOIN_VERSION} +ARG BITCOIN_VERSION=23.0 +ARG BITCOIN_PREFIX=/opt/bitcoin-${BITCOIN_VERSION} ARG SHA256SUMS_HASH=aaff81ea001f499e8f6f3221387d7db960d71a3b7a4a2b1aaf2c8060bc94a391 RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS @@ -121,8 +121,6 @@ RUN chmod +x /healthcheck.sh VOLUME ["${BITCOIN_DATA}"] -EXPOSE 8332 8333 18332 18333 18444 - RUN mkdir -p "${BITCOIN_DATA}" RUN chown -R bitcoin:bitcoin "${BITCOIN_DATA}" diff --git a/bitcoind/entrypoint.sh b/bitcoind/entrypoint.sh index 1e49f65..9f01595 100755 --- a/bitcoind/entrypoint.sh +++ b/bitcoind/entrypoint.sh @@ -1,7 +1,8 @@ #!/bin/sh set -e -cp -u /bitcoin.conf $BITCOIN_DATA/ +cp /bitcoin.conf $BITCOIN_DATA/ +sed -i "1s/^/chain=$BITCOIN_CHAIN\n/" $BITCOIN_DATA/bitcoin.conf if [ $(echo "$1" | cut -c1) = "-" ]; then echo "$0: assuming arguments for bitcoind" @@ -9,5 +10,11 @@ if [ $(echo "$1" | cut -c1) = "-" ]; then set -- bitcoind "$@" fi +if [ $(echo "$1" | cut -c1) = "-" ] || [ "$1" = "bitcoind" ]; then + echo "$0: setting chain to $BITCOIN_CHAIN" + + set -- "$@" -chain=$BITCOIN_CHAIN +fi + echo -exec "$@" \ No newline at end of file +exec "$@" diff --git a/bitcoind/healthcheck.sh b/bitcoind/healthcheck.sh index 593bf1b..d8b421a 100755 --- a/bitcoind/healthcheck.sh +++ b/bitcoind/healthcheck.sh @@ -1 +1 @@ -bitcoin-cli --chain=$BITCOIN_CHAIN getblockchaininfo \ No newline at end of file +bitcoin-cli -chain=$BITCOIN_CHAIN getblockchaininfo \ No newline at end of file diff --git a/docker-compose.mainnet.yml b/docker-compose.mainnet.yml new file mode 100644 index 0000000..6806566 --- /dev/null +++ b/docker-compose.mainnet.yml @@ -0,0 +1,25 @@ +version: "3.8" +name: main +services: + bitcoin-core: + container_name: bitcoind-main + expose: + - 8332 + ports: + - 8333:8333 + environment: + - BITCOIN_CHAIN=main + + core-lightning: + container_name: lightningd-main + command: + - --conf=/home/lightning/.lightning/main-config + - --bitcoin-rpcconnect=bitcoind + expose: + - 9735 + ports: + - 9735:9735 + env_file: + - ./assets/main-env + environment: + - BITCOIN_CHAIN=main \ No newline at end of file diff --git a/docker-compose.regtest.yml b/docker-compose.regtest.yml new file mode 100644 index 0000000..46134c6 --- /dev/null +++ b/docker-compose.regtest.yml @@ -0,0 +1,25 @@ +version: "3.8" +name: regtest +services: + bitcoin-core: + container_name: bitcoind-regtest + expose: + - 38332 + ports: + - 38333:38333 + environment: + - BITCOIN_CHAIN=regtest + + core-lightning: + container_name: lightningd-regtest + command: + - --conf=/home/lightning/.lightning/regtest-config + - --bitcoin-rpcconnect=bitcoind + expose: + - 19846 + ports: + - 19846:19846 + env_file: + - ./assets/regtest-env + environment: + - BITCOIN_CHAIN=regtest \ No newline at end of file diff --git a/docker-compose.testnet.yml b/docker-compose.testnet.yml new file mode 100644 index 0000000..250495a --- /dev/null +++ b/docker-compose.testnet.yml @@ -0,0 +1,10 @@ +version: "3.8" +name: testnet +services: + bitcoin-core: + ports: + - 18333:18333 + + core-lightning: + ports: + - 19735:19735 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b1e6ddb..8760f56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,22 +4,11 @@ services: build: dockerfile: ./bitcoind/Dockerfile image: bitcoind - container_name: bitcoind - command: - - --testnet - - -pid=/home/bitcoin/.bitcoin/testnet3/bitcoind-testnet.pid + container_name: bitcoind-test volumes: - data:/home/bitcoin/.bitcoin expose: - - 8332 - - 8333 - 18332 - - 18333 - - 18444 - ports: - - 8333:8333 - - 18333:18333 - - 38333:38333 networks: LN_testing: aliases: @@ -31,31 +20,24 @@ services: build: dockerfile: ./lightningd/Dockerfile image: lightningd - container_name: lightningd + container_name: lightningd-test command: - --conf=/home/lightning/.lightning/testnet-config - --bitcoin-rpcconnect=bitcoind - - --bind-addr=core-lightning:19735 - - --announce-addr=core-lightning:19735 volumes: - clightning:/home/lightning/.lightning expose: - - 9735 - - 9835 - ports: - - 9735:9735 - - 19735:19735 + - 19735 networks: - LN_testing - links: - - bitcoin-core:bitcoind depends_on: bitcoin-core: condition: service_healthy restart: true env_file: - ./assets/testnet-env - + environment: + - BITCOIN_CHAIN=test volumes: data: @@ -66,4 +48,4 @@ volumes: external: true networks: - LN_testing: \ No newline at end of file + LN_testing: diff --git a/lightningd/Dockerfile b/lightningd/Dockerfile index d8df184..e831aee 100644 --- a/lightningd/Dockerfile +++ b/lightningd/Dockerfile @@ -68,15 +68,13 @@ RUN apk update && \ sqlite-dev ARG LIGHTNINGD_UID=101 -ENV LIGHTNINGD_USER=lightning -ENV LIGHTNINGD_HOME=/home/${LIGHTNINGD_USER} +ARG LIGHTNINGD_USER=lightning +ARG LIGHTNINGD_HOME=/home/${LIGHTNINGD_USER} ENV LIGHTNINGD_DATA=${LIGHTNINGD_HOME}/.lightning \ LIGHTNINGD_RPC_PORT=9835 \ LIGHTNINGD_PORT=9735 \ BITCOIND_HOME=/root/.bitcoin -COPY lightningd/entrypoint.sh /entrypoint.sh - COPY --from=builder /usr/bin/lightningd /usr/bin/ COPY --from=builder /usr/bin/lightning-cli /usr/bin/ COPY --from=builder /usr/bin/lightning-hsmtool /usr/bin/ @@ -87,8 +85,15 @@ COPY --from=builder /usr/bin/clboss /usr/bin/clboss RUN addgroup -S lightning && adduser -S lightning -G lightning && \ mkdir -p ${LIGHTNINGD_DATA} && \ - touch ${LIGHTNINGD_DATA}/config && \ - chown -R lightning:lightning "${LIGHTNINGD_DATA}" + chown -R lightning:lightning ${LIGHTNINGD_DATA} + +COPY assets/bitcoin.conf "${BITCOIND_HOME}"/bitcoin.conf + +COPY lightningd/entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +COPY lightningd/healthcheck.sh /healthcheck.sh +RUN chmod +x /healthcheck.sh VOLUME ["${LIGHTNINGD_DATA}"] @@ -97,11 +102,13 @@ RUN mkdir -p "${BITCOIND_HOME}" && \ COPY assets/bitcoin.conf "${BITCOIND_HOME}"/bitcoin.conf COPY assets/testnet-config /testnet-config +COPY assets/regtest-config /regtest-config +COPY assets/main-config /main-config USER lightning -HEALTHCHECK --interval=30s --timeout=10s --start-period=30s \ - CMD lighting-cli --testnet getinfo +HEALTHCHECK --interval=10s --timeout=10s --start-period=15s \ + CMD ["/bin/sh", "-c", "/healthcheck.sh"] ENTRYPOINT ["/entrypoint.sh"] CMD ["lightningd"] diff --git a/lightningd/entrypoint.sh b/lightningd/entrypoint.sh index dcb89b1..a9fcbfa 100755 --- a/lightningd/entrypoint.sh +++ b/lightningd/entrypoint.sh @@ -2,6 +2,8 @@ set -e cp -u /testnet-config ${LIGHTNINGD_DATA}/testnet-config +cp -u /regtest-config ${LIGHTNINGD_DATA}/regtest-config +cp -u /main-config ${LIGHTNINGD_DATA}/main-config export GREENLIGHT_VERSION=$(lightningd --version) diff --git a/lightningd/healthcheck.sh b/lightningd/healthcheck.sh new file mode 100755 index 0000000..e753eec --- /dev/null +++ b/lightningd/healthcheck.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -ex + +LIGHTNING_NETWORK="" + +case $BITCOIN_CHAIN in + "test") LIGHTNING_NETWORK=testnet ;; + "regtest") LIGHTNING_NETWORK=regtest ;; + "main") LIGHTNING_NETWORK=bitcoin ;; + "signet") LIGHTNING_NETWORK=signet ;; + *) echo "Invalid BITCOIN_CHAIN value: $BITCOIN_CHAIN" && exit 1 ;; +esac + +lightning-cli --network $LIGHTNING_NETWORK getinfo \ No newline at end of file