Repository navigation
Conversation
Contributor
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
Derive each Spark send's idempotency key from the seed, the payment hash and an attempt number, so a retry reuses its attempt's key and Spark never pays an invoice twice. The attempt moves on only past keys Spark lists as failed. A short balance under a reused key keeps the send held, as it can hide the transfer an earlier attempt committed. The refusal while Spark's list can't be read now applies only to an invoice an older build sent under a random key. Verified: just compile, just test, just lint
Verified: just compile, just test, just lint
ovitrif
force-pushed
the
fix/spark-send-keys
branch
from
November 25, 2026 09:49
9de4067 to
a80d84b
Compare
A send refused before anything reached Spark's operators (a short balance or leaves Spark can't select under a never-used key, an expired invoice, a deadline or exit) kept its attempt as the invoice's latest, so a retry counted that unused key as reused and held the invoice pending until it expired. The refusal now puts back the attempt kept before it. Verified: just compile, just test, just lint (after the last edit: lint and test)
A retry under a key whose failure this process already reported, as when Spark's list couldn't be read to move past it, got the failure back with no event, leaving the send screen waiting; it is now refused. A send that lost Spark's key secret is refused instead of throwing, the leaf-selection refusal says so, and the restored cache log leaves out send attempts. Verified: just compile, just test, just lint
A send whose own result came back failed kept the invoice's send hash, so a retry while Spark's list couldn't be read showed it pending; the failed attempt paid nothing, so the hash goes, as when its outcome settles. The leaf-selection retry checks the deadline and exit before it waits, and a connection keeps the send key's secret before it reports connected. Verified: just compile, just test, just lint
Also publishes Spark's connection to other threads with the send key's secret already set, and drops a needless suspend from the retry check. Verified: just compile, just test, just lint
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2019
Closes #2021
Twin: synonymdev/bitkit-ios#1415
Refs: #2014
Description
SparkSendKey: each attempt's key is a UUIDv5 of a secret derived from the wallet seed, the payment hash and the attempt number, so a retry reuses its attempt's key and the Spark operators return the transfer it committed instead of sending again. A seed secret, not the bare hash, so no other wallet derives the same transfer id and the operators can't link the transfer to the invoice. iOS derives the same keys (shared test vector), so a restore across apps keeps them.sparkSendAttempts, kept until the invoice expires). A send moves to the next attempt only past keys Spark's local list shows failed, as a failed key can't send again.Guards:
refuseUnverifiedRestoredInvoice: kept, as it covers sends by older builds and the node rail, which have no derived key.Out of Scope
Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
Journeys
N/A — the combined payment has no journey yet; case 1 covers it.
Manual Tests
Automated Checks
SparkSendKeyTest.kt— derives the shared test vector iOS asserts tooSparkRepoTest.kt— a send goes out under its first attempt's key while Spark's list can't be readSparkRepoTest.kt— a retry reuses its attempt's key until Spark lists that attempt failedSparkRepoTest.kt— a retry takes the next attempt's key once Spark lists its attempt failedSparkRepoTest.kt— a short balance under a reused key keeps the send heldSparkRepoTest.kt— a send retries under its key while Spark can't select its leavesSparkRepoTest.kt— a send whose leaves Spark can't select is refused under a new keySparkRepoTest.kt— leaves Spark can't select under a reused key keep the send heldSparkRepoTest.kt— a send refused before reaching Spark is refused again on retrySparkRepoTest.kt— a refused retry keeps the attempt Spark listed failed before itSparkRepoTest.kt— a retry that gets back a failure already reported is refusedCacheStoreTest.kt— a send attempt drops expired ones and restores the earlier oneSparkRepoTest.kt— the unreadable-list refusal applies to an older build's sendLightningRepoTest.kt— stubs the send keyEvidence
just compile,just testandjust lintat HEAD: all pass.Regtest proof of the SDK behaviour this relies on (spark-sdk 0.28.3 client; operator
breez/spark@b54845cand Breez's test SSP, see Gaps). Each "nothing sent" was checked on the operators' transfers, the SSP's send requests and the receiver's balance.On the SSP route a recovered transfer resumes its Lightning request, which the SSP keys by transfer id, so one key never pays twice; a second payment needs a new attempt's key.
Regtest repro of the leaf-selection failure (found by the swipe-to-pay review run J1 on #2017, local regtest, master at its base): a combined payment moved 29 602 sats to Spark, and Spark's send about 1 s later failed with
Tree service error: generic error: Failed to select leaves after all retries. Master treated that as an unknown outcome, so the payment went Pending and never resolved ("Stopped polling ... until Spark syncs again"); the funds stayed in Spark and a retry paid. 0.28.3 raises it inselect_leaves_with_retryafter its balance check and before any operator call, so a send under the same key can be retried safely.Case 1 on local regtest with Spark (
breez/spark@b54845c, Breez's test SSP), emulator, build of a80d84b (before the attempt-restore and failed-result commits), host load under 14:This operator build rejects every leaf swap (
unable to validate adaptor signature, 51 of 51, including Spark's own leaf optimization after each receive), so Spark pays only amounts it can cover with leaves it already holds. Every failure behaved as this PR intends: retries under one key, then refused with Payment Failed, never an unresolved Payment Pending, funds left in Spark. Case 1 stays unchecked until it can pass on a stack whose leaf swaps work.Gaps
with_leafs_spent_retry!) and select again, so a short balance or a leaf-selection failure after such a retry could follow a committed transfer. Under a new key that path refuses the send, as it already did for a short balance.breez/spark@b54845c, Breez's test SSP), not the servers 0.28.3 pins or Lightspark's production SSP; their duplicate-transfer-id rejection and SSP dedup are proven on these builds only.Journeys
N/A — the combined payment has no journey yet; case 1 covers it.
Manual Tests
Automated Checks
SparkSendKeyTest.kt— derives the shared test vector iOS asserts tooSparkRepoTest.kt— a send goes out under its first attempt's key while Spark's list can't be readSparkRepoTest.kt— a retry reuses its attempt's key until Spark lists that attempt failedSparkRepoTest.kt— a retry takes the next attempt's key once Spark lists its attempt failedSparkRepoTest.kt— a short balance under a reused key keeps the send heldSparkRepoTest.kt— a send retries under its key while Spark can't select its leavesSparkRepoTest.kt— a send whose leaves Spark can't select is refused under a new keySparkRepoTest.kt— leaves Spark can't select under a reused key keep the send heldSparkRepoTest.kt— a send refused before reaching Spark is refused again on retrySparkRepoTest.kt— a refused retry keeps the attempt Spark listed failed before itSparkRepoTest.kt— a retry that gets back a failure already reported is refusedCacheStoreTest.kt— a send attempt drops expired ones and restores the earlier oneSparkRepoTest.kt— the unreadable-list refusal applies to an older build's sendLightningRepoTest.kt— stubs the send keyEvidence
just compile,just testandjust lintat HEAD: all pass.Regtest proof of the SDK behaviour this relies on (spark-sdk 0.28.3 client; operator
breez/spark@b54845cand Breez's test SSP, see Gaps). Each "nothing sent" was checked on the operators' transfers, the SSP's send requests and the receiver's balance.On the SSP route a recovered transfer resumes its Lightning request, which the SSP keys by transfer id, so one key never pays twice; a second payment needs a new attempt's key.
Regtest repro of the leaf-selection failure (found by the swipe-to-pay review run J1 on #2017, local regtest, master at its base): a combined payment moved 29 602 sats to Spark, and Spark's send about 1 s later failed with
Tree service error: generic error: Failed to select leaves after all retries. Master treated that as an unknown outcome, so the payment went Pending and never resolved ("Stopped polling ... until Spark syncs again"); the funds stayed in Spark and a retry paid. 0.28.3 raises it inselect_leaves_with_retryafter its balance check and before any operator call, so a send under the same key can be retried safely.Case 1 on local regtest with Spark (
breez/spark@b54845c, Breez's test SSP), emulator, build of a80d84b (before the attempt-restore and failed-result commits), host load under 14:This operator build rejects every leaf swap (
unable to validate adaptor signature, 51 of 51, including Spark's own leaf optimization after each receive), so Spark pays only amounts it can cover with leaves it already holds. Every failure behaved as this PR intends: retries under one key, then refused with Payment Failed, never an unresolved Payment Pending, funds left in Spark. Case 1 stays unchecked until it can pass on a stack whose leaf swaps work.Gaps
with_leafs_spent_retry!) and select again, so a short balance or a leaf-selection failure after such a retry could follow a committed transfer. Under a new key that path refuses the send, as it already did for a short balance.breez/spark@b54845c, Breez's test SSP), not the servers 0.28.3 pins or Lightspark's production SSP; their duplicate-transfer-id rejection and SSP dedup are proven on these builds only.Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium),Claude Sonnet 5.5(reasoning:high)gemini-4-neon-high(reasoning:Not exposed)Metadata note: the Gemini self-review records the model only, not a reasoning setting.