Skip to content
Merged
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
6 changes: 0 additions & 6 deletions app/src/main/java/to/bitkit/repositories/LightningRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1931,12 +1931,6 @@ class LightningRepo @Inject constructor(
return !isWiped()
}

/** Pays [bolt11] from the node's channels only, for a send quoted on them that must never fall back to Spark. */
suspend fun payInvoiceWithNode(bolt11: String): Result<PaymentId> {
val paymentHash = runCatching { Bolt11Invoice.fromStr(bolt11).paymentHash() }.getOrNull()
return payInvoiceWithLdk(bolt11, null, paymentHash, null, null) { true }
}

/**
* The node's pending or paid send of [bolt11]. While the node can't list its payments (stopped or not started yet),
* a send it started for the invoice may be live or paid, and its event may never come, so the node not started yet
Expand Down
43 changes: 12 additions & 31 deletions app/src/test/java/to/bitkit/repositories/LightningRepoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1560,25 +1560,6 @@ class LightningRepoTest : BaseUnitTest() {
inFlight.await()
Comment thread
ovitrif marked this conversation as resolved.
Resolved
}

@Test
fun `a node-only payment fails instead of falling back to spark`() = test {
startNodeForTesting()
whenever(sparkRepo.canSend(1_000uL)).thenReturn(true)
whenever(sparkRepo.payInvoice(any(), anyOrNull(), anyOrNull(), anyOrNull(), any()))
.thenReturn(Result.success("spark-hash"))
whenever(lightningService.channels).thenReturn(listOf(createChannelDetails().copy(isUsable = true)))
whenever(lightningService.send(any(), anyOrNull(), anyOrNull(), anyOrNull()))
.thenAnswer { throw AppError("Route not found") }
// The unrestricted entry picks Spark when the channels cannot carry the amount.
assertEquals("spark-hash", sut.payInvoice("bolt11", 1_000uL).getOrThrow())

val result = sut.payInvoiceWithNode("bolt11")

assertTrue(result.isFailure)
verify(sparkRepo, times(1)).payInvoice(any(), anyOrNull(), anyOrNull(), anyOrNull(), any())
verify(lightningService).send(eq("bolt11"), anyOrNull(), anyOrNull(), anyOrNull())
}

@Test
fun `an earlier spark failure never settles a retry the node is paying`() = test {
startNodeForTesting()
Expand Down Expand Up @@ -2237,7 +2218,7 @@ class LightningRepoTest : BaseUnitTest() {
val sent = CompletableDeferred<String>()
whenever(lightningService.send(any(), anyOrNull(), anyOrNull(), anyOrNull()))
.doSuspendableAnswer { sent.await() }
val retry = async { sut.payInvoiceWithNode("h") }
val retry = async { sut.payInvoice("h") }
runCurrent()
whenever(lightningService.listPayments()).thenReturn(listOf(nodeSend("h", PaymentStatus.FAILED)))
whenever(sparkRepo.canSend(1_000uL)).thenReturn(true)
Expand All @@ -2264,7 +2245,7 @@ class LightningRepoTest : BaseUnitTest() {
val listed = listOf(nodeSend("h", PaymentStatus.FAILED))
if (!isRetried) {
isRetried = true
sut.payInvoiceWithNode("h")
sut.payInvoice("h")
}
listed
}
Expand All @@ -2286,7 +2267,7 @@ class LightningRepoTest : BaseUnitTest() {
val sent = CompletableDeferred<String>()
whenever(lightningService.send(any(), anyOrNull(), anyOrNull(), anyOrNull()))
.doSuspendableAnswer { sent.await() }
val retry = async { sut.payInvoiceWithNode("h") }
val retry = async { sut.payInvoice("h") }
runCurrent()
var isEnded = false
// The retry recorded before this listing ends while the listing, which still shows it failed, is read.
Expand Down Expand Up @@ -2320,7 +2301,7 @@ class LightningRepoTest : BaseUnitTest() {
val listed = listOf(nodeSend("h", PaymentStatus.FAILED))
if (!isRetried) {
isRetried = true
sut.payInvoiceWithNode("h")
sut.payInvoice("h")
}
listed
}
Expand Down Expand Up @@ -2348,9 +2329,9 @@ class LightningRepoTest : BaseUnitTest() {
whenever(lightningService.send(any(), anyOrNull(), anyOrNull(), anyOrNull())).doSuspendableAnswer {
if (sends++ == 0) queued.await() else throw ServiceError.NodeNotStarted()
}
val first = launch { sut.payInvoiceWithNode("h") }
val first = launch { sut.payInvoice("h") }
runCurrent()
assertTrue(sut.payInvoiceWithNode("h").isFailure)
assertTrue(sut.payInvoice("h").isFailure)
whenever(sparkRepo.canSend(1_000uL)).thenReturn(true)

sut.payInvoice("h", 1_000uL)
Expand All @@ -2374,7 +2355,7 @@ class LightningRepoTest : BaseUnitTest() {
whenever(sparkRepo.payInvoice(any(), anyOrNull(), anyOrNull(), anyOrNull(), any())).doSuspendableAnswer {
val authorizeSend = it.getArgument<suspend () -> Boolean>(4)
check(authorizeSend())
nodeResult = sut.payInvoiceWithNode("h")
nodeResult = sut.payInvoice("h")
Result.success("h")
}

Expand Down Expand Up @@ -2560,7 +2541,7 @@ class LightningRepoTest : BaseUnitTest() {
runSuspendCatching {
authorizeSend()
"h"
}.also { sut.payInvoiceWithNode("h").getOrThrow() }
}.also { sut.payInvoice("h").getOrThrow() }
}
whenever(sparkRepo.lightningSend("h")).thenReturn(SparkLightningSend.Found(SparkPaymentStatus.FAILED, null))

Expand Down Expand Up @@ -2698,7 +2679,7 @@ class LightningRepoTest : BaseUnitTest() {
whenever(lightningService.channels).thenReturn(listOf(createChannelDetails().copy(isUsable = true)))
whenever(lightningService.listPayments()).thenReturn(emptyList())

assertTrue(runCatching { sut.payInvoiceWithNode("h").getOrThrow() }.isFailure)
assertTrue(runCatching { sut.payInvoice("h").getOrThrow() }.isFailure)
verify(lightningService, never()).send(any(), anyOrNull(), anyOrNull(), anyOrNull())
whenever(sparkRepo.canSend(1_000uL)).thenReturn(true)
whenever(sparkRepo.payInvoice(any(), anyOrNull(), anyOrNull(), anyOrNull(), any()))
Expand All @@ -2719,9 +2700,9 @@ class LightningRepoTest : BaseUnitTest() {
whenever(lightningService.send(any(), anyOrNull(), anyOrNull(), anyOrNull()))
.thenAnswer { throw AppError("Route not found") }

assertTrue(runCatching { sut.payInvoiceWithNode("h").getOrThrow() }.isFailure)
assertTrue(runCatching { sut.payInvoice("h").getOrThrow() }.isFailure)
// The node retries and fails before anything leaves.
assertTrue(sut.payInvoiceWithNode("h").isFailure)
assertTrue(sut.payInvoice("h").isFailure)
whenever(sparkRepo.canSend(1_000uL)).thenReturn(true)
whenever(sparkRepo.payInvoice(any(), anyOrNull(), anyOrNull(), anyOrNull(), any()))
.thenReturn(Result.success("h"))
Expand Down Expand Up @@ -2755,7 +2736,7 @@ class LightningRepoTest : BaseUnitTest() {
val current = inner.data.first()
if (isArmed && "h" in current.ldkSendHashes && "h" !in transform(current).ldkSendHashes) {
isArmed = false
node = launch { sut.payInvoiceWithNode("h") }
node = launch { sut.payInvoice("h") }
entered.await()
}
return inner.updateData(transform)
Expand Down
2 changes: 1 addition & 1 deletion journeys/wallet/ordinary-during-paykit-outage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<actions>
<action>Edit an ordinary receive amount and note, then show its QR while public endpoint publication is delayed; verify the QR contains the current amount and note without waiting for Pubky</action>
<action>Close and reopen receive, restore Pubky access and verify current public endpoints reconcile without restoring a superseded invoice or a signed-out identity</action>
<action>With pending order or swap recovery and disabled Paykit UI, start the wallet while endpoint cleanup is delayed; verify unrelated recovery watchers start</action>
<action>With a pending order and disabled Paykit UI, start the wallet while endpoint cleanup is delayed; verify unrelated recovery watchers start</action>
Comment thread
ovitrif marked this conversation as resolved.
Resolved
<action>Hold unrelated proof maintenance, send a controlled ordinary Lightning invoice that fails and verify its error appears without waiting for Paykit; verify no automatic second payment is created</action>
<action>Repeat with a controlled pending Lightning result and verify the original payment hash is tracked and shown as pending; do not submit another payment</action>
<action>Release the service faults, restart and verify retained Paykit work reconciles; a real Paykit request must still require authorization and proof bookkeeping</action>
Expand Down