Skip to content

Commit

Permalink
Merge pull request #115 from anton-rs/rf/feat/net-bin
Browse files Browse the repository at this point in the history
chore: rework binaries
  • Loading branch information
refcell authored Nov 18, 2024
2 parents aac595a + f072a34 commit 05fc0d5
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 148 deletions.
172 changes: 86 additions & 86 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ rustdoc-args = ["--cfg", "docsrs"]
kona-derive = { git = "https://github.com/anton-rs/kona", branch = "rf/chore/alloy-updates" }
kona-driver = { git = "https://github.com/anton-rs/kona", branch = "rf/chore/alloy-updates" }

# Used for the sepolia holocene release
op-alloy-genesis = { git = "https://github.com/alloy-rs/op-alloy", branch = "rf/feat/holocene-timestamps" }

[workspace.dependencies]
# Workspace
hilo = { version = "0.11.0", path = "crates/hilo", default-features = false }
Expand Down Expand Up @@ -72,10 +69,10 @@ alloy-rpc-types-beacon = { version = "0.6.4", default-features = false }
alloy-rpc-types-engine = { version = "0.6.4", default-features = false }

# OP Alloy
op-alloy-genesis = { version = "0.6.6", default-features = false }
op-alloy-protocol = { version = "0.6.6", default-features = false }
op-alloy-consensus = { version = "0.6.6", default-features = false }
op-alloy-rpc-types-engine = { version = "0.6.6", default-features = false }
op-alloy-genesis = { version = "0.6.7", default-features = false }
op-alloy-protocol = { version = "0.6.7", default-features = false }
op-alloy-consensus = { version = "0.6.7", default-features = false }
op-alloy-rpc-types-engine = { version = "0.6.7", default-features = false }

# Reth
reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "7ae8ce1" }
Expand Down
36 changes: 0 additions & 36 deletions bin/hera/src/node.rs

This file was deleted.

4 changes: 2 additions & 2 deletions bin/hera/Cargo.toml → bin/net/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hera"
name = "net"
version = "0.1.0"
description = "Hera is a Rust implementation of the OP Stack Rollup Node"
description = "Networking component of Hilo"

edition.workspace = true
authors.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions bin/net/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `net`

A hilo-powered binary that runs gossip and discovery services.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/hera/src/gossip.rs → bin/net/src/gossip.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Gossip subcommand for Hera.
//! Gossip subcommand.
use crate::globals::GlobalArgs;
use clap::Args;
Expand Down
12 changes: 4 additions & 8 deletions bin/hera/src/main.rs → bin/net/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use eyre::Result;
mod disc;
mod globals;
mod gossip;
mod node;
mod telemetry;

/// The Hera CLI Arguments.
Expand All @@ -21,15 +20,13 @@ pub(crate) struct HeraArgs {
pub global: globals::GlobalArgs,
/// The subcommand to run.
#[clap(subcommand)]
pub subcommand: HeraSubcommand,
pub subcommand: NetSubcommand,
}

/// Subcommands for the CLI.
#[derive(Debug, Clone, Subcommand)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum HeraSubcommand {
/// Run the standalone Hera node.
Node(node::NodeCommand),
pub(crate) enum NetSubcommand {
/// Discovery service command.
Disc(disc::DiscCommand),
/// Gossip service command.
Expand All @@ -46,8 +43,7 @@ async fn main() -> Result<()> {

// Dispatch on subcommand.
match args.subcommand {
HeraSubcommand::Node(node) => node.run(&args.global).await,
HeraSubcommand::Disc(disc) => disc.run(&args.global).await,
HeraSubcommand::Gossip(gossip) => gossip.run(&args.global).await,
NetSubcommand::Disc(disc) => disc.run(&args.global).await,
NetSubcommand::Gossip(gossip) => gossip.run(&args.global).await,
}
}
File renamed without changes.
25 changes: 25 additions & 0 deletions bin/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "node"
version = "0.1.0"
description = "A Rust implementation of the OP Stack Rollup Node"

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

[dependencies]
# Local
# hilo-net.workspace = true
# hilo = { workspace = true, features = ["registry"] }

# Workspace
eyre.workspace = true
tracing.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }
metrics-exporter-prometheus = { workspace = true, features = ["http-listener"] }
15 changes: 7 additions & 8 deletions bin/hera/README.md → bin/node/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
## `hera`
## `node`

_Hera is a Rust implementation of the [OP Stack][opstack] Rollup node._
A rollup or consensus node powered by [hilo] and [kona].

