Skip to content

Conversation

@jvsena42
Copy link
Member

@jvsena42 jvsena42 commented Jan 28, 2026

Fixes #739

This PR prevents channel state divergence during node shutdown by ensuring state is fully persisted before the service is destroyed.

Description

When the app was stopped while a 0-conf channel had uncommitted state updates, the client (LDK) could end up with a different commitment height than the LSP. On reconnect, the LSP detected this mismatch as "possible data loss" and force-closed the channel.

This PR adds two mitigations:

  1. Final sync before shutdown - Calls syncWallets() before stopping the node to ensure the latest channel state is persisted to VSS
  2. Blocking service shutdown - Uses runBlocking in onDestroy() to wait for the node to fully stop before the service is destroyed, with a 5-second timeout to avoid ANR

Preview

CJIT.webm
multiple-transactions-and-poor-signal.webm

QA Notes

1. Test graceful shutdown

  1. Open the app and create or use an existing Lightning channel
  2. Stop the app using the notification "Stop" button
  3. Check logcat for:
    • Performing final sync before shutdown…
    • Final sync completed
    • onDestroy started
    • onDestroy completed
  4. Verify the node stops without errors

2. Test restart after stop

  1. After stopping the app via notification, reopen it
  2. Verify the Lightning channel is still operational
  3. Verify no force-close occurred

3. Regression

  • Send and receive Lightning payments normally
  • Verify wallet balance updates correctly

@jvsena42 jvsena42 self-assigned this Jan 28, 2026
@jvsena42 jvsena42 marked this pull request as ready for review January 28, 2026 14:48
@jvsena42 jvsena42 requested a review from ovitrif January 28, 2026 14:48
@claude

This comment has been minimized.

@jvsena42 jvsena42 linked an issue Jan 28, 2026 that may be closed by this pull request
@jvsena42
Copy link
Member Author

DIdn't find problems in my tests, but this has a timing very difficult to reproduce

@claude
Copy link

claude bot commented Jan 28, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

nit: Probably still good to use non-main thread

Look at runBlocking(dispatcher) option

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.

CJIT channel force closed while attempting LNURL withdrawals

3 participants