Skip to content

Conversation

@reez
Copy link
Collaborator

@reez reez commented Sep 22, 2025

Description

Saw this crash happen. BDK's Esplora client panics with .expect() calls during sync operations when encountering chain inconsistencies (like network mismatches). This causes mobile apps to crash immediately instead of handling the error gracefully.

This PR adds a panic-catching wrapper around EsploraClient.sync() and EsploraClient.fullScan() operations.

This change is under the idea of libraries should provide errors not crashes, but I'm totally open to feedback.

Notes to the reviewers

Tested a local build with these changes on BDK iOS.

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

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 changed the title (draft) fix: catch esplora panics and return parsing error fix: catch esplora panics and return parsing error Sep 22, 2025
@tnull
Copy link

tnull commented Sep 23, 2025

This change is under the idea of libraries should provide errors not crashes, but I'm totally open to feedback.

This is exactly the right idea, which is why I'd strongly be in favor of fixing the panics in bdk_esplora directly, instead of patching it up only for bindings users here. See related issue bitcoindevkit/bdk_wallet#30.

@reez
Copy link
Collaborator Author

reez commented Sep 23, 2025

This change is under the idea of libraries should provide errors not crashes, but I'm totally open to feedback.

This is exactly the right idea, which is why I'd strongly be in favor of fixing the panics in bdk_esplora directly, instead of patching it up only for bindings users here. See related issue bitcoindevkit/bdk_wallet#30.

thanks so much for this feedback @tnull !

And thank you for pointing me towards that open issue! I'll hop on there with a comment too.

I thought as well about the ideal ultimate solution being it is addressed in bdk_esplora directly, so while I was making this bdk-ffi PR yesterday I also made a small branch with that change to test it out in bdk_esplora reez/bdk@823fdf2 ... I wanted to sit on it for the night because I wasn't totally sure if it was the right direction (or the exact right/all-encompassing code), but based on my initial impulse and then your feedback now the general direction of addressing the issue ultimately in bdk_esplora seems right.

(For anyone reviewing this on bdk-ffi I still think it has merit being merged now while we work towards getting a solution in bdk_esplora eventually)

@thunderbiscuit
Copy link
Member

I'm happy to merge this while we wait for the fixes to appear upstream. Your call @reez. Depends on how close you think we are to merging the fix directly in the Rust clients.

@reez
Copy link
Collaborator Author

reez commented Oct 1, 2025

with https://github.com/bitcoindevkit/bdk_wallet/releases/tag/wallet-2.2.0 released and ffi following on pretty quick with our release I think this going into our 2.2 would make sense. I also just opened a pr on upstream to potentially remove any other panics.

I should rebase this and it should be ready

@reez
Copy link
Collaborator Author

reez commented Oct 1, 2025

rebased

@reez reez requested a review from thunderbiscuit October 1, 2025 21:21
Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

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

ACK 58c425b.

Would you mind opening an issue reminding us to fix this up whenever the fixes are merged upstream?

@thunderbiscuit thunderbiscuit merged commit 58c425b into bitcoindevkit:master Oct 2, 2025
6 checks passed
@reez reez mentioned this pull request Oct 2, 2025
@reez
Copy link
Collaborator Author

reez commented Oct 2, 2025

ACK 58c425b.

Would you mind opening an issue reminding us to fix this up whenever the fixes are merged upstream?

Totally, I was actually thinking about opening up issues for future releases to track what we want to test/implement/track, so I opened one up for 3.0/2.3 #869 (and added this as the first item)

@reez reez deleted the i-323 branch October 2, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants