Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): Add RollupConfig to BootInfo #251

Merged
merged 1 commit into from
Jun 16, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions bin/host/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub struct HostCli {
/// Number of the L2 block that the claim is from.
#[clap(long)]
pub l2_block_number: u64,
/// The L2 chain ID.
#[clap(long)]
pub l2_chain_id: u64,
refcell marked this conversation as resolved.
Show resolved Hide resolved
//// Path to the genesis file.
#[clap(long)]
pub l2_genesis_path: PathBuf,
refcell marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
9 changes: 4 additions & 5 deletions bin/host/src/kv/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use super::KeyValueStore;
use crate::cli::HostCli;
use alloy_primitives::B256;
use kona_client::{
L1_HEAD_KEY, L2_CHAIN_CONFIG_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY,
L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY,
L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY, L2_OUTPUT_ROOT_KEY,
L2_ROLLUP_CONFIG_KEY,
};
use kona_preimage::PreimageKey;

Expand All @@ -29,9 +29,8 @@ impl KeyValueStore for LocalKeyValueStore {
L2_OUTPUT_ROOT_KEY => Some(self.cfg.l2_output_root.to_vec()),
L2_CLAIM_KEY => Some(self.cfg.l2_claim.to_vec()),
L2_CLAIM_BLOCK_NUMBER_KEY => Some(self.cfg.l2_block_number.to_be_bytes().to_vec()),
L2_CHAIN_ID_KEY => todo!(),
L2_CHAIN_CONFIG_KEY => todo!(),
L2_ROLLUP_CONFIG_KEY => todo!(),
L2_CHAIN_ID_KEY => Some(self.cfg.l2_chain_id.to_be_bytes().to_vec()),
L2_ROLLUP_CONFIG_KEY => unimplemented!("L2RollupConfig fetching in local store not implemented. Necessary for chain IDs without a known rollup config."),
refcell marked this conversation as resolved.
Show resolved Hide resolved
_ => None,
}
}
Expand Down
1 change: 1 addition & 0 deletions bin/programs/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async-trait.workspace = true
kona-common = { path = "../../../crates/common", version = "0.0.1" }
kona-common-proc = { path = "../../../crates/common-proc", version = "0.0.1" }
kona-preimage = { path = "../../../crates/preimage", version = "0.0.1" }
kona-primitives = { path = "../../../crates/primitives", version = "0.0.1" }
kona-mpt = { path = "../../../crates/mpt", version = "0.0.1" }
kona-derive = { path = "../../../crates/derive", version = "0.0.1" }

Expand Down
2 changes: 2 additions & 0 deletions bin/programs/client/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ run-client-native l1_rpc l1_beacon_rpc l2_rpc verbosity:
L2_OUTPUT_ROOT=$(cast 2b 0)
L2_CLAIM=$(cast 2b 0)
L2_BLOCK_NUMBER=0
L2_CHAIN_ID=10

L1_NODE_ADDRESS="{{l1_rpc}}"
L1_BEACON_ADDRESS="{{l1_beacon_rpc}}"
Expand All @@ -36,6 +37,7 @@ run-client-native l1_rpc l1_beacon_rpc l2_rpc verbosity:
--l2-claim $L2_CLAIM \
--l2-output-root $L2_OUTPUT_ROOT \
--l2-block-number $L2_BLOCK_NUMBER \
--l2-chain-id $L2_CHAIN_ID \
--l1-node-address $L1_NODE_ADDRESS \
--l1-beacon-address $L1_BEACON_ADDRESS \
--l2-node-address $L2_NODE_ADDRESS \
Expand Down
19 changes: 14 additions & 5 deletions bin/programs/client/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use alloy_primitives::{B256, U256};
use anyhow::{anyhow, Result};
use kona_preimage::{PreimageKey, PreimageOracleClient};
use kona_primitives::{RollupConfig, OP_MAINNET_CONFIG};

/// The local key ident for the L1 head hash.
pub const L1_HEAD_KEY: U256 = U256::from_be_slice(&[1]);
Expand All @@ -20,11 +21,8 @@ pub const L2_CLAIM_BLOCK_NUMBER_KEY: U256 = U256::from_be_slice(&[4]);
/// The local key ident for the L2 chain ID.
pub const L2_CHAIN_ID_KEY: U256 = U256::from_be_slice(&[5]);

/// The local key ident for the L2 chain config.
pub const L2_CHAIN_CONFIG_KEY: U256 = U256::from_be_slice(&[6]);

/// The local key ident for the L2 rollup config.
pub const L2_ROLLUP_CONFIG_KEY: U256 = U256::from_be_slice(&[7]);
pub const L2_ROLLUP_CONFIG_KEY: U256 = U256::from_be_slice(&[6]);

/// The boot information for the client program.
///
Expand All @@ -49,6 +47,8 @@ pub struct BootInfo {
pub l2_claim_block: u64,
/// The L2 chain ID.
pub chain_id: u64,
/// The rollup config for the L2 chain.
pub rollup_config: RollupConfig,
}

impl BootInfo {
Expand Down Expand Up @@ -89,7 +89,16 @@ impl BootInfo {
.try_into()
.map_err(|_| anyhow!("Failed to convert L2 chain ID to u64"))?,
);
let rollup_config = rollup_config_from_chain_id(chain_id)?;

Ok(Self { l1_head, l2_output_root, l2_claim, l2_claim_block, chain_id, rollup_config })
}
}

Ok(Self { l1_head, l2_output_root, l2_claim, l2_claim_block, chain_id })
/// Returns the rollup config for the given chain ID.
fn rollup_config_from_chain_id(chain_id: u64) -> Result<RollupConfig> {
match chain_id {
10 => Ok(OP_MAINNET_CONFIG),
_ => anyhow::bail!("Unsupported chain ID: {}", chain_id),
}
refcell marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions bin/programs/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pub use comms::{CachingOracle, HINT_WRITER, ORACLE_READER};

mod boot;
pub use boot::{
BootInfo, L1_HEAD_KEY, L2_CHAIN_CONFIG_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY,
L2_CLAIM_KEY, L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY,
BootInfo, L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY,
L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY,
};
Loading