1//! Version information for reth.
2use alloy_primitives::Bytes;
3use alloy_rpc_types_engine::ClientCode;
4use reth_db::ClientVersion;
56/// The client code for Reth
7pub const CLIENT_CODE: ClientCode = ClientCode::RH;
89/// The human readable name of the client
10pub const NAME_CLIENT: &str = "Reth";
1112/// The latest version from Cargo.toml.
13pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
1415/// The full SHA of the latest commit.
16pub const VERGEN_GIT_SHA_LONG: &str = env!("VERGEN_GIT_SHA");
1718/// The 8 character short SHA of the latest commit.
19pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA_SHORT");
2021/// The build timestamp.
22pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");
2324/// The target triple.
25pub const VERGEN_CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
2627/// The build features.
28pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES");
2930/// The short version information for reth.
31pub const SHORT_VERSION: &str = env!("RETH_SHORT_VERSION");
3233/// The long version information for reth.
34pub const LONG_VERSION: &str = concat!(
35env!("RETH_LONG_VERSION_0"),
36"\n",
37env!("RETH_LONG_VERSION_1"),
38"\n",
39env!("RETH_LONG_VERSION_2"),
40"\n",
41env!("RETH_LONG_VERSION_3"),
42"\n",
43env!("RETH_LONG_VERSION_4")
44);
4546/// The build profile name.
47pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE");
4849/// 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");
6162/// 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 {
73format!("reth/v{}/{}", env!("CARGO_PKG_VERSION"), std::env::consts::OS)
74}
7576/// The default extra data in bytes.
77/// See [`default_extra_data`].
78pub fn default_extra_data_bytes() -> Bytes {
79Bytes::from(default_extra_data().as_bytes().to_vec())
80}
8182/// 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}
9091#[cfg(test)]
92mod tests {
93use super::*;
9495#[test]
96fn assert_extra_data_less_32bytes() {
97let extra_data = default_extra_data();
98assert!(extra_data.len() <= 32, "extra data must be less than 32 bytes: {extra_data}")
99 }
100}