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 std::time::Duration;
use clap::Parser; use clap::Parser;
use quartz_cw::state::{Config, LightClientOpts};
use quartz_proto::quartz::core_server::CoreServer; use quartz_proto::quartz::core_server::CoreServer;
use tonic::transport::Server; use tonic::transport::Server;
use crate::{ use crate::{cli::Cli, server::CoreService};
cli::Cli,
server::{Config, CoreService, LightClientOpts},
};
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> { 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_clock_drift,
args.max_block_lag, 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() Server::builder()
.add_service(CoreServer::new(CoreService(config))) .add_service(CoreServer::new(CoreService::new(config)))
.serve(args.rpc_addr) .serve(args.rpc_addr)
.await?; .await?;

View file

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