diff --git a/Cargo.lock b/Cargo.lock index 0bb4bef..a537e37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2236,20 +2236,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hera" -version = "0.1.0" -dependencies = [ - "clap", - "eyre", - "hilo", - "hilo-net", - "metrics-exporter-prometheus", - "tokio", - "tracing", - "tracing-subscriber", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -2804,9 +2790,9 @@ dependencies = [ [[package]] name = "if-watch" -version = "3.2.0" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6b0422c86d7ce0e97169cc42e04ae643caf278874a7a3c87b8150a220dc7e1e" +checksum = "cdf9d64cfcf380606e64f9a0bcf493616b65331199f984151a6fa11a7b3cde38" dependencies = [ "async-io", "core-foundation", @@ -2815,10 +2801,14 @@ dependencies = [ "if-addrs", "ipnet", "log", + "netlink-packet-core", + "netlink-packet-route", + "netlink-proto", + "netlink-sys", "rtnetlink", - "system-configuration 0.5.1", + "system-configuration", "tokio", - "windows 0.51.1", + "windows 0.53.0", ] [[package]] @@ -3029,7 +3019,7 @@ dependencies = [ [[package]] name = "kona-derive" version = "0.0.6" -source = "git+https://github.com/anton-rs/kona?branch=rf/chore/alloy-updates#02dad9376a13006204a066f7a31648a9cee97746" +source = "git+https://github.com/anton-rs/kona?branch=rf/chore/alloy-updates#09d2df019f5f966961366efca78b0c263b354936" dependencies = [ "alloc-no-stdlib", "alloy-consensus", @@ -3051,7 +3041,7 @@ dependencies = [ [[package]] name = "kona-driver" version = "0.0.0" -source = "git+https://github.com/anton-rs/kona?branch=rf/chore/alloy-updates#02dad9376a13006204a066f7a31648a9cee97746" +source = "git+https://github.com/anton-rs/kona?branch=rf/chore/alloy-updates#09d2df019f5f966961366efca78b0c263b354936" dependencies = [ "alloy-consensus", "alloy-primitives", @@ -3474,7 +3464,7 @@ dependencies = [ "thiserror 1.0.69", "tracing", "yamux 0.12.1", - "yamux 0.13.3", + "yamux 0.13.4", ] [[package]] @@ -3823,23 +3813,36 @@ dependencies = [ "tempfile", ] +[[package]] +name = "net" +version = "0.1.0" +dependencies = [ + "clap", + "eyre", + "hilo", + "hilo-net", + "metrics-exporter-prometheus", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "netlink-packet-core" -version = "0.4.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "345b8ab5bd4e71a2986663e88c56856699d060e78e152e6e9d7966fcd5491297" +checksum = "72724faf704479d67b388da142b186f916188505e7e0b26719019c525882eda4" dependencies = [ "anyhow", "byteorder", - "libc", "netlink-packet-utils", ] [[package]] name = "netlink-packet-route" -version = "0.12.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9ea4302b9759a7a88242299225ea3688e63c85ea136371bb6cf94fd674efaab" +checksum = "053998cea5a306971f88580d0829e90f270f940befd7cf928da179d4187a5a66" dependencies = [ "anyhow", "bitflags 1.3.2", @@ -3863,9 +3866,9 @@ dependencies = [ [[package]] name = "netlink-proto" -version = "0.10.0" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65b4b14489ab424703c092062176d52ba55485a89c076b4f9db05092b7223aa6" +checksum = "86b33524dc0968bfad349684447bfce6db937a9ac3332a1fe60c0c5a5ce63f21" dependencies = [ "bytes", "futures", @@ -3891,15 +3894,27 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" dependencies = [ "bitflags 1.3.2", "cfg-if", "libc", ] +[[package]] +name = "node" +version = "0.1.0" +dependencies = [ + "clap", + "eyre", + "metrics-exporter-prometheus", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -4106,9 +4121,9 @@ dependencies = [ [[package]] name = "op-alloy-consensus" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "862db7293434837c1ca32ef509806a7b330bd24605da95438cd6e928a58b4b2c" +checksum = "72da577a88d35b893fae6467112651f26ef023434c196b2a0b3dc75bc853e0e4" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4117,13 +4132,14 @@ dependencies = [ "alloy-serde", "derive_more", "serde", - "spin 0.9.8", + "thiserror 2.0.3", ] [[package]] name = "op-alloy-genesis" -version = "0.6.6" -source = "git+https://github.com/alloy-rs/op-alloy?branch=rf/feat/holocene-timestamps#47a8eea7c268e7c76cfa8a343ce402e822739d7e" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818180672dd14ca6642fb57942e1cbd602669f42b6e0222b7ea9bbcae065d67e" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4136,28 +4152,30 @@ dependencies = [ [[package]] name = "op-alloy-protocol" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0220768efb59871af53e1685b90983c9f3090cdf45df3d0107348362ba7055ee" +checksum = "1803a1ac96203b8f713b1fa9b7509c46c645ca7bc22b582761a7495e999d4301" dependencies = [ + "alloc-no-stdlib", "alloy-consensus", "alloy-eips", "alloy-primitives", "alloy-rlp", "async-trait", "brotli", - "derive_more", + "miniz_oxide", "op-alloy-consensus", "op-alloy-genesis", + "thiserror 2.0.3", "tracing", "unsigned-varint 0.8.0", ] [[package]] name = "op-alloy-rpc-types" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03db591ad512fdc70170fcb2bff3517b64811443f9fb65d3a1a6344c60acdbf0" +checksum = "a838c125256e02e2f9da88c51e263b02a06cda7e60382fe2551a3385b516f5bb" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4173,9 +4191,9 @@ dependencies = [ [[package]] name = "op-alloy-rpc-types-engine" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd1a11a9cf2f2e8ed9ae11c93dce5990ff81ff98f17995772f567b586a864812" +checksum = "c227fcc7d81d4023363ba12406e57ebcc1c7cbb1075c38ea471ae32138d4706d" dependencies = [ "alloy-eips", "alloy-primitives", @@ -4185,6 +4203,7 @@ dependencies = [ "op-alloy-consensus", "op-alloy-protocol", "snap", + "thiserror 2.0.3", ] [[package]] @@ -4265,9 +4284,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.12" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" +checksum = "8be4817d39f3272f69c59fe05d0535ae6456c2dc2fa1ba02910296c7e0a5c590" dependencies = [ "arrayvec", "bitvec", @@ -4275,19 +4294,20 @@ dependencies = [ "bytes", "impl-trait-for-tuples", "parity-scale-codec-derive", + "rustversion", "serde", ] [[package]] name = "parity-scale-codec-derive" -version = "3.6.12" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" +checksum = "8781a75c6205af67215f382092b6e0a4ff3734798523e69073d4bcd294ec767b" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.87", ] [[package]] @@ -4841,7 +4861,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration 0.6.1", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -5738,14 +5758,17 @@ dependencies = [ [[package]] name = "rtnetlink" -version = "0.10.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322c53fd76a18698f1c27381d58091de3a043d356aa5bd0d510608b565f469a0" +checksum = "7a552eb82d19f38c3beed3f786bd23aa434ceb9ac43ab44419ca6d67a7e186c0" dependencies = [ "futures", "log", + "netlink-packet-core", "netlink-packet-route", + "netlink-packet-utils", "netlink-proto", + "netlink-sys", "nix", "thiserror 1.0.69", "tokio", @@ -6264,9 +6287,6 @@ name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] [[package]] name = "spki" @@ -6412,17 +6432,6 @@ dependencies = [ "windows 0.57.0", ] -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys 0.5.0", -] - [[package]] name = "system-configuration" version = "0.6.1" @@ -6431,17 +6440,7 @@ checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ "bitflags 2.6.0", "core-foundation", - "system-configuration-sys 0.6.0", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", + "system-configuration-sys", ] [[package]] @@ -7152,12 +7151,12 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.51.1" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" +checksum = "efc5cf48f83140dcaab716eeaea345f9e93d0018fb81162753a3f76c3397b538" dependencies = [ - "windows-core 0.51.1", - "windows-targets 0.48.5", + "windows-core 0.53.0", + "windows-targets 0.52.6", ] [[package]] @@ -7172,19 +7171,20 @@ dependencies = [ [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] name = "windows-core" -version = "0.52.0" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "9dcc5b895a6377f1ab9fa55acedab1fd5ac0db66ad1e6c7f47e28a22e446a5dd" dependencies = [ + "windows-result 0.1.2", "windows-targets 0.52.6", ] @@ -7510,9 +7510,9 @@ dependencies = [ [[package]] name = "yamux" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31b5e376a8b012bee9c423acdbb835fc34d45001cfa3106236a624e4b738028" +checksum = "17610762a1207ee816c6fadc29220904753648aba0a9ed61c7b8336e80a559c4" dependencies = [ "futures", "log", diff --git a/Cargo.toml b/Cargo.toml index ad85652..d94fe2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } @@ -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" } diff --git a/bin/hera/src/node.rs b/bin/hera/src/node.rs deleted file mode 100644 index c3de9ab..0000000 --- a/bin/hera/src/node.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! Node subcommand for Hera. - -use clap::Args; -use eyre::Result; -// use rollup::{Driver, HeraArgsExt}; -// use tracing::info; - -use crate::globals::GlobalArgs; - -/// The Hera node subcommand. -#[derive(Debug, Clone, Args)] -#[non_exhaustive] -pub struct NodeCommand { - // The Hera Rollup node configuration. - // #[clap(flatten)] - // pub hera_config: HeraArgsExt, -} - -impl NodeCommand { - /// Run the node subcommand. - pub async fn run(self, _args: &GlobalArgs) -> Result<()> { - // info!( - // "Running the Hera 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(()) - } -} diff --git a/bin/hera/Cargo.toml b/bin/net/Cargo.toml similarity index 88% rename from bin/hera/Cargo.toml rename to bin/net/Cargo.toml index 4a0ee5b..0ab22e7 100644 --- a/bin/hera/Cargo.toml +++ b/bin/net/Cargo.toml @@ -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 diff --git a/bin/net/README.md b/bin/net/README.md new file mode 100644 index 0000000..35268f4 --- /dev/null +++ b/bin/net/README.md @@ -0,0 +1,3 @@ +# `net` + +A hilo-powered binary that runs gossip and discovery services. diff --git a/bin/hera/src/disc.rs b/bin/net/src/disc.rs similarity index 100% rename from bin/hera/src/disc.rs rename to bin/net/src/disc.rs diff --git a/bin/hera/src/globals.rs b/bin/net/src/globals.rs similarity index 100% rename from bin/hera/src/globals.rs rename to bin/net/src/globals.rs diff --git a/bin/hera/src/gossip.rs b/bin/net/src/gossip.rs similarity index 98% rename from bin/hera/src/gossip.rs rename to bin/net/src/gossip.rs index 0644f4a..2734d6d 100644 --- a/bin/hera/src/gossip.rs +++ b/bin/net/src/gossip.rs @@ -1,4 +1,4 @@ -//! Gossip subcommand for Hera. +//! Gossip subcommand. use crate::globals::GlobalArgs; use clap::Args; diff --git a/bin/hera/src/main.rs b/bin/net/src/main.rs similarity index 76% rename from bin/hera/src/main.rs rename to bin/net/src/main.rs index d13a14a..2cf5035 100644 --- a/bin/hera/src/main.rs +++ b/bin/net/src/main.rs @@ -9,7 +9,6 @@ use eyre::Result; mod disc; mod globals; mod gossip; -mod node; mod telemetry; /// The Hera CLI Arguments. @@ -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. @@ -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, } } diff --git a/bin/hera/src/telemetry.rs b/bin/net/src/telemetry.rs similarity index 100% rename from bin/hera/src/telemetry.rs rename to bin/net/src/telemetry.rs diff --git a/bin/node/Cargo.toml b/bin/node/Cargo.toml new file mode 100644 index 0000000..5d20e0a --- /dev/null +++ b/bin/node/Cargo.toml @@ -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"] } diff --git a/bin/hera/README.md b/bin/node/README.md similarity index 53% rename from bin/hera/README.md rename to bin/node/README.md index dd582fc..9208d00 100644 --- a/bin/hera/README.md +++ b/bin/node/README.md @@ -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 ``` +[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 diff --git a/bin/node/src/main.rs b/bin/node/src/main.rs new file mode 100644 index 0000000..b559c3d --- /dev/null +++ b/bin/node/src/main.rs @@ -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(()) +} diff --git a/bin/node/src/telemetry.rs b/bin/node/src/telemetry.rs new file mode 100644 index 0000000..19b6bf2 --- /dev/null +++ b/bin/node/src/telemetry.rs @@ -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(()) +}