Skip to content

Commit 24e0a8f

Browse files
committed
feat: receive network via config file
1 parent 8309d0e commit 24e0a8f

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

aggregation_mode/batcher/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct Config {
88
pub db_connection_url: String,
99
pub eth_rpc_url: String,
1010
pub payment_service_address: String,
11+
pub network: String,
1112
}
1213

1314
impl Config {

aggregation_mode/batcher/src/server/http.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use actix_web::{
88
web::{self, Data},
99
App, HttpRequest, HttpResponse, HttpServer, Responder,
1010
};
11+
use agg_mode_sdk::types::Network;
1112
use aligned_sdk::aggregation_layer::AggregationModeProvingSystem;
1213
use alloy::signers::Signature;
1314
use sp1_sdk::{SP1ProofWithPublicValues, SP1VerifyingKey};
@@ -29,11 +30,17 @@ use crate::{
2930
pub struct BatcherServer {
3031
db: Db,
3132
config: Config,
33+
network: Network,
3234
}
3335

3436
impl BatcherServer {
3537
pub fn new(db: Db, config: Config) -> Self {
36-
Self { db, config }
38+
let network = Network::from_str(&config.network).expect("A valid network in config file");
39+
Self {
40+
db,
41+
config,
42+
network,
43+
}
3744
}
3845

3946
pub async fn start(&self) {
@@ -96,6 +103,12 @@ impl BatcherServer {
96103
req: HttpRequest,
97104
MultipartForm(data): MultipartForm<SubmitProofRequestSP1>,
98105
) -> impl Responder {
106+
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
107+
return HttpResponse::InternalServerError()
108+
.json(AppResponse::new_unsucessfull("Internal server error", 500));
109+
};
110+
111+
let state = state.get_ref();
99112
let Ok(signature) = Signature::from_str(&data.signature_hex.0) else {
100113
return HttpResponse::InternalServerError()
101114
.json(AppResponse::new_unsucessfull("Invalid signature", 500));
@@ -117,21 +130,14 @@ impl BatcherServer {
117130
proof_content.clone(),
118131
vk_content.clone(),
119132
);
120-
let Ok(recovered_address) = signature.recover_address_from_prehash(
121-
&msg.eip712_hash(&agg_mode_sdk::types::Network::Devnet)
122-
.into(),
123-
) else {
133+
let Ok(recovered_address) =
134+
signature.recover_address_from_prehash(&msg.eip712_hash(&state.network).into())
135+
else {
124136
return HttpResponse::InternalServerError()
125137
.json(AppResponse::new_unsucessfull("Internal server error", 500));
126138
};
127139
let recovered_address = recovered_address.to_string().to_lowercase();
128140

129-
let Some(state) = req.app_data::<Data<BatcherServer>>() else {
130-
return HttpResponse::InternalServerError()
131-
.json(AppResponse::new_unsucessfull("Internal server error", 500));
132-
};
133-
let state = state.get_ref();
134-
135141
let Ok(count) = state.db.count_tasks_by_address(&recovered_address).await else {
136142
return HttpResponse::InternalServerError()
137143
.json(AppResponse::new_unsucessfull("Internal server error", 500));

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

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

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

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

0 commit comments

Comments
 (0)