# HTLC Watchtower

**URL:** https://forum.hypercore.one/t/htlc-watchtower/50
**Category:** Development
**Created:** [May 9, 2023, 2:14pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50 "2023-05-09T14:14:26Z")
**Posts on this page:** 12
**Page:** 2

<div class="post-metadata">

### Author: ![vilkris](https://forum.hypercore.one/user_avatar/forum.hypercore.one/vilkris/32/47_2.png) [@vilkris](https://forum.hypercore.one/u/vilkris)
#### Post date: [May 10, 2023, 6:43am UTC](https://forum.hypercore.one/t/htlc-watchtower/50/21 "2023-05-10T06:43:56Z")

</div>

It generates the schema file for the database’s data model: `htlc_data.g.dart` This file has to exist.  
The `libisar.so` library is automatically downloaded by the database when it initializes itself for the first time. I’m not 100% sure if this works as expected with Docker.

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 10, 2023, 10:09am UTC](https://forum.hypercore.one/t/htlc-watchtower/50/22 "2023-05-10T10:09:42Z")

</div>

I can get it to build in docker, just can’t run it. probably b/ I’m missing the DB.

Does `main` only need `htlc_data.g.dart` and `config.json` to run after being built? And it seems like `htlc_data.g.dart` needs to persist on a volume? I can get docker to do this. I’m going to add this to znndNode if I can get it to work.

---

<div class="post-metadata">

### Author: ![vilkris](https://forum.hypercore.one/user_avatar/forum.hypercore.one/vilkris/32/47_2.png) [@vilkris](https://forum.hypercore.one/u/vilkris)
#### Post date: [May 10, 2023, 10:56am UTC](https://forum.hypercore.one/t/htlc-watchtower/50/23 "2023-05-10T10:56:03Z")

</div>

`htlc_data.g.dart` is a source file used at compile time. Are you getting some error when trying to run it?

I’m not really familiar with Docker, but these commands should be enough to build and run the service (on Ubuntu). In the top level directory:

```auto
dart pub get
dart run build_runner build --delete-conflicting-outputs
mkdir build
dart compile exe src/main.dart -o build/htlc-watchtower
cp example.config.json build/config.json

```

This will build the `htlc-watchtower` binary into a directory named `build`. The `libisar.so` library has to be in the `build` directory as well. The service will automatically attempt to download it when its run, but maybe this doesn’t work with Docker.

To download the library on command line in Ubuntu this should work:

```auto
wget https://github.com/isar/isar/releases/download/3.1.0/libisar_linux_x64.so -O build/libisar.so

```

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 10, 2023, 12:23pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/24 "2023-05-10T12:23:40Z")

</div>

perfect. this is exactly what I need. I’ll get this running and report back.

---

<div class="post-metadata">

### Author: ![vilkris](https://forum.hypercore.one/user_avatar/forum.hypercore.one/vilkris/32/47_2.png) [@vilkris](https://forum.hypercore.one/u/vilkris)
#### Post date: [May 10, 2023, 1:15pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/25 "2023-05-10T13:15:50Z")

</div>

I added this option to the config.json: `unlock_threshold_in_minutes`

It can be used to configure a custom threshold for how much time is left until expiration before the watchtower unlocks an HTLC.

The default is 60 minutes, which means that the watchtower will unlock an HTLC once it is 60 minutes away from expiring. The minimum it can be set to is 30 minutes.

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 10, 2023, 6:26pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/26 "2023-05-10T18:26:56Z")

</div>

With this last change, I get the following error when running locally on Ubuntu

```auto
x3639@0x3639-NoM:~/Github/htlc-watchtower/build$ ./htlc-watchtower 
INFO: 2023-05-10 13:25:44.132974: Initializing websocket connection ...
SEVERE: 2023-05-10 13:25:44.134157: Failed to connect to Zenon node. Is the node running?

```

`cat config.json`

```auto
x3639@0x3639-NoM:~/Github/htlc-watchtower/build$ cat config.json 
node_url_ws: 'ws://public.deeZNNodez.com:35998'
unlock_threshold_in_minutes: 60

```

I’ve tried 3 different nodes - both ws and wss

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 10, 2023, 6:56pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/27 "2023-05-10T18:56:34Z")

