@@ -39,7 +39,7 @@ use crate::db::{
39
39
} ;
40
40
use crate :: ord:: height:: Height ;
41
41
42
- use crate :: config:: Config ;
42
+ use crate :: config:: { Config , LogConfig } ;
43
43
44
44
use crate :: db:: format_outpoint_to_watch;
45
45
use chainhook_sdk:: indexer:: bitcoin:: {
@@ -70,6 +70,7 @@ pub struct HordConfig {
70
70
pub cache_size : usize ,
71
71
pub db_path : PathBuf ,
72
72
pub first_inscription_height : u64 ,
73
+ pub logs : LogConfig ,
73
74
}
74
75
75
76
pub fn parse_ordinals_and_standardize_block (
@@ -1109,8 +1110,12 @@ pub fn get_transactions_to_process(
1109
1110
cache_l1 : & mut HashMap < ( TransactionIdentifier , usize ) , TraversalResult > ,
1110
1111
inscriptions_db_conn : & mut Connection ,
1111
1112
ctx : & Context ,
1112
- ) -> Vec < ( TransactionIdentifier , usize ) > {
1113
+ ) -> (
1114
+ Vec < ( TransactionIdentifier , usize ) > ,
1115
+ Vec < ( TransactionIdentifier , usize ) > ,
1116
+ ) {
1113
1117
let mut transactions_ids: Vec < ( TransactionIdentifier , usize ) > = vec ! [ ] ;
1118
+ let mut l1_cache_hits = vec ! [ ] ;
1114
1119
1115
1120
for tx in block. transactions . iter ( ) . skip ( 1 ) {
1116
1121
// Have a new inscription been revealed, if so, are looking at a re-inscription
@@ -1126,11 +1131,12 @@ pub fn get_transactions_to_process(
1126
1131
continue ;
1127
1132
}
1128
1133
} ;
1129
-
1130
- if cache_l1. contains_key ( & (
1134
+ let key = (
1131
1135
tx. transaction_identifier . clone ( ) ,
1132
1136
inscription_data. inscription_input_index ,
1133
- ) ) {
1137
+ ) ;
1138
+ if cache_l1. contains_key ( & key) {
1139
+ l1_cache_hits. push ( key) ;
1134
1140
continue ;
1135
1141
}
1136
1142
@@ -1155,7 +1161,7 @@ pub fn get_transactions_to_process(
1155
1161
}
1156
1162
}
1157
1163
}
1158
- transactions_ids
1164
+ ( transactions_ids, l1_cache_hits )
1159
1165
}
1160
1166
1161
1167
pub fn retrieve_inscribed_satoshi_points_from_block_v3 (
@@ -1167,23 +1173,30 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
1167
1173
hord_config : & HordConfig ,
1168
1174
ctx : & Context ,
1169
1175
) -> Result < bool , String > {
1170
- let mut transactions_ids =
1176
+ let ( mut transactions_ids, l1_cache_hits ) =
1171
1177
get_transactions_to_process ( block, cache_l1, inscriptions_db_conn, ctx) ;
1172
1178
1173
- let has_transactions_to_process = !transactions_ids. is_empty ( ) ;
1179
+ let inner_ctx = if hord_config. logs . ordinals_computation {
1180
+ ctx. clone ( )
1181
+ } else {
1182
+ Context :: empty ( )
1183
+ } ;
1184
+
1185
+ let has_transactions_to_process = !transactions_ids. is_empty ( ) || !l1_cache_hits. is_empty ( ) ;
1174
1186
1175
1187
if has_transactions_to_process {
1176
- let expected_traversals = transactions_ids. len ( ) ;
1188
+ let expected_traversals = transactions_ids. len ( ) + l1_cache_hits . len ( ) ;
1177
1189
let ( traversal_tx, traversal_rx) = channel ( ) ;
1178
- let traversal_data_pool = ThreadPool :: new ( hord_config. ingestion_thread_max ) ;
1179
1190
1191
+ let traversal_data_pool = ThreadPool :: new ( hord_config. ingestion_thread_max ) ;
1180
1192
let mut tx_thread_pool = vec ! [ ] ;
1193
+
1181
1194
for thread_index in 0 ..hord_config. ingestion_thread_max {
1182
1195
let ( tx, rx) = channel ( ) ;
1183
1196
tx_thread_pool. push ( tx) ;
1184
1197
1185
1198
let moved_traversal_tx = traversal_tx. clone ( ) ;
1186
- let moved_ctx = ctx . clone ( ) ;
1199
+ let moved_ctx = inner_ctx . clone ( ) ;
1187
1200
let moved_hord_db_path = hord_config. db_path . clone ( ) ;
1188
1201
let local_cache = cache_l2. clone ( ) ;
1189
1202
@@ -1206,12 +1219,22 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
1206
1219
} ) ;
1207
1220
}
1208
1221
1222
+ // Empty cache
1223
+ let mut thread_index = 0 ;
1224
+ for key in l1_cache_hits. iter ( ) {
1225
+ if let Some ( entry) = cache_l1. remove ( key) {
1226
+ let _ = traversal_tx. send ( ( Ok ( entry) , true , thread_index) ) ;
1227
+ thread_index = ( thread_index + 1 ) % hord_config. ingestion_thread_max ;
1228
+ }
1229
+ }
1230
+
1209
1231
ctx. try_log ( |logger| {
1210
1232
info ! (
1211
1233
logger,
1212
- "Number of inscriptions in block #{} to process: {}" ,
1234
+ "Number of inscriptions in block #{} to process: {} (L1 cache hits: {}) " ,
1213
1235
block. block_identifier. index,
1214
- transactions_ids. len( )
1236
+ transactions_ids. len( ) ,
1237
+ l1_cache_hits. len( ) ,
1215
1238
)
1216
1239
} ) ;
1217
1240
@@ -1245,7 +1268,7 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
1245
1268
}
1246
1269
match traversal_result {
1247
1270
Ok ( traversal) => {
1248
- ctx . try_log ( |logger| {
1271
+ inner_ctx . try_log ( |logger| {
1249
1272
info ! (
1250
1273
logger,
1251
1274
"Satoshi #{} was minted in block #{} at offset {} and was transferred {} times (progress: {traversals_received}/{expected_traversals}) (priority queue: {prioritary}, thread: {thread_index})." ,
@@ -1277,7 +1300,7 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
1277
1300
let _ = tx_thread_pool[ thread_index] . send ( Some ( w) ) ;
1278
1301
} else {
1279
1302
if let Some ( next_block) = next_block_iter. next ( ) {
1280
- let mut transactions_ids = get_transactions_to_process (
1303
+ let ( mut transactions_ids, _ ) = get_transactions_to_process (
1281
1304
next_block,
1282
1305
cache_l1,
1283
1306
inscriptions_db_conn,
@@ -1358,7 +1381,11 @@ pub fn update_hord_db_and_augment_bitcoin_block_v3(
1358
1381
let inner_ctx = if discard_changes {
1359
1382
Context :: empty ( )
1360
1383
} else {
1361
- ctx. clone ( )
1384
+ if hord_config. logs . ordinals_computation {
1385
+ ctx. clone ( )
1386
+ } else {
1387
+ Context :: empty ( )
1388
+ }
1362
1389
} ;
1363
1390
1364
1391
let transaction = inscriptions_db_conn_rw. transaction ( ) . unwrap ( ) ;
0 commit comments