Can I test Lightning on Bitcoin regtest?

4

I want to do some Lightning experiments, but want to avoid the burden of synchronizing the blockchain (even testnet). Can I experiment with Lightning using regtest? Is there a manual for setting it up?

Sergei Tikhomirov

Posted 2019-05-10T09:38:50.943

Reputation: 1 189

Answers

2

Yes this is possible and (at least with clightning) very easy to do. I always use this script by Nadav Ivgi from his spark wallet. The key part is this : (MIT license by Nadav Ivgi)

$ mkdir -p /tmp/spark-env/{btc,ln1,ln2}

$ bitcoind --regtest --datadir=/tmp/spark-env/btc --printtoconsole
$ lightningd --network regtest --lightning-dir /tmp/spark-env/ln1 --bitcoin-datadir /tmp/spark-env/btc --addr 127.0.0.1:9600
$ lightningd --network regtest --lightning-dir /tmp/spark-env/ln2 --bitcoin-datadir /tmp/spark-env/btc --addr 127.0.0.1:9601

$ alias btc='bitcoin-cli --regtest --datadir=/tmp/spark-env/btc' \
        ln1='lightning-cli --lightning-dir /tmp/spark-env/ln1' \
        ln2='lightning-cli --lightning-dir /tmp/spark-env/ln2'

$ btc generate 101 && btc sendtoaddress $(ln1 newaddr | jq -r .address) 5 && btc generate 1

# wait for onchain funds to show up on `ln1 listfunds` (updated every 30s)

$ ln1 connect $(ln2 getinfo | jq -r .id) 127.0.0.1 9601 && \
  ln1 fundchannel $(ln2 getinfo | jq -r .id) 16777215 1100perkb && btc generate 1

If you use docker you can even spin up Nadavs docker image with:

$ docker run -e NETWORK=regtest -e API_TOKEN=1234 -p 9112:9112 shesek/lightning-charge

but if you want more lightning nodes fired up that already form a network you can use lnet by Christian Decker. With that script you can provide a weighed graph and get the lightning nodes as the graph defines.

Rene Pickhardt

Posted 2019-05-10T09:38:50.943

Reputation: 6 565

Is lnet supposed to be used only with c-lightning?Sergei Tikhomirov 2019-05-10T13:23:56.330

I think so. But I think it would be possible to extend to other lightning implementations (: maybe you find something in the test cases of each implementation. I think I remember that a fair fraction of lnet code comes from clightning test cases.Rene Pickhardt 2019-05-10T13:55:32.790

1I did some experiments with lnd in regtest mode. Just normally start bitcoind with zmq in regtest. Put the zmq connection and lnd chain mode to regtest. I will post an in-depth answer with exact configuration and commands latersanket1729 2019-05-10T20:45:40.903