Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .claude/plugins/.claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"name": "blocktank-api",
"source": "./blocktank-api",
"description": "Blocktank staging API: regtest mining, deposits, invoice payments and lookups of existing orders."
},
{
"name": "spark-regtest",
"source": "./spark-regtest",
"description": "Run a Bitkit dev build on Spark's regtest: Lightspark's hosted network or bitkit-docker's local ./spark stack."
}
]
}
4 changes: 4 additions & 0 deletions .claude/plugins/spark-regtest/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "spark-regtest",
"description": "Run a Bitkit dev build on Spark's regtest: Lightspark's hosted network or bitkit-docker's local ./spark stack."
}
18 changes: 18 additions & 0 deletions .claude/plugins/spark-regtest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Spark Regtest Plugin

A Claude Code plugin with the `spark-regtest` skill: build a Bitkit dev build for Spark's regtest, fund it and pick
between Lightspark's hosted regtest and bitkit-docker's local `./spark` stack.

## Setup

Run once from the repo root (re-run anytime to update):

```sh
./.claude/install-plugins.sh
```

Restart Claude Code once. The `spark-regtest:spark-regtest` skill is then available.

## Usage

The skill triggers on things like "spark regtest", "fund spark", "spark faucet", "ESPLORA_URL" or "./spark".
84 changes: 84 additions & 0 deletions .claude/plugins/spark-regtest/skills/spark-regtest/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
name: spark-regtest
description: >
This skill should be used when running a Bitkit dev build on Spark's regtest: building it for
Spark, funding Savings or the Spark (Spending) balance, paying between dev builds, Move to Spark,
or Spark emergency exit tests. Triggers: "spark regtest", "local spark", "fund spark",
"spark faucet", "spark deposit address", "Transfer Unavailable", "ESPLORA_URL",
"SPARK_LOCAL_CONFIG_B64", "./spark", "Lightspark regtest".
version: 0.1.0
---

# Spark regtest

Dev builds run Spark through the Breez SDK. Two Spark regtest networks exist, and neither shares a chain with Blocktank's
staging regtest (`stag0.blocktank.to`). Coins and Lightning payments never cross between them.

| | Lightspark hosted (default) | Local `./spark` (bitkit-docker) |
| --- | --- | --- |
| Use for | Quick checks, physical phones, two-device Spark payments | Lightning to or from a node you control, Move to Spark with a channel, emergency exits, offline E2E |
Comment thread
jvsena42 marked this conversation as resolved.
Resolved
| Lightning | Only through Lightspark's provider; no node you control | Alice, a Lightning node with a channel to the provider |
| Chain | Lightspark's own | bitkit-docker's local regtest (`spark-bitcoind` peers with `bitcoind`) |
| Funding | Faucet | `./spark pay`, `./spark send` |
| Docs | `scripts/spark-regtest-esplora.py`, `scripts/spark-regtest-fund.py` (headers) | `bitkit-docker/docs/spark-regtest.md` |

Sibling checkouts are assumed next to this repo (`../bitkit-docker`); from a worktree, use the main checkout's
siblings. Run `./spark` commands from bitkit-docker. Read the named docs and script headers for details. The steps below are what is not obvious from them.

## Lightspark hosted regtest

