fort-nix / nix-bitcoin

A collection of Nix packages and NixOS modules for easily installing full-featured Bitcoin nodes with an emphasis on security.
https://nixbitcoin.org
MIT License
512 stars 106 forks source link

Running Lightning Network Cluster in a Container for Testing #536

Open DanGould opened 2 years ago

DanGould commented 2 years ago

I'd like to automate integration testing using nix-bitcoin. Our project opens lightning channels, so I'd like to run bitcoind and a cluster of 2 LND nodes. I believe using nix lets us control the environment such that we could even onboard devs in a repl.it link like @kodylow did at btc++.

Because some teammates run mac, and some linux, it seems like the NixOS VM isn't ready for this solution yet. If I understand correctly we could run such a NixOS VM in a docker container to solve this problem for now. We've got to use docker to support Umbrel and btcpayserver plugins, anyhow. Building that container from Nix also seems like the best way to a reproducible, maintainable build.

So far I've written a flake to 1. nix-build the binary 2. nix-develop in a defaultShell that includes tools to build that binary and 3. Spit out a docker container that includes the build.

I'm lost on how to get bitcoind, and then LND instances running in that container. Does it make to write logic that runs them in the flake? What do you make of the docker approach? If the approach makes sense, how does one define a running bitcoind and lightning cluster from a flake?

I figure others will want to do this in the future so an issue here could help.

nepet commented 2 years ago

So, we are not using any flake, but we are using nix-bitcoin or better the nix-pkgs bitcoin elementsd clightning and some helper packages for our dev environment on https://github.com/ElementsProject/peerswap.

We use the nix-shell command to spawn a shell that has the dependencies set and a helper shell script to spawn a network with several nodes. This is currently in a bad shape as we mix it also with some docker containers for the local playground, but the integration tests use the packages from the nix-shell environment.

Maybe take a look at the repo and especially at the following files:

Hope this is a helpful starting point. By the way: mac is also possible if the nix-pkgs are usable on mac, I added mac compatibility to the clightning nix package some time ago for example.

Maybe we could write a walk-trough/tutorial some time.

Cheers, Peter

DanGould commented 2 years ago

@nepet This is the way to go. Thank you for your thorough response.

re: .contrrib/startup_regtest.sh using the binaries provided by nix-shell, is there any way to use the declarative nix modules/configuration setup to avoid shell scripting the startup? I'm a bit confused between how things run in NixOS vm vs in binaries the shell has access to