-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
main.rs
57 lines (50 loc) · 2.11 KB
/
main.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
use anyhow::Context as _;
use config::TeeProverConfig;
use tee_prover::TeeProverLayer;
use zksync_config::configs::{ObservabilityConfig, PrometheusConfig};
use zksync_env_config::FromEnv;
use zksync_node_framework::{
implementations::layers::{
prometheus_exporter::PrometheusExporterLayer, sigint::SigintHandlerLayer,
},
service::ZkStackServiceBuilder,
};
use zksync_vlog::prometheus::PrometheusExporterConfig;
mod api_client;
mod config;
mod error;
mod metrics;
mod tee_prover;
/// This application serves as a TEE verifier, a.k.a. a TEE prover.
///
/// - It's an application that retrieves data about batches executed by the sequencer and verifies
/// them in the TEE.
/// - It's a stateless application, e.g. it interacts with the sequencer via API and does not have
/// any kind of persistent state.
/// - It submits proofs for proven batches back to the sequencer.
/// - When the application starts, it registers the attestation on the sequencer, and then runs in a
/// loop, polling the sequencer for new jobs (batches), verifying them, and submitting generated
/// proofs back.
fn main() -> anyhow::Result<()> {
let observability_config =
ObservabilityConfig::from_env().context("ObservabilityConfig::from_env()")?;
let tee_prover_config = TeeProverConfig::from_env()?;
let prometheus_config = PrometheusConfig::from_env()?;
let mut builder = ZkStackServiceBuilder::new()?;
let observability_guard = {
// Observability initialization should be performed within tokio context.
let _context_guard = builder.runtime_handle().enter();
observability_config.install()?
};
builder
.add_layer(SigintHandlerLayer)
.add_layer(TeeProverLayer::new(tee_prover_config));
let exporter_config = if let Some(gateway) = prometheus_config.gateway_endpoint() {
PrometheusExporterConfig::push(gateway, prometheus_config.push_interval())
} else {
PrometheusExporterConfig::pull(prometheus_config.listener_port)
};
builder.add_layer(PrometheusExporterLayer(exporter_config));
builder.build().run(observability_guard)?;
Ok(())
}