@@ -503,19 +503,6 @@ impl SenderAllocationState {
503503 ) ,
504504 _ => e. into ( ) ,
505505 } ) ?;
506- if !invalid_receipts. is_empty ( ) {
507- warn ! (
508- "Found {} invalid receipts for allocation {} and sender {}." ,
509- invalid_receipts. len( ) ,
510- self . allocation_id,
511- self . sender
512- ) ;
513-
514- // Save invalid receipts to the database for logs.
515- // TODO: consider doing that in a spawned task?
516- self . store_invalid_receipts ( invalid_receipts. as_slice ( ) )
517- . await ?;
518- }
519506 let client = HttpClientBuilder :: default ( )
520507 . request_timeout ( Duration :: from_secs (
521508 self . config . tap . rav_request_timeout_secs ,
@@ -538,9 +525,27 @@ impl SenderAllocationState {
538525 . with_label_values ( & [ & self . sender . to_string ( ) ] )
539526 . observe ( rav_response_time. as_secs_f64 ( ) ) ;
540527
528+ // we only save invalid receipts when we are about to store our rav
529+ //
530+ // store them before we call remove_obsolete_receipts()
531+ if !invalid_receipts. is_empty ( ) {
532+ warn ! (
533+ "Found {} invalid receipts for allocation {} and sender {}." ,
534+ invalid_receipts. len( ) ,
535+ self . allocation_id,
536+ self . sender
537+ ) ;
538+
539+ // Save invalid receipts to the database for logs.
540+ // TODO: consider doing that in a spawned task?
541+ self . store_invalid_receipts ( invalid_receipts. as_slice ( ) )
542+ . await ?;
543+ }
544+
541545 if let Some ( warnings) = response. warnings {
542546 warn ! ( "Warnings from sender's TAP aggregator: {:?}" , warnings) ;
543547 }
548+
544549 match self
545550 . tap_manager
546551 . verify_and_store_rav ( expected_rav. clone ( ) , response. data . clone ( ) )
0 commit comments