@@ -206,6 +206,21 @@ pub fn open_readonly_hord_db_conn_rocks_db(
206
206
Ok ( db)
207
207
}
208
208
209
+ pub fn open_readonly_hord_db_conn_rocks_db_loop ( base_dir : & PathBuf , ctx : & Context ) -> DB {
210
+ let blocks_db = loop {
211
+ match open_readonly_hord_db_conn_rocks_db ( & base_dir, & ctx) {
212
+ Ok ( db) => break db,
213
+ Err ( e) => {
214
+ ctx. try_log ( |logger| {
215
+ slog:: warn!( logger, "Unable to open db: {e}" , ) ;
216
+ } ) ;
217
+ continue ;
218
+ }
219
+ }
220
+ } ;
221
+ blocks_db
222
+ }
223
+
209
224
pub fn open_readwrite_hord_dbs (
210
225
base_dir : & PathBuf ,
211
226
ctx : & Context ,
@@ -251,6 +266,7 @@ pub fn find_last_block_inserted(blocks_db: &DB) -> u32 {
251
266
pub fn find_lazy_block_at_block_height (
252
267
block_height : u32 ,
253
268
retry : u8 ,
269
+ try_iterator : bool ,
254
270
blocks_db : & DB ,
255
271
ctx : & Context ,
256
272
) -> Option < LazyBlock > {
@@ -265,7 +281,7 @@ pub fn find_lazy_block_at_block_height(
265
281
match blocks_db. get ( block_height. to_be_bytes ( ) ) {
266
282
Ok ( Some ( res) ) => return Some ( LazyBlock :: new ( res) ) ,
267
283
_ => {
268
- if attempt == 1 {
284
+ if attempt == 1 && try_iterator {
269
285
ctx. try_log ( |logger| {
270
286
slog:: warn!(
271
287
logger,
@@ -971,7 +987,7 @@ pub fn parse_outpoint_to_watch(outpoint_to_watch: &str) -> (TransactionIdentifie
971
987
}
972
988
973
989
pub fn retrieve_satoshi_point_using_lazy_storage (
974
- blocks_db : & DB ,
990
+ blocks_db_dir : & PathBuf ,
975
991
block_identifier : & BlockIdentifier ,
976
992
transaction_identifier : & TransactionIdentifier ,
977
993
input_index : usize ,
@@ -987,6 +1003,8 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
987
1003
let mut ordinal_block_number = block_identifier. index as u32 ;
988
1004
let txid = transaction_identifier. get_8_hash_bytes ( ) ;
989
1005
1006
+ let mut blocks_db = open_readonly_hord_db_conn_rocks_db_loop ( & blocks_db_dir, & ctx) ;
1007
+
990
1008
let ( sats_ranges, inscription_offset_cross_outputs) = match traversals_cache
991
1009
. get ( & ( block_identifier. index as u32 , txid. clone ( ) ) )
992
1010
{
@@ -997,21 +1015,38 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
997
1015
tx. get_cumulated_sats_in_until_input_index ( input_index) ,
998
1016
)
999
1017
}
1000
- None => match find_lazy_block_at_block_height ( ordinal_block_number, 3 , & blocks_db, & ctx) {
1001
- None => {
1002
- return Err ( format ! ( "block #{ordinal_block_number} not in database" ) ) ;
1003
- }
1004
- Some ( block) => match block. find_and_serialize_transaction_with_txid ( & txid) {
1005
- Some ( tx) => {
1006
- let sats_ranges = tx. get_sat_ranges ( ) ;
1007
- let inscription_offset_cross_outputs =
1008
- tx. get_cumulated_sats_in_until_input_index ( input_index) ;
1009
- traversals_cache. insert ( ( ordinal_block_number, txid. clone ( ) ) , tx) ;
1010
- ( sats_ranges, inscription_offset_cross_outputs)
1018
+ None => {
1019
+ let mut attempt = 0 ;
1020
+ loop {
1021
+ match find_lazy_block_at_block_height (
1022
+ ordinal_block_number,
1023
+ 3 ,
1024
+ false ,
1025
+ & blocks_db,
1026
+ & ctx,
1027
+ ) {
1028
+ None => {
1029
+ if attempt < 3 {
1030
+ attempt += 1 ;
1031
+ blocks_db =
1032
+ open_readonly_hord_db_conn_rocks_db_loop ( & blocks_db_dir, & ctx) ;
1033
+ } else {
1034
+ return Err ( format ! ( "block #{ordinal_block_number} not in database" ) ) ;
1035
+ }
1036
+ }
1037
+ Some ( block) => match block. find_and_serialize_transaction_with_txid ( & txid) {
1038
+ Some ( tx) => {
1039
+ let sats_ranges = tx. get_sat_ranges ( ) ;
1040
+ let inscription_offset_cross_outputs =
1041
+ tx. get_cumulated_sats_in_until_input_index ( input_index) ;
1042
+ traversals_cache. insert ( ( ordinal_block_number, txid. clone ( ) ) , tx) ;
1043
+ break ( sats_ranges, inscription_offset_cross_outputs) ;
1044
+ }
1045
+ None => return Err ( format ! ( "txid not in block #{ordinal_block_number}" ) ) ,
1046
+ } ,
1011
1047
}
1012
- None => return Err ( format ! ( "txid not in block #{ordinal_block_number}" ) ) ,
1013
- } ,
1014
- } ,
1048
+ }
1049
+ }
1015
1050
} ;
1016
1051
1017
1052
for ( i, ( min, max) ) in sats_ranges. into_iter ( ) . enumerate ( ) {
@@ -1095,13 +1130,29 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
1095
1130
}
1096
1131
}
1097
1132
1098
- let lazy_block =
1099
- match find_lazy_block_at_block_height ( ordinal_block_number, 3 , & blocks_db, & ctx) {
1100
- Some ( block) => block,
1101
- None => {
1102
- return Err ( format ! ( "block #{ordinal_block_number} not in database" ) ) ;
1133
+ let lazy_block = {
1134
+ let mut attempt = 0 ;
1135
+ loop {
1136
+ match find_lazy_block_at_block_height (
1137
+ ordinal_block_number,
1138
+ 3 ,
1139
+ false ,
1140
+ & blocks_db,
1141
+ & ctx,
1142
+ ) {
1143
+ Some ( block) => break block,
1144
+ None => {
1145
+ if attempt < 3 {
1146
+ attempt += 1 ;
1147
+ blocks_db =
1148
+ open_readonly_hord_db_conn_rocks_db_loop ( & blocks_db_dir, & ctx) ;
1149
+ } else {
1150
+ return Err ( format ! ( "block #{ordinal_block_number} not in database" ) ) ;
1151
+ }
1152
+ }
1103
1153
}
1104
- } ;
1154
+ }
1155
+ } ;
1105
1156
1106
1157
let coinbase_txid = lazy_block. get_coinbase_txid ( ) ;
1107
1158
let txid = tx_cursor. 0 ;
0 commit comments