Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kona-preimage = {git="https://github.com/op-rs/kona", rev= "kona-node/v1.1.6", d
kona-providers-alloy= { git="https://github.com/op-rs/kona", rev= "kona-node/v1.1.6", default-features = false }
kona-genesis = { git="https://github.com/op-rs/kona", rev= "kona-node/v1.1.6", default-features = false }
kona-protocol = { git="https://github.com/op-rs/kona", rev= "kona-node/v1.1.6", default-features = false }
kona-registry = { git="https://github.com/op-rs/kona", rev= "kona-node/v1.1.6", default-features = false }

# Alloy
alloy-rlp = { version = "0.3.12", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ kona-host = { workspace = true, features=["single"] }
kona-proof = { workspace = true, features = ["std"] }
kona-preimage = { workspace = true, features = ["std"] }
kona-genesis = { workspace = true, features = ["std", "serde"] }
kona-registry = { workspace = true }

# Alloy
alloy-primitives = { workspace = true, features = ["map", "serde"] }

# optimism derivation
optimism-derivation = { git = "https://github.com/datachainlab/optimism-elc", rev = "v0.1.6", default-features = false }
optimism-derivation = { git = "https://github.com/datachainlab/optimism-elc", rev = "44d4019cd3fa354eb5a5915a4a2d094f9888404f", default-features = false }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rev will be replaced with the tag that will be created after this PR is merged, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 41b1997

base64 = "0.22.1"

[dev-dependencies]
Expand Down
12 changes: 7 additions & 5 deletions server/src/host/single/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use tokio::sync::RwLock;
#[derive(Debug, Clone)]
pub struct DerivationRequest {
pub config: Config,
pub rollup_config: RollupConfig,
pub rollup_config: Option<RollupConfig>,
pub l2_chain_id: u64,
/// for L2 derivation
pub agreed_l2_head_hash: B256,
Expand Down Expand Up @@ -102,11 +102,13 @@ impl DerivationRequest {
let mut lock = kv_store.write().await;
std::mem::take(&mut lock.used)
};
let local_key = PreimageKey::new_local(L2_ROLLUP_CONFIG_KEY.to());
let roll_up_config_json = serde_json::to_vec(&self.rollup_config)?;
used.insert(local_key, roll_up_config_json);

// In devnet, we need to provide L1 chain config preimage
// In devnet, we need to provide L1 chain config and l2 rollup config
if let Some(rollup_config) = &self.rollup_config {
let local_key = PreimageKey::new_local(L2_ROLLUP_CONFIG_KEY.to());
let roll_up_config_json = serde_json::to_vec(rollup_config)?;
used.insert(local_key, roll_up_config_json);
}
if let Some(l1_chain_config) = &self.l1_chain_config {
let local_key = PreimageKey::new_local(L1_CONFIG_KEY.to());
let l1_chain_config_json = serde_json::to_vec(l1_chain_config)?;
Expand Down
30 changes: 13 additions & 17 deletions server/src/host/single/local_kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@ impl KeyValueStore for LocalKeyValueStore {
L2_CLAIM_KEY => Some(self.cfg.l2_output_root.to_vec()),
L2_CLAIM_BLOCK_NUMBER_KEY => Some(self.cfg.l2_block_number.to_be_bytes().to_vec()),
L2_CHAIN_ID_KEY => Some(self.cfg.l2_chain_id.to_be_bytes().to_vec()),
L2_ROLLUP_CONFIG_KEY => {
let rollup_config = self.cfg.rollup_config.clone();
let serialized = serde_json::to_vec(&rollup_config).ok()?;
Some(serialized)
}
L1_CONFIG_KEY => {
let l1_chain_config = self.cfg.l1_chain_config.clone();
match l1_chain_config {
None => {
tracing::error!("L1 chain config is not provided in derivation request");
None
}
Some(l1_chain_config) => {
let serialized = serde_json::to_vec(&l1_chain_config).ok()?;
Some(serialized)
}
L2_ROLLUP_CONFIG_KEY => match &self.cfg.rollup_config {
None => {
tracing::error!("Rollup config is not provided in derivation request");
None
}
}
Some(rollup_config) => serde_json::to_vec(rollup_config).ok(),
},
L1_CONFIG_KEY => match &self.cfg.l1_chain_config {
None => {
tracing::error!("L1 chain config is not provided in derivation request");
None
}
Some(l1_chain_config) => serde_json::to_vec(l1_chain_config).ok(),
},
_ => None,
}
}
Expand Down
18 changes: 12 additions & 6 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::host::single::config::Config;
use crate::server::{start_http_server_task, DerivationState};
use base64::Engine;
use clap::Parser;
use kona_registry::ROLLUP_CONFIGS;
use l2_client::L2Client;
use tracing::info;
use tracing_subscriber::filter;
Expand Down Expand Up @@ -29,22 +30,27 @@ async fn main() -> anyhow::Result<()> {
config.l2_rollup_address.to_string(),
config.l2_node_address.to_string(),
);
let rollup_config = l2_client.rollup_config().await?;
let chain_id = l2_client.chain_id().await?;

let l1_chain_config = if let Some(l1_chain_config) = &config.l1_chain_config {
let (rollup_config, l1_chain_config) = if ROLLUP_CONFIGS.get(&chain_id).is_none() {
// devnet only
info!(
"fetching rollup config and l1 chain config because chain id {} is devnet",
chain_id
);
let l2_config = l2_client.rollup_config().await?;
let l1_chain_config = config.l1_chain_config.as_ref().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this part uses unwrap while other parts handle errors properly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Fixed by 6d32380

let decoded = base64::engine::general_purpose::STANDARD.decode(l1_chain_config)?;
let l1_chain_config: kona_genesis::L1ChainConfig = serde_json::from_slice(&decoded)?;
Some(l1_chain_config)
(Some(l2_config), Some(l1_chain_config))
} else {
None
(None, None)
};

// Start HTTP server
let http_server_task = start_http_server_task(
config.http_server_addr.as_str(),
DerivationState {
rollup_config: rollup_config.clone(),
rollup_config,
l1_chain_config,
config: config.clone(),
l2_chain_id: chain_id,
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tokio::task::JoinHandle;
use tracing::{error, info};

pub struct DerivationState {
pub rollup_config: RollupConfig,
pub rollup_config: Option<RollupConfig>,
pub l1_chain_config: Option<L1ChainConfig>,
pub config: Config,
pub l2_chain_id: u64,
Expand Down
3 changes: 1 addition & 2 deletions server/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async fn test_make_preimages_success() {
assert_eq!(preimage_bytes.status(), 200);

let preimage_bytes = preimage_bytes.bytes().await.unwrap();
let rollup_config = l2_client.rollup_config().await.unwrap();

tracing::info!("start derivation ");
let preimages = Preimages::decode(preimage_bytes).unwrap();
Expand All @@ -85,7 +84,7 @@ async fn test_make_preimages_success() {
);

let chain_id = l2_client.chain_id().await.unwrap();
let result = derivation.verify(chain_id, &rollup_config, oracle);
let result = derivation.verify(chain_id, oracle);
match result {
Ok(h) => tracing::info!("Derivation verified successfully {:? }", h),
Err(e) => {
Expand Down
Loading