### Overview

Hera can be run as either a standalone node or as an [Execution Extension][exex]
It can be run as either a standalone node or as an [Execution Extension][exex]
on top of an L1 [Reth][reth] node in the same process.

Under the hood, Hera is powered by the [Kona-derive][kona] library which handles
Under the hood, the node is powered by the [Kona-derive][kona] library which handles
the [derivation pipeline][derivation] of the L2 payloads from L1 transactions.

### Usage

```
cargo run --bin hera
cargo run --bin node
```


<!-- Links -->

[hilo]: https://github.com/anton-rs/hilo
[kona]: https://github.com/anton-rs/kona
[reth]: https://github.com/paradigmxyz/reth
[kona]: https://github.com/ethereum-optimism/kona
[exex]: https://www.paradigm.xyz/2024/05/reth-exex
[opstack]: https://docs.optimism.io/
[derivation]: https://docs.optimism.io/stack/protocol/derivation-pipeline
52 changes: 52 additions & 0 deletions bin/node/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#![doc = include_str!("../README.md")]
#![doc(issue_tracker_base_url = "https://github.com/anton-rs/hilo/issues/")]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use clap::Parser;
use eyre::Result;

mod telemetry;

/// CLI Arguments.
#[derive(Parser, Clone, Debug)]
#[command(author, version, about, long_about = None)]
pub(crate) struct NodeArgs {
/// The L2 chain ID to use.
#[clap(long, short = 'c', default_value = "10", help = "The L2 chain ID to use")]
pub l2_chain_id: u64,
/// A port to serve prometheus metrics on.
#[clap(
long,
short = 'm',
default_value = "9090",
help = "The port to serve prometheus metrics on"
)]
pub metrics_port: u16,
// The hilo Rollup node configuration.
// #[clap(flatten)]
// pub hilo_config: HiloArgsExt,
}

#[tokio::main]
async fn main() -> Result<()> {
// Parse arguments.
let args = NodeArgs::parse();

// Initialize the telemetry stack.
telemetry::init_stack(args.metrics_port)?;

// info!(
// "Running the Hilo Node in Standalone mode. Attributes validation: {}",
// self.hera_config.validation_mode
// );
//
// let cfg = self.hera_config.get_l2_config()?;
// let driver = Driver::standalone(self.hera_config, cfg).await?;
//
// if let Err(e) = driver.start().await {
// bail!("[CRIT] Rollup driver failed: {:?}", e)
// }

Ok(())
}
50 changes: 50 additions & 0 deletions bin/node/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::{io::IsTerminal, net::SocketAddr};

use eyre::{bail, Result};
use metrics_exporter_prometheus::PrometheusBuilder;
use tracing::{info, Level};
use tracing_subscriber::{
fmt::Layer as FmtLayer, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer,
};

/// Initialize the tracing stack and Prometheus metrics recorder.
///
/// This function should be called at the beginning of the program.
pub fn init_stack(metrics_port: u16) -> Result<()> {
let filter = EnvFilter::builder().with_default_directive("hera=info".parse()?).from_env_lossy();

// Whether to use ANSI formatting and colors in the console output.
// If unset, always use colors if stdout is a tty.
// If set to "never", just disable all colors.
let should_use_colors = match std::env::var("RUST_LOG_STYLE") {
Ok(val) => val != "never",
Err(_) => std::io::stdout().is_terminal(),
};

// Whether to show the tracing target in the console output.
// If set, always show the target unless explicitly set to "0".
// If unset, show target only if the filter is more verbose than INFO.
let should_show_target = match std::env::var("RUST_LOG_TARGET") {
Ok(val) => val != "0",
Err(_) => filter.max_level_hint().map_or(true, |max_level| max_level > Level::INFO),
};

let std_layer = FmtLayer::new()
.with_ansi(should_use_colors)
.with_target(should_show_target)
.with_writer(std::io::stdout)
.with_filter(filter);

tracing_subscriber::registry().with(std_layer).try_init()?;

let prometheus_addr = SocketAddr::from(([0, 0, 0, 0], metrics_port));
let builder = PrometheusBuilder::new().with_http_listener(prometheus_addr);

if let Err(e) = builder.install() {
bail!("failed to install Prometheus recorder: {:?}", e);
} else {
info!("Telemetry initialized. Serving Prometheus metrics at: http://{}", prometheus_addr);
}

Ok(())
}

0 comments on commit 05fc0d5

Please sign in to comment.