diff --git a/bin/host/src/interop/cfg.rs b/bin/host/src/interop/cfg.rs index d75a36e5ec..311040c6ea 100644 --- a/bin/host/src/interop/cfg.rs +++ b/bin/host/src/interop/cfg.rs @@ -19,7 +19,7 @@ use kona_providers_alloy::{OnlineBeaconClient, OnlineBlobProvider}; use kona_std_fpvm::{FileChannel, FileDescriptor}; use op_alloy_network::Optimism; use serde::Serialize; -use std::{collections::HashMap, fs, path::PathBuf, str::FromStr, sync::Arc}; +use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::Arc}; use tokio::{ sync::RwLock, task::{self, JoinHandle}, @@ -93,11 +93,11 @@ pub struct InteropHost { /// The rollup configs should be stored as serde-JSON serialized files. #[arg(long, alias = "rollup-cfgs", value_delimiter = ',', env)] pub rollup_config_paths: Option>, - /// Path to l1 configs. If provided, the host will use this config instead of attempting to - /// look up the configs in the superchain registry. - /// The l1 configs should be stored as serde-JSON serialized files. - #[arg(long, alias = "l1-cfgs", value_delimiter = ',', env)] - pub l1_config_paths: Option>, + /// Path to l1 config. If provided, the host will use this config instead of attempting to + /// look up the config in the superchain registry. + /// The l1 config should be stored as serde-JSON serialized files. + #[arg(long, alias = "l1-cfg")] + pub l1_config_path: Option, } /// An error that can occur when handling interop hosts @@ -112,9 +112,9 @@ pub enum InteropHostError { /// A JSON parse error. #[error("Failed deserializing RollupConfig: {0}")] ParseError(#[from] serde_json::Error), - /// Impossible to find the L1 chain config for the given chain ID. - #[error("L1 chain config not found for chain ID: {0}")] - L1ChainConfigNotFound(u64), + /// No l1 config found. + #[error("No l1 config found")] + NoL1Config, /// Task failed to execute to completion. #[error("Join error: {0}")] ExecutionError(#[from] tokio::task::JoinError), @@ -237,19 +237,15 @@ impl InteropHost { /// Reads the [`L1ChainConfig`]s from the file system and returns a map of L1 chain ID -> /// [`L1ChainConfig`]s. - pub fn read_l1_configs(&self) -> Option, InteropHostError>> { - let l1_config_paths = self.l1_config_paths.as_ref()?; - - Some(l1_config_paths.iter().try_fold(HashMap::default(), |mut acc, path| { - // Read the serialized config from the file system. - let ser_config = fs::read_to_string(path)?; + pub fn read_l1_config(&self) -> Result { + let path = self.l1_config_path.as_ref().ok_or_else(|| InteropHostError::NoL1Config)?; - // Deserialize the config and return it. - let cfg: L1ChainConfig = serde_json::from_str(&ser_config)?; + // Read the serialized config from the file system. + let ser_config = std::fs::read_to_string(path)?; - acc.insert(cfg.chain_id, cfg); - Ok(acc) - })) + // Deserialize the config and return it. + serde_json::from_str(&ser_config) + .map_err(|_| InteropHostError::Other("failed to parse L1 config")) } /// Creates the key-value store for the host backend. diff --git a/bin/host/src/interop/handler.rs b/bin/host/src/interop/handler.rs index 82bcb4ebb4..daa9db2ec6 100644 --- a/bin/host/src/interop/handler.rs +++ b/bin/host/src/interop/handler.rs @@ -442,18 +442,16 @@ impl HintHandler for InteropHintHandler { .ok_or(anyhow!("No rollup config found for chain ID: {chain_id}"))?; let l1_config = cfg - .read_l1_configs() - // If an error occurred while reading the l1 configs, return the error. - .transpose()? - // Try to find the appropriate l1 config for the chain ID. - .and_then(|configs| configs.get(&rollup_config.l1_chain_id).cloned()) - // If we can't find the l1 config, try to find it in the global l1 configs. - .or_else(|| L1_CONFIGS.get(&rollup_config.l1_chain_id).cloned()) - .map(Arc::new) - .ok_or(anyhow!( - "No l1 config found for chain ID: {}", - rollup_config.l1_chain_id - ))?; + .read_l1_config() + .or_else(|_| { + L1_CONFIGS.get(&rollup_config.l1_chain_id).cloned().ok_or_else(|| { + anyhow!( + "No L1 config found for chain ID: {}", + rollup_config.l1_chain_id + ) + }) + }) + .map(Arc::new)?; // Check if the block is canonical before continuing. let parent_block = l2_provider diff --git a/bin/host/src/interop/local_kv.rs b/bin/host/src/interop/local_kv.rs index a7e548542a..7c95932f62 100644 --- a/bin/host/src/interop/local_kv.rs +++ b/bin/host/src/interop/local_kv.rs @@ -39,8 +39,8 @@ impl KeyValueStore for InteropLocalInputs { serde_json::to_vec(&rollup_configs).ok() } L1_CONFIG_KEY => { - let l1_configs = self.cfg.read_l1_configs()?.ok()?; - serde_json::to_vec(&l1_configs).ok() + let l1_config = self.cfg.read_l1_config().ok()?; + serde_json::to_vec(&l1_config).ok() } _ => None, }