From d2ce2ecd3349270a958657cef183d4dc1fed9ad8 Mon Sep 17 00:00:00 2001 From: Dev Kalra Date: Tue, 30 Apr 2024 20:10:48 +0530 Subject: [PATCH] feat(fortuna): add a cli arg to run keeper (#1517) * optional run keeper * update comment * instead of flag use the keeper key file * update version * rename method --- apps/fortuna/Cargo.lock | 2 +- apps/fortuna/Cargo.toml | 2 +- apps/fortuna/src/command/run.rs | 7 ++++--- apps/fortuna/src/config/run.rs | 12 ++++++++---- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/fortuna/Cargo.lock b/apps/fortuna/Cargo.lock index e1491874..20b11c01 100644 --- a/apps/fortuna/Cargo.lock +++ b/apps/fortuna/Cargo.lock @@ -1488,7 +1488,7 @@ dependencies = [ [[package]] name = "fortuna" -version = "5.0.0" +version = "5.1.0" dependencies = [ "anyhow", "axum", diff --git a/apps/fortuna/Cargo.toml b/apps/fortuna/Cargo.toml index 40b20e16..2fc238b4 100644 --- a/apps/fortuna/Cargo.toml +++ b/apps/fortuna/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fortuna" -version = "5.0.0" +version = "5.1.0" edition = "2021" [dependencies] diff --git a/apps/fortuna/src/command/run.rs b/apps/fortuna/src/command/run.rs index d4964c48..234133fa 100644 --- a/apps/fortuna/src/command/run.rs +++ b/apps/fortuna/src/command/run.rs @@ -127,7 +127,6 @@ pub async fn run(opts: &RunOptions) -> Result<()> { .provider_config .as_ref() .map(|path| ProviderConfig::load(&path).expect("Failed to load provider config")); - let private_key = opts.load_private_key()?; let secret = opts.randomness.load_secret()?; let (tx_exit, rx_exit) = watch::channel(false); @@ -141,7 +140,6 @@ pub async fn run(opts: &RunOptions) -> Result<()> { .as_ref() .map(|c| c.get_sorted_commitments()) .unwrap_or_else(|| Vec::new()); - println!("{} {:?}", chain_id, provider_commitments); let provider_info = contract.get_provider_info(opts.provider).call().await?; let latest_metadata = @@ -212,7 +210,10 @@ pub async fn run(opts: &RunOptions) -> Result<()> { Ok::<(), Error>(()) }); - spawn(run_keeper(chains.clone(), config, private_key)); + + if let Some(keeper_private_key) = opts.load_keeper_private_key()? { + spawn(run_keeper(chains.clone(), config, keeper_private_key)); + } run_api(opts.addr.clone(), chains, rx_exit).await?; diff --git a/apps/fortuna/src/config/run.rs b/apps/fortuna/src/config/run.rs index 203e1f7e..c52e3168 100644 --- a/apps/fortuna/src/config/run.rs +++ b/apps/fortuna/src/config/run.rs @@ -36,16 +36,20 @@ pub struct RunOptions { #[arg(env = "FORTUNA_PROVIDER")] pub provider: Address, - /// Path to a file containing a 20-byte (40 char) hex encoded Ethereum private key. + /// If provided, the keeper will run alongside the Fortuna API service. + /// It should be a path to a file containing a 20-byte (40 char) hex encoded Ethereum private key. /// This key is required to submit transactions for entropy callback requests. /// This key should not be a registered provider. #[arg(long = "keeper-private-key")] #[arg(env = "KEEPER_PRIVATE_KEY")] - pub keeper_private_key_file: String, + pub keeper_private_key_file: Option, } impl RunOptions { - pub fn load_private_key(&self) -> Result { - return Ok((fs::read_to_string(&self.keeper_private_key_file))?); + pub fn load_keeper_private_key(&self) -> Result> { + if let Some(ref keeper_private_key_file) = self.keeper_private_key_file { + return Ok(Some(fs::read_to_string(keeper_private_key_file)?)); + } + return Ok(None); } }