浏览代码

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
Dev Kalra 1 年之前
父节点
当前提交
d2ce2ecd33
共有 4 个文件被更改,包括 14 次插入9 次删除
  1. 1 1
      apps/fortuna/Cargo.lock
  2. 1 1
      apps/fortuna/Cargo.toml
  3. 4 3
      apps/fortuna/src/command/run.rs
  4. 8 4
      apps/fortuna/src/config/run.rs

+ 1 - 1
apps/fortuna/Cargo.lock

@@ -1488,7 +1488,7 @@ dependencies = [
 
 [[package]]
 name = "fortuna"
-version = "5.0.0"
+version = "5.1.0"
 dependencies = [
  "anyhow",
  "axum",

+ 1 - 1
apps/fortuna/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name    = "fortuna"
-version = "5.0.0"
+version = "5.1.0"
 edition = "2021"
 
 [dependencies]

+ 4 - 3
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?;
 

+ 8 - 4
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<String>,
 }
 
 impl RunOptions {
-    pub fn load_private_key(&self) -> Result<String> {
-        return Ok((fs::read_to_string(&self.keeper_private_key_file))?);
+    pub fn load_keeper_private_key(&self) -> Result<Option<String>> {
+        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);
     }
 }