From e09ed75a9bd38edee3a50c5f9740ba4534d6247f Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Thu, 27 Jun 2024 21:03:40 +1000 Subject: [PATCH] fix: use 8 byte SHA in getClientVersionV1 (#9137) --- Cargo.lock | 44 +++++++++++++++++-- Cargo.toml | 1 + crates/node-core/Cargo.toml | 2 +- crates/node-core/build.rs | 5 ++- .../node-core/src/metrics/version_metrics.rs | 4 +- crates/node-core/src/version.rs | 29 +++++++----- deny.toml | 1 + 7 files changed, 66 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8aded4fc5..e8a803923 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1865,10 +1865,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] -name = "const-str" -version = "0.5.7" +name = "const_format" +version = "0.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3618cccc083bb987a415d85c02ca6c9994ea5b44731ec28b9ecf09658655fba9" +checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" +dependencies = [ + "const_format_proc_macros", + "konst", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] [[package]] name = "convert_case" @@ -4500,6 +4515,21 @@ dependencies = [ "sha3-asm", ] +[[package]] +name = "konst" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330f0e13e6483b8c34885f7e6c9f19b1a7bd449c673fbb948a51c99d66ef74f4" +dependencies = [ + "konst_macro_rules", +] + +[[package]] +name = "konst_macro_rules" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" + [[package]] name = "lazy_static" version = "1.5.0" @@ -7539,7 +7569,7 @@ dependencies = [ "alloy-genesis", "alloy-rpc-types-engine", "clap", - "const-str", + "const_format", "derive_more", "dirs-next", "eyre", @@ -10358,6 +10388,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "universal-hash" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 8f101dc70..7cc284de4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/node-core/Cargo.toml b/crates/node-core/Cargo.toml index 82e5c4dfc..2390cbfb1 100644 --- a/crates/node-core/Cargo.toml +++ b/crates/node-core/Cargo.toml @@ -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 diff --git a/crates/node-core/build.rs b/crates/node-core/build.rs index 043505cdf..1a78793a4 100644 --- a/crates/node-core/build.rs +++ b/crates/node-core/build.rs @@ -8,19 +8,20 @@ fn main() -> Result<(), Box> { 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(()) diff --git a/crates/node-core/src/metrics/version_metrics.rs b/crates/node-core/src/metrics/version_metrics.rs index f0b11c3b7..253e759db 100644 --- a/crates/node-core/src/metrics/version_metrics.rs +++ b/crates/node-core/src/metrics/version_metrics.rs @@ -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()), ]; diff --git a/crates/node-core/src/version.rs b/crates/node-core/src/version.rs index db8bf09d1..5151b861d 100644 --- a/crates/node-core/src/version.rs +++ b/crates/node-core/src/version.rs @@ -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"); @@ -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, ")" ); @@ -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"), @@ -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") ); @@ -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)] diff --git a/deny.toml b/deny.toml index 4dff1b9ce..bfe416979 100644 --- a/deny.toml +++ b/deny.toml @@ -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