Skip to content

fix: allow transfers on local spark regtest - #2139

Merged
ovitrif merged 2 commits into
masterfrom
fix/local-spark-transfer
Nov 26, 2026
Merged

ovitrif merged 2 commits into
masterfrom
fix/local-spark-transfer

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Refs:

Description

  • Fixes Savings → Transfer To Spending opening Transfer Unavailable on a local Spark regtest build (SPARK_LOCAL_CONFIG_B64 + SPARK_LOCAL_CHAIN_URL against bitkit-docker's spark profile), because Env.sparkSharesNodeChain returned false for every local Spark config, although that stack's Spark and the node read the same chain.
  • sparkSharesNodeChain now follows iOS's Env.sharesLocalSparkChain. A local config shares the node's chain only when all of these hold:
    • Spark reads the fixture's REST at :23090/api, on E2E_LOCAL_HOST or on 127.0.0.1 (the emulator reaches the fixture over adb reverse);
    • the running node syncs from the fixture's Electrum, tcp://<E2E_LOCAL_HOST>:60001;
    • no ESPLORA_URL is set.
  • The case test: enable local spark e2e on android #1980 guarded stays false: an Electrum server chosen by a restore or in settings, an Esplora node source, or an incomplete fixture config. On Android, hardware wallets read the node's Electrum setting, so the one check covers both, where iOS checks them separately.
  • LightningService publishes the node's Electrum server to Env.activeElectrumServerUrl once node.start() succeeds, and clears it on stop(). The Funding screen collects it, so its on-chain options follow the running node.
  • The same flag also gates Spark withdrawals to Savings and emergency exit fees paid from Savings. Both now work on the local stack under the same rule.
  • Updates the spark-regtest skill note, which said the local stack always turns these off on Android.
  • Updates the spark-transfer-to-spending.xml precondition so the journey runs on the local stack too.

Before: Savings → Transfer To Spending opens Transfer Unavailable on the local stack.
After: it opens the transfer flow.

Out of Scope

  • Hosted regtest and mainnet: unchanged. Hosted regtest still needs the Spark Esplora proxy (ESPLORA_URL), and mainnet always shares the chain.
  • SparkExitRepo, SparkExitViewModel, TransferViewModel: they read the flag when they act, so they need no change.
  • journeys/README.md: listing the local ./spark stack in the Capabilities table goes in a follow-up PR after this merges, raised in fix: allow transfers on local spark regtest #2139 (comment).

Design

N/A — no UI changes.

Preview

N/A

QA Notes

Setup

bitkit-docker's local Spark stack (./spark up), and a dev debug build made as in .claude/plugins/spark-regtest/skills/spark-regtest/SKILL.md, "Local ./spark stack":

ESPLORA_URL= E2E=true E2E_BACKEND=local SPARK_LOCAL_CONFIG_B64="$(../bitkit-docker/spark config --base64)" \
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

Fund Savings with ./spark send <savings address> 100000, then ./spark mine 1.

Journeys

  • J1: updated spark-transfer-to-spending.xml — on the local stack, Savings → Transfer To Spending opens the transfer flow instead of Transfer Unavailable

Manual Tests

N/A

Automated Checks

  • updated SparkChainServiceTest.kt — a local fixture shares the node's chain only when the node runs on the fixture's Electrum; another Electrum, an Esplora source, another Spark host or port, and an incomplete config stay false
  • updated LightningServiceTest.kt — the node's Electrum is published only after the node starts, and cleared on stop

Evidence

  • The new SparkChainServiceTest case failed on the old rule and passes with this change.
  • just compile, just test and just lint passed.
  • J1's transfer entry on the local stack, on an Android 15 emulator at 725d977: Savings → Transfer To Spending opens the transfer intro and then the amount screen; master opens Transfer Unavailable. Recording and screenshot are in the QA comment.

Gaps

  • J1 was driven up to the amount screen only, not through its confirm-screen steps or a completed transfer.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium), Claude Sonnet 5.5 (reasoning: high)
  • Review: Not performed

A local Spark config made Env.sparkSharesNodeChain false even when the
node and hardware wallets sync from the fixture's own Electrum, so
Savings → Transfer To Spending opened Transfer Unavailable on the local
stack. It now matches iOS: true when Spark reads the fixture's REST on
the local host (or loopback over adb reverse) and the running node uses
the fixture's Electrum. A restored or chosen Electrum server, an Esplora
node source or an incomplete config keep it false.

Verified: just compile, just test, just lint (the new SparkChainServiceTest
case failed on the old rule)
@ovitrif ovitrif self-assigned this Nov 26, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T17:57:16.401282Z 4044efb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4044efb22e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/src/main/java/to/bitkit/env/Env.kt Resolved
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking hardware-funding edge case during regtest server changes.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The behavior is limited to local Spark regtest but reaches several Savings workflows.

The PR appears safe to merge, with a non-blocking hardware-funding edge case during regtest server changes.

Findings

  1. P2 Hardware transfers use another chain ▶

Summary