1. A dev build connects with no key. Without `ESPLORA_URL`, Savings stays on Blocktank's staging chain, so the app
shows the Transfer Unavailable sheet instead of Transfer to Spending (`Env.sparkSharesNodeChain`).
2. Put Savings on Spark's chain: run `python3 scripts/spark-regtest-esplora.py --port 3999`, then build with
`ESPLORA_URL=http://10.0.2.2:3999 ./gradlew assembleDevDebug`.
- `ESPLORA_URL` has the same sources as `BREEZ_API_KEY` (environment, Gradle property, `local.properties`, keychain)
and applies to the dev flavor only.
- The proxy stops after `--max-seconds` (default 3 h). The build then loses its chain; restart the proxy.
- A phone: `adb reverse tcp:3999 tcp:3999` with `ESPLORA_URL=http://127.0.0.1:3999`, or `--bind 0.0.0.0` with the
host's LAN IP.
3. Fund:
- Web faucet: https://app.lightspark.com/regtest-faucet, up to 50,000 sats per deposit. The user submits it in a
browser.
- Script: `SPARK_REGTEST_MNEMONIC=… uv run scripts/spark-regtest-fund.py <bcrt1… address> [sats]`. The mnemonic is a
GitHub secret. Ask the developer to set it locally, or use the web faucet. Keep it out of chat.
- Spark's deposit address is on Settings › Advanced › Lightning Connections › Spark. Fund it to fill Spending
directly, or fund Savings to test Transfer to Spending.
4. Lightspark mines about once a minute. Spark claims a deposit after 3 confirmations unless an Instant transfer claims
it early.
5. Two-device payment: fund the payer's Spark balance, copy the invoice from Receive › Spending on the other dev build,
and pay it from the payer. It goes over Lightning through Lightspark's provider.

## Local `./spark` stack

Run `./spark up` from a bitkit-docker checkout on `main`. The app reads the local settings only in a debug, regtest,
local-E2E build (`Env.localSparkSettings`), so the build needs `E2E=true` (`E2E_BACKEND` defaults to `local`). Without
it, the build silently stays on the hosted regtest.

```bash
../bitkit-docker/spark up && \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW: Preserve the public host on the chained Spark startup.

The LAN-phone instructions below start the fixture with SPARK_PUBLIC_HOST=<LAN IP> ./spark up, then apply LAN overrides to the build. That inline variable is gone when this newly added, unqualified spark up runs. Compose defaults PUBLIC_HOST to 127.0.0.1, and its init script rewrites the existing operator and SSP URLs, so the resulting phone build points Spark at the phone's own loopback. I reproduced that rewrite with the fixture's real init script. Export SPARK_PUBLIC_HOST for the whole recipe, or tell the LAN instructions to set it on this chained startup. Compose default, config generation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Pass the LAN host into the chained spark up

After the LAN phone steps start the fixture with SPARK_PUBLIC_HOST=<LAN IP> ./spark up, running the local build block rewrites that host to loopback and bakes it into the app.

The LAN note (SKILL.md:78-80) sets SPARK_PUBLIC_HOST only on that one ./spark up, then says to build with the LAN IP in E2E_LOCAL_HOST and SPARK_LOCAL_CHAIN_URL. The build block now begins with an unqualified ../bitkit-docker/spark up (SKILL.md:58). The prefix does not carry into that later command. spark runs docker compose --profile spark up -d with no --no-recreate (spark:9 and spark:75 at bitkit-docker ad995c1a07567cd06139cbacbbad73e458527fdd). Root docker-compose.yml includes spark-regtest/compose.yml, where spark-init sets PUBLIC_HOST from ${SPARK_PUBLIC_HOST:-127.0.0.1} (compose.yml:105). Compose recreates a service when that configuration changes. init.sh:102-106 and init.sh:137-139 write spark-config.json on every run, with operator URLs http://$PUBLIC_HOST:23535 (and 23536, 23537) and the SSP at http://$PUBLIC_HOST:23049. The next line of the block reads that file into SPARK_LOCAL_CONFIG_B64, and SparkService.configureLocalSpark passes it to the SDK as sparkConfig (SparkService.kt:107).

A phone on the LAN then dials the operators and the SSP at its own loopback, so Spark does not connect. Starting again with SPARK_PUBLIC_HOST set and rebuilding restores the URLs.

The chained spark up should receive the same SPARK_PUBLIC_HOST, or the LAN steps should say to set it on that command.

Evidence basis: source analysis of the skill, spark, the Compose include, and init.sh at ad995c1a07567cd06139cbacbbad73e458527fdd. A bash/jq probe of the same URL construction wrote http://192.168.1.50:23535, :23536, :23537, and SSP http://192.168.1.50:23049, then http://127.0.0.1 for those ports when the host was 127.0.0.1. Docker's compose up documentation says existing containers are recreated when the service configuration changes. This review did not run the Docker daemon. The same mechanism is in discussion. No matching GitHub issue was found.

CFG="$(../bitkit-docker/spark config --base64)" && \
Comment thread
jvsena42 marked this conversation as resolved.
Resolved
ESPLORA_URL= E2E=true E2E_BACKEND=local SPARK_LOCAL_CONFIG_B64="$CFG" \
SPARK_LOCAL_CHAIN_URL=http://127.0.0.1:23090/api ./gradlew assembleDevDebug && \
for port in 23535 23536 23537 23049 23090 60001; do adb reverse tcp:$port tcp:$port; done
```

