Skip to content

esplora: don't panic in raw_to_num on bad response - #102

Merged
vincenzopalazzo merged 1 commit into
mainfrom
esplora/raw-to-num-no-panic
May 5, 2026
Merged

esplora: don't panic in raw_to_num on bad response#102
vincenzopalazzo merged 1 commit into
mainfrom
esplora/raw-to-num-no-panic

Conversation

@vincenzopalazzo

@vincenzopalazzo vincenzopalazzo commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • raw_to_num previously .expect()-ed both the UTF-8 decode and the i64::parse, which crashed the bitcoin backend whenever an esplora endpoint returned anything non-numeric (HTML error page, captive portal interstitial, mangled body through a proxy, etc.). The panic message was "impossible parse a string into a i64: ParseIntError { kind: InvalidDigit }" and took the whole node down.
  • Change the function to return Result<i64, PluginError> and surface the offending bytes in the error, so RecoveryStrategy::apply can retry instead of crashing.
  • Trim whitespace before parsing as a small robustness improvement, and log the parsed value at debug for diagnostics.
  • Updated the two .map(|raw| raw_to_num(&raw)) callers in sync_block_by_height and sync_chain_info to .and_then(...) to match the new signature.

Test plan

  • cargo build --release -p folgore-esplora -p folgore_plugin succeeds with no warnings.
  • Reproduced the original panic on a node that hit the bug, then verified the patched plugin recovers cleanly — bitcoin backend stays alive and raw_to_num input: "..." (len=N) debug logs show clean integer bodies on each /blocks/tip/height poll.
  • Node getinfo returns healthy state and the daemon resumes block sync after the patch.

🤖 Generated with Claude Code

Fixes #100

raw_to_num used .expect() for both the UTF-8 decode and the i64 parse,
crashing the bitcoin backend if the esplora endpoint ever returns a
non-numeric body (HTML error page, captive portal, malformed proxy
response, etc.). Switch the function to return Result<i64, PluginError>
and propagate a structured error including the offending body, so the
recovery strategy can retry instead of taking the daemon down. Trim
whitespace before parsing for safety, and log the parsed input at debug
level for diagnostics.

Update the two callers in sync_block_by_height and sync_chain_info from
.map() to .and_then() to match the new signature.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vincenzopalazzo
vincenzopalazzo merged commit 9f24ec5 into main May 5, 2026
4 checks passed
@vincenzopalazzo
vincenzopalazzo deleted the esplora/raw-to-num-no-panic branch May 5, 2026 12:10
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.

crash with the modern blockstream API

1 participant