Skip to main content

lnregtest - Lightning Networks on Bitcoin regtest

Implements 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 the network_definitions folder.

An example of a graph (star_ring) with 7 nodes and 12 channels is shown here (for initial channel balance details, have a look at network_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 -> B

This 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.

Features

  • No external python dependencies
  • Arbitrary lightning network graphs with up to number of nodes on the order of 10 (depends on your resources)
  • LND support
  • Lightning graph state comparison
  • Restarting from already created networks
  • Abstraction of random identifiers (public keys, channel ids) to human readable identifiers
  • Library and command-line execution

Planned features

  • Arbitrary lightning daemon binary detection (lnd, clightning, ...)
  • Time-dependent transaction series
  • Automatic sanity check of user defined networks

Creating your own network topology

Networks of arbitrary shape can be defined as a python dictionary in the network_definitions folder. See the examples for a general structure.

The requirements are:

  • Node A is the master node
  • Nodes are uniquely named by subsequent characters A, B, C, ...
  • Channels are uniquely numbered by incremental integers 1, 2, 3, ...
  • Ports must be set uniquely
  • Local balances must be larger than remote balances

Testing other (python) projects

Test examples can be found in the test folder and more information on how lnregtest is used for lightning network integration testing can be found in TEST.

This package is also used in production in lndmanage.

Setup

In order to have a complete immediate graph view, we need to compile LND in a special way by setting defaultTrickleDelay = 1 in config.go.

The binaries bitcoind, bitcoin-cli, lnd, and lncli are expected to be found in $PATH.

You can use the tool in two different standalone modes:

Git repository mode:

$ git clone https://github.com/bitromortac/lnregtest
$ cd lnregtest

Run network:

$ python3 lnregtest.py -h

Package mode:

$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install lnregtest

Run network:

$ lnregtest -h

Test if lnregest works

To run all tests, run python3 -m unittest discover test from the root folder.

Troubleshooting

  • all 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. If you experience startup problems, increase LOAD_BALANCING_LND_STARTUP_TIME_SEC in lib.common. 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.

Metadata

Release files for lnregtest 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lnregtest 0.1.1
File Size Uploaded
lnregtest-0.1.1.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lnregtest 0.1.1
File Interpreter ABI Platform
lnregtest-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.7 kB

Release files / lnregtest-0.1.1.tar.gz

Download URL lnregtest-0.1.1.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b8951da6c7360895f8f95bc3ff9d65cd98427ae1ee54433720d8e623e7b8b33a
BLAKE2b-256 checksum
How to use checksums
0214efd7da447900671eadf39ee2fe7d30072b91e2dbf9ebc689f54cfd8c0308
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

Release files / lnregtest-0.1.1-py3-none-any.whl

Download URL lnregtest-0.1.1-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd77278b14fb218c36268e6c1796847df2bcd525e8ef98b28d097f3a10eb44bb
BLAKE2b-256 checksum
How to use checksums
89cd7cd0c9375b9c34f6c8a3f7b1591aca1ce1b695ee8cc8cd5cab29ee1e7f9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

Release history Release notifications | RSS feed

0.2.2

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page