Package: lnregtest
lnregtest - Lightning Networks on Bitcoin regtestImplements functioning lightning networks for (Python) integration testing
operating on a Bitcoin regtest network by running several lightning node
instances.The simulated lightning networks can have different shapes as defined
in thenetwork_definitionsfolder.An example of a graph (star_ring) with 7 nodes and 12 channels is shown
here (for initial channel balance details, have a look atnetwork_definitions/star_ring.py):Star-like component with channels (where A is the master node):
A -> B, A -> C, A -> D, A -> E, A -> F, A -> G,
Ring-like component with channels (which surrounds the master node):
B -> C, C -> D, D -> E, E -> F, F -> G, G -> BThis star and ring-like lightning network can then be used to test interactions
with the network from the master node's perspective, like rebalancing channels,
routing payments, sending payments and so on.FeaturesNo external python dependenciesArbitrary lightning network graphs with up to number of nodes on the order of
10 (depends on your resources)LND supportElectrum supportLightning graph state comparisonRestarting from already created networksAbstraction of random identifiers (public keys, channel ids) to human readable
identifiersLibrary and command-line executionAutomatic sanity check of user defined networksPlanned featuresArbitrary lightning daemon binary detection (lnd, clightning, ...)Time-dependent transaction seriesCreating your own network topologyNetworks of arbitrary shape can be defined as a python dictionary in thenetwork_definitionsfolder. See the examples for a general structure.The requirements are:Node A is the master nodeNodes are uniquely named by subsequent characters A, B, C, ...Channels are uniquely numbered by integers 1, 2, 3, ...Ports must be set uniquelyTesting other (python) projectsTest examples can be found in thetestfolder and more information on how
lnregtest is used for lightning network integration testing can be found inTEST.This package is also used in production inlndmanage.SetupThe binaries bitcoind (v22.0), bitcoin-cli, lnd (v0.14), and lncli are expected to be
found in$PATH, e.g., put these binaries into your ~/bin folder.You can use the tool in two different standalone modes:Git repository mode:$ git clone https://github.com/bitromortac/lnregtest
$ cd lnregtestRun network:$ python3 lnregtest.py -hPackage mode:$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install lnregtestRun network:$ lnregtest -hTest if lnregest worksTo run all tests, runpython3 -m unittest discover testfrom the root folder.Running under Docker$ docker build -t lnregtest:local .
$ docker run --rm -it lnregtest:local python3 -m unittest discover testTroubleshootingall SubConns are in TransientFailure:
Typically, here it happens that lnd is not given enough time to start.The
simulation of a lightning network is memory and CPU intensive.Each LN
node needs some time to get up and running and consumes resources.
Currently, the startup of each lnd node is delayed to distribute CPU load.
The settings were tested on a quadcore processor and 8 GB of RAM.bitcoind and lnd processes are not terminated:
Sometimes it happens that the processes are not terminated correctly, so
before you start new tests, make sure to do so manually.Related ProjectsMedium article on how regtest lightning networks can be set up:bitstein-mediumDockerized lightning networks:simverseDockerized version for the medium article:bitstein-test-env