Skip to content

fix(build-info): 移除对外构建时间字段 - #853

Open
nekomoto911 wants to merge 2 commits into
mainfrom
fix/build-info-source-date-epoch
Open

nekomoto911 wants to merge 2 commits into
mainfrom
fix/build-info-source-date-epoch

Conversation

@nekomoto911

@nekomoto911 nekomoto911 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

问题与改动

本仓库的构建信息把实际编译时间作为 build_time 暴露给版本详情、启动日志、遥测等调用方,并把它作为 gravity_node_build_info 的标签。这个时间会随重新编译变化,给产物引入与源码版本无关的差异。

本次直接移除该字段:

  • 删除本仓库 build-info::BUILD_TIME 常量及 build_time 映射项。
  • 删除运行时 BUILD_DATE 覆盖入口,避免环境变量重新插入字段。
  • 同步删除 gravity_node_build_info 中的 build_time 标签及其对应值。
  • 撤回原先在构建脚本中把 SOURCE_DATE_EPOCH 默认设为 Git 提交时间的方案。版本号、提交哈希等其余构建信息继续保留。

兼容性与范围

这是有意的接口变更:读取 build_time 的脚本和依赖该监控标签的查询需要同步调整;直接引用 build-info::BUILD_TIME 的 Rust 使用方也需要更新。普通指标名称保持不变。

本次修改仅覆盖本仓库共享的构建信息和节点指标。依赖 gravity-aptos 自己提供的节点检查服务 /system_information 仍使用独立的构建信息;本次没有更改该依赖。shadow-rs 仍可生成内部时间常量,本次不宣称完整二进制已经能够逐字节复现。

验证

  • 回归测试先在原实现上因仍存在 build_time 失败,再在删除后通过;测试同时覆盖设置 BUILD_DATE 后字段仍然缺失,并保留原有提交哈希、分支和标签覆盖断言。
  • cargo test --locked -p build-info。
  • cargo clippy --locked -p build-info --all-targets -- -D warnings。
  • cargo +nightly-2026-09-05 fmt --all -- --check。
  • 独立编译并运行实际的节点指标模块,验证指标成功注册、标签中不含 build_time、其余身份标签仍对应正确的值。

本地没有构建或运行完整节点。Cargo 仍报告已有的未使用 tonic 补丁和工具链最低版本配置不一致提示;本次没有修改这些配置。

评审

评审等级为 L2,因为本次删除对外字段和监控标签。两路独立只读评审分别检查调用路径与遗漏,以及指标标签匹配、兼容性和回滚影响。

shadow-rs stamps BUILD_TIME with the wall clock (in the builder's local
timezone) unless SOURCE_DATE_EPOCH is set, so every rebuild of the same
commit embeds a different timestamp and yields a different sha256. That
rules out verifying a release binary by rebuilding its tag.

Default SOURCE_DATE_EPOCH to `git log -1 --format=%ct` in the build
script. An explicit SOURCE_DATE_EPOCH still takes precedence, and builds
without git (e.g. docker builds without .git) keep the old wall-clock
behaviour. `build_time` in `--version` and the build_info metric now
reports the commit time in UTC.

This only removes the timestamp; a byte-identical rebuild still needs a
matching toolchain, source path and build environment.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T16:38:48.367091Z 63f4304 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a9fb6fd21

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/build-info/build.rs Outdated
Comment on lines +23 to +24
if std::env::var_os("SOURCE_DATE_EPOCH").is_none() {
if let Some(epoch) = head_commit_epoch() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Track the resolved Git ref before caching its timestamp

When an incremental build advances the current branch without changing this crate (for example, git pull followed by cargo build), .git/HEAD remains ref: refs/heads/<branch> and only the referenced file changes. Because the script watches ../../.git/HEAD but not the resolved ref, Cargo does not rerun it under Cargo's documented rerun-if-changed behavior, so this block retains the previous commit's epoch rather than the new HEAD time. Watch the resolved ref/packed refs (including worktree Git dirs), or otherwise ensure HEAD changes rerun the script.

AGENTS.md reference: AGENTS.md:L12-L12

Useful? React with 👍 / 👎.

@nekomoto911 nekomoto911 changed the title fix(build-info): pin BUILD_TIME to the HEAD commit time fix(build-info): 移除对外构建时间字段 Nov 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 63f430415f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

pub const BUILD_COMMIT_HASH: &str = "build_commit_hash";
pub const BUILD_TAG: &str = "build_tag";
pub const BUILD_TIME: &str = "build_time";
pub const BUILD_OS: &str = "build_os";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve build_time in exported build metadata

Removing this key makes every build_information!() caller omit build_time: gravity_node --version and gravity_cli --version format this map directly, the node logger and telemetry API forward it, and node_metrics.rs now also removes the corresponding Prometheus label. Thus releases built from this commit no longer provide the timestamp that the change promises to pin to the HEAD commit, while consumers of the existing CLI/telemetry schema see a compatibility break. Keep the field and populate it deterministically rather than deleting it; rebuilding and inspecting gravity_node --version is a minimal validation.

AGENTS.md reference: AGENTS.md:L5-L6

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant