diff --git a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt index 722664cf44..58e2e73abf 100644 --- a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt @@ -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 { - 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 diff --git a/app/src/test/java/to/bitkit/repositories/LightningRepoTest.kt b/app/src/test/java/to/bitkit/repositories/LightningRepoTest.kt index c65102dc1c..c92cf0f1d2 100644 --- a/app/src/test/java/to/bitkit/repositories/LightningRepoTest.kt +++ b/app/src/test/java/to/bitkit/repositories/LightningRepoTest.kt @@ -1560,25 +1560,6 @@ class LightningRepoTest : BaseUnitTest() { inFlight.await() } - @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() @@ -2237,7 +2218,7 @@ class LightningRepoTest : BaseUnitTest() { val sent = CompletableDeferred() 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) @@ -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 } @@ -2286,7 +2267,7 @@ class LightningRepoTest : BaseUnitTest() { val sent = CompletableDeferred() 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. @@ -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 } @@ -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) @@ -2374,7 +2355,7 @@ class LightningRepoTest : BaseUnitTest() { whenever(sparkRepo.payInvoice(any(), anyOrNull(), anyOrNull(), anyOrNull(), any())).doSuspendableAnswer { val authorizeSend = it.getArgument Boolean>(4) check(authorizeSend()) - nodeResult = sut.payInvoiceWithNode("h") + nodeResult = sut.payInvoice("h") Result.success("h") } @@ -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)) @@ -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())) @@ -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")) @@ -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) diff --git a/journeys/wallet/ordinary-during-paykit-outage.xml b/journeys/wallet/ordinary-during-paykit-outage.xml index d1b3f042ec..2ff94d0612 100644 --- a/journeys/wallet/ordinary-during-paykit-outage.xml +++ b/journeys/wallet/ordinary-during-paykit-outage.xml @@ -12,7 +12,7 @@ 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 Close and reopen receive, restore Pubky access and verify current public endpoints reconcile without restoring a superseded invoice or a signed-out identity - With pending order or swap recovery and disabled Paykit UI, start the wallet while endpoint cleanup is delayed; verify unrelated recovery watchers start + With a pending order and disabled Paykit UI, start the wallet while endpoint cleanup is delayed; verify unrelated recovery watchers start 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 Repeat with a controlled pending Lightning result and verify the original payment hash is tracked and shown as pending; do not submit another payment Release the service faults, restart and verify retained Paykit work reconciles; a real Paykit request must still require authorization and proof bookkeeping