Skip to content

Commit d9847df

Browse files
committed
refactor: rename proofs for tasks
1 parent ad969e4 commit d9847df

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

aggregation_mode/batcher/src/db.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,27 @@ impl Db {
2525
Ok(Self { pool })
2626
}
2727

28-
pub async fn count_proofs_by_address(&self, address: &str) -> Result<i64, sqlx::Error> {
29-
let (count,) =
30-
sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM proofs WHERE address = $1")
31-
.bind(address.to_lowercase())
32-
.fetch_one(&self.pool)
33-
.await?;
28+
pub async fn count_tasks_by_address(&self, address: &str) -> Result<i64, sqlx::Error> {
29+
let (count,) = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM tasks WHERE address = $1")
30+
.bind(address.to_lowercase())
31+
.fetch_one(&self.pool)
32+
.await?;
3433

3534
Ok(count)
3635
}
3736

38-
pub async fn get_merkle_path_by_proof_id(
37+
pub async fn get_merkle_path_by_task_id(
3938
&self,
40-
proof_id: Uuid,
39+
task_id: Uuid,
4140
) -> Result<Option<Vec<u8>>, sqlx::Error> {
42-
sqlx::query_scalar::<_, Option<Vec<u8>>>(
43-
"SELECT merkle_path FROM proofs WHERE proof_id = $1",
44-
)
45-
.bind(proof_id)
46-
.fetch_optional(&self.pool)
47-
.await
48-
.map(|res| res.flatten())
41+
sqlx::query_scalar::<_, Option<Vec<u8>>>("SELECT merkle_path FROM tasks WHERE task_id = $1")
42+
.bind(task_id)
43+
.fetch_optional(&self.pool)
44+
.await
45+
.map(|res| res.flatten())
4946
}
5047

51-
pub async fn insert_proof(
48+
pub async fn insert_task(
5249
&self,
5350
address: &str,
5451
proving_system_id: i32,
@@ -57,14 +54,14 @@ impl Db {
5754
merkle_path: Option<&[u8]>,
5855
) -> Result<Uuid, sqlx::Error> {
5956
sqlx::query_scalar::<_, Uuid>(
60-
"INSERT INTO proofs (
57+
"INSERT INTO tasks (
6158
address,
6259
proving_system_id,
6360
proof,
6461
program_commitment,
6562
merkle_path
6663
) VALUES ($1, $2, $3, $4, $5)
67-
RETURNING proof_id",
64+
RETURNING task_id",
6865
)
6966
.bind(address.to_lowercase())
7067
.bind(proving_system_id)

aggregation_mode/batcher/src/server/http.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl BatcherServer {
6969
};
7070

7171
let state = state.get_ref();
72-
match state.db.count_proofs_by_address(address).await {
72+
match state.db.count_tasks_by_address(address).await {
7373
Ok(count) => HttpResponse::Ok().json(AppResponse::new_sucessfull(serde_json::json!(
7474
{
7575
"nonce": count
@@ -95,7 +95,7 @@ impl BatcherServer {
9595
};
9696
let state = state.get_ref();
9797

98-
let Ok(count) = state.db.count_proofs_by_address(&recovered_address).await else {
98+
let Ok(count) = state.db.count_tasks_by_address(&recovered_address).await else {
9999
return HttpResponse::InternalServerError()
100100
.json(AppResponse::new_unsucessfull("Internal server error", 500));
101101
};
@@ -142,7 +142,7 @@ impl BatcherServer {
142142

143143
match state
144144
.db
145-
.insert_proof(
145+
.insert_task(
146146
&recovered_address,
147147
AggregationModeProvingSystem::SP1.as_u16() as i32,
148148
&data.message.proof,
@@ -151,8 +151,8 @@ impl BatcherServer {
151151
)
152152
.await
153153
{
154-
Ok(proof_id) => HttpResponse::Ok().json(AppResponse::new_sucessfull(
155-
serde_json::json!({ "proof_id": proof_id.to_string() }),
154+
Ok(task_id) => HttpResponse::Ok().json(AppResponse::new_sucessfull(
155+
serde_json::json!({ "task_id": task_id.to_string() }),
156156
)),
157157
Err(_) => HttpResponse::InternalServerError()
158158
.json(AppResponse::new_unsucessfull("Internal server error", 500)),
@@ -181,7 +181,7 @@ impl BatcherServer {
181181
// TODO: maybe also accept proof commitment in query param
182182
let Some(id) = params.id.clone() else {
183183
return HttpResponse::BadRequest().json(AppResponse::new_unsucessfull(
184-
"Provide proof `id` query param",
184+
"Provide task `id` query param",
185185
400,
186186
));
187187
};
@@ -198,7 +198,7 @@ impl BatcherServer {
198198
.json(AppResponse::new_unsucessfull("Proof id invalid uuid", 400));
199199
};
200200

201-
let db_result = state.db.get_merkle_path_by_proof_id(proof_id).await;
201+
let db_result = state.db.get_merkle_path_by_task_id(proof_id).await;
202202
let merkle_path = match db_result {
203203
Ok(Some(merkle_path)) => merkle_path,
204204
Ok(None) => {

aggregation_mode/db/migrations/001_init.sql

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

3-
CREATE TABLE proofs (
4-
proof_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
3+
CREATE TABLE tasks (
4+
task_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
55
address CHAR(42),
66
proving_system_id INT,
77
proof BYTEA,
88
program_commitment BYTEA,
99
merkle_path BYTEA,
10-
status proof_status DEFAULT 'pending'
10+
status task_status DEFAULT 'pending'
1111
);
1212

1313
CREATE TABLE payment_events (

0 commit comments

Comments
 (0)