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
Changes from 1 commit
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
Next Next commit
fix(tap-agent): make RAV table sequelize-friendly
By adding the `createdAt` and `updatedAt` columns.
Sequelize is used in indexer-agent, and it needs to access the RAV table to redeem RAVs.
See https://sequelize.org/docs/v6/core-concepts/model-basics/#timestamps

Signed-off-by: Alexis Asseman <alexis@semiotic.ai>
aasseman committed Feb 21, 2024
commit 66872152055aa980d733716ad9639d6a9d5d352b

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

This file was deleted.

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
@@ -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"))
})
}
6 changes: 5 additions & 1 deletion migrations/20230915230734_tap_ravs.up.sql
Original file line number Diff line number Diff line change
@@ -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 DEFAULT CURRENT_TIMESTAMP,
updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- This table is used to store failed RAV requests.
4 changes: 2 additions & 2 deletions service/src/database.rs
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
14 changes: 12 additions & 2 deletions tap-agent/src/tap/rav_storage_adapter.rs
Original file line number Diff line number Diff line change
@@ -40,10 +40,20 @@ impl RAVStorageAdapterTrait for RAVStorageAdapter {

let _fut = sqlx::query!(
r#"
INSERT INTO scalar_tap_ravs (sender_address, signature, allocation_id, timestamp_ns, value_aggregate)
INSERT INTO scalar_tap_ravs (
sender_address,
signature,
allocation_id,
timestamp_ns,
value_aggregate
)
VALUES ($1, $2, $3, $4, $5)
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 = default
"#,
self.sender.encode_hex::<String>(),
signature_bytes,