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 <somisettybhuvan5@gmail.com>
prev_tip: CheckPoint<BlockHash>,
) -> 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.