]> Untitled Git - bdk/commitdiff
refactor(esplora): in debug build assert that `latest_blocks` is not empty
authorvalued mammal <valuedmammal@protonmail.com>
Sat, 7 Jun 2025 14:43:11 +0000 (10:43 -0400)
committervalued mammal <valuedmammal@protonmail.com>
Tue, 1 Jul 2025 15:24:26 +0000 (11:24 -0400)
crates/esplora/src/async_ext.rs
crates/esplora/src/blocking_ext.rs

index 4ea697c932b84b41780f6b89eaaa07d71885c7d5..dc82063bd661c754ece63b3fc0e499ec70f9e77d 100644 (file)
@@ -205,10 +205,16 @@ async fn fetch_block<S: Sleeper>(
 
     // 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?))
index 6977c8f0bcf2fd4051db7ce982c87ee7cf04f560..6c4966bfb9e844e801e9b447e7834e49aac65deb 100644 (file)
@@ -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)?))