Repository navigation
perf(tempo): stamp version metadata in main.rs, not the tempo library - #9406
Zygimantass wants to merge 2 commits into
Conversation
The tempo library expanded tempo_version_metadata!, so every new build time compiled the whole library again before the binary. main.rs now stamps it; the library sets unstamped metadata for programs that embed it, unless the binary already set its own.
👁️ Cyclops Security Review✅ Reviewed 953c689 (latest) · Coverage: partial · no open findings · report |
| // The `tempo` binary stamps its version before it calls this. Expanding the stamp here would | ||
| // compile this library again whenever the build time changes. | ||
| tempo_node::init_unstamped_version_metadata(); |
There was a problem hiding this comment.
🟡 (optional) Programs that embed Tempo through tempo_main_with, including examples/programmatic-node, now report "unknown" commit, build time and profile. Today they report the real stamped values. The library used to expand tempo_version_metadata! with env vars from bin/tempo/build.rs, which also covers the lib target. It now falls back to init_unstamped_version_metadata. Fix: give embedders a way to keep stamped metadata without rebuilding the library on each build. Otherwise, state the regression in the PR description and in the tempo_main_with docs. Also show embedders how to call init_version_metadata themselves.
Why this was flagged
examples/programmatic-node/src/main.rs:51 calls tempo_main_with(overrides) without setting version metadata first, and that crate has no build.rs. On the base branch, bin/tempo/src/lib.rs expanded tempo_node::tempo_version_metadata!(), and the tempo package's build.rs set its env vars for the lib target too. Embedders therefore got the real SHA, build timestamp, features, profile and RETH_P2P_CLIENT_VERSION (tempo/v{ver}-{sha}/{triple}). After this change, crates/node/src/version.rs:17-33 sets every vergen field to "unknown" and long_version to only Version: {version}. It also sets p2p_client_version to tempo/v{version}/{os}, so --version output and the devp2p client id peers see lose the commit and target. No embedder can expand tempo_version_metadata! itself, because the VERGEN_*/RETH_* env vars exist only in Tempo's own build script. The PR description does not mention this behavior change, which the style skill requires.
Verification: Trigger: any program that calls tempo_main_with/tempo_main without calling init_version_metadata first. After the change, lib.rs:211 calls tempo_node::init_unstamped_version_metadata(). Effect: embedders' --version output and the client version their peers see both lose the commit and build details they had on the base.
| /// For binaries without Tempo's build script, such as programs that embed the node. | ||
| pub fn init_unstamped_version_metadata() { | ||
| let version = env!("CARGO_PKG_VERSION"); | ||
| let _ = try_init_version_metadata(RethCliVersionConsts { |
There was a problem hiding this comment.
🟡 nit (optional): the result of try_init_version_metadata is discarded with let _ =. The style skill forbids that and says to ignore only the expected variant. Fix: match the Err case explicitly, with a comment that it means a binary already stamped metadata. Also build p2p_client_version from extra_data() instead of repeating its format! at line 30.
Why this was flagged
crates/node/src/version.rs:19 uses let _ = try_init_version_metadata(...). The tempo-rust-style skill says "Never discard a fallible result with .ok() or let _ =. Ignore only the specific variant you expect." Line 30 repeats format!("tempo/v{version}/{}", env::consts::OS), which is the body of extra_data() at line 74. That breaks the rule "When the same logic appears twice... extract one helper." Neither changes runtime behavior. Both are convention slips this diff introduces.
Verification: nit. Nothing changes at runtime. crates/node/src/version.rs:19 reads let _ = try_init_version_metadata(RethCliVersionConsts { ... });. .agents/skills/tempo-rust-style/SKILL.md:63 says "Never discard a fallible result with .ok() or let _ =." Line 30 builds the same string as the body of extra_data() at line 74. Line 30 could reuse extra_data().
| /// its own with [`init_version_metadata`]. | ||
| /// | ||
| /// For binaries without Tempo's build script, such as programs that embed the node. | ||
| pub fn init_unstamped_version_metadata() { |
There was a problem hiding this comment.
🟡 nit (optional): no test covers the new guard that keeps a binary's stamped metadata when init_unstamped_version_metadata runs later. If that ever regresses, tempo --version loses its commit and build time without any test failing. The style skill requires a test for every new guard. Fix: add a test that calls init_version_metadata with a marker value and then init_unstamped_version_metadata(). It should assert that reth_node_core::version::version_metadata() still returns the marker.
Why this was flagged
crates/node/src/version.rs:17-33 adds a public function. It sets metadata only when none is set yet; that is the behaviour the PR depends on for bin/tempo/src/main.rs:19, which stamps first, and bin/tempo/src/lib.rs:211, which runs this function afterwards. The diff adds no test for that ordering or for the unstamped fallback values. .agents/skills/tempo-rust-style/SKILL.md:79 says "Every new branch, guard, error path, and access check gets a test in the same PR." Suppose a later change makes the function call init_version_metadata (which panics on a second set) or overwrite existing metadata. The release binary would then panic at startup or report "unknown" commit and build time, and no test would catch it.
Verification: The behavior is new: crates/node/src/version.rs:19 calls let _ = try_init_version_metadata(...), which sets the metadata only if none is set yet. crates/node/src/version.rs has no mod tests at all. If the ordering or the try-init semantics regress, tempo --version loses its commit and build time and no test catches it.
Picks up paradigmxyz/reth#28567, which stamps reth's version metadata in the binary instead of reth-node-core.
Follow-up to #9378. The
tempolibrary still expandedtempo_version_metadata!, so every new build time compiled the whole library again before the binary.main.rsnow stamps it, and the library sets unstamped metadata for programs that embed it unless the binary already set its own.Two fresh checkouts of this branch built with a shared compile cache: the second restored the
tempolibrary and compiled only the binary (2.1 s, against 8.1 s + 2.1 s on main).tempo --versionstill shows the commit and build time.