Files
giza-kmp/testing/regtest/regtest.sh
T
Kgothatso NgakoandClaude Opus 5.5 d8d8d038f9 test(lightning): the group's wallet end to end on regtest, and what it found
`testing/regtest/` builds bitcoind, electrs, an eclair v0.14.4 LSP set up as
a Phoenix LSP, and a payer. `GroupLightningRegtestJvmTest` (run with
BENNU_REGTEST=1) drives four devices through it with a real lightning-kmp
node: open, receive on a channel opened on the fly, pay through the LSP's
trampoline, close mutually, then force-close a second channel and sweep its
delayed output with a FROST script-path spend. It passes from a fresh
network in about thirty seconds.

The run found four bugs in the operator's node, fixed here:

- It learned the chain's height only at the next block, and until then
  could answer no invoice request and take no payment. It now asks as it
  starts.
- It turned down every on-the-fly channel, because lightning-kmp's default
  liquidity policy caps fees at 2,000 sats and the statement's signed
  `maxLiquidityFeeSat` never reached it. The node's policy is now the
  statement's.
- A channel could ask for round one before the pool held it. The node now
  waits for a minimum pool before connecting, and otherwise refuses and
  retries.
- A force close waited forever for feerates, which lightning-kmp fetches
  only once. The node now refreshes them, and takes a flat rate on regtest.

Public eclair cannot route a Bolt11 payment to a wallet by its peer-id
route hint, so the run pays the group's Bolt12 offer. The offer is now part
of the wallet: every snapshot carries it, every member keeps it only if
its own copy of the seed derives it, and the receive screen shows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 22:30:25 +02:00

41 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# The group Lightning wallet's regtest network. `up` builds it from nothing: bitcoind with three
# wallets (a miner, the LSP's, the payer's), electrs, both eclair nodes, and a channel from the payer to
# the LSP. `down` removes all of it.
set -euo pipefail
cd "$(dirname "$0")"
btc() { docker compose exec -T bitcoind bitcoin-cli -regtest -rpcuser=foo -rpcpassword=bar "$@"; }
lsp() { local m=$1; shift; curl -sf -u :lsp -X POST "http://127.0.0.1:28080/$m" "$@"; }
payer() { local m=$1; shift; curl -sf -u :payer -X POST "http://127.0.0.1:28081/$m" "$@"; }
mine() { btc -rpcwallet=miner generatetoaddress "${1:-1}" "$(btc -rpcwallet=miner getnewaddress)" >/dev/null; }
wait_for() { for _ in $(seq 1 90); do if eval "$1" >/dev/null 2>&1; then return 0; fi; sleep 1; done; echo "timed out waiting for: $1" >&2; return 1; }
case "${1:-}" in
up)
docker compose up -d bitcoind
wait_for "btc getblockchaininfo"
for w in miner lsp payer; do btc -named createwallet wallet_name=$w load_on_startup=true >/dev/null 2>&1 || btc loadwallet $w >/dev/null 2>&1 || true; done
mine 150
btc -rpcwallet=miner sendtoaddress "$(btc -rpcwallet=lsp getnewaddress)" 10 >/dev/null
btc -rpcwallet=miner sendtoaddress "$(btc -rpcwallet=payer getnewaddress)" 10 >/dev/null
mine 6
docker compose up -d electrs lsp payer
wait_for "lsp getinfo"
wait_for "payer getinfo"
lspId=$(lsp getinfo | python3 -c 'import sys,json; print(json.load(sys.stdin)["nodeId"])')
payer connect -d uri="$lspId@lsp:9735" >/dev/null
payer open -d nodeId="$lspId" -d fundingSatoshis=5000000 >/dev/null
# The funding transaction reaches the mempool a moment after the open is answered.
wait_for "[ \$(btc getmempoolinfo | python3 -c 'import sys,json; print(json.load(sys.stdin)[\"size\"])') -gt 0 ]"
wait_for "mine 1; payer channels | grep -q NORMAL"
echo "LSP $lspId on 127.0.0.1:29735, electrs on 127.0.0.1:28001"
;;
down) docker compose down -v ;;
mine) mine "${2:-1}" ;;
btc) shift; btc "$@" ;;
lsp) shift; lsp "$@"; echo ;;
payer) shift; payer "$@"; echo ;;
*) echo "usage: $0 up | down | mine [n] | btc <args> | lsp <method> [-d k=v] | payer <method> [-d k=v]"; exit 1 ;;
esac