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
  • Electrum 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
  • Automatic sanity check of user defined networks

Planned features

  • Arbitrary lightning daemon binary detection (lnd, clightning, ...)
  • Time-dependent transaction series

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 integers 1, 2, 3, ...
  • Ports must be set uniquely

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

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

Running under Docker

$ docker build -t lnregtest:local .
$ docker run --rm -it lnregtest:local python3 -m unittest discover test

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

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.2.2
File Size Uploaded Provenance
lnregtest-0.2.2.tar.gz 23.8 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 51.1 kB

Release files / lnregtest-0.2.2.tar.gz

Download URL lnregtest-0.2.2.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
73aaedc5a261ecd026bd2a0a46616821497035baaa7e66f2f0bbee1903256c18
BLAKE2b-256 checksum
How to use checksums
0acce85b99b37aa597618b274956d26128d8e767a00679a7ab5f5afd702500e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

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

Download URL lnregtest-0.2.2-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bedbe299360fd468b0119dab7f10e0e574073177f73d4a0bedbe91e3231acc9a
BLAKE2b-256 checksum
How to use checksums
f6c3c6111fa05eb2a3afcad426c08f046c7aa7944c4cb56421de4d8b1e2c23dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for lnregtest 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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