Skip to content

Commit f718071

Browse files
author
Ludo Galabru
committed
fix: attempt to retrieve blocks from iterator
1 parent bc9ca0f commit f718071

File tree

1 file changed

+17
-1
lines changed
  • components/chainhook-sdk/src/hord/db

1 file changed

+17
-1
lines changed

components/chainhook-sdk/src/hord/db/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub fn find_lazy_block_at_block_height(
254254
blocks_db: &DB,
255255
ctx: &Context,
256256
) -> Option<LazyBlock> {
257-
let mut attempt = 0;
257+
let mut attempt = 1;
258258
// let mut read_options = rocksdb::ReadOptions::default();
259259
// read_options.fill_cache(true);
260260
// read_options.set_verify_checksums(false);
@@ -265,6 +265,22 @@ pub fn find_lazy_block_at_block_height(
265265
match blocks_db.get(block_height.to_be_bytes()) {
266266
Ok(Some(res)) => return Some(LazyBlock::new(res)),
267267
_ => {
268+
if attempt == 1 {
269+
ctx.try_log(|logger| {
270+
slog::warn!(
271+
logger,
272+
"Attempt to retrieve block {} through iterator",
273+
block_height,
274+
)
275+
});
276+
let mut iter = blocks_db.iterator(rocksdb::IteratorMode::End);
277+
let block_height_bytes = block_height.to_be_bytes();
278+
while let Some(Ok((k, res))) = iter.next() {
279+
if (*k).eq(&block_height_bytes) {
280+
return Some(LazyBlock::new(res.to_vec()));
281+
}
282+
}
283+
}
268284
attempt += 1;
269285
backoff = 2.0 * backoff + (backoff * rng.gen_range(0.0..1.0));
270286
let duration = std::time::Duration::from_millis((backoff * 1_000.0) as u64);

0 commit comments

Comments
 (0)