From: merge-script Date: Sun, 18 Oct 2026 14:31:28 +0000 (+1100) Subject: Merge bitcoindevkit/bdk#2349: fix(electrum): return error when tip height overflows u32 X-Git-Url: http://internal-gitweb-vhost/-client-interface/%22https:/rusqlite-error.html?a=commitdiff_plain;h=HEAD;p=bdk Merge bitcoindevkit/bdk#2349: fix(electrum): return error when tip height overflows u32 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 --- 096f5e944aa4bb0bac5b135a25d8fbc6b3721268 diff --cc crates/electrum/src/bdk_electrum_client.rs index 2612c261,98309021..752d00c8 --- a/crates/electrum/src/bdk_electrum_client.rs +++ b/crates/electrum/src/bdk_electrum_client.rs @@@ -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, + block_header_cache: &mut HashMap, ) -> Result<(CheckPoint, BTreeMap), 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.