Skip to content

Commit

Permalink
fix: changes according to Petar's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zk committed Nov 7, 2024
1 parent 92a9e44 commit 0c11f9a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions fhevm-engine/coprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ tonic-build = "0.12"

[[bin]]
name = "coprocessor"
path = "src/main.rs"
path = "src/bin/coprocessor.rs"

[[bin]]
name = "cli"
path = "src/tenant_cli.rs"
path = "src/bin/cli.rs"
File renamed without changes.
13 changes: 13 additions & 0 deletions fhevm-engine/coprocessor/src/bin/coprocessor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
let args = coprocessor::daemon_cli::parse_args();
assert!(
args.work_items_batch_size < args.tenant_key_cache_size,
"Work items batch size must be less than tenant key cache size"
);

if args.generate_fhe_keys {
coprocessor::generate_dump_fhe_keys();
} else {
coprocessor::start_runtime(args, None);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
use std::sync::Once;

use ::tracing::{error, info};
use fhevm_engine_common::keys::{FhevmKeys, SerializedFhevmKeys};
use tokio::task::JoinSet;
use ::tracing::{error, info};

mod daemon_cli;
pub mod daemon_cli;
mod db_queries;
mod metrics;
mod server;
pub mod metrics;
pub mod server;
#[cfg(test)]
mod tests;
mod tfhe_worker;
mod tracing;
pub mod tfhe_worker;
pub mod tracing;
mod types;
mod utils;

fn main() {
let args = crate::daemon_cli::parse_args();
assert!(
args.work_items_batch_size < args.tenant_key_cache_size,
"Work items batch size must be less than tenant key cache size"
);

if args.generate_fhe_keys {
generate_dump_fhe_keys();
} else {
start_runtime(args, None);
}
}

// separate function for testing
pub fn start_runtime(
args: crate::daemon_cli::Args,
args: daemon_cli::Args,
close_recv: Option<tokio::sync::watch::Receiver<bool>>,
) {
tokio::runtime::Builder::new_multi_thread()
Expand Down Expand Up @@ -64,8 +49,8 @@ pub fn start_runtime(
// Used for testing as we would call `async_main()` multiple times.
static TRACING_INIT: Once = Once::new();

async fn async_main(
args: crate::daemon_cli::Args,
pub async fn async_main(
args: daemon_cli::Args,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
TRACING_INIT.call_once(|| {
tracing_subscriber::fmt().json().with_level(true).init();
Expand All @@ -78,17 +63,17 @@ async fn async_main(
let mut set = JoinSet::new();
if args.run_server {
info!(target: "async_main", "Initializing api server");
set.spawn(crate::server::run_server(args.clone()));
set.spawn(server::run_server(args.clone()));
}

if args.run_bg_worker {
info!(target: "async_main", "Initializing background worker");
set.spawn(crate::tfhe_worker::run_tfhe_worker(args.clone()));
set.spawn(tfhe_worker::run_tfhe_worker(args.clone()));
}

if !args.metrics_addr.is_empty() {
info!(target: "async_main", "Initializing metrics server");
set.spawn(crate::metrics::run_metrics_server(args.clone()));
set.spawn(metrics::run_metrics_server(args.clone()));
}

if set.is_empty() {
Expand All @@ -104,8 +89,8 @@ async fn async_main(
Ok(())
}

fn generate_dump_fhe_keys() {
pub fn generate_dump_fhe_keys() {
let keys = FhevmKeys::new();
let ser_keys: SerializedFhevmKeys = keys.into();
ser_keys.save_to_disk();
}
}

0 comments on commit 0c11f9a

Please sign in to comment.