Merge branch 'regtest' into 'main'

feat: multi chain support

See merge request lightning-signer/vls-container!3
This commit is contained in:
dev random 2023-09-29 20:11:30 +00:00
commit 6290fbb8af
17 changed files with 193 additions and 47 deletions

View File

@ -13,6 +13,40 @@ docker volume create lightning_data
docker compose up --build 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 <override_file> 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 ### References
- [bitcoind](https://github.com/ruimarinho/docker-bitcoin-core/blob/master/23/alpine/Dockerfile) by @ruimarinho - [bitcoind](https://github.com/ruimarinho/docker-bitcoin-core/blob/master/23/alpine/Dockerfile) by @ruimarinho

View File

@ -2,15 +2,29 @@
## bitcoin.conf configuration file. Lines beginning with # are comments. ## bitcoin.conf configuration file. Lines beginning with # are comments.
## ##
[test]
server=1 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 rpcuser=rpcuser
rpcpassword=VLSsigner1 rpcpassword=VLSsigner1
rpcport=18332 rpcport=18332
port=18333
[regtest]
rpcbind=0.0.0.0 rpcbind=0.0.0.0
rpcallowip=0.0.0.0/0 rpcuser=rpcuser
whitelist=0.0.0.0/0 rpcpassword=VLSsigner1
zmqpubrawblock=tcp://bitcoind:38332 rpcport=38332
zmqpubrawtx=tcp://bitcoind:38333 port=38333
txindex=1
blockfilterindex=1

9
assets/main-config Normal file
View File

@ -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

4
assets/main-env Normal file
View File

@ -0,0 +1,4 @@
VLS_PORT=17701
VLS_NETWORK=regtest
BITCOIND_RPC_URL=http://rpcuser:VLSsigner1@bitcoind:8332
RUST_LOG=info

9
assets/regtest-config Normal file
View File

@ -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

4
assets/regtest-env Normal file
View File

@ -0,0 +1,4 @@
VLS_PORT=17701
VLS_NETWORK=regtest
BITCOIND_RPC_URL=http://rpcuser:VLSsigner1@bitcoind:38332
RUST_LOG=info

View File

@ -6,3 +6,4 @@ log-level=info
max-locktime-blocks=288 max-locktime-blocks=288
important-plugin=/usr/bin/clboss important-plugin=/usr/bin/clboss
clboss-auto-close=true clboss-auto-close=true
bind-addr=0.0.0.0:19735

View File

@ -46,8 +46,8 @@ RUN set -ex \
done && \ done && \
wget -O- https://raw.githubusercontent.com/Kvaciral/kvaciral/main/kvaciral.asc | gpg --import wget -O- https://raw.githubusercontent.com/Kvaciral/kvaciral/main/kvaciral.asc | gpg --import
ENV BITCOIN_VERSION=23.0 ARG BITCOIN_VERSION=23.0
ENV BITCOIN_PREFIX=/opt/bitcoin-${BITCOIN_VERSION} ARG BITCOIN_PREFIX=/opt/bitcoin-${BITCOIN_VERSION}
ARG SHA256SUMS_HASH=aaff81ea001f499e8f6f3221387d7db960d71a3b7a4a2b1aaf2c8060bc94a391 ARG SHA256SUMS_HASH=aaff81ea001f499e8f6f3221387d7db960d71a3b7a4a2b1aaf2c8060bc94a391
RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS
@ -121,8 +121,6 @@ RUN chmod +x /healthcheck.sh
VOLUME ["${BITCOIN_DATA}"] VOLUME ["${BITCOIN_DATA}"]
EXPOSE 8332 8333 18332 18333 18444
RUN mkdir -p "${BITCOIN_DATA}" RUN mkdir -p "${BITCOIN_DATA}"
RUN chown -R bitcoin:bitcoin "${BITCOIN_DATA}" RUN chown -R bitcoin:bitcoin "${BITCOIN_DATA}"

View File

@ -1,7 +1,8 @@
#!/bin/sh #!/bin/sh
set -e 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 if [ $(echo "$1" | cut -c1) = "-" ]; then
echo "$0: assuming arguments for bitcoind" echo "$0: assuming arguments for bitcoind"
@ -9,5 +10,11 @@ if [ $(echo "$1" | cut -c1) = "-" ]; then
set -- bitcoind "$@" set -- bitcoind "$@"
fi fi
if [ $(echo "$1" | cut -c1) = "-" ] || [ "$1" = "bitcoind" ]; then
echo "$0: setting chain to $BITCOIN_CHAIN"
set -- "$@" -chain=$BITCOIN_CHAIN
fi
echo echo
exec "$@" exec "$@"

View File

@ -1 +1 @@
bitcoin-cli --chain=$BITCOIN_CHAIN getblockchaininfo bitcoin-cli -chain=$BITCOIN_CHAIN getblockchaininfo

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,10 @@
version: "3.8"
name: testnet
services:
bitcoin-core:
ports:
- 18333:18333
core-lightning:
ports:
- 19735:19735

View File

@ -4,22 +4,11 @@ services:
build: build:
dockerfile: ./bitcoind/Dockerfile dockerfile: ./bitcoind/Dockerfile
image: bitcoind image: bitcoind
container_name: bitcoind container_name: bitcoind-test
command:
- --testnet
- -pid=/home/bitcoin/.bitcoin/testnet3/bitcoind-testnet.pid
volumes: volumes:
- data:/home/bitcoin/.bitcoin - data:/home/bitcoin/.bitcoin
expose: expose:
- 8332
- 8333
- 18332 - 18332
- 18333
- 18444
ports:
- 8333:8333
- 18333:18333
- 38333:38333
networks: networks:
LN_testing: LN_testing:
aliases: aliases:
@ -31,31 +20,24 @@ services:
build: build:
dockerfile: ./lightningd/Dockerfile dockerfile: ./lightningd/Dockerfile
image: lightningd image: lightningd
container_name: lightningd container_name: lightningd-test
command: command:
- --conf=/home/lightning/.lightning/testnet-config - --conf=/home/lightning/.lightning/testnet-config
- --bitcoin-rpcconnect=bitcoind - --bitcoin-rpcconnect=bitcoind
- --bind-addr=core-lightning:19735
- --announce-addr=core-lightning:19735
volumes: volumes:
- clightning:/home/lightning/.lightning - clightning:/home/lightning/.lightning
expose: expose:
- 9735 - 19735
- 9835
ports:
- 9735:9735
- 19735:19735
networks: networks:
- LN_testing - LN_testing
links:
- bitcoin-core:bitcoind
depends_on: depends_on:
bitcoin-core: bitcoin-core:
condition: service_healthy condition: service_healthy
restart: true restart: true
env_file: env_file:
- ./assets/testnet-env - ./assets/testnet-env
environment:
- BITCOIN_CHAIN=test
volumes: volumes:
data: data:

View File

@ -68,15 +68,13 @@ RUN apk update && \
sqlite-dev sqlite-dev
ARG LIGHTNINGD_UID=101 ARG LIGHTNINGD_UID=101
ENV LIGHTNINGD_USER=lightning ARG LIGHTNINGD_USER=lightning
ENV LIGHTNINGD_HOME=/home/${LIGHTNINGD_USER} ARG LIGHTNINGD_HOME=/home/${LIGHTNINGD_USER}
ENV LIGHTNINGD_DATA=${LIGHTNINGD_HOME}/.lightning \ ENV LIGHTNINGD_DATA=${LIGHTNINGD_HOME}/.lightning \
LIGHTNINGD_RPC_PORT=9835 \ LIGHTNINGD_RPC_PORT=9835 \
LIGHTNINGD_PORT=9735 \ LIGHTNINGD_PORT=9735 \
BITCOIND_HOME=/root/.bitcoin BITCOIND_HOME=/root/.bitcoin
COPY lightningd/entrypoint.sh /entrypoint.sh
COPY --from=builder /usr/bin/lightningd /usr/bin/ COPY --from=builder /usr/bin/lightningd /usr/bin/
COPY --from=builder /usr/bin/lightning-cli /usr/bin/ COPY --from=builder /usr/bin/lightning-cli /usr/bin/
COPY --from=builder /usr/bin/lightning-hsmtool /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 && \ RUN addgroup -S lightning && adduser -S lightning -G lightning && \
mkdir -p ${LIGHTNINGD_DATA} && \ 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}"] VOLUME ["${LIGHTNINGD_DATA}"]
@ -97,11 +102,13 @@ RUN mkdir -p "${BITCOIND_HOME}" && \
COPY assets/bitcoin.conf "${BITCOIND_HOME}"/bitcoin.conf COPY assets/bitcoin.conf "${BITCOIND_HOME}"/bitcoin.conf
COPY assets/testnet-config /testnet-config COPY assets/testnet-config /testnet-config
COPY assets/regtest-config /regtest-config
COPY assets/main-config /main-config
USER lightning USER lightning
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s \ HEALTHCHECK --interval=10s --timeout=10s --start-period=15s \
CMD lighting-cli --testnet getinfo CMD ["/bin/sh", "-c", "/healthcheck.sh"]
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]
CMD ["lightningd"] CMD ["lightningd"]

View File

@ -2,6 +2,8 @@
set -e set -e
cp -u /testnet-config ${LIGHTNINGD_DATA}/testnet-config 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) export GREENLIGHT_VERSION=$(lightningd --version)

15
lightningd/healthcheck.sh Executable file
View File

@ -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