Skip to content

Commit d623ed0

Browse files
feat(agg-mode): separate payment poller from the HTTP server (#2193)
Co-authored-by: JuArce <[email protected]>
1 parent 584a098 commit d623ed0

File tree

25 files changed

+244
-130
lines changed

25 files changed

+244
-130
lines changed

.github/workflows/build-and-test-rust.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ jobs:
124124
- name: Run AggregationMode tests
125125
run: |
126126
cd aggregation_mode/proof_aggregator && cargo test
127-
cd ../batcher && cargo test
127+
cd ../gateway && cargo test
128+
cd ../payments_poller && cargo test

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,25 @@ agg_mode_docker_clean: agg_mode_docker_down
317317
agg_mode_run_migrations: agg_mode_docker_up
318318
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin migrate -- postgres://postgres:postgres@localhost:5435/
319319

320-
agg_mode_batcher_start_local: agg_mode_run_migrations
321-
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin agg_mode_batcher -- config-files/config-agg-mode-batcher.yaml
320+
agg_mode_gateway_start_local: agg_mode_run_migrations
321+
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin gateway -- config-files/config-agg-mode-gateway.yaml
322322

323-
agg_mode_batcher_start_ethereum_package: agg_mode_run_migrations
324-
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin agg_mode_batcher -- config-files/config-agg-mode-batcher-ethereum-package.yaml
323+
agg_mode_gateway_start_ethereum_package: agg_mode_run_migrations
324+
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin gateway -- config-files/config-agg-mode-gateway-ethereum-package.yaml
325+
326+
agg_mode_payments_poller_start_local: agg_mode_run_migrations
327+
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin payments_poller -- config-files/config-agg-mode-gateway.yaml
328+
329+
agg_mode_payments_poller_start_ethereum_package: agg_mode_run_migrations
330+
cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin payments_poller -- config-files/config-agg-mode-gateway-ethereum-package.yaml
325331

326332
AGG_MODE_SENDER ?= 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
327-
agg_mode_batcher_send_payment:
333+
agg_mode_gateway_send_payment:
328334
@cast send --value 1ether \
329335
0x922D6956C99E12DFeB3224DEA977D0939758A1Fe \
330336
--private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
331337

332-
agg_mode_batcher_send_sp1_proof:
338+
agg_mode_gateway_send_sp1_proof:
333339
@cargo run --manifest-path aggregation_mode/cli/Cargo.toml -- submit sp1 \
334340
--proof scripts/test_files/sp1/sp1_fibonacci_5_0_0.proof \
335341
--vk scripts/test_files/sp1/sp1_fibonacci_5_0_0_vk.bin \

aggregation_mode/Cargo.lock

Lines changed: 38 additions & 21 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["./batcher", "./proof_aggregator", "./db", "./sdk", "./cli"]
3+
members = ["./gateway", "./proof_aggregator", "./db", "./payments_poller", "./sdk", "./cli"]
44

55
[workspace.package]
66
version = "0.1.0"

aggregation_mode/batcher/src/server/mod.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "agg_mode_batcher"
2+
name = "gateway"
33
version = "0.1.0"
44
edition = "2021"
55

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use serde::{Deserialize, Serialize};
66
pub struct Config {
77
pub port: u16,
88
pub db_connection_url: String,
9-
pub eth_rpc_url: String,
10-
pub payment_service_address: String,
119
pub network: String,
1210
pub max_daily_proofs_per_user: i64,
1311
}
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,29 +138,6 @@ impl Db {
138138
.await
139139
}
140140

141-
pub async fn insert_payment_event(
142-
&self,
143-
address: &str,
144-
started_at: &BigDecimal,
145-
amount: &BigDecimal,
146-
valid_until: &BigDecimal,
147-
tx_hash: &str,
148-
) -> Result<(), sqlx::Error> {
149-
sqlx::query(
150-
"INSERT INTO payment_events (address, started_at, amount, valid_until, tx_hash)
151-
VALUES ($1, $2, $3, $4, $5)
152-
ON CONFLICT (tx_hash) DO NOTHING",
153-
)
154-
.bind(address.to_lowercase())
155-
.bind(started_at)
156-
.bind(amount)
157-
.bind(valid_until)
158-
.bind(tx_hash)
159-
.execute(&self.pool)
160-
.await
161-
.map(|_| ())
162-
}
163-
164141
pub async fn has_active_payment_event(
165142
&self,
166143
address: &str,
File renamed without changes.

aggregation_mode/batcher/src/server/http.rs renamed to aggregation_mode/gateway/src/http.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ use super::{
2222
use crate::{
2323
config::Config,
2424
db::Db,
25-
server::types::{GetReceiptsResponse, SubmitProofRequestRisc0, SubmitProofRequestSP1},
25+
types::{GetReceiptsResponse, SubmitProofRequestRisc0, SubmitProofRequestSP1},
2626
verifiers::{verify_sp1_proof, VerificationError},
2727
};
2828

2929
#[derive(Clone, Debug)]
30-
pub struct BatcherServer {
30+
pub struct GatewayServer {
3131
db: Db,
3232
config: Config,
3333
network: Network,
3434
}
3535

36-
impl BatcherServer {
36+
impl GatewayServer {
3737
pub fn new(db: Db, config: Config) -> Self {
3838
let network = Network::from_str(&config.network).expect("A valid network in config file");
3939
Self {
@@ -44,7 +44,7 @@ impl BatcherServer {
4444
}
4545

4646
pub async fn start(&self) {
47-
// Note: BatcherServer is thread safe so we can just clone it (no need to add mutexes)
47+
// Note: GatewayServer is thread safe so we can just clone it (no need to add mutexes)
4848
let port = self.config.port;
4949
let state = self.clone();
5050

@@ -79,7 +79,7 @@ impl BatcherServer {
7979

8080
let address = address_raw.to_lowercase();
8181

82-
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
82+
let Some(state) = req.app_data::<Data<GatewayServer>>() else {
8383
return HttpResponse::InternalServerError()
8484
.json(AppResponse::new_unsucessfull("Internal server error", 500));
8585
};
@@ -96,12 +96,12 @@ impl BatcherServer {
9696
}
9797
}
9898

99-
// Posts an SP1 proof to the batcher, recovering the address from the signature
99+
// Posts an SP1 proof to the gateway, recovering the address from the signature
100100
async fn post_proof_sp1(
101101
req: HttpRequest,
102102
MultipartForm(data): MultipartForm<SubmitProofRequestSP1>,
103103
) -> impl Responder {
104-
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
104+
let Some(state) = req.app_data::<Data<GatewayServer>>() else {
105105
return HttpResponse::InternalServerError()
106106
.json(AppResponse::new_unsucessfull("Internal server error", 500));
107107
};
@@ -235,7 +235,7 @@ impl BatcherServer {
235235
}
236236

237237
/// TODO: complete for risc0 (see `post_proof_sp1`)
238-
// Posts a Risc0 proof to the batcher, recovering the address from the signature
238+
// Posts a Risc0 proof to the gateway, recovering the address from the signature
239239
async fn post_proof_risc0(
240240
_req: HttpRequest,
241241
MultipartForm(_): MultipartForm<SubmitProofRequestRisc0>,
@@ -249,7 +249,7 @@ impl BatcherServer {
249249
req: HttpRequest,
250250
params: web::Query<GetReceiptsQueryParams>,
251251
) -> impl Responder {
252-
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
252+
let Some(state) = req.app_data::<Data<GatewayServer>>() else {
253253
return HttpResponse::InternalServerError().json(AppResponse::new_unsucessfull(
254254
"Internal server error: Failed to get app data",
255255
500,

0 commit comments

Comments
 (0)