Skip to content

Commit

Permalink
fix: use 8 byte SHA in getClientVersionV1 (#9137)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul authored Jun 27, 2024
1 parent 793aa85 commit e09ed75
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 20 deletions.
44 changes: 40 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ aquamarine = "0.5"
bytes = "1.5"
bitflags = "2.4"
clap = "4"
const_format = { version = "0.2.32", features = ["rust_1_64"] }
dashmap = "5.5"
derive_more = "0.99.17"
fdlimit = "0.3.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/node-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ eyre.workspace = true
clap = { workspace = true, features = ["derive"] }
humantime.workspace = true
thiserror.workspace = true
const-str = "0.5.6"
const_format.workspace = true
rand.workspace = true
derive_more.workspace = true
once_cell.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/node-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder()
.git_describe(false, true, None)
.git_dirty(true)
.git_sha(true)
.git_sha(false)
.build_timestamp()
.cargo_features()
.cargo_target_triple()
.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";
// > git describe --always --tags
// if not on a tag: v0.2.0-beta.3-82-g1939939b
// if on a tag: v0.2.0-beta.3
let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha}"));
let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha_short}"));
let is_dev = is_dirty || not_on_tag;
println!("cargo:rustc-env=RETH_VERSION_SUFFIX={}", if is_dev { "-dev" } else { "" });
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/node-core/src/metrics/version_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! This exposes reth's version information over prometheus.
use crate::version::build_profile_name;
use crate::version::{build_profile_name, VERGEN_GIT_SHA};
use metrics::gauge;

const LABELS: [(&str, &str); 6] = [
("version", env!("CARGO_PKG_VERSION")),
("build_timestamp", env!("VERGEN_BUILD_TIMESTAMP")),
("cargo_features", env!("VERGEN_CARGO_FEATURES")),
("git_sha", env!("VERGEN_GIT_SHA")),
("git_sha", VERGEN_GIT_SHA),
("target_triple", env!("VERGEN_CARGO_TARGET_TRIPLE")),
("build_profile", build_profile_name()),
];
Expand Down
29 changes: 18 additions & 11 deletions crates/node-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ pub const NAME_CLIENT: &str = "Reth";
/// The latest version from Cargo.toml.
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

/// The short SHA of the latest commit.
pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA");
/// The full SHA of the latest commit.
pub const VERGEN_GIT_SHA_LONG: &str = env!("VERGEN_GIT_SHA");

/// The 8 character short SHA of the latest commit.
pub const VERGEN_GIT_SHA: &str = const_format::str_index!(VERGEN_GIT_SHA_LONG, ..8);

/// The build timestamp.
pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
Expand All @@ -27,11 +30,11 @@ pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
/// ```text
/// 0.1.0 (defa64b2)
/// ```
pub const SHORT_VERSION: &str = concat!(
pub const SHORT_VERSION: &str = const_format::concatcp!(
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
" (",
env!("VERGEN_GIT_SHA"),
VERGEN_GIT_SHA,
")"
);

Expand All @@ -52,13 +55,13 @@ pub const SHORT_VERSION: &str = concat!(
/// Build Features: jemalloc
/// Build Profile: maxperf
/// ```
pub const LONG_VERSION: &str = const_str::concat!(
pub const LONG_VERSION: &str = const_format::concatcp!(
"Version: ",
env!("CARGO_PKG_VERSION"),
env!("RETH_VERSION_SUFFIX"),
"\n",
"Commit SHA: ",
env!("VERGEN_GIT_SHA"),
VERGEN_GIT_SHA_LONG,
"\n",
"Build Timestamp: ",
env!("VERGEN_BUILD_TIMESTAMP"),
Expand All @@ -81,11 +84,11 @@ pub const LONG_VERSION: &str = const_str::concat!(
/// reth/v{major}.{minor}.{patch}-{sha1}/{target}
/// ```
/// e.g.: `reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin`
pub(crate) const P2P_CLIENT_VERSION: &str = concat!(
pub(crate) const P2P_CLIENT_VERSION: &str = const_format::concatcp!(
"reth/v",
env!("CARGO_PKG_VERSION"),
"-",
env!("VERGEN_GIT_SHA"),
VERGEN_GIT_SHA,
"/",
env!("VERGEN_CARGO_TARGET_TRIPLE")
);
Expand Down Expand Up @@ -118,9 +121,13 @@ pub(crate) const fn build_profile_name() -> &'static str {
// We split on the path separator of the *host* machine, which may be different from
// `std::path::MAIN_SEPARATOR_STR`.
const OUT_DIR: &str = env!("OUT_DIR");
const SEP: char = if const_str::contains!(OUT_DIR, "/") { '/' } else { '\\' };
let parts = const_str::split!(OUT_DIR, SEP);
parts[parts.len() - 4]
let unix_parts = const_format::str_split!(OUT_DIR, '/');
if unix_parts.len() >= 4 {
unix_parts[unix_parts.len() - 4]
} else {
let win_parts = const_format::str_split!(OUT_DIR, '\\');
win_parts[win_parts.len() - 4]
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ allow = [
"Unicode-DFS-2016",
"Unlicense",
"Unicode-3.0",
"Zlib",
# https://github.com/briansmith/ring/issues/902
"LicenseRef-ring",
# https://github.com/rustls/webpki/blob/main/LICENSE ISC Style
Expand Down

0 comments on commit e09ed75

Please sign in to comment.