Skip to content

Commit

Permalink
update documents and remove unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
joemphilips committed Aug 30, 2022
1 parent ae08a2a commit d1ff895
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 370 deletions.
6 changes: 5 additions & 1 deletion NLoop.Server/JsonRpcServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions docs/cln_regtest.md
Original file line number Diff line number Diff line change
@@ -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
```
18 changes: 18 additions & 0 deletions docs/compile.md
Original file line number Diff line number Diff line change
@@ -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.

70 changes: 70 additions & 0 deletions docs/lnd_regtest.md
Original file line number Diff line number Diff line change
@@ -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
```
11 changes: 11 additions & 0 deletions scripts/lightning-cli.sh
Original file line number Diff line number Diff line change
@@ -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 \
$@

29 changes: 19 additions & 10 deletions scripts/restart_plugin.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
12 changes: 12 additions & 0 deletions scripts/start_cln_with_local_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
157 changes: 0 additions & 157 deletions tests/NLoop.Server.Tests/Dockerfiles/lightning

This file was deleted.

Loading

0 comments on commit d1ff895

Please sign in to comment.