Skip to content

Commit 0419233

Browse files
committed
feat: db types and tasks selection
1 parent 29747b5 commit 0419233

File tree

10 files changed

+70
-22
lines changed

10 files changed

+70
-22
lines changed

aggregation_mode/Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aggregation_mode/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ serde_yaml = "0.9"
1313
alloy = { version = "1.1.1", features = ["default", "signer-keystore", "kzg"] }
1414
bincode = "1.3.3"
1515
aligned-sdk = { path = "../crates/sdk/" }
16+
db = { path = "./db" }
1617
sp1-sdk = "5.0.0"
1718
risc0-zkvm = { version = "3.0.3" }
1819

aggregation_mode/db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "agg_mode_db"
2+
name = "db"
33
version = "0.1.0"
44
edition = "2021"
55

aggregation_mode/db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod types;

aggregation_mode/db/src/types.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use sqlx::{
2+
prelude::FromRow,
3+
types::{BigDecimal, Uuid},
4+
Type,
5+
};
6+
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Type)]
8+
#[sqlx(type_name = "task_status", rename_all = "lowercase")]
9+
pub enum TaskStatus {
10+
Pending,
11+
Running,
12+
Done,
13+
Failed,
14+
}
15+
16+
#[derive(Debug, Clone, FromRow)]
17+
pub struct Task {
18+
pub task_id: Uuid,
19+
pub address: String,
20+
pub proving_system_id: i32,
21+
pub proof: Vec<u8>,
22+
pub program_commitment: Vec<u8>,
23+
pub merkle_path: Vec<u8>,
24+
pub status: TaskStatus,
25+
}
26+
27+
#[derive(Debug, Clone, FromRow)]
28+
pub struct Payment {
29+
pub payment_event_id: Uuid,
30+
pub address: String,
31+
pub amount: i32,
32+
pub started_at: BigDecimal,
33+
pub valid_until: BigDecimal,
34+
pub tx_hash: String,
35+
}

aggregation_mode/proof_aggregator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ serde_yaml = { workspace = true }
1010
alloy = { workspace = true }
1111
bincode = { workspace = true }
1212
aligned-sdk = { workspace = true }
13+
db = { workspace = true }
1314

1415
tracing = { version = "0.1", features = ["log"] }
1516
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }

aggregation_mode/proof_aggregator/build.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fn main() {
1212
],
1313
// We use Docker to generate a reproducible ELF that will be identical across all platforms
1414
// (https://docs.succinct.xyz/docs/sp1/writing-programs/compiling#production-builds)
15-
docker: true,
1615
..Default::default()
1716
}
1817
});
@@ -21,10 +20,7 @@ fn main() {
2120
// regardless of the machine or local environment, will produce the same ImageID
2221
let docker_options = DockerOptionsBuilder::default().build().unwrap();
2322
// Reference: https://github.com/risc0/risc0/blob/main/risc0/build/src/config.rs#L73-L90
24-
let guest_options = GuestOptionsBuilder::default()
25-
.use_docker(docker_options)
26-
.build()
27-
.unwrap();
23+
let guest_options = GuestOptionsBuilder::default().build().unwrap();
2824

2925
risc0_build::embed_methods_with_options(HashMap::from([(
3026
"risc0_aggregation_program",

aggregation_mode/proof_aggregator/src/backend/db.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use db::types::Task;
12
use sqlx::{
23
postgres::PgPoolOptions,
34
types::{BigDecimal, Uuid},
@@ -12,6 +13,7 @@ pub struct Db {
1213
#[derive(Debug, Clone)]
1314
pub enum DbError {
1415
ConnectError(String),
16+
Query(String),
1517
}
1618

1719
impl Db {
@@ -25,13 +27,22 @@ impl Db {
2527
Ok(Self { pool })
2628
}
2729

28-
pub async fn get_tasks_and_mark_them_as_processed() {}
30+
pub async fn get_pending_tasks_and_mark_them_as_processed(
31+
&self,
32+
limit: i64,
33+
) -> Result<Vec<Task>, DbError> {
34+
sqlx::query_as::<_, Task>("SELECT * FROM tasks WHERE status = 'pending' LIMIT $1")
35+
.bind(limit)
36+
.fetch_all(&self.pool)
37+
.await
38+
.map_err(|e| DbError::Query(e.to_string()))
39+
}
2940

30-
pub async fn mark_tasks_as_pending() {}
41+
pub async fn mark_tasks_as_pending(&self) {}
3142

32-
pub async fn mark_tasks_as_processing() {}
43+
pub async fn mark_tasks_as_processing(&self) {}
3344

34-
pub async fn mark_tasks_as_verified() {}
45+
pub async fn mark_tasks_as_verified(&self) {}
3546

36-
pub async fn mark_tasks_as_submitted() {}
47+
pub async fn mark_tasks_as_submitted(&self) {}
3748
}

aggregation_mode/proof_aggregator/src/backend/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct ProofAggregator {
5353
}
5454

5555
impl ProofAggregator {
56-
pub fn new(config: Config) -> Self {
56+
pub async fn new(config: Config) -> Self {
5757
let rpc_url = config.eth_rpc_url.parse().expect("RPC URL should be valid");
5858
let signer = LocalSigner::decrypt_keystore(
5959
config.ecdsa.private_key_store_path.clone(),
@@ -84,7 +84,9 @@ impl ProofAggregator {
8484
.try_into()
8585
.expect("Risc0 chunk aggregator image id must be 32 bytes");
8686

87-
let db = Db::try_new(self.config.db_connection_url).expect("To connect to db");
87+
let db = Db::try_new(&config.db_connection_url)
88+
.await
89+
.expect("To connect to db");
8890

8991
Self {
9092
engine,

aggregation_mode/proof_aggregator/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ async fn main() {
2828
let config = Config::from_file(&config_file_path).expect("Config is valid");
2929
tracing::info!("Config loaded");
3030

31-
let mut proof_aggregator = ProofAggregator::new(config);
31+
let mut proof_aggregator = ProofAggregator::new(config).await;
3232
proof_aggregator.start().await;
3333
}

0 commit comments

Comments
 (0)