Skip to content

Commit ac29327

Browse files
Merge branch 'staging' into feat/recover-address
2 parents 4a3be02 + b6e50e4 commit ac29327

File tree

7 files changed

+37
-3
lines changed

7 files changed

+37
-3
lines changed

aggregation_mode/batcher/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct Config {
99
pub eth_rpc_url: String,
1010
pub payment_service_address: String,
1111
pub network: String,
12+
pub max_daily_proofs_per_user: i64,
1213
}
1314

1415
impl Config {

aggregation_mode/batcher/src/db.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ impl Db {
9696
.await
9797
}
9898

99+
pub async fn get_daily_tasks_by_address(&self, address: &str) -> Result<i64, sqlx::Error> {
100+
sqlx::query_scalar::<_, i64>(
101+
"SELECT COUNT(*)
102+
FROM tasks
103+
WHERE address = $1
104+
AND inserted_at::date = CURRENT_DATE",
105+
)
106+
.bind(address.to_lowercase())
107+
.fetch_one(&self.pool)
108+
.await
109+
}
110+
99111
pub async fn insert_task(
100112
&self,
101113
address: &str,

aggregation_mode/batcher/src/server/http.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ impl BatcherServer {
136136
};
137137
let recovered_address = recovered_address.to_string().to_lowercase();
138138

139+
// Checking if this address has submited more proofs than the ones allowed per day
140+
let Ok(daily_tasks_by_address) = state
141+
.db
142+
.get_daily_tasks_by_address(&recovered_address)
143+
.await
144+
else {
145+
return HttpResponse::InternalServerError()
146+
.json(AppResponse::new_unsucessfull("Internal server error", 500));
147+
};
148+
149+
if daily_tasks_by_address >= state.config.max_daily_proofs_per_user {
150+
return HttpResponse::InternalServerError().json(AppResponse::new_unsucessfull(
151+
"Request denied: Query limit exceeded.",
152+
400,
153+
));
154+
}
155+
139156
let Ok(count) = state.db.count_tasks_by_address(&recovered_address).await else {
140157
return HttpResponse::InternalServerError()
141158
.json(AppResponse::new_unsucessfull("Internal server error", 500));

aggregation_mode/db/migrations/001_init.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ CREATE TABLE tasks (
88
program_commitment BYTEA,
99
merkle_path BYTEA,
1010
status task_status DEFAULT 'pending',
11-
nonce BIGINT NOT NULL
11+
nonce BIGINT NOT NULL,
12+
inserted_at TIMESTAMPTZ NOT NULL DEFAULT now()
1213
);
1314

1415
CREATE TABLE payment_events (
@@ -17,5 +18,6 @@ CREATE TABLE payment_events (
1718
amount BIGINT,
1819
started_at BIGINT,
1920
valid_until BIGINT,
20-
tx_hash CHAR(66) UNIQUE
21+
tx_hash CHAR(66) UNIQUE,
22+
inserted_at TIMESTAMPTZ NOT NULL DEFAULT now()
2123
);

aggregation_mode/proof_aggregator/src/backend/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Db {
6161

6262
for (task_id, merkle_path) in updates {
6363
if let Err(e) = sqlx::query(
64-
"UPDATE tasks SET merkle_path = $1, status = 'verified' WHERE task_id = $2",
64+
"UPDATE tasks SET merkle_path = $1, status = 'verified', proof = NULL WHERE task_id = $2",
6565
)
6666
.bind(merkle_path)
6767
.bind(task_id)

config-files/config-agg-mode-batcher-ethereum-package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ db_connection_url: "postgres://postgres:postgres@localhost:5435/"
33
eth_rpc_url: "http://localhost:8545"
44
payment_service_address: "0x922D6956C99E12DFeB3224DEA977D0939758A1Fe"
55
network: "devnet"
6+
max_daily_proofs_per_user: 32

config-files/config-agg-mode-batcher.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ db_connection_url: "postgres://postgres:postgres@localhost:5435/"
33
eth_rpc_url: "http://localhost:8545"
44
payment_service_address: "0x922D6956C99E12DFeB3224DEA977D0939758A1Fe"
55
network: "devnet"
6+
max_daily_proofs_per_user: 4

0 commit comments

Comments
 (0)