@@ -27,7 +27,7 @@ use tap_core::{
2727 signed_message:: EIP712SignedMessage ,
2828} ;
2929use thegraph_core:: Address ;
30- use tracing:: { error, warn} ;
30+ use tracing:: { debug , error, warn} ;
3131
3232use crate :: { agent:: sender_account:: ReceiptFees , lazy_static} ;
3333
@@ -685,6 +685,15 @@ impl SenderAllocationState {
685685 & mut self ,
686686 receipts : & [ ReceiptWithState < Failed > ] ,
687687 ) -> Result < ( ) > {
688+ let reciepts_len = receipts. len ( ) ;
689+ let mut reciepts_signers = Vec :: with_capacity ( reciepts_len) ;
690+ let mut encoded_signatures = Vec :: with_capacity ( reciepts_len) ;
691+ let mut allocation_ids = Vec :: with_capacity ( reciepts_len) ;
692+ let mut timestamps = Vec :: with_capacity ( reciepts_len) ;
693+ let mut nounces = Vec :: with_capacity ( reciepts_len) ;
694+ let mut values = Vec :: with_capacity ( reciepts_len) ;
695+ let mut error_logs = Vec :: with_capacity ( reciepts_len) ;
696+
688697 for received_receipt in receipts. iter ( ) {
689698 let receipt = received_receipt. signed_receipt ( ) ;
690699 let allocation_id = receipt. message . allocation_id ;
@@ -696,31 +705,53 @@ impl SenderAllocationState {
696705 error ! ( "Failed to recover receipt signer: {}" , e) ;
697706 anyhow ! ( e)
698707 } ) ?;
699- sqlx:: query!(
700- r#"
701- INSERT INTO scalar_tap_receipts_invalid (
702- signer_address,
703- signature,
704- allocation_id,
705- timestamp_ns,
706- nonce,
707- value,
708- error_log
709- )
710- VALUES ($1, $2, $3, $4, $5, $6, $7)
711- "# ,
712- receipt_signer. encode_hex( ) ,
713- encoded_signature,
708+ debug ! (
709+ "Receipt for allocation {} and signer {} failed reason: {}" ,
714710 allocation_id. encode_hex( ) ,
715- BigDecimal :: from( receipt. message. timestamp_ns) ,
716- BigDecimal :: from( receipt. message. nonce) ,
717- BigDecimal :: from( BigInt :: from( receipt. message. value) ) ,
711+ receipt_signer. encode_hex( ) ,
718712 receipt_error
719- )
720- . execute ( & self . pgpool )
721- . await
722- . map_err ( |e| anyhow ! ( "Failed to store invalid receipt: {:?}" , e) ) ?;
713+ ) ;
714+ reciepts_signers. push ( receipt_signer. encode_hex ( ) ) ;
715+ encoded_signatures. push ( encoded_signature) ;
716+ allocation_ids. push ( allocation_id. encode_hex ( ) ) ;
717+ timestamps. push ( BigDecimal :: from ( receipt. message . timestamp_ns ) ) ;
718+ nounces. push ( BigDecimal :: from ( receipt. message . nonce ) ) ;
719+ values. push ( BigDecimal :: from ( BigInt :: from ( receipt. message . value ) ) ) ;
720+ error_logs. push ( receipt_error) ;
723721 }
722+ sqlx:: query!(
723+ r#"INSERT INTO scalar_tap_receipts_invalid (
724+ signer_address,
725+ signature,
726+ allocation_id,
727+ timestamp_ns,
728+ nonce,
729+ value,
730+ error_log
731+ ) SELECT * FROM UNNEST(
732+ $1::CHAR(40)[],
733+ $2::BYTEA[],
734+ $3::CHAR(40)[],
735+ $4::NUMERIC(20)[],
736+ $5::NUMERIC(20)[],
737+ $6::NUMERIC(40)[],
738+ $7::TEXT[]
739+ )"# ,
740+ & reciepts_signers,
741+ & encoded_signatures,
742+ & allocation_ids,
743+ & timestamps,
744+ & nounces,
745+ & values,
746+ & error_logs
747+ )
748+ . execute ( & self . pgpool )
749+ . await
750+ . map_err ( |e| {
751+ error ! ( "Failed to store invalid receipt: {}" , e) ;
752+ anyhow ! ( e)
753+ } ) ?;
754+
724755 let fees = receipts
725756 . iter ( )
726757 . map ( |receipt| receipt. signed_receipt ( ) . message . value )
0 commit comments