From: bhuvan-somisetty Date: Thu, 8 Oct 2026 02:48:08 +0000 (+0530) Subject: fix(electrum): return error when tip height overflows u32 X-Git-Url: http://internal-gitweb-vhost/-client-interface/%22https:/src/struct.WScriptHash.html?a=commitdiff_plain;h=92ca220ce1c3346af9ec8ab7e36dc4280dc2c385;p=bdk fix(electrum): return error when tip height overflows u32 Validate that the tip height returned from `block_headers_subscribe` fits in `u32` via `u32::try_from` instead of silently truncating with `as u32`. Signed-off-by: bhuvan-somisetty --- diff --git a/crates/electrum/src/bdk_electrum_client.rs b/crates/electrum/src/bdk_electrum_client.rs index a7c94315..98309021 100644 --- a/crates/electrum/src/bdk_electrum_client.rs +++ b/crates/electrum/src/bdk_electrum_client.rs @@ -654,7 +654,8 @@ fn fetch_tip_and_latest_blocks( prev_tip: CheckPoint, ) -> 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.