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(host): Host program scaffold #184

Merged
merged 3 commits into from
May 29, 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
421 changes: 258 additions & 163 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["crates/*", "bin/host", "bin/programs/*"]
exclude = ["fpvm-tests/cannon-rs-tests", "bin/programs/optimism"]
exclude = ["fpvm-tests/cannon-rs-tests"]
resolver = "2"

[workspace.package]
Expand Down
16 changes: 16 additions & 0 deletions bin/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,24 @@ exclude.workspace = true
anyhow.workspace = true
tracing.workspace = true
alloy-primitives = { workspace = true, features = ["serde"] }
revm = { workspace = true, features = ["std", "c-kzg", "secp256k1", "portable", "blst"] }

# local
kona-common = { path = "../../crates/common", version = "0.0.1" }
kona-preimage = { path = "../../crates/preimage", version = "0.0.1" }
kona-mpt = { path = "../../crates/mpt", version = "0.0.1" }

# external
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07" }
reqwest = "0.12"
tokio = { version = "1.37.0", features = ["full"] }
clap = { version = "4.5.4", features = ["derive", "env"] }
serde = { version = "1.0.198", features = ["derive"] }
tracing-subscriber = "0.3.18"
command-fds = "0.3.0"
tempfile = "3.10"
26 changes: 13 additions & 13 deletions bin/host/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod parser;
pub(crate) use parser::parse_b256;

mod types;
pub(crate) use types::{Network, RpcKind};
pub(crate) use types::Network;

mod tracing_util;
pub(crate) use tracing_util::init_tracing_subscriber;
Expand All @@ -31,7 +31,7 @@ pub struct HostCli {
pub data_dir: Option<PathBuf>,
/// Address of L2 JSON-RPC endpoint to use (eth and debug namespace required).
#[clap(long)]
pub l2_node_address: String,
pub l2_node_address: Option<String>,
/// Hash of the L1 head block. Derivation stops after this block is processed.
#[clap(long, value_parser = parse_b256)]
pub l1_head: B256,
Expand All @@ -52,23 +52,23 @@ pub struct HostCli {
pub l2_genesis_path: PathBuf,
/// Address of L1 JSON-RPC endpoint to use (eth namespace required)
#[clap(long)]
pub l1_node_address: String,
pub l1_node_address: Option<String>,
/// Address of the L1 Beacon API endpoint to use.
#[clap(long)]
pub l1_beacon_address: String,
/// Trust the L1 RPC, sync faster at risk of malicious/buggy RPC providing bad or inconsistent
/// L1 data
#[clap(long)]
pub l1_trust_rpc: bool,
/// The kind of RPC provider, used to inform optimal transactions receipts fetching, and thus
/// reduce costs.
#[clap(long)]
pub l1_rpc_provider_kind: RpcKind,
pub l1_beacon_address: Option<String>,
/// Run the specified client program as a separate process detached from the host. Default is
/// to run the client program in the host process.
#[clap(long)]
pub exec: String,
/// Run in pre-image server mode without executing any client program.
/// Run in pre-image server mode without executing any client program. Defaults to `false`.
#[clap(long)]
pub server: bool,
}

impl HostCli {
pub fn is_offline(&self) -> bool {
self.l1_node_address.is_none() ||
self.l2_node_address.is_none() ||
self.l1_beacon_address.is_none()
}
}
9 changes: 2 additions & 7 deletions bin/host/src/cli/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ use serde::Serialize;
pub enum Network {
/// Optimism Mainnet
Optimism,
}

/// Available RPC provider types.
#[derive(Debug, Clone, ValueEnum, Serialize)]
pub enum RpcKind {
/// debug alloy provider
DebugRpc,
/// Optimism Sepolia
OptimismSepolia,
}
72 changes: 72 additions & 0 deletions bin/host/src/fetcher/hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//! This module contains the [HintType] enum.
refcell marked this conversation as resolved.
Show resolved Hide resolved

use std::fmt::Display;

/// The [HintType] enum is used to specify the type of hint that was received.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum HintType {
/// A hint that specifies the block header of a layer 1 block.
L1BlockHeader,
/// A hint that specifies the transactions of a layer 1 block.
L1Transactions,
/// A hint that specifies the state node of a layer 1 block.
L1Receipts,
/// A hint that specifies a blob in the layer 1 beacon chain.
L1Blob,
/// A hint that specifies a precompile call on layer 1.
L1Precompile,
/// A hint that specifies the block header of a layer 2 block.
L2BlockHeader,
/// A hint that specifies the transactions of a layer 2 block.
L2Transactions,
/// A hint that specifies the state node in the L2 state trie.
L2StateNode,
/// A hint that specifies the code of a contract on layer 2.
L2Code,
/// A hint that specifies the output root of a block on layer 2.
L2Output,
}

impl TryFrom<&str> for HintType {
type Error = anyhow::Error;

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"l1-block-header" => Ok(HintType::L1BlockHeader),
"l1-transactions" => Ok(HintType::L1Transactions),
"l1-receipts" => Ok(HintType::L1Receipts),
"l1-blob" => Ok(HintType::L1Blob),
"l1-precompile" => Ok(HintType::L1Precompile),
"l2-block-header" => Ok(HintType::L2BlockHeader),
"l2-transactions" => Ok(HintType::L2Transactions),
"l2-state-node" => Ok(HintType::L2StateNode),
"l2-code" => Ok(HintType::L2Code),
"l2-output" => Ok(HintType::L2Output),
_ => anyhow::bail!("Invalid hint type: {value}"),
}
}
}

impl From<HintType> for &str {
fn from(value: HintType) -> Self {
match value {
HintType::L1BlockHeader => "l1-block-header",
HintType::L1Transactions => "l1-transactions",
HintType::L1Receipts => "l1-receipts",
HintType::L1Blob => "l1-blob",
HintType::L1Precompile => "l1-precompile",
HintType::L2BlockHeader => "l2-block-header",
HintType::L2Transactions => "l2-transactions",
HintType::L2StateNode => "l2-state-node",
HintType::L2Code => "l2-code",
HintType::L2Output => "l2-output",
}
}
}

impl Display for HintType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s: &str = (*self).into();
write!(f, "{}", s)
}
}
Loading
Loading