- The `&&` chain stops at the first failure. `spark up` can fail while a config from an earlier run survives, and
`spark config` fails when the stack is not up or the `bitkit-docker` path is wrong; inline, Gradle would still run with
an empty config, and Spark refuses to start.
- `E2E=true` also points Savings at Electrum on `E2E_LOCAL_HOST:60001` (default `10.0.2.2`), bitkit-docker's chain.
Comment thread
jvsena42 marked this conversation as resolved.
Resolved
`ESPLORA_URL=` blanks a hosted proxy URL saved in another source, which Savings would otherwise use instead.
- An existing dev install keeps the Electrum server saved in its settings, which includes the old default. Uninstall
first (backups are off, so nothing comes back), or use Settings › Advanced › Electrum Server › Reset To Default, then
Connect To Host (Reset only fills the form).
- On Android the local stack turns off Transfer to Spending and exit fees paid from Savings
(`Env.sparkSharesNodeChain`). Fund Spark with `./spark send <deposit address> <sats>` or
`./spark pay <Spending invoice> [sats]`, and pay exit funding with `./spark send`. iOS allows both when its URLs match the fixture.
- A deposit is claimed after 1 block here.
- Mine with `./spark mine`, not `./bitcoin-cli mine`: only `spark-bitcoind` relays Spark's v3 packages.
- A phone over adb: set `E2E_LOCAL_HOST=127.0.0.1` and keep the `adb reverse` loop. Over the LAN: start with
`SPARK_PUBLIC_HOST=<LAN IP> ./spark up`, and build with `E2E_LOCAL_HOST=<LAN IP>` and
`SPARK_LOCAL_CHAIN_URL=http://<LAN IP>:23090/api`.
- bitkit-e2e-tests' `README.md` (Spark tests on local regtest) runs the same stack from its pinned
`BITKIT_DOCKER_REVISION`, not your checkout.

Regtest needs no `BREEZ_API_KEY`. For mainnet builds see `README.md`, "Breez API key".
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Reports are generated in: `app/build/reports/detekt/`.
The repo ships Claude Code plugins under `.claude/plugins/` to give Claude domain-specific skills for local development:

- [**blocktank-api**](.claude/plugins/blocktank-api/README.md) — `/lsp` skill for Blocktank staging's regtest tools (mine, deposit, pay invoice) and lookups of existing orders.
- [**spark-regtest**](.claude/plugins/spark-regtest/README.md) — build, fund and pay on Spark's regtest, hosted by Lightspark or local through bitkit-docker's `./spark`.

Install or update all bundled plugins with:

Expand Down Expand Up @@ -271,6 +272,7 @@ Destructive operations like `rm -rf`, `git commit`, and `git push` still require
Claude Code plugins provide specialized skills for development workflows. See [`.claude/plugins/`](.claude/plugins/) for available plugins.

- [blocktank-api](.claude/plugins/blocktank-api/README.md) — Blocktank staging regtest tools and order lookups
- [spark-regtest](.claude/plugins/spark-regtest/README.md) — Spark regtest builds and funding

## License

Expand Down
Loading