Skip to content

Commit 29747b5

Browse files
committed
feat: initial structs for db integration
1 parent 9392503 commit 29747b5

File tree

8 files changed

+50
-2
lines changed

8 files changed

+50
-2
lines changed

aggregation_mode/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation_mode/db/migrations/001_init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE TYPE task_status AS ENUM ('pending', 'processing', 'verified');
1+
CREATE TYPE task_status AS ENUM ('pending', 'processing', 'verified', 'submitted');
22

33
CREATE TABLE tasks (
44
task_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),

aggregation_mode/proof_aggregator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ciborium = "=0.2.2"
2121
lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "5f8f2cfcc8a1a22f77e8dff2d581f1166eefb80b", features = ["serde"]}
2222
rayon = "1.10.0"
2323
backon = "1.2.0"
24+
sqlx = { version = "0.8", features = [ "runtime-tokio", "postgres", "uuid", "bigdecimal" ] }
2425

2526
# zkvms
2627
sp1-sdk = { workspace = true }

aggregation_mode/proof_aggregator/src/backend/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Config {
2525
pub total_proofs_limit: u16,
2626
pub sp1_chunk_aggregator_vk_hash: String,
2727
pub risc0_chunk_aggregator_image_id: String,
28+
pub db_connection_url: String,
2829
}
2930

3031
impl Config {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use sqlx::{
2+
postgres::PgPoolOptions,
3+
types::{BigDecimal, Uuid},
4+
Pool, Postgres,
5+
};
6+
7+
#[derive(Clone, Debug)]
8+
pub struct Db {
9+
pool: Pool<Postgres>,
10+
}
11+
12+
#[derive(Debug, Clone)]
13+
pub enum DbError {
14+
ConnectError(String),
15+
}
16+
17+
impl Db {
18+
pub async fn try_new(connection_url: &str) -> Result<Self, DbError> {
19+
let pool = PgPoolOptions::new()
20+
.max_connections(5)
21+
.connect(connection_url)
22+
.await
23+
.map_err(|e| DbError::ConnectError(e.to_string()))?;
24+
25+
Ok(Self { pool })
26+
}
27+
28+
pub async fn get_tasks_and_mark_them_as_processed() {}
29+
30+
pub async fn mark_tasks_as_pending() {}
31+
32+
pub async fn mark_tasks_as_processing() {}
33+
34+
pub async fn mark_tasks_as_verified() {}
35+
36+
pub async fn mark_tasks_as_submitted() {}
37+
}

aggregation_mode/proof_aggregator/src/backend/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
pub mod config;
2+
mod db;
23
pub mod fetcher;
34
mod merkle_tree;
45
mod retry;
56
mod s3;
67
mod types;
78

8-
use crate::aggregators::{AlignedProof, ProofAggregationError, ZKVMEngine};
9+
use crate::{
10+
aggregators::{AlignedProof, ProofAggregationError, ZKVMEngine},
11+
backend::db::Db,
12+
};
913

1014
use alloy::{
1115
consensus::{BlobTransactionSidecar, EnvKzgSettings, EthereumTxEnvelope, TxEip4844WithSidecar},
@@ -80,6 +84,8 @@ impl ProofAggregator {
8084
.try_into()
8185
.expect("Risc0 chunk aggregator image id must be 32 bytes");
8286

87+
let db = Db::try_new(self.config.db_connection_url).expect("To connect to db");
88+
8389
Self {
8490
engine,
8591
proof_aggregation_service,

config-files/config-proof-aggregator-ethereum-package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ proofs_per_chunk: 512 # Amount of proofs to process per chunk
1212
# Since each proof commitments takes 32 bytes hash
1313
# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob
1414
total_proofs_limit: 3968
15+
db_connection_url: "postgres://postgres:postgres@localhost:5435/"
1516

1617
# These program ids are the ones from the chunk aggregator programs
1718
# Can be found in the Proof Aggregation Service deployment config

config-files/config-proof-aggregator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ proofs_per_chunk: 512 # Amount of proofs to process per chunk
1212
# Since each proof commitments takes 32 bytes hash
1313
# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob
1414
total_proofs_limit: 3968
15+
db_connection_url: "postgres://postgres:postgres@localhost:5435/"
1516

1617
# These program ids are the ones from the chunk aggregator programs
1718
# Can be found in the Proof Aggregation Service deployment config

0 commit comments

Comments
 (0)