</div>

When I try to run the Dockerfile Image I get the folllowing error:

`SEVERE: 2023-05-10 18:51:41.965667: Invalid argument(s): Failed to load dynamic library '/app/src/libisar.so': libgcc_s.so.1: cannot open shared object file: No such file or directory `

But I doubt that is related to the issue above. I’ve manually downloaded `https://github.com/isar/isar/releases/download/3.1.0/libisar_linux_x64.so` and moved here `src/libisar.so` If we can get the native build to work in Ubuntu, I can trouble shoot the `Dockerfile`

```auto
FROM dart:stable AS build

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get

# Copy app source code and AOT compile it.
COPY . .
# Ensure packages are still up-to-date if anything has changed
RUN dart pub get --offline
RUN dart run build_runner build --delete-conflicting-outputs
RUN dart compile exe src/main.dart -o src/main

# Build minimal serving image from AOT-compiled `/main` and required system
# libraries and configuration files stored in `/runtime/` from the build stage.
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/src/. /app/src/

#Start service.
CMD ["/app/src/main"]

```

---

<div class="post-metadata">

### Author: ![vilkris](https://forum.hypercore.one/user_avatar/forum.hypercore.one/vilkris/32/47_2.png) [@vilkris](https://forum.hypercore.one/u/vilkris)
#### Post date: [May 11, 2023, 6:27am UTC](https://forum.hypercore.one/t/htlc-watchtower/50/28 "2023-05-11T06:27:24Z")

</div>

Looks like I typo’d the file extension in the last post, it should be:

```auto
cp example.config.yaml build/config.yaml

```

And for this:

> [@0x3639](#):
>
> and moved here `src/libisar.so`

> [@vilkris](#):
>
> The `libisar.so` library has to be in the `build` directory

I’ll have to write some proper instructions and add them to the repo’s readme.

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 11, 2023, 2:08pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/29 "2023-05-11T14:08:03Z")

</div>

got it. makes sense now. `build` is required. I’ll get this going today.

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 11, 2023, 6:04pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/31 "2023-05-11T18:04:21Z")

</div>

I got the Dockerfile to work!!! I’ll make it less shitty and share here. Maybe I can submit a PR to add that to your repo along with instructions.

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 11, 2023, 10:25pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/32 "2023-05-11T22:25:55Z")

</div>

```auto
x3639@0x3639-NoM:~/Github/htlc-watchtower$ docker run -v wallet:/root/.znn/wallet htlc-watchtower
INFO: 2023-05-11 22:18:28.464656: Initializing websocket connection ...
INFO: 2023-05-11 22:18:28.729298: Websocket connection successfully established
INFO: 2023-05-11 22:18:28.729423: Connected to node ws://public.deeznnodez.com:35998
INFO: 2023-05-11 22:18:28.750339: Node is in sync
INFO: 2023-05-11 22:18:28.816243: Loading ./libargon2_ffi_plugin.so from path /root/.pub-cache/git/znn_sdk_dart-abf887d30311494d7e6cd87b2d74b87f55d37abd/lib/src/argon2/blobs/./libargon2_ffi_plugin.so
INFO: 2023-05-11 22:18:29.684808: The watchtower does not have enough Plasma. Please fuse at least 120 QSR to address: z1qpu77xejhe2pcxmkhyh5m9vlssxynxaakmk34c
INFO: 2023-05-11 22:18:29.684876: Waiting for Plasma
INFO: 2023-05-11 22:25:20.597073: The watchtower has enough Plasma now
INFO: 2023-05-11 22:25:20.597150: Watchtower initialized with address z1qpu77xejhe2pcxmkhyh5m9vlssxynxaakmk34c
INFO: 2023-05-11 22:25:20.597238: Running watchtower

```

---

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [May 11, 2023, 10:27pm UTC](https://forum.hypercore.one/t/htlc-watchtower/50/33 "2023-05-11T22:27:37Z")

</div>

That was not easy to get this to work with Docker. I gave up on downloading the `libisar.so` file on build. I just downloaded manually and put in the `build` folder. Maybe I’ll try again later.

[Previous page](https://forum.hypercore.one/t/htlc-watchtower/50.md?page=1)
