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
13 changes: 12 additions & 1 deletion app/src/main/java/to/bitkit/repositories/LightningRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,17 @@ class LightningRepo @Inject constructor(
* Scheduling and cancelling are atomic: [cancelPendingStop] runs on the repo dispatcher while this
* runs on the caller thread, so an interleaved cancel could otherwise miss the job being installed
* and stop the node after the app is back in the foreground.
*
* [BACKGROUND_STOP_DELAY] must stay under the cached-app freezer debounce (~10s once the process
* drops to `oom_adj` 900) so [stop] is at least entered before the process can be frozen. Past
* that the process freezes mid-delay and the stop only fires on unfreeze, racing
* [cancelPendingStop] to tear the node down just as the user returns — and [stop] runs
* `NonCancellable`, so losing that race is unrecoverable.
*
* Whether the stop *completes* in that window is out of scope here: on a wallet with real
* payment history ldk_node reliably hits its own 30s event-handling deadline, so no delay value
* makes the teardown fit. That also makes an avoided teardown valuable, since a user returning
* mid-stop waits it out before the ~8s node rebuild can start.
*/
fun stopDebounced() = synchronized(pendingStopLock) {
val job = scope.launch {
Expand Down Expand Up @@ -1896,7 +1907,7 @@ class LightningRepo @Inject constructor(
private const val VSS_KEY_EXTERNAL_SCORES_CACHE = "external_pathfinding_scores_cache"
private const val MS_SYNC_LOOP_DEBOUNCE = 500L
private const val SYNC_RETRY_DELAY_MS = 15_000L
private val BACKGROUND_STOP_DELAY = 3.seconds
private val BACKGROUND_STOP_DELAY = 5.seconds
private val CHANNELS_USABLE_TIMEOUT = 15.seconds
private val NO_USABLE_CHANNELS_FEEDBACK_DELAY = 2_500.milliseconds
val SEND_LN_TIMEOUT = 10.seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import kotlin.time.Duration.Companion.seconds
class LightningRepoTest : BaseUnitTest() {
companion object {
private const val NO_USABLE_CHANNELS_FEEDBACK_DELAY_MS = 2_500L
private const val BACKGROUND_STOP_DELAY_MS = 3_000L
private const val BACKGROUND_STOP_DELAY_MS = 5_000L
}

private lateinit var sut: LightningRepo
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1146.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bitkit now keeps the Lightning node running a little longer when you briefly leave the app, so quick trips to another app no longer reload the wallet on return.
Loading