reth_node_core/
version.rs

1//! Version information for reth.
2use alloy_primitives::Bytes;
3use alloy_rpc_types_engine::ClientCode;
4use reth_db::ClientVersion;
5
6/// The client code for Reth
7pub const CLIENT_CODE: ClientCode = ClientCode::RH;
8
9/// The human readable name of the client
10pub const NAME_CLIENT: &str = "Reth";
11
12/// The latest version from Cargo.toml.
13pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
14
15/// The full SHA of the latest commit.
16pub const VERGEN_GIT_SHA_LONG: &str = env!("VERGEN_GIT_SHA");
17
18/// The 8 character short SHA of the latest commit.
19pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA_SHORT");
20
21/// The build timestamp.
22pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
23
24/// The target triple.
25pub const VERGEN_CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
26
27/// The build features.
28pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES");
29
30/// The short version information for reth.
31pub const SHORT_VERSION: &str = env!("RETH_SHORT_VERSION");
32
33/// The long version information for reth.
34pub const LONG_VERSION: &str = concat!(
35    env!("RETH_LONG_VERSION_0"),
36    "\n",
37    env!("RETH_LONG_VERSION_1"),
38    "\n",
39    env!("RETH_LONG_VERSION_2"),
40    "\n",
41    env!("RETH_LONG_VERSION_3"),
42    "\n",
43    env!("RETH_LONG_VERSION_4")
44);
45
46/// The build profile name.
47pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE");
48
49/// The version information for reth formatted for P2P (devp2p).
50///
51/// - The latest version from Cargo.toml
52/// - The target triple
53///
54/// # Example
55///
56/// ```text
57/// reth/v{major}.{minor}.{patch}-{sha1}/{target}
58/// ```
59/// e.g.: `reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin`
60pub(crate) const P2P_CLIENT_VERSION: &str = env!("RETH_P2P_CLIENT_VERSION");
61
62/// The default extra data used for payload building.
63///
64/// - The latest version from Cargo.toml
65/// - The OS identifier
66///
67/// # Example
68///
69/// ```text
70/// reth/v{major}.{minor}.{patch}/{OS}
71/// ```
72pub fn default_extra_data() -> String {
73    format!("reth/v{}/{}", env!("CARGO_PKG_VERSION"), std::env::consts::OS)
74}
75
76/// The default extra data in bytes.
77/// See [`default_extra_data`].
78pub fn default_extra_data_bytes() -> Bytes {
79    Bytes::from(default_extra_data().as_bytes().to_vec())
80}
81
82/// The default client version accessing the database.
83pub fn default_client_version() -> ClientVersion {
84    ClientVersion {
85        version: CARGO_PKG_VERSION.to_string(),
86        git_sha: VERGEN_GIT_SHA.to_string(),
87        build_timestamp: VERGEN_BUILD_TIMESTAMP.to_string(),
88    }
89}
90
91#[cfg(test)]
92mod tests {
93    use super::*;
94
95    #[test]
96    fn assert_extra_data_less_32bytes() {
97        let extra_data = default_extra_data();
98        assert!(extra_data.len() <= 32, "extra data must be less than 32 bytes: {extra_data}")
99    }
100}