Skip to content

Commit

Permalink
Merge pull request #121 from anton-rs/rf/feat/node-crate
Browse files Browse the repository at this point in the history
chore: node crate
  • Loading branch information
refcell authored Nov 20, 2024
2 parents ed8424d + 518d9c4 commit 54585d2
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 36 deletions.
59 changes: 36 additions & 23 deletions 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 @@ -45,6 +45,7 @@ kona-driver = { git = "https://github.com/anton-rs/kona", branch = "rf/test/op-a
# Workspace
hilo = { version = "0.11.0", path = "crates/hilo", default-features = false }
hilo-net = { version = "0.11.0", path = "crates/net", default-features = false }
hilo-node = { version = "0.11.0", path = "crates/node", default-features = false }
hilo-driver = { version = "0.11.0", path = "crates/driver", default-features = false }
hilo-engine = { version = "0.11.0", path = "crates/engine", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust-version.workspace = true

[dependencies]
# Local
hilo-node.workspace = true
hilo-engine.workspace = true
# hilo-net.workspace = true
# hilo = { workspace = true, features = ["registry"] }
Expand Down
54 changes: 41 additions & 13 deletions bin/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use op_alloy_genesis::RollupConfig;
use op_alloy_registry::ROLLUP_CONFIGS;

use hilo_engine::ValidationMode;
use hilo_node::SyncMode;

/// The default L2 chain ID to use. This corresponds to OP Mainnet.
pub const DEFAULT_L2_CHAIN_ID: u64 = 10;
Expand Down Expand Up @@ -44,28 +45,31 @@ pub(crate) struct NodeArgs {

/// Path to a custom L2 rollup configuration file
/// (overrides the default rollup configuration from the registry)
#[clap(long = "hera.l2-config-file")]
#[clap(long = "l2-config-file")]
pub l2_config_file: Option<PathBuf>,

/// RPC URL of an L2 execution client
#[clap(long = "hera.l2-rpc-url", default_value = DEFAULT_L2_RPC_URL)]
pub l2_rpc_url: Url,

/// RPC URL of an L1 execution client
/// (This is only needed when running in Standalone mode)
#[clap(long = "hera.l1-rpc-url", default_value = DEFAULT_L1_RPC_URL)]
#[clap(long = "l1-rpc-url", default_value = DEFAULT_L1_RPC_URL)]
pub l1_rpc_url: Url,

/// URL of an L1 beacon client to fetch blobs
#[clap(long = "hera.l1-beacon-client-url", default_value = DEFAULT_L1_BEACON_CLIENT_URL)]
#[clap(long = "l1-beacon-client-url", default_value = DEFAULT_L1_BEACON_CLIENT_URL)]
pub l1_beacon_client_url: Url,

/// RPC URL of an L2 execution client
#[clap(long = "l2-rpc-url", default_value = DEFAULT_L2_RPC_URL)]
pub l2_rpc_url: Url,

#[clap(short = 'm', long, default_value = "full")]
pub sync_mode: SyncMode,

/// URL of the blob archiver to fetch blobs that are expired on
/// the beacon client but still needed for processing.
///
/// Blob archivers need to implement the `blob_sidecars` API:
/// <https://ethereum.github.io/beacon-APIs/#/Beacon/getBlobSidecars>
#[clap(long = "hera.l1-blob-archiver-url")]
#[clap(long = "l1-blob-archiver-url")]
pub l1_blob_archiver_url: Option<Url>,

/// The payload validation mode to use.
Expand All @@ -74,29 +78,29 @@ pub(crate) struct NodeArgs {
/// same block and comparing the results.
/// - Engine API: use a local or remote engine API of an L2 execution client. Validation
/// happens by sending the `new_payload` to the API and expecting a VALID response.
#[clap(long = "hera.validation-mode", default_value = "engine-api")]
#[clap(long = "validation-mode", default_value = "engine-api")]
pub validation_mode: ValidationMode,

/// URL of the engine API endpoint of an L2 execution client.
#[clap(long = "hera.l2-engine-api-url", env = "L2_ENGINE_API_URL")]
#[clap(long = "l2-engine-api-url", env = "L2_ENGINE_API_URL")]
pub l2_engine_api_url: Url,

/// JWT secret for the auth-rpc endpoint of the execution client.
/// This MUST be a valid path to a file containing the hex-encoded JWT secret.
#[clap(long = "hera.l2-engine-jwt-secret", env = "L2_ENGINE_JWT_SECRET")]
#[clap(long = "l2-engine-jwt-secret", env = "L2_ENGINE_JWT_SECRET")]
pub l2_engine_jwt_secret: PathBuf,

/// The maximum **number of blocks** to keep cached in the chain provider.
///
/// This is used to limit the memory usage of the chain provider.
/// When the limit is reached, the oldest blocks are discarded.
#[clap(long = "hera.l1-chain-cache-size", default_value_t = 256)]
#[clap(long = "l1-chain-cache-size", default_value_t = 256)]
pub l1_chain_cache_size: usize,
}

#[allow(unused)]
impl NodeArgs {
/// Get the L2 rollup config, either from a file or the superchain registry.
#[allow(unused)]
pub fn get_l2_config(&self) -> Result<Arc<RollupConfig>> {
match &self.l2_config_file {
Some(path) => {
Expand All @@ -113,4 +117,28 @@ impl NodeArgs {
}
}
}

/// Returns the JWT secret for the engine API
/// using the provided [PathBuf]. If the file is not found,
/// it will return the default JWT secret.
pub fn jwt_secret(&self) -> Option<String> {
match std::fs::read_to_string(&self.l2_engine_jwt_secret) {
Ok(content) => Some(content),
Err(_) => Self::default_jwt_secret(),
}
}

/// Uses the current directory to attempt to read
/// the JWT secret from a file named `jwt.hex`.
/// If the file is not found, it will return `None`.
pub fn default_jwt_secret() -> Option<String> {
let cur_dir = std::env::current_dir().ok()?;
match std::fs::read_to_string(cur_dir.join("jwt.hex")) {
Ok(content) => Some(content),
Err(_) => {
tracing::error!("Failed to read JWT secret from file: {:?}", cur_dir);
None
}
}
}
}
25 changes: 25 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "hilo-node"
description = "The Hilo Consensus Node"

version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
keywords.workspace = true
categories.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
# Alloy
alloy-primitives.workspace = true
alloy-rpc-types-engine = { workspace = true, features = ["jwt", "serde"] }

# op-alloy
op-alloy-genesis = { workspace = true, features = ["serde"] }

# Misc
serde.workspace = true
url = { workspace = true, features = ["serde"] }
3 changes: 3 additions & 0 deletions crates/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `hilo-node`

Hilo's consensus node.
Loading

0 comments on commit 54585d2

Please sign in to comment.