-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
lib.rs
128 lines (119 loc) · 4.52 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use std::{net::SocketAddr, sync::Arc};
use anyhow::Context as _;
use axum::{extract::Path, routing::post, Json, Router};
use request_processor::RequestProcessor;
use tee_request_processor::TeeRequestProcessor;
use tokio::sync::watch;
use zksync_config::configs::ProofDataHandlerConfig;
use zksync_dal::{ConnectionPool, Core};
use zksync_object_store::ObjectStore;
use zksync_prover_interface::api::{
ProofGenerationDataRequest, RegisterTeeAttestationRequest, SubmitProofRequest,
SubmitTeeProofRequest, TeeProofGenerationDataRequest,
};
use zksync_types::commitment::L1BatchCommitmentMode;
#[cfg(test)]
mod tests;
mod errors;
mod metrics;
mod request_processor;
mod tee_request_processor;
pub async fn run_server(
config: ProofDataHandlerConfig,
blob_store: Arc<dyn ObjectStore>,
connection_pool: ConnectionPool<Core>,
commitment_mode: L1BatchCommitmentMode,
mut stop_receiver: watch::Receiver<bool>,
) -> anyhow::Result<()> {
let bind_address = SocketAddr::from(([0, 0, 0, 0], config.http_port));
tracing::debug!("Starting proof data handler server on {bind_address}");
let app = create_proof_processing_router(blob_store, connection_pool, config, commitment_mode);
let listener = tokio::net::TcpListener::bind(bind_address)
.await
.with_context(|| format!("Failed binding proof data handler server to {bind_address}"))?;
axum::serve(listener, app)
.with_graceful_shutdown(async move {
if stop_receiver.changed().await.is_err() {
tracing::warn!("Stop signal sender for proof data handler server was dropped without sending a signal");
}
tracing::info!("Stop signal received, proof data handler server is shutting down");
})
.await
.context("Proof data handler server failed")?;
tracing::info!("Proof data handler server shut down");
Ok(())
}
fn create_proof_processing_router(
blob_store: Arc<dyn ObjectStore>,
connection_pool: ConnectionPool<Core>,
config: ProofDataHandlerConfig,
commitment_mode: L1BatchCommitmentMode,
) -> Router {
let get_proof_gen_processor = RequestProcessor::new(
blob_store.clone(),
connection_pool.clone(),
config.clone(),
commitment_mode,
);
let submit_proof_processor = get_proof_gen_processor.clone();
let mut router = Router::new()
.route(
"/proof_generation_data",
post(
// we use post method because the returned data is not idempotent,
// i.e we return different result on each call.
move |payload: Json<ProofGenerationDataRequest>| async move {
get_proof_gen_processor
.get_proof_generation_data(payload)
.await
},
),
)
.route(
"/submit_proof/:l1_batch_number",
post(
move |l1_batch_number: Path<u32>, payload: Json<SubmitProofRequest>| async move {
submit_proof_processor
.submit_proof(l1_batch_number, payload)
.await
},
),
);
if config.tee_support {
let get_tee_proof_gen_processor =
TeeRequestProcessor::new(blob_store, connection_pool, config.clone());
let submit_tee_proof_processor = get_tee_proof_gen_processor.clone();
let register_tee_attestation_processor = get_tee_proof_gen_processor.clone();
router = router.route(
"/tee/proof_inputs",
post(
move |payload: Json<TeeProofGenerationDataRequest>| async move {
get_tee_proof_gen_processor
.get_proof_generation_data(payload)
.await
},
),
)
.route(
"/tee/submit_proofs/:l1_batch_number",
post(
move |l1_batch_number: Path<u32>, payload: Json<SubmitTeeProofRequest>| async move {
submit_tee_proof_processor
.submit_proof(l1_batch_number, payload)
.await
},
),
)
.route(
"/tee/register_attestation",
post(
move |payload: Json<RegisterTeeAttestationRequest>| async move {
register_tee_attestation_processor
.register_tee_attestation(payload)
.await
},
),
);
}
router
}