diff --git a/NLoop.Server/JsonRpcServer.fs b/NLoop.Server/JsonRpcServer.fs index 297595b6..ad6eee14 100644 --- a/NLoop.Server/JsonRpcServer.fs +++ b/NLoop.Server/JsonRpcServer.fs @@ -154,7 +154,11 @@ type NLoopJsonRpcServer override this.Options = NLoopServerCommandLine.getOptions() - |> Seq.filter(fun o -> PluginOptions.unnecessaryCliOptions |> Seq.contains o.Name |> not ) + |> Seq.filter(fun o -> + PluginOptions.unnecessaryCliOptions + |> Seq.contains o.Name + |> not + ) |> Seq.map(PluginOptions.fromRootCLIOption) member private this.SetArrayedProperty<'T>(opts: NLoopOptions, p: Reflection.PropertyInfo, values, ?next) = diff --git a/README.md b/README.md index 32f28780..53bfddf3 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,12 @@ and run with `--help` to see the possible configuration option. Probably the best way to check its behaviour is to run it in the regtest. Check the following guide for how-to. -### How to try `nloopd` with local docker-compose environment in regtest. +### How-to -Check [README.md in test project](./tests/NLoop.Server.Tests/README.md) +Check tutorial documents under `docs` + +* [Running with lnd](./docs/lnd_regtest.md) +* [Running as a c-lightning plugin](./docs/cln_regtest.md) ## REST API diff --git a/docs/cln_regtest.md b/docs/cln_regtest.md new file mode 100644 index 00000000..cc68d7b0 --- /dev/null +++ b/docs/cln_regtest.md @@ -0,0 +1,40 @@ +## NLoop Regtest guide (c-lightning) + +You can try running `nloopd` as a plugin for c-lightning in the +similar [way we did with lnd](./lnd_regtest.md) + +But since c-lightning does not work well with docker as lnd does, we run +`lightningd` on the host machine. + +* First, download [c-lightning binary](https://github.com/ElementsProject/lightning/releases), or [compile by yourself](https://github.com/ElementsProject/lightning/blob/master/doc/INSTALL.md). +* Next, download [`nloopd` binary](https://github.com/bitbankinc/NLoop/releases/tag/v1.2.0.0-beta) or [compile by yourself](./compile.md) +* run all other dependencies as we did in lnd ... `cd tests/NLoop.Server.Tests/ && docker-compose up -d` +* Run `./scripts/start_cln_with_local_docker.sh` in project root, this will launch `lightningd` in regtest mode with using nloopd binary in your PATH as a plugin. + * It uses appropriate startup option for talking to dependent services. + * You can check all plugin startup options by +`lightningd --plugin=/path/to/nloopd -help` +* Now you can talk to lightningd as usual + * all RPC methods for nloop has a prefix `nloop-`, run `lightning-cli --lightning-dir=./tests/NLoop.Server.Tests/data/lightning_user --network=regtest help` to see those RPCs. + * (For convenience, you can instead just run `./scripts/lightning-cli.sh help`) + * It must be the same with those of [the rest api](https://bitbankinc.github.io/NLoop/) + + +Now check `lightningd` is running correctly with nloopd as a plugin with +`./scripts/lightning-cli.sh --network=regtest nloop_getinfo` + +You can use utility scripts under `tests/NLoop.Server.Tests/cliutils` in the same way we did for lnd. + +```sh +cd tests/NLoop.Server.Tests +./cliutils/prepare_funds.sh +./cliutils/prepare_tx_for_fee.sh +./cliutils/open_from_user_to_server.sh +``` + +And also to reset the state +```sh +cd tests/NLoop.Server.Tests +docker-compose down +rm -rf data +git checkout -- data +``` \ No newline at end of file diff --git a/docs/compile.md b/docs/compile.md new file mode 100644 index 00000000..e7a5f581 --- /dev/null +++ b/docs/compile.md @@ -0,0 +1,18 @@ +### How to compile nloopd. + +It is faily simple to compile nloopd by yourself. +All you need is to install latest dotnet sdk (>= 6) +and run + +``` +dotnet publish NLoop.Server \ + -p:PublishReadyToRun=true \ + -p:PublishSingleFile=true \ + -p:PublishTrimmed=false \ + -p:RuntimeIdentifier=linux-x64 \ + -p:IncludeNativeLibrariesForSelfExtract=true \ + --self-contained true +``` + +`RuntimeIdentifier` must be modified according to the machine you want to run. + diff --git a/docs/lnd_regtest.md b/docs/lnd_regtest.md new file mode 100644 index 00000000..fbcb1f4f --- /dev/null +++ b/docs/lnd_regtest.md @@ -0,0 +1,70 @@ +## NLoop Regtest guide (lnd) + +This guide walks through the steps to test `nloop` in regtest mode with lnd. + +### Service dependencies graph. + +![Test dependency graph](../images/test_deps.png) + +### How-to + +Note that this requires .NET SDK with compatible version installed. + +You also have to enable [docker buildkit](https://docs.docker.com/develop/develop-images/build_enhancements/), by setting + +```bash +DOCKER_BUILDKIT=1 +COMPOSE_DOCKER_CLI_BUILD=1 +``` + +```sh +# --- prepare dependent services --- +cd tests/NLoop.Server.Tests + +docker-compose up -d # Start dependencies such as bitcoind and lnd + +# prepare dummy funds for all clients. +./cliutils/prepare_funds.sh + +# regtest blockchain is too empty that clients fails to estimate the fee. +# So fill in some dummy tx's and funds by this command, it may take a while to complete. +# This is necessary only for performing an actual swap and not for running the server itself. +./cliutils/prepare_tx_for_fee.sh + +./cliutils/open_from_user_to_server.sh + +# you can also use these scripts for invoking RPC methods for bitcoind, lnd. +./docker-bitcoin-cli.sh getblockchaininfo +./docker-litecoin-cli.sh getblockchaininfo +./docker-lncli-user.sh getinfo +./docker-lncli-server_ltc.sh getinfo +# Some interactive operation (e.g. lnd's `payinvoice`) may require you to execute it with the pseudo-tty. +# in that case do not use these scripts and run `docker-compose exec` without `-T` option + +cd ../.. +# --- --- + +# --- start running nloopd --- + +# You must run this as a same user with a `docker-compose`. +# Since it reads files in `tests/NLoop.Server.Tests/data` generated by the docker-compose command above. +./scripts/start_with_local_docker.sh + +# --- --- + +# Get general information about NLoop. +curl http://localhost:5000/v1/info +``` + +Now you can play with [nloop rest api described here](https://bitbankinc.github.io/NLoop/) + +You can access http://localhost:2113 for EventStoreDB admin ui to check the current state of the db. + +To reset the state, you can just run the following commands after stopping the docker-compose. + +```sh +cd tests/NLoop.Server.Tests +docker-compose down +rm -rf data +git checkout -- data +``` \ No newline at end of file diff --git a/scripts/lightning-cli.sh b/scripts/lightning-cli.sh new file mode 100755 index 00000000..e5f3c662 --- /dev/null +++ b/scripts/lightning-cli.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -eu + +cln_datadir=`pwd`/tests/NLoop.Server.Tests/data/lightning_user + +lightning-cli \ + --lightning-dir=$cln_datadir \ + --network=regtest \ + $@ + diff --git a/scripts/restart_plugin.sh b/scripts/restart_plugin.sh index 2299e8a8..76ca0344 100755 --- a/scripts/restart_plugin.sh +++ b/scripts/restart_plugin.sh @@ -1,18 +1,27 @@ #!/usr/bin/env bash -lightning-cli --network=regtest plugin stop nloopd - set -eu -dotnet publish NLoop.Server -p:PublishReadyToRun=true \ - -p:PublishSingleFile=true \ - -p:PublishTrimmed=false \ - -p:RuntimeIdentifier=linux-x64 \ - -p:IncludeNativeLibrariesForSelfExtract=true \ - --self-contained true +cln_datadir=`pwd`/tests/NLoop.Server.Tests/data/lightning_user +nloopd=`command -v nloopd` + +lightning-cli \ + --lightning-dir=$cln_datadir \ + --network=regtest plugin stop nloopd + +dotnet publish NLoop.Server \ + -p:PublishReadyToRun=true \ + -p:PublishSingleFile=true \ + -p:PublishTrimmed=false \ + -p:RuntimeIdentifier=linux-x64 \ + -p:IncludeNativeLibrariesForSelfExtract=true \ + --self-contained true -lightning-cli --network=regtest -k plugin subcommand=start \ - plugin=/home/joemphilips/working/sandbox/fsharp/NLoop/NLoop.Server/bin/Debug/net6.0/linux-x64/nloopd \ +lightning-cli \ + --lightning-dir=$cln_datadir \ + --network=regtest \ + -k plugin subcommand=start \ + plugin=$nloopd \ nloop-nohttps=true \ nloop-btc.rpcuser=johndoe \ nloop-btc.rpcpassword=unsafepassword \ diff --git a/scripts/start_cln_with_local_docker.sh b/scripts/start_cln_with_local_docker.sh index a7aaf67d..0a0b0d86 100755 --- a/scripts/start_cln_with_local_docker.sh +++ b/scripts/start_cln_with_local_docker.sh @@ -2,17 +2,29 @@ set -eu +bitcoin_datadir=`pwd`/tests/NLoop.Server.Tests/data/bitcoin +cln_datadir=`pwd`/tests/NLoop.Server.Tests/data/lightning_user +nloopd=`command -v nloopd` + lightningd \ --network=regtest \ --nloop-nohttps=true \ + --plugin=$nloopd \ + --lightning-dir=$cln_datadir \ + --bitcoin-datadir=$bitcoin_datadir \ --bitcoin-rpcuser=johndoe \ --bitcoin-rpcpassword=unsafepassword \ --bitcoin-rpcconnect=localhost \ --bitcoin-rpcport=43782 \ + --log-level=debug:nloop \ --nloop-ltc.rpcuser=johndoe \ --nloop-ltc.rpcpassword=unsafepassword \ --nloop-ltc.rpchost=localhost \ --nloop-ltc.rpcport=43783 \ + --nloop-btc.rpcuser=johndoe \ + --nloop-btc.rpcpassword=unsafepassword \ + --nloop-btc.rpchost=localhost \ + --nloop-btc.rpcport=43782 \ --nloop-eventstoreurl tcp://admin:changeit@localhost:1113 \ --nloop-boltzhost http://localhost \ --nloop-boltzport 6028 \ diff --git a/tests/NLoop.Server.Tests/Dockerfiles/lightning b/tests/NLoop.Server.Tests/Dockerfiles/lightning deleted file mode 100644 index f75287d1..00000000 --- a/tests/NLoop.Server.Tests/Dockerfiles/lightning +++ /dev/null @@ -1,157 +0,0 @@ -# syntax = edrevo/dockerfile-plus - -# This dockerfile is meant to compile a c-lightning x64 image -# It is using multi stage build: -# * downloader: Download litecoin/bitcoin and qemu binaries needed for c-lightning -# * builder: Compile c-lightning dependencies, then c-lightning itself with static linking -# * final: Copy the binaries required at runtime -# The resulting image uploaded to dockerhub will only contain what is needed for runtime. -# From the root of the repository, run "docker build -t yourimage:yourtag ." - -FROM debian:bullseye-slim as downloader - -RUN set -ex \ - && apt-get update \ - && apt-get install -qq --no-install-recommends dirmngr wget ca-certificates - -RUN update-ca-certificates - -WORKDIR /opt - -RUN wget -qO /opt/tini "https://github.com/krallin/tini/releases/download/v0.18.0/tini" \ - && echo "12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855 /opt/tini" | sha256sum -c - \ - && chmod +x /opt/tini - -ARG BITCOIN_VERSION=0.21.1 -ENV BITCOIN_TARBALL bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz -ENV BITCOIN_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/$BITCOIN_TARBALL -ENV BITCOIN_ASC_URL https://bitcoincore.org/bin/bitcoin-core-$BITCOIN_VERSION/SHA256SUMS.asc - -# wget sometimes complains that bitcoin.org ca-certificate -# is not valid. Since this happens only inside docker image. -# and this image is for test. We just ignore by --no-check-certificate option. -RUN mkdir /opt/bitcoin && cd /opt/bitcoin \ - && wget --no-check-certificate -qO $BITCOIN_TARBALL "$BITCOIN_URL" \ - && wget --no-check-certificate -qO bitcoin.asc "$BITCOIN_ASC_URL" \ - && grep $BITCOIN_TARBALL bitcoin.asc | tee SHA256SUMS.asc \ - && sha256sum -c SHA256SUMS.asc \ - && BD=bitcoin-$BITCOIN_VERSION/bin \ - && tar -xzvf $BITCOIN_TARBALL $BD/bitcoin-cli --strip-components=1 \ - && rm $BITCOIN_TARBALL - -ENV DESCHASHPLUGIN_URL https://github.com/fiatjaf/sparko/releases/download/invoicewithdescriptionhash-v1.2/invoicewithdescriptionhash_linux_amd64 -ENV DESCHASHPLUGIN_SHA256 E3EA0D076A26D774BA68D1D5E3FE48D267CE02D077933EF3CBAE1FC39007FB11 -RUN mkdir /opt/deschashplugin && cd /opt/deschashplugin \ - && wget -qO invoicewithdescriptionhash "$DESCHASHPLUGIN_URL" \ - && echo "$DESCHASHPLUGIN_SHA256 invoicewithdescriptionhash" | sha256sum -c - \ - && chmod a+x invoicewithdescriptionhash - -FROM debian:bullseye-slim as builder - -ENV LIGHTNINGD_VERSION=v0.10.1 -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates autoconf automake build-essential git libtool python3 python3-pip python3-setuptools python3-mako wget gnupg dirmngr git gettext - -RUN wget https://zlib.net/zlib-1.2.12.tar.gz \ -&& tar xvf zlib-1.2.12.tar.gz \ -&& cd zlib-1.2.12 \ -&& ./configure \ -&& make \ -&& make install && cd .. && rm zlib-1.2.12.tar.gz && rm -rf zlib-1.2.12 - -RUN apt-get install -y --no-install-recommends unzip tclsh \ -&& wget -q https://www.sqlite.org/2019/sqlite-src-3290000.zip \ -&& unzip sqlite-src-3290000.zip \ -&& cd sqlite-src-3290000 \ -&& ./configure --enable-static --disable-readline --disable-threadsafe --disable-load-extension \ -&& make \ -&& make install && cd .. && rm sqlite-src-3290000.zip && rm -rf sqlite-src-3290000 - -RUN wget -q https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz \ -&& tar xvf gmp-6.1.2.tar.xz \ -&& cd gmp-6.1.2 \ -&& ./configure --disable-assembly \ -&& make \ -&& make install && cd .. && rm gmp-6.1.2.tar.xz && rm -rf gmp-6.1.2 - -WORKDIR /opt/lightningd -RUN git clone --recursive https://github.com/ElementsProject/lightning . && \ - git checkout $LIGHTNINGD_VERSION - -ARG DEVELOPER=0 -ENV PYTHON_VERSION=3 -RUN pip3 install mrkd -RUN ./configure --prefix=/tmp/lightning_install --enable-static && make -j3 DEVELOPER=${DEVELOPER} && make install - - -FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim-amd64 as plugins - -ARG TRACE_TOOLS=false -ENV TRACE_TOOLS=$TRACE_TOOLS -ENV TRACE_LOCATION=/opt/traces -VOLUME /opt/traces - -COPY --from=downloader /opt/tini /usr/bin/tini - -RUN apt-get update && apt-get install -y --no-install-recommends socat inotify-tools python3 python3-pip \ - && \ - ( ! $TRACE_TOOLS || \ - ( \ - apt-get install -y --no-install-recommends perl linux-base curl ca-certificates && \ - mkdir FlameGraph && cd FlameGraph && \ - curl -Lo FlameGraph.tar.gz "https://github.com/brendangregg/FlameGraph/archive/v1.0.tar.gz" && \ - tar -zxvf FlameGraph.tar.gz --strip-components=1 && rm FlameGraph.tar.gz && cd .. \ - ) \ - ) \ - && rm -rf /var/lib/apt/lists/* - -ENV LIGHTNINGD_DATA=/root/.lightning -ENV LIGHTNINGD_RPC_PORT=9835 -ENV LIGHTNINGD_PORT=9735 -ENV LIGHTNINGD_NETWORK=bitcoin - -RUN mkdir $LIGHTNINGD_DATA && \ - mkdir /etc/bundledplugins && \ - mkdir $LIGHTNINGD_DATA/plugins && \ - touch $LIGHTNINGD_DATA/config - -VOLUME [ "/root/.lightning" ] - -# -- plugins -- -ARG EXTRA_PLUGINS='--recurse-submodules=csvexportpays \ ---recurse-submodules=graphql \ ---recurse-submodules=jwt-factory \ ---recurse-submodules=python-teos \ ---recurse-submodules=trustedcoin \ ---recurse-submodules=webhook' - -RUN apt-get update && apt-get install -y --no-install-recommends build-essential python3-wheel python3-dev python3-venv libleveldb-dev pkg-config libc-bin git libpq-dev postgresql man - -COPY --from=builder /opt/lightningd/ /opt/lightningd/ - -RUN mkdir /tmp/oldplugins && mv /opt/lightningd/plugins/* /tmp/oldplugins/ && \ - rm -rf /opt/lightningd/plugins && \ - cd /opt/lightningd/ && \ - git clone --depth 1 --shallow-submodules -j4 \ - ${EXTRA_PLUGINS} \ - https://github.com/lightningd/plugins /opt/lightningd/plugins && \ - cd /opt/lightningd/plugins && \ - pip3 install setuptools && \ - find -name requirements.txt -exec pip3 install -r {} \; && \ - mv /tmp/oldplugins/* /opt/lightningd/plugins/ && rmdir /tmp/oldplugins -# -- -- -# prepare nloopd as a plugin -INCLUDE+ NLoop.Server/Dockerfile.debug - -FROM plugins AS clightning_final - -COPY --from=builder /tmp/lightning_install/ /usr/local/ -COPY --from=downloader /opt/bitcoin/bin /usr/bin -COPY --from=downloader /opt/deschashplugin $LIGHTNINGD_DATA/plugins -COPY --from=downloader /opt/deschashplugin /etc/bundledplugins -COPY --from=final /app/nloopd /opt/lightningd/plugins -#RUN mv /app/nloopd /opt/lightningd/plugins - -COPY "tests/NLoop.Server.Tests/Dockerfiles/lightning-entrypoint.sh" ./entrypoint.sh - -EXPOSE 9735 9835 -ENTRYPOINT [ "/usr/bin/tini", "-g", "--", "./entrypoint.sh" ] diff --git a/tests/NLoop.Server.Tests/Dockerfiles/lightning-entrypoint.sh b/tests/NLoop.Server.Tests/Dockerfiles/lightning-entrypoint.sh deleted file mode 100755 index 22e19600..00000000 --- a/tests/NLoop.Server.Tests/Dockerfiles/lightning-entrypoint.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash - -: "${EXPOSE_TCP:=false}" - -cat <<-EOF > "$LIGHTNINGD_DATA/config" -${LIGHTNINGD_OPT} -bind-addr=0.0.0.0:${LIGHTNINGD_PORT} -EOF - -: "${EXPOSE_TCP:=false}" - -LIGHTNINGD_NETWORK_NAME="" - -if [ "$LIGHTNINGD_CHAIN" == "btc" ] && [ "$LIGHTNINGD_NETWORK" == "mainnet" ]; then - LIGHTNINGD_NETWORK_NAME="bitcoin" -elif [ "$LIGHTNINGD_CHAIN" == "btc" ] && [ "$LIGHTNINGD_NETWORK" == "testnet" ]; then - LIGHTNINGD_NETWORK_NAME="testnet" -elif [ "$LIGHTNINGD_CHAIN" == "btc" ] && [ "$LIGHTNINGD_NETWORK" == "regtest" ]; then - LIGHTNINGD_NETWORK_NAME="regtest" -elif [ "$LIGHTNINGD_CHAIN" == "ltc" ] && [ "$LIGHTNINGD_NETWORK" == "mainnet" ]; then - LIGHTNINGD_NETWORK_NAME="litecoin" -elif [ "$LIGHTNINGD_CHAIN" == "ltc" ] && [ "$LIGHTNINGD_NETWORK" == "testnet" ]; then - LIGHTNINGD_NETWORK_NAME="litecoin-testnet" -else - echo "Invalid combinaion of LIGHTNINGD_NETWORK and LIGHTNINGD_CHAIN. LIGHTNINGD_CHAIN should be btc or ltc. LIGHTNINGD_NETWORK should be mainnet, testnet or regtest." - echo "ltc regtest is not supported" - exit -fi - -echo "network=$LIGHTNINGD_NETWORK_NAME" >> "$LIGHTNINGD_DATA/config" -echo "network=$LIGHTNINGD_NETWORK_NAME added in $LIGHTNINGD_DATA/config" - -if [[ $TRACE_TOOLS == "true" ]]; then -echo "Trace tools detected, installing sample.sh..." -echo 0 > /proc/sys/kernel/kptr_restrict -echo " -# This script will take one minute of stacktrace samples and plot it in a flamegraph -LIGHTNING_PROCESSES=\$(pidof lightningd lightning_chann lightning_closi lightning_gossi lightning_hsmd lightning_oncha lightning_openi lightning_hsmd lightning_gossipd lightning_channeld | sed -e 's/\s/,/g') -perf record -F 99 -g -a --pid \$LIGHTNING_PROCESSES -o \"$TRACE_LOCATION/perf.data\" -- sleep 60 -perf script -i \"$TRACE_LOCATION/perf.data\" > \"$TRACE_LOCATION/output.trace\" -cd /FlameGraph -./stackcollapse-perf.pl \"$TRACE_LOCATION/output.trace\" > \"$TRACE_LOCATION/output.trace.folded\" -svg=\"$TRACE_LOCATION/\$((\$SECONDS / 60))min.svg\" -./flamegraph.pl \"$TRACE_LOCATION/output.trace.folded\" > \"\$svg\" -rm \"$TRACE_LOCATION/perf.data\" -rm \"$TRACE_LOCATION/output.trace\" -rm \"$TRACE_LOCATION/output.trace.folded\" -echo \"flamegraph taken: \$svg\" -" > /usr/bin/sample.sh -chmod +x /usr/bin/sample.sh - -echo " -# This script will run sample.sh after 2 min then every 10 minutes -sleep 120 -sample.sh -while true; do - sleep 300 - . sample.sh -done -" > /usr/bin/sample-loop.sh -chmod +x /usr/bin/sample-loop.sh -fi - -if [[ "${LIGHTNINGD_ANNOUNCEADDR}" ]]; then - echo "announce-addr=$LIGHTNINGD_ANNOUNCEADDR:${LIGHTNINGD_PORT}" >> "$LIGHTNINGD_DATA/config" -fi - -if [[ "${LIGHTNINGD_ALIAS}" ]]; then - # This allow to strip this parameter if LND_ALIGHTNINGD_ALIASLIAS is empty or null, and truncate it - LIGHTNINGD_ALIAS="$(echo "$LIGHTNINGD_ALIAS" | cut -c -32)" - echo "alias=$LIGHTNINGD_ALIAS" >> "$LIGHTNINGD_DATA/config" - echo "alias=$LIGHTNINGD_ALIAS added to $LIGHTNINGD_DATA/config" -fi - -if [[ "${LIGHTNINGD_READY_FILE}" ]]; then - echo "Waiting $LIGHTNINGD_READY_FILE to be created..." - while [ ! -f "$LIGHTNINGD_READY_FILE" ]; do sleep 1; done - echo "The chain is fully synched" -fi - -if [[ "${LIGHTNINGD_HIDDENSERVICE_HOSTNAME_FILE}" ]]; then - echo "Waiting $LIGHTNINGD_HIDDENSERVICE_HOSTNAME_FILE to be created by tor..." - while [ ! -f "$LIGHTNINGD_HIDDENSERVICE_HOSTNAME_FILE" ]; do sleep 1; done - HIDDENSERVICE_ONION="$(head -n 1 "$LIGHTNINGD_HIDDENSERVICE_HOSTNAME_FILE"):${LIGHTNINGD_PORT}" - echo "announce-addr=$HIDDENSERVICE_ONION" >> "$LIGHTNINGD_DATA/config" - echo "announce-addr=$HIDDENSERVICE_ONION added to $LIGHTNINGD_DATA/config" -fi - -if ! grep -q "^rpc-file=" "$LIGHTNINGD_DATA/config"; then - echo "rpc-file=$LIGHTNINGD_DATA/lightning-rpc" >> "$LIGHTNINGD_DATA/config" - echo "rpc-file=$LIGHTNINGD_DATA/lightning-rpc added to $LIGHTNINGD_DATA/config" -fi - -echo "Installing bundled plugins" -mkdir -p "$LIGHTNINGD_DATA/plugins" -cp -u /etc/bundledplugins/* $LIGHTNINGD_DATA/plugins/ - -# copy more as you needed in here. -cp -ur /opt/lightningd/plugins/summary $LIGHTNINGD_DATA/plugins/summary -cp -ur /opt/lightningd/plugins/helpme $LIGHTNINGD_DATA/plugins/helpme -cp -ur /opt/lightningd/plugins/monitor $LIGHTNINGD_DATA/plugins/monitor -cp -u /opt/lightningd/plugins/nloopd $LIGHTNINGD_DATA/plugins/nloopd - -echo "C-Lightning starting, listening on port ${LIGHTNINGD_PORT}" -echo "C-lightning arguments are $@" -if [ "$EXPOSE_TCP" == "true" ]; then - set -m - lightningd "$@" & - echo "C-Lightning starting" - while read -r i; do if [ "$i" = "lightning-rpc" ]; then break; fi; done \ - < <(inotifywait -e create,open --format '%f' --quiet "$LIGHTNINGD_DATA" --monitor) - echo "C-Lightning started, RPC available on port $LIGHTNINGD_RPC_PORT" - socat "TCP4-listen:$LIGHTNINGD_RPC_PORT,fork,reuseaddr" "UNIX-CONNECT:$LIGHTNINGD_DATA/lightning-rpc" & - fg %- -else - exec lightningd "$@" -fi diff --git a/tests/NLoop.Server.Tests/build_clightning_docker.sh b/tests/NLoop.Server.Tests/build_clightning_docker.sh deleted file mode 100755 index d9a0bd27..00000000 --- a/tests/NLoop.Server.Tests/build_clightning_docker.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -docker-compose -f docker-compose.yml -f docker-compose.clightning.yml build diff --git a/tests/NLoop.Server.Tests/cliutils/open_from_server_to_user.sh b/tests/NLoop.Server.Tests/cliutils/open_from_server_to_user.sh index 9c46c64e..980d1f8b 100755 --- a/tests/NLoop.Server.Tests/cliutils/open_from_server_to_user.sh +++ b/tests/NLoop.Server.Tests/cliutils/open_from_server_to_user.sh @@ -2,9 +2,12 @@ set -eu -user_pubkey=$(lightning-cli --network=regtest getinfo | jq -r ".id") +if [[ pgrep -x lightningd ]]; then + user_pubkey=$(lightning-cli --network=regtest getinfo | jq -r ".id") +elif + user_pubkey=$(./docker-lncli-user.sh getinfo | jq -r ".identity_pubkey") +fi ./docker-lncli-server_btc.sh openchannel --private $user_pubkey 500000 - -./docker-bitcoin-cli.sh generatetoaddress 3 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m +./docker-bitcoin-cli.sh generatetoaddress 4 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m diff --git a/tests/NLoop.Server.Tests/cliutils/open_from_user_to_server.sh b/tests/NLoop.Server.Tests/cliutils/open_from_user_to_server.sh index be4e8a96..a76d4f6e 100755 --- a/tests/NLoop.Server.Tests/cliutils/open_from_user_to_server.sh +++ b/tests/NLoop.Server.Tests/cliutils/open_from_user_to_server.sh @@ -4,7 +4,11 @@ set -eu server_pubkey=$(curl http://localhost:6028/getnodes | jq ".nodes.BTC.nodeKey") -feerate=$(lightning-cli --network=regtest feerates perkw | jq ".perkw.opening") -lightning-cli --network=regtest fundchannel $server_pubkey 500000 $feerate false - -./docker-bitcoin-cli.sh generatetoaddress 3 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m +if [[ pgrep -x lightningd ]]; then + feerate=$(lightning-cli --network=regtest feerates perkw | jq ".perkw.opening") + lightning-cli --network=regtest fundchannel $server_pubkey 500000 $feerate false +elif + ./docker-lncli-user.sh openchannel --private $server_pubkey 500000 +fi + +./docker-bitcoin-cli.sh generatetoaddress 4 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m diff --git a/tests/NLoop.Server.Tests/cliutils/prepare_funds.tx b/tests/NLoop.Server.Tests/cliutils/prepare_funds.tx index 7368589c..e4c98a5e 100755 --- a/tests/NLoop.Server.Tests/cliutils/prepare_funds.tx +++ b/tests/NLoop.Server.Tests/cliutils/prepare_funds.tx @@ -11,16 +11,18 @@ bitcoin() { # send on-chain funds to both sides. ./docker-lncli-user.sh newaddress p2wkh | jq -r ".address" | xargs -IXX ./docker-bitcoin-cli.sh sendtoaddress XX 10 ./docker-lncli-server_btc.sh newaddress p2wkh | jq -r ".address" | xargs -IXX ./docker-bitcoin-cli.sh sendtoaddress XX 10 - lightning-cli --network=regtest newaddr | jq -r ".bech32" | xargs -IXX ./docker-bitcoin-cli.sh sendtoaddress XX 10 - ./docker-bitcoin-cli.sh generatetoaddress 1 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m # Just for confirmation - ./docker-bitcoin-cli.sh generatetoaddress 1 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m # Just for confirmation - ./docker-bitcoin-cli.sh generatetoaddress 4 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m # Just for confirmation + if [[ pgrep -x lightningd ]]; then + lightning-cli --network=regtest newaddr | jq -r ".bech32" | xargs -IXX ./docker-bitcoin-cli.sh sendtoaddress XX 10 + fi; - # Connect peers - ./docker-lncli-user.sh getinfo | jq ".uris[0]" | xargs -IXX ./docker-lncli-server_btc.sh connect XX - ./docker-lncli-server_btc.sh getinfo | jq ".uris[0]" | xargs lightning-cli --network=regtest connect + ./docker-bitcoin-cli.sh generatetoaddress 6 bcrt1qjwfqxekdas249pr9fgcpxzuhmndv6dqlulh44m # Just for confirmation + # Connect peers + ./docker-lncli-user.sh getinfo | jq ".uris[0]" | xargs -IXX ./docker-lncli-server_btc.sh connect XX + if [[ pgrep -x lightningd ]]; then + ./docker-lncli-server_btc.sh getinfo | jq ".uris[0]" | xargs lightning-cli --network=regtest connect + fi; } litecoin() { diff --git a/tests/NLoop.Server.Tests/data/lightning_user/.gitkeep b/tests/NLoop.Server.Tests/data/lightning_user/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/tests/NLoop.Server.Tests/docker-compose.clightning.yml b/tests/NLoop.Server.Tests/docker-compose.clightning.yml deleted file mode 100644 index 3511c3af..00000000 --- a/tests/NLoop.Server.Tests/docker-compose.clightning.yml +++ /dev/null @@ -1,60 +0,0 @@ -version: "3" - -services: - clightning_user: - restart: unless-stopped - image: nloop/lightningd:v0.10.1 - build: - context: ../../ - dockerfile: tests/NLoop.Server.Tests/Dockerfiles/lightning - args: - LIGHTNINGD_VERSION: "v0.10.1" - cache_from: - - nloop/lightningd:v0.10.1 - environment: - EXPOSE_TCP: "true" - LIGHTNINGD_NETWORK: regtest - LIGHTNINGD_CHAIN: btc - LIGHTNINGD_PORT: 9735 - LIGHTNINGD_RPC_PORT: 9835 - LIGHTNINGD_ANNOUNCEADDR: clightning_user - LIGHTNINGD_DATA: /root/.lightning - command: - - "--network=regtest" - - "--lightning-dir=/root/.lightning" - - "--allow-deprecated-apis=false" - - "--bitcoin-datadir=/deps/.bitcoin" - - "--bitcoin-rpcuser=johndoe" - - "--bitcoin-rpcpassword=unsafepassword" - - "--bitcoin-rpcconnect=bitcoind" - - "--bitcoin-rpcport=43782" - - "--nloop-network=regtest" - - "--nloop-nohttps=true" - - "--nloop-btc.rpcuser=johndoe" - - "--nloop-btc.rpcpassword=unsafepassword" - - "--nloop-btc.rpchost=localhost" - - "--nloop-btc.rpcport=43782" - - "--nloop-ltc.rpcuser=johndoe" - - "--nloop-ltc.rpcpassword=unsafepassword" - - "--nloop-ltc.rpchost=localhost" - - "--nloop-ltc.rpcport=43783" - - "--nloop-eventstoreurl=tcp://admin:changeit@localhost:1113" - - "--nloop-boltzhost=http://localhost" - - "--nloop-boltzport=6028" - - "--nloop-exchanges=FTX" - # - "--plugin-dir=/plugins" - # - "--plugin=/root/.lightning/plugins/summary" - # - "--plugin=/opt/lightningd/plugins/summary" - depends_on: - - bitcoind - volumes: - - "clightning_user:/root/.lightning" - - "./data/bitcoin:/deps/.bitcoin" - expose: - - "9735" - ports: - - "9835:9835" - -volumes: - clightning_user: - diff --git a/tests/NLoop.Server.Tests/docker-lightning-cli-user.sh b/tests/NLoop.Server.Tests/docker-lightning-cli-user.sh deleted file mode 100755 index d9070fff..00000000 --- a/tests/NLoop.Server.Tests/docker-lightning-cli-user.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -docker-compose -f docker-compose.yml -f docker-compose.clightning.yml exec -T clightning_user lightning-cli --rpc-file /root/.lightning/lightning-rpc --network regtest --lightning-dir /root/.lightning $@ -