Skip to content

fix: crash on startup#212

Merged
reez merged 3 commits intomainfrom
cr
Jun 20, 2025
Merged

fix: crash on startup#212
reez merged 3 commits intomainfrom
cr

Conversation

@reez
Copy link
Copy Markdown
Owner

@reez reez commented Jun 20, 2025

Description

The app was crashing with Fatal error: 'try!' expression unexpectedly
raised an error: LDKNode.BuildError.WalletSetupFailed when accessing
LightningNodeService.shared after restart/reset operations.

Screenshot 2025-06-20 at 3 58 09 PM

Cause:

  1. restart() and reset() methods were setting _shared = nil, destroying the singleton instance
  2. The wallet data remained in the storage directory
  3. When recreating the singleton, nodeBuilder.build() would fail because LDK Node refuses to overwrite existing wallet data as a safety measure
  4. This failure caused the force unwrap (return _shared!) to crash with a nil value

Solution:

  1. Fixed restart() method:
  • Now reuses the existing node instance (stop → start) instead of
    destroying and recreating
  • Prevents wallet data conflicts and is more efficient
  1. Fixed reset() method:
  • Properly cleans up the wallet data directory before setting _shared =
    nil
  • Ensures next initialization has a clean state
  1. Added automatic recovery for existing users:
  • Detects WalletSetupFailed errors during initialization
  • Automatically cleans corrupted wallet data and retries
  • TestFlight users with corrupted data will work without manual intervention (previous data will delete, but they won't have to manually delete app or anyting)

Summary:

  • Fixes crash for all users performing restart operations
  • Provides automatic recovery for users with corrupted wallet data
  • No manual app deletion/reinstall required for affected TestFlight users

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I have formatted my code with swift-format per .swift-format file

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@reez reez merged commit c581cbc into main Jun 20, 2025
1 check passed
@reez reez deleted the cr branch June 20, 2025 21:24
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.

1 participant