Enables local Spark regtest transfers when Spark's REST URL and the running node's Electrum URL match the fixture.

  • Local Spark regtest transfers work when Spark and the node share the fixture chain.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Configure node source] --> B[Start node]
    B --> C[Publish active Electrum URL]
    C --> D[Check local fixture URLs]
    D --> E[Update Funding options]
    F[Stop node] --> G[Clear active Electrum URL]
    G --> D
    H[Saved Electrum setting] --> I[Hardware compose and broadcast]
Loading

Reviews (1) · Last reviewed commit: "fix: allow transfers on local spark regt..." · Reviewed by Greptile

Comment thread app/src/main/java/to/bitkit/env/Env.kt Resolved

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No findings. Lets a local Spark regtest build (fixture REST on :23090/api, node on the fixture's Electrum, no ESPLORA_URL) count as sharing the node's chain, so Transfer To Spending, Spark withdrawals to Savings and exit fees from Savings work on bitkit-docker's spark stack; the node's Electrum is published to Env.activeElectrumServerUrl on start and cleared on stop. Reviewed 4044efb, full tier, static: build skipped, the Bitkit track does not build bitkit-android branches on this reviewer's machine, so this is reasoned from the code and CI.

What I checked, and 5 candidates I ruled out

Read in full: Env.kt (sparkSharesNodeChain, ElectrumServers, LocalSparkSettings), LightningService.kt (buildNode, configureChainSource, start, stop), the restartWithElectrumServer / skipStartForRunningNode paths in LightningRepo.kt, HwWalletRepo.syncWatchers, the Funding route and the three sparkSharesNodeChain gates in ContentView.kt.
Call sites traced: every reader of Env.sparkSharesNodeChain (SparkExitRepo, SparkExitViewModel, TransferViewModel, ContentView); every writer of the node's Electrum URL (customServerUrl ?: settings.electrumServer).
CI: build-and-test, lint, compose-ui and build-local were still running when this was posted.

Ruled out

  • Hardware wallet on a different Electrum than the node: the node uses customServerUrl only inside restartWithElectrumServer, which persists the same URL to settings on success and rebuilds from settings on failure, and a failed start never publishes, so the published URL and the one HwWalletRepo watchers read agree outside that window.
  • Stale URL after a failed start: chainElectrumUrl keeps the last build's value, but it is published only after node.start() returns, and the next build overwrites it in configureChainSource on both the Esplora and Electrum branches.
  • A running node not reported after a skipped start: skipStartForRunningNode refuses a custom server, and a plain skip leaves the value the earlier successful start published.
  • Funding screen showing a stale answer: it now collects sparkSharesNodeChainFlow; the other gates read the flag when they act, and before the node starts they read false, which is the guarded case.
  • Default emulator setup missing the rule: the local backend's default Electrum is ElectrumServers.REGTEST.LOCAL, the same tcp://<E2E_LOCAL_HOST>:60001 the check compares against, and loopback Spark URLs under adb reverse are accepted.

Merge confidence: 4/5, no findings, but CI had not finished and the branch was not built here; SparkChainServiceTest and LightningServiceTest cover the new rule and the publish/clear.

Reviewer model: Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: Not exposed (the review session's runtime does not report an effort setting)

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 725d977 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

QA for 725d977:
Tested on Android 15 emulator (Pixel 9), dev debug build against bitkit-docker's local Spark stack (E2E=true E2E_BACKEND=local, SPARK_LOCAL_CONFIG_B64, SPARK_LOCAL_CHAIN_URL=http://127.0.0.1:23090/api, ports forwarded with adb reverse). Each installed APK's sha256 matches its build.

🟢 J1: Savings → Transfer To Spending on the local stack
J1: Savings → Transfer To Spending on the local stack

A fresh wallet connected Spark to the fixture's chain, the node synced from the fixture's Electrum (tcp://10.0.2.2:60001), and Savings was funded with 100 000 sats. Savings → Transfer To Spending opens the "Transfer to spending" intro, and Get Started opens the amount screen with ₿ 99 890 available.

caseB-fix2x.mp4

🟢 Before: the same tap on master
Before: the same tap on master

The same setup on master c12ff7c opens the Transfer Unavailable sheet. Its recording stopped before the tap, so the screenshot is the evidence.


@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code scan at 725d977: no HIGH/MEDIUM. One LOW (journey docs), inline.

Checked and clean:

  • Release and default dev builds are unchanged. In Env.kt:175-189, the network != REGTEST and localSpark == null branches give the same result as the old rule and don't read nodeElectrumUrl. Only the localSpark != null branch changed. localSparkSettings is non-null only for debug + local E2E backend + regtest with SPARK_LOCAL_* set, so mainnet, tnet, every release build and the hosted-Spark dev build never reach it.
  • chainElectrumUrl is published only after node.start() returns and cleared first in stop(). Its only readers are the two sparkSharesNodeChain* members, which ignore it outside the local branch. lifecycleMutex keeps a start from publishing after a concurrent stop's clear.
  • Fails safe: while the node is stopped or restarting on a local build, the transfer gates read false and show Transfer Unavailable, TransferViewModel skips the Spark withdrawal, and SparkExitRepo refuses.
  • tcp://<E2E_LOCAL_HOST>:60001 and http://<host>:23090/api are one chain on bitkit-docker main (spark-bitcoind -addnode=bitcoind), and "Reset To Default → Connect To Host" saves exactly that URL string.
  • The SKILL.md bullet matches Env.kt and bitkit-docker's spark commands and published ports.

perf: not relevant.

Device gate (partial): 725d977 — not run yet; J1 needs the local Spark stack. Result to follow.

Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating and verifying; Fable 5.2 (claude-fable-5-2) primary review
Reasoning effort: Not exposed

@piotr-iohk piotr-iohk left a comment

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.

QA review

Scope: full PR diff against its merge base, at 725d977.

No new actionable code findings.

No new actionable code findings. The new Env.sparkSharesNodeChain rule gives the same result as the old one for mainnet, hosted regtest and every build without localSparkSettings. Only the localSpark != null branch changed, and localSparkSettings is non-null only in a debug, local-E2E, regtest build. The node's Electrum URL is published to Env.activeElectrumServerUrl only after node.start() succeeds, and LightningService.stop() clears it first. lifecycleMutex in LightningRepo serializes start and stop, and stop() always nulls the node handle, so a stale non-null URL cannot outlive a stopped node. While the node is stopped or restarting on the local stack, every gate (Funding, the Savings, Spending and HW Transfer To Spending buttons, TransferViewModel, SparkExitRepo and SparkExitViewModel) reads false and fails safe. The click-time gates in ContentView read the current value when tapped, and Funding collects the new flow.

Existing review threads:

  • jvsena42's LOW still applies at this head and its thread is open: the journeys/README.md Capabilities row for Spark still names only hosted regtest. The author has deferred it to a follow-up PR.
  • The Codex journey-precondition thread is resolved, and spark-transfer-to-spending.xml is updated at this head.
  • Greptile's hardware-wallet chain-split thread is resolved and withdrawn. I confirmed at this head that the split needs a failed settings write after restartWithElectrumServer has already started the node on the new server. In every other path the node and HW wallets both read settingsStore.electrumServer.

Validation: CI run 45874331337 for 725d977 passed build-and-test (which includes the updated SparkChainServiceTest and LightningServiceTest), lint and compose-ui; the local e2e jobs also passed. I ran no tests myself.

iOS comparison (bitkit-ios d30d2d6, Env.sharesLocalSparkChain and SparkManager.readsSavingsChain): iOS requires the Spark URL on the fixture host and checks the hardware wallet's Electrum separately. Android also accepts 127.0.0.1, for adb reverse, and covers hardware wallets through the node's saved Electrum setting. The PR body states both differences, and I found no violated requirement.

Device testing: not performed in this review. The author's QA comment reports J1 on an Android 15 emulator at 725d977, reaching only the amount screen.

Suggested additional test cases

  • Android, local ./spark stack build as in the PR's QA setup, Savings funded: open Funding and verify "Transfer from Savings" and "Transfer from HW wallet" are enabled. Then use Settings › Advanced › Electrum Server to connect to a different Electrum server, return to Funding, and verify both options are disabled and Savings → Transfer To Spending opens Transfer Unavailable. Reset to default, connect, and verify they are enabled again.
  • Android, same setup: background the app until the node stops, return, and immediately tap Savings → Transfer To Spending. Expect Transfer Unavailable until the node is running, then the transfer intro, with no crash or stuck state.
  • Android, same setup: start an emergency exit and choose to pay the exit fee from Savings. Verify the Savings option is offered and the payment completes on the local chain; on base it was never offered.

Reviewer model: claude-opus-5-5
Reasoning effort: high

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged: approved by @piotr-iohk, checks green, and the device run on 725d977 is posted above. I resolved @jvsena42's README thread as deferred; the Capabilities row change follows in its own PR.

@ovitrif
ovitrif merged commit afb8f3e into master Nov 26, 2026
23 checks passed
@ovitrif
ovitrif deleted the fix/local-spark-transfer branch November 26, 2026 20:41
@jvsena42

Copy link
Copy Markdown
Member

Device gate (partial): 725d977 — run on the Android emulator against the local bitkit-docker Spark stack, unpatched PR build, node on the default local Electrum.

  • J1 (spark-transfer-to-spending.xml): all actions reached. Funding's Transfer and Hardware rows are enabled. Transfer from Savings opens the intro and then the amount screen. Confirm shows Network 365, Service 496, Total 100 000.
  • With Electrum set to any other URL (tcp://127.0.0.1:60001, the same server over adb reverse), the Transfer Unavailable sheet shows and the rows are grey. Reset To Default enables them again.
  • While the node is restarting, a tap gives Transfer Unavailable; after Node started, it gives the amount screen.
  • Before this change (the old rule build), the same setup shows Transfer Unavailable with the node running.
  • Side effect: the Spark exit's Emergency fees screen offers "Deducted from your Savings balance" on this build without last week's sparkSharesNodeChain patch.

Still running: the driver's run of the runbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants