diff --git a/Cargo.lock b/Cargo.lock index 55384ec..7e52838 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4724,7 +4724,7 @@ checksum = "1fafa6961cabd9c63bcd77a45d7e3b7f3b552b70417831fb0f56db717e72407e" [[package]] name = "morph-chainspec" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-chains", "alloy-consensus", @@ -4747,7 +4747,7 @@ dependencies = [ [[package]] name = "morph-consensus" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-evm", @@ -4765,7 +4765,7 @@ dependencies = [ [[package]] name = "morph-engine-api" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4792,7 +4792,7 @@ dependencies = [ [[package]] name = "morph-evm" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-evm", @@ -4818,7 +4818,7 @@ dependencies = [ [[package]] name = "morph-node" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4868,11 +4868,13 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", + "vergen", + "vergen-git2", ] [[package]] name = "morph-payload-builder" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4900,7 +4902,7 @@ dependencies = [ [[package]] name = "morph-payload-types" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4921,7 +4923,7 @@ dependencies = [ [[package]] name = "morph-primitives" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4941,7 +4943,7 @@ dependencies = [ [[package]] name = "morph-reth" -version = "0.2.0" +version = "0.2.2" dependencies = [ "clap", "eyre", @@ -4959,7 +4961,7 @@ dependencies = [ [[package]] name = "morph-revm" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4982,7 +4984,7 @@ dependencies = [ [[package]] name = "morph-rpc" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5022,7 +5024,7 @@ dependencies = [ [[package]] name = "morph-txpool" -version = "0.2.0" +version = "0.2.2" dependencies = [ "alloy-consensus", "alloy-eips", diff --git a/Cargo.toml b/Cargo.toml index 0eafe89..901cfcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.2.1" +version = "0.2.2" edition = "2024" rust-version = "1.88" license = "MIT OR Apache-2.0" @@ -175,6 +175,8 @@ tokio-stream = "0.1.17" tokio-util = "0.7.16" tracing = "0.1.41" tracing-subscriber = "0.3.22" +vergen = "9.1.0" +vergen-git2 = "9.1.0" criterion = "0.7.0" test-case = "3" pyroscope = "0.5.8" diff --git a/bin/morph-reth/src/main.rs b/bin/morph-reth/src/main.rs index 6be14ee..624da7f 100644 --- a/bin/morph-reth/src/main.rs +++ b/bin/morph-reth/src/main.rs @@ -15,6 +15,10 @@ use std::sync::Arc; use tracing::info; fn main() { + // Override reth's default version info with morph-reth's own version, + // commit SHA, and build timestamp. Must be called before CLI parsing. + morph_node::version::init_version_metadata(); + // Install signal handler for segmentation faults sigsegv_handler::install(); diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index fb81c88..93842b5 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -23,6 +23,7 @@ morph-txpool.workspace = true # Reth dependencies reth-db.workspace = true +reth-node-core.workspace = true reth-chainspec.workspace = true reth-engine-local.workspace = true reth-engine-tree.workspace = true @@ -67,6 +68,10 @@ alloy-rlp = { workspace = true, optional = true } alloy-signer = { workspace = true, optional = true } alloy-signer-local = { workspace = true, optional = true } +[build-dependencies] +vergen.workspace = true +vergen-git2.workspace = true + [dev-dependencies] tokio = { workspace = true, features = ["full"] } reth-db = { workspace = true, features = ["test-utils"] } diff --git a/crates/node/build.rs b/crates/node/build.rs new file mode 100644 index 0000000..d068046 --- /dev/null +++ b/crates/node/build.rs @@ -0,0 +1,70 @@ +#![allow(missing_docs)] + +use std::{env, error::Error}; +use vergen::{BuildBuilder, CargoBuilder, Emitter}; +use vergen_git2::Git2Builder; + +fn main() -> Result<(), Box> { + let mut emitter = Emitter::default(); + + let build_builder = BuildBuilder::default().build_timestamp(true).build()?; + emitter.add_instructions(&build_builder)?; + + let cargo_builder = CargoBuilder::default() + .features(true) + .target_triple(true) + .build()?; + emitter.add_instructions(&cargo_builder)?; + + let git_builder = Git2Builder::default() + .describe(false, true, None) + .dirty(true) + .sha(false) + .build()?; + emitter.add_instructions(&git_builder)?; + + emitter.emit_and_set()?; + + let sha = env::var("VERGEN_GIT_SHA")?; + let sha_short = &sha[0..7]; + + let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true"; + // if not on a tag: v0.2.1-4-gabcdef1 + // if on a tag: v0.2.1 + let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha_short}")); + let version_suffix = if is_dirty || not_on_tag { "-dev" } else { "" }; + + println!("cargo:rustc-env=MORPH_VERSION_SUFFIX={version_suffix}"); + println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={}", &sha[..8]); + + let out_dir = env::var("OUT_DIR").unwrap(); + let profile = out_dir.rsplit(std::path::MAIN_SEPARATOR).nth(3).unwrap(); + println!("cargo:rustc-env=MORPH_BUILD_PROFILE={profile}"); + + let pkg_version = env!("CARGO_PKG_VERSION"); + + // Short: "0.2.1 (c957148)" + println!("cargo:rustc-env=MORPH_SHORT_VERSION={pkg_version}{version_suffix} ({sha_short})"); + + // Long version lines (matches reth's RETH_LONG_VERSION_* naming so we can reuse + // RethCliVersionConsts without patching upstream) + println!("cargo:rustc-env=MORPH_LONG_VERSION_0=Version: {pkg_version}{version_suffix}"); + println!("cargo:rustc-env=MORPH_LONG_VERSION_1=Commit SHA: {sha}"); + println!( + "cargo:rustc-env=MORPH_LONG_VERSION_2=Build Timestamp: {}", + env::var("VERGEN_BUILD_TIMESTAMP")? + ); + println!( + "cargo:rustc-env=MORPH_LONG_VERSION_3=Build Features: {}", + env::var("VERGEN_CARGO_FEATURES")? + ); + println!("cargo:rustc-env=MORPH_LONG_VERSION_4=Build Profile: {profile}"); + + // P2P client version: morph-reth/v0.2.1-c957148/x86_64-unknown-linux-gnu + println!( + "cargo:rustc-env=MORPH_P2P_CLIENT_VERSION=morph-reth/v{pkg_version}-{sha_short}/{}", + env::var("VERGEN_CARGO_TARGET_TRIPLE")? + ); + + Ok(()) +} diff --git a/crates/node/src/lib.rs b/crates/node/src/lib.rs index 1af9dc7..399c8a5 100644 --- a/crates/node/src/lib.rs +++ b/crates/node/src/lib.rs @@ -26,6 +26,7 @@ pub mod node; #[cfg(feature = "test-utils")] pub mod test_utils; pub mod validator; +pub mod version; // Re-export main node types pub use add_ons::MorphAddOns; diff --git a/crates/node/src/version.rs b/crates/node/src/version.rs new file mode 100644 index 0000000..fef55f2 --- /dev/null +++ b/crates/node/src/version.rs @@ -0,0 +1,46 @@ +//! Morph-Reth version metadata. +//! +//! Overrides reth's default version info so `--version` reports morph-reth's +//! own version, commit SHA, and build timestamp instead of the upstream reth +//! fork's values. + +use reth_node_core::version::{RethCliVersionConsts, try_init_version_metadata}; +use std::{borrow::Cow, env}; + +/// Initialise global version metadata for Morph-Reth. +/// +/// Must be called once at startup, before any CLI parsing. +pub fn init_version_metadata() { + try_init_version_metadata(version_metadata()) + .expect("Version metadata initialised more than once"); +} + +/// Build the [`RethCliVersionConsts`] for morph-reth using compile-time env vars +/// emitted by `build.rs`. +pub fn version_metadata() -> RethCliVersionConsts { + RethCliVersionConsts { + name_client: Cow::Borrowed("Morph-Reth"), + cargo_pkg_version: Cow::Borrowed(env!("CARGO_PKG_VERSION")), + vergen_git_sha_long: Cow::Borrowed(env!("VERGEN_GIT_SHA")), + vergen_git_sha: Cow::Borrowed(env!("VERGEN_GIT_SHA_SHORT")), + vergen_build_timestamp: Cow::Borrowed(env!("VERGEN_BUILD_TIMESTAMP")), + vergen_cargo_target_triple: Cow::Borrowed(env!("VERGEN_CARGO_TARGET_TRIPLE")), + vergen_cargo_features: Cow::Borrowed(env!("VERGEN_CARGO_FEATURES")), + short_version: Cow::Borrowed(env!("MORPH_SHORT_VERSION")), + long_version: Cow::Owned(format!( + "{}\n{}\n{}\n{}\n{}", + env!("MORPH_LONG_VERSION_0"), + env!("MORPH_LONG_VERSION_1"), + env!("MORPH_LONG_VERSION_2"), + env!("MORPH_LONG_VERSION_3"), + env!("MORPH_LONG_VERSION_4"), + )), + build_profile_name: Cow::Borrowed(env!("MORPH_BUILD_PROFILE")), + p2p_client_version: Cow::Borrowed(env!("MORPH_P2P_CLIENT_VERSION")), + extra_data: Cow::Owned(format!( + "morph-reth/v{}/{}", + env!("CARGO_PKG_VERSION"), + env::consts::OS + )), + } +} diff --git a/deny.toml b/deny.toml index b6004ef..9000cea 100644 --- a/deny.toml +++ b/deny.toml @@ -11,6 +11,13 @@ ignore = [ # https://rustsec.org/advisories/RUSTSEC-2026-0002 lru 0.12.x unsound IterMut # pinned by reth fork at 0.12.5, fix requires 0.16.3 (semver-incompatible) "RUSTSEC-2026-0002", + # https://rustsec.org/advisories/RUSTSEC-2026-0097 rand unsound with custom logger + # pinned transitively via reth; no fix available upstream yet + "RUSTSEC-2026-0097", + # https://rustsec.org/advisories/RUSTSEC-2026-0098 rustls-webpki URI name constraints + "RUSTSEC-2026-0098", + # https://rustsec.org/advisories/RUSTSEC-2026-0099 rustls-webpki wildcard name constraints + "RUSTSEC-2026-0099", ] # This section is considered when running `cargo deny check bans`.