Skip to content

Commit 568a366

Browse files
committed
refactor(esplora): in debug build assert that latest_blocks is not empty
1 parent dd394cb commit 568a366

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

crates/esplora/src/async_ext.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,16 @@ async fn fetch_block<S: Sleeper>(
205205

206206
// We avoid fetching blocks higher than previously fetched `latest_blocks` as the local chain
207207
// tip is used to signal for the last-synced-up-to-height.
208-
if let Some(tip_height) = latest_blocks.keys().last().copied() {
209-
if height > tip_height {
208+
match latest_blocks.keys().last().copied() {
209+
None => {
210+
debug_assert!(false, "`latest_blocks` should not be empty");
210211
return Ok(None);
211212
}
213+
Some(tip_height) => {
214+
if height > tip_height {
215+
return Ok(None);
216+
}
217+
}
212218
}
213219

214220
Ok(Some(client.get_block_hash(height).await?))

crates/esplora/src/blocking_ext.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,16 @@ fn fetch_block(
190190

191191
// We avoid fetching blocks higher than previously fetched `latest_blocks` as the local chain
192192
// tip is used to signal for the last-synced-up-to-height.
193-
if let Some(tip_height) = latest_blocks.keys().last().copied() {
194-
if height > tip_height {
193+
match latest_blocks.keys().last().copied() {
194+
None => {
195+
debug_assert!(false, "`latest_blocks` should not be empty");
195196
return Ok(None);
196197
}
198+
Some(tip_height) => {
199+
if height > tip_height {
200+
return Ok(None);
201+
}
202+
}
197203
}
198204

199205
Ok(Some(client.get_block_hash(height)?))

0 commit comments

Comments
 (0)