Skip to content

perf(node-core): stamp version metadata in the binaries - #28567

Open
Zygimantass wants to merge 5 commits into
mainfrom
perf/build-timestamp-in-binary
Open

Zygimantass wants to merge 5 commits into
mainfrom
perf/build-timestamp-in-binary

Conversation

@Zygimantass

@Zygimantass Zygimantass commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Moves all version metadata (git SHA and describe, features, profile, target triple and build timestamp) out of reth-node-core's build script into a build script in each binary, reth and reth-bb, through a new reth-node-version-build crate. Binaries set it at startup with try_init_version_metadata(reth_version_metadata!()). --version output is unchanged, except that Build Features now lists the binary's features.

The metadata changes with every commit, and the timestamp with every build. Stamped into reth-node-core, it gave every crate that depends on it new output: incremental and shared build caches (sccache and the like) miss all of them. Now only the binaries change.

Downstream binaries that don't set version metadata get the package version and unknown for the rest; they can call reth_node_version_build::emit_version_metadata from their build script and set it the same way.

Migration

Breaking for downstream binaries built on reth-node-core:

  • default_reth_version_metadata() is renamed to unknown_version_metadata(), and it no longer carries stamped values. Apart from the package version, every field is unknown.
  • reth-node-core doesn't stamp version metadata any more. A binary that never calls try_init_version_metadata, or that builds on the default metadata, now reports unknown for git SHA, build timestamp, target triple, features and profile (--version, the P2P client version, web3_clientVersion).

To keep real values, stamp the metadata in the binary itself:

// build.rs (add reth-node-version-build under [build-dependencies])
fn main() -> Result<(), Box<dyn std::error::Error>> {
    reth_node_version_build::emit_version_metadata()
}

// main.rs, before anything reads the metadata
reth_node_core::version::try_init_version_metadata(reth_node_core::reth_version_metadata!())
    .expect("version metadata is set once");

Binaries that already build their own RethCliVersionConsts from their own build script don't need to change anything.

@Zygimantass Zygimantass added the C-perf A change motivated by improving speed, memory usage or disk footprint label Nov 16, 2026
@tempoxyz-bot

tempoxyz-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

👁️ Cyclops Security Review

✅ Reviewed c655999 (latest) · Coverage: partial · ⚠️ 1 open, 1 not rechecked findings · report
⚠️ Not checked: Dependency context is partial: vendoring available, Librarian unavailable (covered 0 of 3 requested), Sem unavailable
⚠️ Not checked: Caller-specific metadata generation through the extracted build helper: ruled out without reading the cited code at this commit
ℹ️ Not verifiable from the source alone (needs running code or deployed state): Out-of-workspace library consumers of reth-node-core (custom nodes) now report 'unknown' metadata unless they adopt the build helper. This is the same root cause as the prior fallback finding, so the
⏸️ The review of c655999 did not recheck 1 earlier finding, so whether it still applies is unknown

# Severity Finding Introduced Status
1 🟢 Low reth build script leaves Build Timestamp stale after HEAD changes dc2883b ✅ Fixed in fd15aab
2 🟢 Low reth-bb reports build timestamp as unknown after stamping moved to bin/reth dc2883b ✅ Fixed in c655999
3 ⚪ Informational reth-node-core keeps smolgen's unused 'build' feature after dropping Build dc2883b ⏸️ Not rechecked since dc2883b
4 🟢 Low Node-core version fallback drops git SHA, triple and P2P identity downstream 912f01d 🟠 Open

Comment thread bin/reth/build.rs Resolved
Comment thread crates/node/core/src/version.rs Resolved
@tempoxyz-bot

Copy link
Copy Markdown
Member

Informational: reth-node-core keeps smolgen's unused `build` feature after dropping Build

The PR removes the only use of smolgen::Build from reth-node-core's build script but leaves the build feature enabled on its smolgen build-dependency. The script compiles and emits every env var the crate reads without that feature. First reported at dc2883b; recheck at this head: still present.

Valid? React with 👍 / 👎.

Moves the git SHA, describe, features, profile and target triple out of
reth-node-core's build script, with the timestamp, into a build script of
each binary (reth and reth-bb) through the new reth-node-version-build
crate. reth-node-core no longer rebuilds, with everything above it, on
every commit.
@Zygimantass Zygimantass changed the title perf(node-core): stamp the build timestamp in the reth binary perf(node-core): stamp version metadata in the binaries Nov 16, 2026
Comment on lines 106 to 129
pub fn version_metadata() -> &'static RethCliVersionConsts {
VERSION_METADATA.get_or_init(default_reth_version_metadata)
VERSION_METADATA.get_or_init(unknown_version_metadata)
}

/// default reth version metadata using compile-time env! macros.
pub fn default_reth_version_metadata() -> RethCliVersionConsts {
/// Version metadata without anything a build script stamps: the package version and `unknown`
/// for the rest.
pub fn unknown_version_metadata() -> RethCliVersionConsts {
let version = env!("CARGO_PKG_VERSION");
let unknown = || Cow::Borrowed("unknown");
RethCliVersionConsts {
name_client: Cow::Borrowed("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!("RETH_SHORT_VERSION")),
long_version: Cow::Owned(format!(
"{}\n{}\n{}\n{}\n{}",
env!("RETH_LONG_VERSION_0"),
env!("RETH_LONG_VERSION_1"),
env!("RETH_LONG_VERSION_2"),
env!("RETH_LONG_VERSION_3"),
env!("RETH_LONG_VERSION_4"),
)),

build_profile_name: Cow::Borrowed(env!("RETH_BUILD_PROFILE")),
p2p_client_version: Cow::Borrowed(env!("RETH_P2P_CLIENT_VERSION")),
cargo_pkg_version: Cow::Borrowed(version),
vergen_git_sha_long: unknown(),
vergen_git_sha: unknown(),
vergen_build_timestamp: unknown(),
vergen_cargo_target_triple: unknown(),
vergen_cargo_features: unknown(),
short_version: Cow::Borrowed(version),
long_version: Cow::Owned(format!("Version: {version}")),
build_profile_name: unknown(),
p2p_client_version: Cow::Owned(format!("reth/v{version}/{}", std::env::consts::OS)),
extra_data: Cow::Owned(default_extra_data()),
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: Node-core version fallback drops git SHA, triple and P2P identity downstream

Removing reth-node-core's build script made version_metadata() fall back to all-"unknown" metadata. Every node binary that does not add the new build.rs and call try_init_version_metadata now reports commit "unknown" in engine_getClientVersionV1. Database ClientVersion records, metrics build info and the default devp2p identity lose the SHA, triple and profile as well.

Full finding

Removing reth-node-core's build script made version_metadata() fall back to all-"unknown" metadata. Every node binary that does not add the new build.rs and call try_init_version_metadata now reports commit "unknown" in engine_getClientVersionV1. Database ClientVersion records, metrics build info and the default devp2p identity lose the SHA, triple and profile as well.

First reported at 912f01d; recheck at this head: still present.

Valid? React with 👍 / 👎.

@Zygimantass Zygimantass added S-breaking This PR includes a breaking change M-migration-notes A breaking change that should be covered in release notes M-changelog This change should be included in the changelog labels Nov 16, 2026 — with Tempo Pyramid Production

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-perf A change motivated by improving speed, memory usage or disk footprint M-changelog This change should be included in the changelog M-migration-notes A breaking change that should be covered in release notes S-breaking This PR includes a breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants