Use config from quartz-cw crate

This commit is contained in:
hu55a1n1 2024-02-23 12:51:20 -08:00
parent d2e8c612f4
commit 092c221d48
2 changed files with 27 additions and 56 deletions

View file

@ -21,13 +21,11 @@ mod types;
use std::time::Duration;
use clap::Parser;
use quartz_cw::state::{Config, LightClientOpts};
use quartz_proto::quartz::core_server::CoreServer;
use tonic::transport::Server;
use crate::{
cli::Cli,
server::{Config, CoreService, LightClientOpts},
};
use crate::{cli::Cli, server::CoreService};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -43,10 +41,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
args.max_clock_drift,
args.max_block_lag,
);
let config = Config::new(Duration::from_secs(30 * 24 * 60), light_client_opts);
let config = Config::new(
args.mr_enclave,
Duration::from_secs(30 * 24 * 60),
light_client_opts,
);
Server::builder()
.add_service(CoreServer::new(CoreService(config)))
.add_service(CoreServer::new(CoreService::new(config)))
.serve(args.rpc_addr)
.await?;

View file

@ -1,5 +1,9 @@
use std::time::Duration;
use quartz_cw::{
msg::{execute::attested::HasUserData, instantiate::CoreInstantiate},
state::{Config, UserData},
};
use quartz_proto::quartz::{
core_server::Core, InstantiateRequest, InstantiateResponse, SessionCreateRequest,
SessionCreateResponse,
@ -10,7 +14,15 @@ use tendermint_light_client::types::{Height, TrustThreshold};
use tonic::{Request, Response, Status};
#[derive(Clone, Debug)]
pub struct CoreService(pub Config);
pub struct CoreService {
config: Config,
}
impl CoreService {
pub fn new(config: Config) -> Self {
Self { config }
}
}
#[tonic::async_trait]
impl Core for CoreService {
@ -40,54 +52,11 @@ impl Core for CoreService {
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
epoch_duration: Duration,
light_client_opts: LightClientOpts,
}
pub fn attestion_quote(user_data: UserData) -> IoResult<Vec<u8>> {
let mut user_report_data = File::create("/dev/attestation/user_report_data")?;
user_report_data.write_all(user_data.as_slice())?;
user_report_data.flush()?;
impl Config {
pub fn new(epoch_duration: Duration, light_client_opts: LightClientOpts) -> Self {
Self {
epoch_duration,
light_client_opts,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LightClientOpts {
chain_id: String,
target_height: Height,
trusted_height: Height,
trusted_hash: Hash,
trust_threshold: TrustThreshold,
trusting_period: u64,
max_clock_drift: u64,
max_block_lag: u64,
}
impl LightClientOpts {
#[allow(clippy::too_many_arguments)]
pub fn new(
chain_id: String,
target_height: Height,
trusted_height: Height,
trusted_hash: Hash,
trust_threshold: TrustThreshold,
trusting_period: u64,
max_clock_drift: u64,
max_block_lag: u64,
) -> Self {
Self {
chain_id,
target_height,
trusted_height,
trusted_hash,
trust_threshold,
trusting_period,
max_clock_drift,
max_block_lag,
}
}
let quote = read("/dev/attestation/quote")?;
Ok(quote)
}