From: valued mammal Date: Sat, 7 Jun 2025 14:43:11 +0000 (-0400) Subject: refactor(esplora): in debug build assert that `latest_blocks` is not empty X-Git-Tag: bitcoind_rpc-0.21.0~14^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/static/struct.CheckPointIter.html?a=commitdiff_plain;h=568a36642c43d74132339a4e42dd41c545a764e1;p=bdk refactor(esplora): in debug build assert that `latest_blocks` is not empty --- diff --git a/crates/esplora/src/async_ext.rs b/crates/esplora/src/async_ext.rs index 4ea697c9..dc82063b 100644 --- a/crates/esplora/src/async_ext.rs +++ b/crates/esplora/src/async_ext.rs @@ -205,10 +205,16 @@ async fn fetch_block( // We avoid fetching blocks higher than previously fetched `latest_blocks` as the local chain // tip is used to signal for the last-synced-up-to-height. - if let Some(tip_height) = latest_blocks.keys().last().copied() { - if height > tip_height { + match latest_blocks.keys().last().copied() { + None => { + debug_assert!(false, "`latest_blocks` should not be empty"); return Ok(None); } + Some(tip_height) => { + if height > tip_height { + return Ok(None); + } + } } Ok(Some(client.get_block_hash(height).await?)) diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 6977c8f0..6c4966bf 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -190,10 +190,16 @@ fn fetch_block( // We avoid fetching blocks higher than previously fetched `latest_blocks` as the local chain // tip is used to signal for the last-synced-up-to-height. - if let Some(tip_height) = latest_blocks.keys().last().copied() { - if height > tip_height { + match latest_blocks.keys().last().copied() { + None => { + debug_assert!(false, "`latest_blocks` should not be empty"); return Ok(None); } + Some(tip_height) => { + if height > tip_height { + return Ok(None); + } + } } Ok(Some(client.get_block_hash(height)?))