diff --git a/.sqlx/query-0d4e055d87b4496202041f3c28618688afa91dc0b8eeb8e551b271fc73c1157e.json b/.sqlx/query-0d4e055d87b4496202041f3c28618688afa91dc0b8eeb8e551b271fc73c1157e.json new file mode 100644 index 000000000..4ebee3864 --- /dev/null +++ b/.sqlx/query-0d4e055d87b4496202041f3c28618688afa91dc0b8eeb8e551b271fc73c1157e.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO scalar_tap_receipts_invalid (\n signer_address,\n signature,\n allocation_id,\n timestamp_ns,\n nonce,\n value\n ) SELECT * FROM UNNEST(\n $1::CHAR(40)[],\n $2::BYTEA[],\n $3::CHAR(40)[],\n $4::NUMERIC(20)[],\n $5::NUMERIC(20)[],\n $6::NUMERIC(40)[]\n )", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "BpcharArray", + "ByteaArray", + "BpcharArray", + "NumericArray", + "NumericArray", + "NumericArray" + ] + }, + "nullable": [] + }, + "hash": "0d4e055d87b4496202041f3c28618688afa91dc0b8eeb8e551b271fc73c1157e" +} diff --git a/.sqlx/query-56c3678866ffe0ec2eed7290394d07007990cc244f598b763ec5470515efe019.json b/.sqlx/query-56c3678866ffe0ec2eed7290394d07007990cc244f598b763ec5470515efe019.json index 698533680..ff0584398 100644 --- a/.sqlx/query-56c3678866ffe0ec2eed7290394d07007990cc244f598b763ec5470515efe019.json +++ b/.sqlx/query-56c3678866ffe0ec2eed7290394d07007990cc244f598b763ec5470515efe019.json @@ -37,11 +37,6 @@ "ordinal": 6, "name": "value", "type_info": "Numeric" - }, - { - "ordinal": 7, - "name": "error_log", - "type_info": "Text" } ], "parameters": { @@ -54,7 +49,6 @@ false, false, false, - false, false ] }, diff --git a/.sqlx/query-6c365bc1b0728ec8d9f1239d7bffe7861ff17c6b8de4365a39f28099f5711613.json b/.sqlx/query-6c365bc1b0728ec8d9f1239d7bffe7861ff17c6b8de4365a39f28099f5711613.json deleted file mode 100644 index 1e45b7ef7..000000000 --- a/.sqlx/query-6c365bc1b0728ec8d9f1239d7bffe7861ff17c6b8de4365a39f28099f5711613.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO scalar_tap_receipts_invalid (\n signer_address,\n signature,\n allocation_id,\n timestamp_ns,\n nonce,\n value,\n error_log\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Bpchar", - "Bytea", - "Bpchar", - "Numeric", - "Numeric", - "Numeric", - "Text" - ] - }, - "nullable": [] - }, - "hash": "6c365bc1b0728ec8d9f1239d7bffe7861ff17c6b8de4365a39f28099f5711613" -} diff --git a/migrations/20230915230734_tap_ravs.down.sql b/migrations/20230915230734_tap_ravs.down.sql index 0ad115b3b..a411faed2 100644 --- a/migrations/20230915230734_tap_ravs.down.sql +++ b/migrations/20230915230734_tap_ravs.down.sql @@ -1,2 +1,2 @@ -DROP TABLE IF EXISTS scalar_tap_ravs CASCADE; -DROP TABLE IF EXISTS scalar_tap_rav_requests_failed CASCADE; +-- DROP TABLE IF EXISTS scalar_tap_ravs CASCADE; +-- DROP TABLE IF EXISTS scalar_tap_rav_requests_failed CASCADE; diff --git a/tap-agent/src/agent/sender_allocation.rs b/tap-agent/src/agent/sender_allocation.rs index a25b6df71..f7b069faa 100644 --- a/tap-agent/src/agent/sender_allocation.rs +++ b/tap-agent/src/agent/sender_allocation.rs @@ -685,6 +685,14 @@ impl SenderAllocationState { &mut self, receipts: &[ReceiptWithState], ) -> Result<()> { + let reciepts_len = receipts.len(); + let mut reciepts_signers = Vec::with_capacity(reciepts_len); + let mut encoded_signatures = Vec::with_capacity(reciepts_len); + let mut allocation_ids = Vec::with_capacity(reciepts_len); + let mut timestamps = Vec::with_capacity(reciepts_len); + let mut nounces = Vec::with_capacity(reciepts_len); + let mut values = Vec::with_capacity(reciepts_len); + for received_receipt in receipts.iter() { let receipt = received_receipt.signed_receipt(); let allocation_id = receipt.message.allocation_id; @@ -696,31 +704,43 @@ impl SenderAllocationState { error!("Failed to recover receipt signer: {}", e); anyhow!(e) })?; - sqlx::query!( - r#" - INSERT INTO scalar_tap_receipts_invalid ( - signer_address, - signature, - allocation_id, - timestamp_ns, - nonce, - value, - error_log - ) - VALUES ($1, $2, $3, $4, $5, $6, $7) - "#, - receipt_signer.encode_hex(), - encoded_signature, - allocation_id.encode_hex(), - BigDecimal::from(receipt.message.timestamp_ns), - BigDecimal::from(receipt.message.nonce), - BigDecimal::from(BigInt::from(receipt.message.value)), - receipt_error - ) - .execute(&self.pgpool) - .await - .map_err(|e| anyhow!("Failed to store invalid receipt: {:?}", e))?; + reciepts_signers.push(receipt_signer.encode_hex()); + encoded_signatures.push(encoded_signature); + allocation_ids.push(allocation_id.encode_hex()); + timestamps.push(BigDecimal::from(receipt.message.timestamp_ns)); + nounces.push(BigDecimal::from(receipt.message.nonce)); + values.push(BigDecimal::from(BigInt::from(receipt.message.value))); } + sqlx::query!( + r#"INSERT INTO scalar_tap_receipts_invalid ( + signer_address, + signature, + allocation_id, + timestamp_ns, + nonce, + value + ) SELECT * FROM UNNEST( + $1::CHAR(40)[], + $2::BYTEA[], + $3::CHAR(40)[], + $4::NUMERIC(20)[], + $5::NUMERIC(20)[], + $6::NUMERIC(40)[] + )"#, + &reciepts_signers, + &encoded_signatures, + &allocation_ids, + ×tamps, + &nounces, + &values, + ) + .execute(&self.pgpool) + .await + .map_err(|e| { + error!("Failed to store receipt: {}", e); + anyhow!(e) + })?; + let fees = receipts .iter() .map(|receipt| receipt.signed_receipt().message.value)