@@ -9,12 +9,14 @@ use chainhook_types::{
9
9
OrdinalOperation , TransactionIdentifier ,
10
10
} ;
11
11
use dashmap:: DashMap ;
12
+ use fxhash:: { FxBuildHasher , FxHasher } ;
12
13
use hiro_system_kit:: slog;
13
14
use rand:: seq:: SliceRandom ;
14
15
use rand:: thread_rng;
15
16
use rocksdb:: DB ;
16
17
use rusqlite:: Connection ;
17
18
use std:: collections:: { BTreeMap , HashMap , VecDeque } ;
19
+ use std:: hash:: BuildHasherDefault ;
18
20
use std:: path:: PathBuf ;
19
21
use std:: sync:: mpsc:: channel;
20
22
use std:: sync:: Arc ;
@@ -162,10 +164,24 @@ pub fn revert_hord_db_with_augmented_bitcoin_block(
162
164
Ok ( ( ) )
163
165
}
164
166
167
+ pub fn new_traversals_cache (
168
+ ) -> DashMap < ( u32 , [ u8 ; 8 ] ) , ( Vec < ( [ u8 ; 8 ] , u32 , u16 , u64 ) > , Vec < u64 > ) , BuildHasherDefault < FxHasher > >
169
+ {
170
+ let hasher = FxBuildHasher :: default ( ) ;
171
+ DashMap :: with_hasher ( hasher)
172
+ }
173
+
165
174
pub fn retrieve_inscribed_satoshi_points_from_block (
166
175
block : & BitcoinBlockData ,
167
176
inscriptions_db_conn : Option < & Connection > ,
168
177
hord_db_path : & PathBuf ,
178
+ traversals_cache : & Arc <
179
+ DashMap <
180
+ ( u32 , [ u8 ; 8 ] ) ,
181
+ ( Vec < ( [ u8 ; 8 ] , u32 , u16 , u64 ) > , Vec < u64 > ) ,
182
+ BuildHasherDefault < FxHasher > ,
183
+ > ,
184
+ > ,
169
185
ctx : & Context ,
170
186
) -> HashMap < TransactionIdentifier , TraversalResult > {
171
187
let mut transactions_ids = vec ! [ ] ;
@@ -202,14 +218,12 @@ pub fn retrieve_inscribed_satoshi_points_from_block(
202
218
203
219
let mut rng = thread_rng ( ) ;
204
220
transactions_ids. shuffle ( & mut rng) ;
205
- let hasher = fxhash:: FxBuildHasher :: default ( ) ;
206
- let shared_cache = Arc :: new ( DashMap :: with_hasher ( hasher) ) ;
207
221
for transaction_id in transactions_ids. into_iter ( ) {
208
222
let moved_traversal_tx = traversal_tx. clone ( ) ;
209
223
let moved_ctx = ctx. clone ( ) ;
210
224
let block_identifier = block. block_identifier . clone ( ) ;
211
225
let moved_hord_db_path = hord_db_path. clone ( ) ;
212
- let cache = shared_cache . clone ( ) ;
226
+ let local_cache = traversals_cache . clone ( ) ;
213
227
traversal_data_pool. execute ( move || loop {
214
228
match open_readonly_hord_db_conn_rocks_db ( & moved_hord_db_path, & moved_ctx) {
215
229
Ok ( blocks_db) => {
@@ -218,7 +232,7 @@ pub fn retrieve_inscribed_satoshi_points_from_block(
218
232
& block_identifier,
219
233
& transaction_id,
220
234
0 ,
221
- cache ,
235
+ local_cache ,
222
236
& moved_ctx,
223
237
) ;
224
238
let _ = moved_traversal_tx. send ( ( transaction_id, traversal) ) ;
@@ -262,7 +276,6 @@ pub fn retrieve_inscribed_satoshi_points_from_block(
262
276
}
263
277
}
264
278
let _ = traversal_data_pool. join ( ) ;
265
- std:: thread:: spawn ( move || drop ( shared_cache) ) ;
266
279
}
267
280
268
281
traversals
@@ -274,6 +287,13 @@ pub fn update_hord_db_and_augment_bitcoin_block(
274
287
inscriptions_db_conn_rw : & Connection ,
275
288
write_block : bool ,
276
289
hord_db_path : & PathBuf ,
290
+ traversals_cache : & Arc <
291
+ DashMap <
292
+ ( u32 , [ u8 ; 8 ] ) ,
293
+ ( Vec < ( [ u8 ; 8 ] , u32 , u16 , u64 ) > , Vec < u64 > ) ,
294
+ BuildHasherDefault < FxHasher > ,
295
+ > ,
296
+ > ,
277
297
ctx : & Context ,
278
298
) -> Result < ( ) , String > {
279
299
if write_block {
@@ -299,6 +319,7 @@ pub fn update_hord_db_and_augment_bitcoin_block(
299
319
& new_block,
300
320
Some ( inscriptions_db_conn_rw) ,
301
321
hord_db_path,
322
+ traversals_cache,
302
323
ctx,
303
324
) ;
304
325
0 commit comments