@@ -6,8 +6,7 @@ use chainhook_event_observer::chainhooks::bitcoin::{
6
6
BitcoinChainhookOccurrence , BitcoinTriggerChainhook ,
7
7
} ;
8
8
use chainhook_event_observer:: chainhooks:: types:: {
9
- BitcoinChainhookSpecification , BitcoinPredicateType ,
10
- Protocols ,
9
+ BitcoinChainhookSpecification , BitcoinPredicateType , Protocols ,
11
10
} ;
12
11
use chainhook_event_observer:: hord:: db:: {
13
12
fetch_and_cache_blocks_in_hord_db, find_all_inscriptions, find_block_at_block_height,
@@ -27,7 +26,7 @@ use chainhook_event_observer::utils::{file_append, send_request, Context};
27
26
use chainhook_types:: { BitcoinChainEvent , BitcoinChainUpdatedWithBlocksData } ;
28
27
use std:: collections:: { BTreeMap , HashMap } ;
29
28
30
- pub async fn scan_bitcoin_chain_with_predicate_via_http (
29
+ pub async fn scan_bitcoin_chainstate_via_http_using_predicate (
31
30
predicate_spec : BitcoinChainhookSpecification ,
32
31
config : & Config ,
33
32
ctx : & Context ,
@@ -137,6 +136,7 @@ pub async fn scan_bitcoin_chain_with_predicate_via_http(
137
136
138
137
let mut blocks_scanned = 0 ;
139
138
let mut actions_triggered = 0 ;
139
+ let mut err_count = 0 ;
140
140
141
141
let event_observer_config = config. get_event_observer_config ( ) ;
142
142
let bitcoin_config = event_observer_config. get_bitcoin_config ( ) ;
@@ -199,8 +199,14 @@ pub async fn scan_bitcoin_chain_with_predicate_via_http(
199
199
ctx,
200
200
) ;
201
201
202
- actions_triggered +=
203
- execute_predicates_action ( hits, & event_observer_config, & ctx) . await ;
202
+ match execute_predicates_action ( hits, & event_observer_config, & ctx) . await {
203
+ Ok ( actions) => actions_triggered += actions,
204
+ Err ( _) => err_count += 1 ,
205
+ }
206
+
207
+ if err_count >= 3 {
208
+ return Err ( format ! ( "Scan aborted (consecutive action errors >= 3)" ) ) ;
209
+ }
204
210
}
205
211
} else {
206
212
let use_scan_to_seed_hord_db = true ;
@@ -242,8 +248,14 @@ pub async fn scan_bitcoin_chain_with_predicate_via_http(
242
248
ctx,
243
249
) ;
244
250
245
- actions_triggered +=
246
- execute_predicates_action ( hits, & event_observer_config, & ctx) . await ;
251
+ match execute_predicates_action ( hits, & event_observer_config, & ctx) . await {
252
+ Ok ( actions) => actions_triggered += actions,
253
+ Err ( _) => err_count += 1 ,
254
+ }
255
+
256
+ if err_count >= 3 {
257
+ return Err ( format ! ( "Scan aborted (consecutive action errors >= 3)" ) ) ;
258
+ }
247
259
}
248
260
}
249
261
info ! (
@@ -258,7 +270,7 @@ pub async fn execute_predicates_action<'a>(
258
270
hits : Vec < BitcoinTriggerChainhook < ' a > > ,
259
271
config : & EventObserverConfig ,
260
272
ctx : & Context ,
261
- ) -> u32 {
273
+ ) -> Result < u32 , ( ) > {
262
274
let mut actions_triggered = 0 ;
263
275
let proofs = gather_proofs ( & hits, & config, & ctx) ;
264
276
for hit in hits. into_iter ( ) {
@@ -269,13 +281,17 @@ pub async fn execute_predicates_action<'a>(
269
281
Ok ( action) => {
270
282
actions_triggered += 1 ;
271
283
match action {
272
- BitcoinChainhookOccurrence :: Http ( request) => send_request ( request, & ctx) . await ,
273
- BitcoinChainhookOccurrence :: File ( path, bytes) => file_append ( path, bytes, & ctx) ,
284
+ BitcoinChainhookOccurrence :: Http ( request) => {
285
+ send_request ( request, & ctx) . await ?
286
+ }
287
+ BitcoinChainhookOccurrence :: File ( path, bytes) => {
288
+ file_append ( path, bytes, & ctx) ?
289
+ }
274
290
BitcoinChainhookOccurrence :: Data ( _payload) => unreachable ! ( ) ,
275
- }
291
+ } ;
276
292
}
277
293
}
278
294
}
279
295
280
- actions_triggered
296
+ Ok ( actions_triggered)
281
297
}
0 commit comments