Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tap-agent): make RAV table sequelize-friendly #123

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/src/subgraph_client/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn monitor_deployment_status(

response.map_err(|e| format!("{e}")).and_then(|data| {
data.indexing_statuses
.and_then(|statuses| statuses.get(0).map(Clone::clone))
.and_then(|statuses| statuses.first().map(Clone::clone))
.ok_or_else(|| format!("Deployment `{deployment}` not found"))
})
}
Expand Down
6 changes: 5 additions & 1 deletion migrations/20230915230734_tap_ravs.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ CREATE TABLE IF NOT EXISTS scalar_tap_ravs (
value_aggregate NUMERIC(39) NOT NULL,

final BOOLEAN DEFAULT FALSE NOT NULL,
PRIMARY KEY (allocation_id, sender_address)
PRIMARY KEY (allocation_id, sender_address),

-- To make indexer-agent's sequelize happy
"createdAt" TIMESTAMP WITH TIME ZONE,
"updatedAt" TIMESTAMP WITH TIME ZONE
);

-- This table is used to store failed RAV requests.
Expand Down
4 changes: 2 additions & 2 deletions service/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ mod test {

// Second test: query with a deployment filter
let sample_deployments = vec![
test_models.get(0).unwrap().deployment,
test_models.first().unwrap().deployment,
test_models.get(1).unwrap().deployment,
];
let models = cost_models(&pool, &sample_deployments)
Expand Down Expand Up @@ -394,7 +394,7 @@ mod test {

// Second test: fetch cost models, filtering by the first two deployment IDs
let sample_deployments = vec![
test_models.get(0).unwrap().deployment,
test_models.first().unwrap().deployment,
test_models.get(1).unwrap().deployment,
];
let models = dbg!(cost_models(&pool, &sample_deployments).await)
Expand Down
1 change: 1 addition & 0 deletions tap-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
21 changes: 17 additions & 4 deletions tap-agent/src/tap/rav_storage_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,16 +40,29 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter {

let _fut = sqlx::query!(
r#"
INSERT INTO scalar_tap_ravs (sender_address, signature, allocation_id, timestamp_ns, value_aggregate)
VALUES ($1, $2, $3, $4, $5)
INSERT INTO scalar_tap_ravs (
sender_address,
signature,
allocation_id,
timestamp_ns,
value_aggregate,
"createdAt",
"updatedAt"
)
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
DO UPDATE SET
signature = $2,
timestamp_ns = $4,
value_aggregate = $5,
"updatedAt" = $6
"#,
self.sender.encode_hex::<String>(),
signature_bytes,
self.allocation_id.encode_hex::<String>(),
BigDecimal::from(rav.message.timestamp_ns),
BigDecimal::from(BigInt::from(rav.message.value_aggregate)),
chrono::Utc::now()
)
.execute(&self.pgpool)
.await
Expand Down
Loading