@@ -11,6 +11,7 @@ use chainhook_types::{
11
11
use dashmap:: DashMap ;
12
12
use fxhash:: FxHasher ;
13
13
use hiro_system_kit:: slog;
14
+ use rand:: { thread_rng, Rng } ;
14
15
15
16
use rocksdb:: DB ;
16
17
use rusqlite:: { Connection , OpenFlags , ToSql } ;
@@ -254,12 +255,17 @@ pub fn find_lazy_block_at_block_height(
254
255
// let mut read_options = rocksdb::ReadOptions::default();
255
256
// read_options.fill_cache(true);
256
257
// read_options.set_verify_checksums(false);
258
+ let mut backoff: f64 = 1.0 ;
259
+ let mut rng = thread_rng ( ) ;
260
+
257
261
loop {
258
262
match blocks_db. get ( block_height. to_be_bytes ( ) ) {
259
263
Ok ( Some ( res) ) => return Some ( LazyBlock :: new ( res) ) ,
260
264
_ => {
261
265
attempt += 1 ;
262
- std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 2 ) ) ;
266
+ backoff = 2.0 * backoff + ( backoff * rng. gen_range ( 0.0 ..1.0 ) ) ;
267
+ let duration = std:: time:: Duration :: from_millis ( ( backoff * 1_000.0 ) as u64 ) ;
268
+ std:: thread:: sleep ( duration) ;
263
269
if attempt > retry {
264
270
return None ;
265
271
}
@@ -965,7 +971,7 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
965
971
traversals_cache. insert ( ( ordinal_block_number, txid. clone ( ) ) , tx) ;
966
972
( sats_ranges, inscription_offset_cross_outputs)
967
973
}
968
- None => return Err ( format ! ( "block #{ordinal_block_number} not in database " ) ) ,
974
+ None => return Err ( format ! ( "txid not in block #{ordinal_block_number}" ) ) ,
969
975
} ,
970
976
} ,
971
977
} ;
0 commit comments