From 790086192a43eff7d9129ea198e1276c3a67eefc Mon Sep 17 00:00:00 2001 From: refcell Date: Wed, 20 Nov 2024 10:08:59 -0500 Subject: [PATCH] fixes --- Cargo.lock | 5 +++-- bin/node/Cargo.toml | 3 +++ bin/node/src/cli.rs | 47 ++++++++++++++++++++++++++++++++------- crates/node/src/config.rs | 19 ++++++++++------ crates/node/src/sync.rs | 2 +- 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09669b0..fb6c5f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3475,9 +3475,9 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cca1eb2bc1fd29f099f3daaab7effd01e1a54b7c577d0ed082521034d912e8" +checksum = "257b5621d159b32282eac446bed6670c39c7dc68a200a992d8f056afa0066f6d" dependencies = [ "asn1_der", "bs58", @@ -4142,6 +4142,7 @@ dependencies = [ name = "node" version = "0.1.0" dependencies = [ + "alloy-rpc-types-engine", "clap", "eyre", "hilo-engine", diff --git a/bin/node/Cargo.toml b/bin/node/Cargo.toml index 201bf1b..442b698 100644 --- a/bin/node/Cargo.toml +++ b/bin/node/Cargo.toml @@ -19,6 +19,9 @@ hilo-engine.workspace = true # hilo = { workspace = true, features = ["registry"] } # Alloy +alloy-rpc-types-engine = { workspace = true, features = ["jwt"] } + +# op-alloy op-alloy-genesis.workspace = true op-alloy-registry.workspace = true diff --git a/bin/node/src/cli.rs b/bin/node/src/cli.rs index ee7025b..fdb58dd 100644 --- a/bin/node/src/cli.rs +++ b/bin/node/src/cli.rs @@ -1,6 +1,6 @@ //! CLI arguments for the Hilo Node. -use std::{fs::File, path::PathBuf, sync::Arc}; +use std::{fs::File, path::PathBuf}; use clap::Parser; use eyre::{bail, Context, Result}; @@ -8,6 +8,7 @@ use serde_json::from_reader; use tracing::debug; use url::Url; +use alloy_rpc_types_engine::JwtSecret; use op_alloy_genesis::RollupConfig; use op_alloy_registry::ROLLUP_CONFIGS; @@ -39,6 +40,14 @@ pub(crate) struct NodeArgs { )] pub metrics_port: u16, + /// URL of the checkpoint sync server to fetch checkpoints from. + #[clap(long = "checkpoint-sync-url")] + pub checkpoint_sync_url: Option, + + /// An RPC URL to run the node's rpc server. + #[clap(long = "rpc-url")] + pub rpc_url: Option, + /// Chain ID of the L2 network #[clap(long = "l2-chain-id", default_value_t = DEFAULT_L2_CHAIN_ID)] pub l2_chain_id: u64, @@ -101,19 +110,19 @@ pub(crate) struct NodeArgs { #[allow(unused)] impl NodeArgs { /// Get the L2 rollup config, either from a file or the superchain registry. - pub fn get_l2_config(&self) -> Result> { + pub fn get_l2_config(&self) -> Result { match &self.l2_config_file { Some(path) => { debug!("Loading l2 config from file: {:?}", path); let file = File::open(path).wrap_err("Failed to open l2 config file")?; - Ok(Arc::new(from_reader(file).wrap_err("Failed to read l2 config file")?)) + Ok(from_reader(file).wrap_err("Failed to read l2 config file")?) } None => { debug!("Loading l2 config from superchain registry"); let Some(cfg) = ROLLUP_CONFIGS.get(&self.l2_chain_id).cloned() else { bail!("Failed to find l2 config for chain ID {}", self.l2_chain_id); }; - Ok(Arc::new(cfg)) + Ok(cfg) } } } @@ -121,9 +130,9 @@ 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 { + pub fn jwt_secret(&self) -> Option { match std::fs::read_to_string(&self.l2_engine_jwt_secret) { - Ok(content) => Some(content), + Ok(content) => JwtSecret::from_hex(content).ok(), Err(_) => Self::default_jwt_secret(), } } @@ -131,10 +140,10 @@ impl NodeArgs { /// 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 { + pub fn default_jwt_secret() -> Option { let cur_dir = std::env::current_dir().ok()?; match std::fs::read_to_string(cur_dir.join("jwt.hex")) { - Ok(content) => Some(content), + Ok(content) => JwtSecret::from_hex(content).ok(), Err(_) => { tracing::error!("Failed to read JWT secret from file: {:?}", cur_dir); None @@ -142,3 +151,25 @@ impl NodeArgs { } } } + +impl From for hilo_node::Config { + fn from(args: NodeArgs) -> Self { + let rollup_config = args.get_l2_config().unwrap(); + let jwt_secret = args.jwt_secret().unwrap(); + Self { + l2_chain_id: args.l2_chain_id, + l1_rpc_url: args.l1_rpc_url, + l1_beacon_url: args.l1_beacon_client_url, + l2_rpc_url: args.l2_rpc_url, + l2_engine_url: args.l2_engine_api_url, + rollup_config, + jwt_secret, + checkpoint_sync_url: args.checkpoint_sync_url, + sync_mode: args.sync_mode, + rpc_url: args.rpc_url, + devnet: false, + // metrics_port: args.metrics_port, + // l1_blob_archiver_url: args.l1_blob_archiver_url, + } + } +} diff --git a/crates/node/src/config.rs b/crates/node/src/config.rs index e62ae57..60fec41 100644 --- a/crates/node/src/config.rs +++ b/crates/node/src/config.rs @@ -1,5 +1,6 @@ //! Contains the configuration for the hilo-node. +use crate::SyncMode; use alloy_rpc_types_engine::JwtSecret; use op_alloy_genesis::RollupConfig; use serde::{Deserialize, Serialize}; @@ -8,14 +9,16 @@ use url::Url; /// The global node configuration. #[derive(Debug, Clone, Deserialize)] pub struct Config { + /// The L2 Chain ID. + pub l2_chain_id: u64, /// The L1 chain RPC URL - pub l1_rpc_url: String, + pub l1_rpc_url: Url, /// The base chain beacon client RPC URL - pub l1_beacon_url: String, + pub l1_beacon_url: Url, /// The L2 chain RPC URL - pub l2_rpc_url: String, + pub l2_rpc_url: Url, /// The L2 engine API URL - pub l2_engine_url: String, + pub l2_engine_url: Url, /// The rollup config pub rollup_config: RollupConfig, /// Engine API JWT Secret. @@ -23,12 +26,14 @@ pub struct Config { #[serde(deserialize_with = "deserialize_jwt_secret")] pub jwt_secret: JwtSecret, /// A trusted L2 RPC URL to use for fast/checkpoint syncing - pub checkpoint_sync_url: Option, - /// The port of the `Magi` RPC server - pub rpc_url: Url, + pub checkpoint_sync_url: Option, + /// The hilo-node RPC server + pub rpc_url: Option, /// The devnet mode. /// If devnet is enabled. pub devnet: bool, + /// The mode to sync. + pub sync_mode: SyncMode, } impl Serialize for Config { diff --git a/crates/node/src/sync.rs b/crates/node/src/sync.rs index 6346776..22806d8 100644 --- a/crates/node/src/sync.rs +++ b/crates/node/src/sync.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; -/// Sync Mode Specifies how `magi` should sync the L2 chain +/// Sync Mode Specifies how to sync the L2 chain #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] pub enum SyncMode { /// Fast sync mode