]> Untitled Git - bdk/commitdiff
Merge bitcoindevkit/bdk#2349: fix(electrum): return error when tip height overflows u32 master github/master
authormerge-script <hello@evanlinjin.me>
Sun, 18 Oct 2026 14:31:28 +0000 (01:31 +1100)
committermerge-script <hello@evanlinjin.me>
Sun, 18 Oct 2026 14:31:28 +0000 (01:31 +1100)
92ca220ce1c3346af9ec8ab7e36dc4280dc2c385 fix(electrum): return error when tip height overflows u32 (bhuvan-somisetty)

Pull request description:

  ### Description

  `fetch_tip_and_latest_blocks` cast the server's `usize` tip height with `height as u32`, so on 64-bit a height above `u32::MAX` was silently truncated. It now uses `u32::try_from` and returns `Error::Message` on overflow.

  Fixes #2294.

  ### Changelog notice

  - Fixed: an overflowing Electrum tip height now returns an error instead of being truncated (#2294).

  ### Checklists

  #### All Submissions:

  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)

  #### Bugfixes:

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

ACKs for top commit:
  evanlinjin:
    ACK 92ca220ce1c3346af9ec8ab7e36dc4280dc2c385

Tree-SHA512: 88c9a187c99ba063a07b0f1cbcfe46c05c3b51f8ddb4e0ef6e2e3e3d9da25ec12576d8739c0a6445a36802b4a20554e816e56693680ee1785025ebae45caca43

1  2 
crates/electrum/src/bdk_electrum_client.rs

index 2612c261fe3660230dc487554c65cfce23c1185d,9830902182efd28c13b2c48ee70349faaeeb98ae..752d00c8dfbbe8a906c828fe3a268398bf68d0a5
@@@ -687,10 -652,10 +687,11 @@@ fn check_batch_len(method: &str, expect
  fn fetch_tip_and_latest_blocks(
      client: &impl ElectrumApi,
      prev_tip: CheckPoint<BlockHash>,
 +    block_header_cache: &mut HashMap<u32, Header>,
  ) -> Result<(CheckPoint<BlockHash>, BTreeMap<u32, BlockHash>), Error> {
      let HeaderNotification { height, .. } = client.block_headers_subscribe()?;
-     let new_tip_height = height as u32;
+     let new_tip_height = u32::try_from(height)
+         .map_err(|_| Error::Message(format!("server tip height {height} overflows u32")))?;
  
      // If electrum returns a tip height that is lower than our previous tip, then checkpoints do
      // not need updating. We just return the previous tip and use that as the point of agreement.