Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions bin/host/src/interop/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<Vec<PathBuf>>,
/// 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<Vec<PathBuf>>,
/// 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<PathBuf>,
}

/// An error that can occur when handling interop hosts
Expand All @@ -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),
Expand Down Expand Up @@ -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<Result<HashMap<u64, L1ChainConfig>, 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<L1ChainConfig, InteropHostError> {
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.
Expand Down
22 changes: 10 additions & 12 deletions bin/host/src/interop/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/host/src/interop/local_kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Loading