@@ -317,7 +317,8 @@ impl StateBridge {
317
317
let global_offer_report = self . global_offer_report . clone ( ) ;
318
318
tokio:: spawn ( async move {
319
319
let timer = metrics. start_process_timer ( "spawn_offer_state_proof" ) ;
320
- match timeout (
320
+
321
+ let result = timeout (
321
322
SERVE_BLOCK_TIMEOUT ,
322
323
StateNetworkApiClient :: trace_offer (
323
324
& portal_client,
@@ -326,43 +327,49 @@ impl StateBridge {
326
327
content_value. encode ( ) ,
327
328
) ,
328
329
)
329
- . await
330
- {
331
- Ok ( result) => match result {
332
- Ok ( result) => {
333
- global_offer_report
334
- . lock ( )
335
- . expect ( "to acquire lock" )
336
- . update ( & result) ;
337
- offer_report
338
- . lock ( )
339
- . expect ( "to acquire lock" )
340
- . update ( & enr, & result) ;
341
- }
342
- Err ( e) => {
343
- global_offer_report
344
- . lock ( )
345
- . expect ( "to acquire lock" )
346
- . update ( & OfferTrace :: Failed ) ;
347
- offer_report
348
- . lock ( )
349
- . expect ( "to acquire lock" )
350
- . update ( & enr, & OfferTrace :: Failed ) ;
351
- warn ! ( "Error offering to: {enr}, error: {e:?}" ) ;
330
+ . await ;
331
+
332
+ let offer_trace = match & result {
333
+ Ok ( Ok ( result) ) => {
334
+ if matches ! ( result, & OfferTrace :: Failed ) {
335
+ warn ! ( "Internal error offering to: {enr}" ) ;
352
336
}
353
- } ,
337
+ result
338
+ }
339
+ Ok ( Err ( err) ) => {
340
+ warn ! ( "Error offering to: {enr}, error: {err:?}" ) ;
341
+ & OfferTrace :: Failed
342
+ }
354
343
Err ( _) => {
355
- global_offer_report
356
- . lock ( )
357
- . expect ( "to acquire lock" )
358
- . update ( & OfferTrace :: Failed ) ;
359
- offer_report
360
- . lock ( )
361
- . expect ( "to acquire lock" )
362
- . update ( & enr, & OfferTrace :: Failed ) ;
363
344
error ! ( "trace_offer timed out on state proof {content_key}: indicating a bug is present" ) ;
345
+ & OfferTrace :: Failed
364
346
}
365
347
} ;
348
+
349
+ // Update report and metrics
350
+ global_offer_report
351
+ . lock ( )
352
+ . expect ( "to acquire lock" )
353
+ . update ( offer_trace) ;
354
+ offer_report
355
+ . lock ( )
356
+ . expect ( "to acquire lock" )
357
+ . update ( & enr, offer_trace) ;
358
+
359
+ metrics. report_offer (
360
+ match content_key {
361
+ StateContentKey :: AccountTrieNode ( _) => "account_trie_node" ,
362
+ StateContentKey :: ContractStorageTrieNode ( _) => "contract_storage_trie_node" ,
363
+ StateContentKey :: ContractBytecode ( _) => "contract_bytecode" ,
364
+ } ,
365
+ match offer_trace {
366
+ OfferTrace :: Success ( _) => "success" ,
367
+ OfferTrace :: Declined => "declined" ,
368
+ OfferTrace :: Failed => "failed" ,
369
+ } ,
370
+ ) ;
371
+
372
+ // Release permit
366
373
drop ( permit) ;
367
374
metrics. stop_process_timer ( timer) ;
368
375
} ) ;
0 commit comments