cycles-quartz/apps/mtcs/enclave/src/main.rs

76 lines
1.8 KiB
Rust
Raw Normal View History

2024-02-20 11:27:10 +00:00
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(
clippy::checked_conversions,
clippy::panic,
clippy::panic_in_result_fn,
missing_docs,
trivial_casts,
trivial_numeric_casts,
rust_2018_idioms,
unused_lifetimes,
unused_import_braces,
unused_qualifications
)]
2024-02-22 20:48:13 +00:00
mod cli;
2024-02-29 11:59:39 +00:00
mod mtcs_server;
2024-02-29 11:30:25 +00:00
mod proto;
2024-02-20 11:27:10 +00:00
use std::{
sync::{Arc, Mutex},
time::Duration,
};
2024-02-22 20:48:13 +00:00
use clap::Parser;
use cli::Cli;
use mtcs_server::MtcsService;
use proto::clearing_server::ClearingServer as MtcsServer;
2024-02-23 20:51:20 +00:00
use quartz_cw::state::{Config, LightClientOpts};
use quartz_enclave::{
2024-02-27 22:30:36 +00:00
attestor::{Attestor, EpidAttestor},
server::CoreService,
};
use quartz_proto::quartz::core_server::CoreServer;
use tonic::transport::Server;
2024-02-20 11:27:10 +00:00
#[tokio::main(flavor = "current_thread")]
2024-02-20 11:27:10 +00:00
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2024-02-22 20:48:13 +00:00
let args = Cli::parse();
let light_client_opts = LightClientOpts::new(
args.chain_id,
2024-02-27 23:29:06 +00:00
args.trusted_height.into(),
Vec::from(args.trusted_hash)
.try_into()
.expect("invalid trusted hash"),
(
args.trust_threshold.numerator(),
args.trust_threshold.denominator(),
),
2024-02-22 20:48:13 +00:00
args.trusting_period,
args.max_clock_drift,
args.max_block_lag,
2024-02-27 23:29:06 +00:00
)?;
2024-02-23 20:51:20 +00:00
let config = Config::new(
2024-02-27 22:30:36 +00:00
EpidAttestor.mr_enclave()?,
2024-02-23 20:51:20 +00:00
Duration::from_secs(30 * 24 * 60),
light_client_opts,
);
2024-02-20 11:27:10 +00:00
let sk = Arc::new(Mutex::new(None));
2024-02-20 11:27:10 +00:00
Server::builder()
.add_service(CoreServer::new(CoreService::new(
config,
sk.clone(),
EpidAttestor,
)))
2024-02-29 11:59:39 +00:00
.add_service(MtcsServer::new(MtcsService::new(sk.clone(), EpidAttestor)))
2024-02-22 20:48:13 +00:00
.serve(args.rpc_addr)
2024-02-20 11:27:10 +00:00
.await?;
Ok(())
}