diff --git a/Cargo.lock b/Cargo.lock index 6aa158aad..b36a557d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5986,6 +5986,7 @@ dependencies = [ "bigdecimal 0.3.1", "byteorder", "bytes", + "chrono", "crc", "crossbeam-queue", "dotenvy", @@ -6069,6 +6070,7 @@ dependencies = [ "bitflags 2.4.1", "byteorder", "bytes", + "chrono", "crc", "digest 0.10.7", "dotenvy", @@ -6113,6 +6115,7 @@ dependencies = [ "bigdecimal 0.3.1", "bitflags 2.4.1", "byteorder", + "chrono", "crc", "dotenvy", "etcetera", @@ -6152,6 +6155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d59dc83cf45d89c555a577694534fcd1b55c545a816c816ce51f20bbe56a4f3f" dependencies = [ "atoi", + "chrono", "flume", "futures-channel", "futures-core", diff --git a/migrations/20230915230734_tap_ravs.up.sql b/migrations/20230915230734_tap_ravs.up.sql index 5937a3a26..9f933bc2f 100644 --- a/migrations/20230915230734_tap_ravs.up.sql +++ b/migrations/20230915230734_tap_ravs.up.sql @@ -11,8 +11,8 @@ CREATE TABLE IF NOT EXISTS scalar_tap_ravs ( PRIMARY KEY (allocation_id, sender_address), -- To make indexer-agent's sequelize happy - createdAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP + createdAt TIMESTAMP WITH TIME ZONE, + updatedAt TIMESTAMP WITH TIME ZONE ); -- This table is used to store failed RAV requests. diff --git a/tap-agent/Cargo.toml b/tap-agent/Cargo.toml index f37025c2b..f4970c4ce 100644 --- a/tap-agent/Cargo.toml +++ b/tap-agent/Cargo.toml @@ -31,6 +31,7 @@ sqlx = { version = "0.7.2", features = [ "runtime-tokio", "bigdecimal", "rust_decimal", + "chrono", ] } tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", branch = "aasseman/tap_core_0_7_0_fix_toolshed_dep" } tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", branch = "aasseman/tap_core_0_7_0_fix_toolshed_dep" } diff --git a/tap-agent/src/tap/rav_storage_adapter.rs b/tap-agent/src/tap/rav_storage_adapter.rs index 534e7bf7b..5956f38b9 100644 --- a/tap-agent/src/tap/rav_storage_adapter.rs +++ b/tap-agent/src/tap/rav_storage_adapter.rs @@ -9,7 +9,7 @@ use bigdecimal::num_bigint::{BigInt, ToBigInt}; use bigdecimal::ToPrimitive; use ethers::types::Signature; use open_fastrlp::{Decodable, Encodable}; -use sqlx::types::BigDecimal; +use sqlx::types::{chrono, BigDecimal}; use sqlx::PgPool; use tap_core::adapters::rav_storage_adapter::RAVStorageAdapter as RAVStorageAdapterTrait; use tap_core::receipt_aggregate_voucher::ReceiptAggregateVoucher; @@ -45,21 +45,24 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter { signature, allocation_id, timestamp_ns, - value_aggregate + value_aggregate, + createdAt, + updatedAt ) - VALUES ($1, $2, $3, $4, $5) + VALUES ($1, $2, $3, $4, $5, $6, $6) ON CONFLICT (allocation_id, sender_address) DO UPDATE SET signature = $2, timestamp_ns = $4, value_aggregate = $5, - updatedAt = default + updatedAt = $6 "#, self.sender.encode_hex::(), signature_bytes, self.allocation_id.encode_hex::(), BigDecimal::from(rav.message.timestamp_ns), BigDecimal::from(BigInt::from(rav.message.value_aggregate)), + chrono::Utc::now() ) .execute(&self.pgpool) .await