Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/cli/commands/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use clap::Parser;
use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_node_core::version::SHORT_VERSION;
use reth_node_core::version::version_metadata;
use std::{path::PathBuf, sync::Arc};
use tracing::info;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> ImportComm
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
Comp: CliNodeComponents<N>,
{
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
info!(target: "reth::cli", "reth {} starting", version_metadata().short_version);

let Environment { provider_factory, config, .. } = self.env.init::<N>(AccessRights::RW)?;

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/commands/src/import_era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_era_downloader::{read_dir, EraClient, EraStream, EraStreamConfig};
use reth_era_utils as era;
use reth_etl::Collector;
use reth_fs_util as fs;
use reth_node_core::version::SHORT_VERSION;
use reth_node_core::version::version_metadata;
use reth_provider::StaticFileProviderFactory;
use reth_static_file_types::StaticFileSegment;
use std::{path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> ImportEraC
where
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
{
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
info!(target: "reth::cli", "reth {} starting", version_metadata().short_version);

let Environment { provider_factory, config, .. } = self.env.init::<N>(AccessRights::RW)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/commands/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where
where
L: Launcher<C, Ext>,
{
tracing::info!(target: "reth::cli", version = ?version::SHORT_VERSION, "Starting reth");
tracing::info!(target: "reth::cli", version = ?version::version_metadata().short_version, "Starting reth");

let Self {
datadir,
Expand Down
17 changes: 7 additions & 10 deletions crates/cli/commands/src/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ use reth_network::BlockDownloaderProvider;
use reth_network_p2p::HeadersClient;
use reth_node_core::{
args::{NetworkArgs, StageEnum},
version::{
BUILD_PROFILE_NAME, CARGO_PKG_VERSION, VERGEN_BUILD_TIMESTAMP, VERGEN_CARGO_FEATURES,
VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
},
version::version_metadata,
};
use reth_node_metrics::{
chain::ChainSpecInfo,
Expand Down Expand Up @@ -123,12 +120,12 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>
let config = MetricServerConfig::new(
listen_addr,
VersionInfo {
version: CARGO_PKG_VERSION,
build_timestamp: VERGEN_BUILD_TIMESTAMP,
cargo_features: VERGEN_CARGO_FEATURES,
git_sha: VERGEN_GIT_SHA,
target_triple: VERGEN_CARGO_TARGET_TRIPLE,
build_profile: BUILD_PROFILE_NAME,
version: version_metadata().cargo_pkg_version.as_ref(),
build_timestamp: version_metadata().vergen_build_timestamp.as_ref(),
cargo_features: version_metadata().vergen_cargo_features.as_ref(),
git_sha: version_metadata().vergen_git_sha.as_ref(),
target_triple: version_metadata().vergen_cargo_target_triple.as_ref(),
build_profile: version_metadata().build_profile_name.as_ref(),
},
ChainSpecInfo { name: provider_factory.chain_spec().chain().to_string() },
ctx.task_executor,
Expand Down
7 changes: 2 additions & 5 deletions crates/ethereum/cli/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use reth_cli_runner::CliRunner;
use reth_db::DatabaseEnv;
use reth_node_api::NodePrimitives;
use reth_node_builder::{NodeBuilder, WithLaunchContext};
use reth_node_core::{
args::LogArgs,
version::{LONG_VERSION, SHORT_VERSION},
};
use reth_node_core::{args::LogArgs, version::version_metadata};
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthEvmConfig, EthereumNode};
use reth_node_metrics::recorder::install_prometheus_recorder;
use reth_tracing::FileWorkerGuard;
Expand All @@ -29,7 +26,7 @@ use tracing::info;
///
/// This is the entrypoint to the executable.
#[derive(Debug, Parser)]
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
#[command(author, version =version_metadata().short_version.as_ref(), long_version = version_metadata().long_version.as_ref(), about = "Reth", long_about = None)]
pub struct Cli<C: ChainSpecParser = EthereumChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
{
/// The command to run
Expand Down
17 changes: 7 additions & 10 deletions crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ use reth_node_core::{
dirs::{ChainPath, DataDirPath},
node_config::NodeConfig,
primitives::BlockHeader,
version::{
BUILD_PROFILE_NAME, CARGO_PKG_VERSION, VERGEN_BUILD_TIMESTAMP, VERGEN_CARGO_FEATURES,
VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
},
version::version_metadata,
};
use reth_node_metrics::{
chain::ChainSpecInfo,
Expand Down Expand Up @@ -589,12 +586,12 @@ where
let config = MetricServerConfig::new(
addr,
VersionInfo {
version: CARGO_PKG_VERSION,
build_timestamp: VERGEN_BUILD_TIMESTAMP,
cargo_features: VERGEN_CARGO_FEATURES,
git_sha: VERGEN_GIT_SHA,
target_triple: VERGEN_CARGO_TARGET_TRIPLE,
build_profile: BUILD_PROFILE_NAME,
version: version_metadata().cargo_pkg_version.as_ref(),
build_timestamp: version_metadata().vergen_build_timestamp.as_ref(),
cargo_features: version_metadata().vergen_cargo_features.as_ref(),
git_sha: version_metadata().vergen_git_sha.as_ref(),
target_triple: version_metadata().vergen_cargo_target_triple.as_ref(),
build_profile: version_metadata().build_profile_name.as_ref(),
},
ChainSpecInfo { name: self.left().config.chain.chain().to_string() },
self.task_executor().clone(),
Expand Down
8 changes: 4 additions & 4 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_node_api::{
};
use reth_node_core::{
node_config::NodeConfig,
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
version::{version_metadata, CLIENT_CODE},
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadStore};
use reth_rpc::eth::{core::EthRpcConverterFor, EthApiTypes, FullEthApiServer};
Expand Down Expand Up @@ -1233,9 +1233,9 @@ where
let engine_validator = payload_validator_builder.build(ctx).await?;
let client = ClientVersionV1 {
code: CLIENT_CODE,
name: NAME_CLIENT.to_string(),
version: CARGO_PKG_VERSION.to_string(),
commit: VERGEN_GIT_SHA.to_string(),
name: version_metadata().name_client.to_string(),
version: version_metadata().cargo_pkg_version.to_string(),
commit: version_metadata().vergen_git_sha.to_string(),
};
Ok(EngineApi::new(
ctx.node.provider().clone(),
Expand Down
7 changes: 3 additions & 4 deletions crates/node/core/src/args/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
path::PathBuf,
};

use crate::version::version_metadata;
use clap::Args;
use reth_chainspec::EthChainSpec;
use reth_config::Config;
Expand Down Expand Up @@ -37,8 +38,6 @@ use reth_network_peers::{mainnet_nodes, TrustedPeer};
use secp256k1::SecretKey;
use tracing::error;

use crate::version::P2P_CLIENT_VERSION;

/// Parameters for configuring the network more granularity via CLI
#[derive(Debug, Clone, Args, PartialEq, Eq)]
#[command(next_help_heading = "Networking")]
Expand Down Expand Up @@ -74,7 +73,7 @@ pub struct NetworkArgs {
pub peers_file: Option<PathBuf>,

/// Custom node identity
#[arg(long, value_name = "IDENTITY", default_value = P2P_CLIENT_VERSION)]
#[arg(long, value_name = "IDENTITY", default_value = version_metadata().p2p_client_version.as_ref())]
pub identity: String,

/// Secret key to use for this node.
Expand Down Expand Up @@ -325,7 +324,7 @@ impl Default for NetworkArgs {
bootnodes: None,
dns_retries: 0,
peers_file: None,
identity: P2P_CLIENT_VERSION.to_string(),
identity: version_metadata().p2p_client_version.to_string(),
p2p_secret_key: None,
no_persist_peers: false,
nat: NatResolver::Any,
Expand Down
146 changes: 94 additions & 52 deletions crates/node/core/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,73 @@
//! Version information for reth.
use std::{borrow::Cow, sync::OnceLock};

use alloy_primitives::Bytes;
use alloy_rpc_types_engine::ClientCode;
use reth_db::ClientVersion;

/// The client code for Reth
pub const CLIENT_CODE: ClientCode = ClientCode::RH;

/// The human readable name of the client
pub const NAME_CLIENT: &str = "Reth";

/// The latest version from Cargo.toml.
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

/// 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 = env!("VERGEN_GIT_SHA_SHORT");

/// The build timestamp.
pub const VERGEN_BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP");

/// The target triple.
pub const VERGEN_CARGO_TARGET_TRIPLE: &str = env!("VERGEN_CARGO_TARGET_TRIPLE");
/// Global static version metadata
static VERSION_METADATA: OnceLock<RethCliVersionConsts> = OnceLock::new();

/// The build features.
pub const VERGEN_CARGO_FEATURES: &str = env!("VERGEN_CARGO_FEATURES");

/// The short version information for reth.
pub const SHORT_VERSION: &str = env!("RETH_SHORT_VERSION");

/// The long version information for reth.
pub const LONG_VERSION: &str = concat!(
env!("RETH_LONG_VERSION_0"),
"\n",
env!("RETH_LONG_VERSION_1"),
"\n",
env!("RETH_LONG_VERSION_2"),
"\n",
env!("RETH_LONG_VERSION_3"),
"\n",
env!("RETH_LONG_VERSION_4")
);

/// The build profile name.
pub const BUILD_PROFILE_NAME: &str = env!("RETH_BUILD_PROFILE");
/// Initialize the global version metadata.
pub fn try_init_version_metadata(
metadata: RethCliVersionConsts,
) -> Result<(), RethCliVersionConsts> {
VERSION_METADATA.set(metadata)
}

/// The version information for reth formatted for P2P (devp2p).
///
/// - The latest version from Cargo.toml
/// - The target triple
///
/// # Example
/// Constants for reth-cli
///
/// ```text
/// 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 = env!("RETH_P2P_CLIENT_VERSION");
/// Global defaults can be set via [`try_init_version_metadata`].
#[derive(Debug, Default)]
pub struct RethCliVersionConsts {
/// The human readable name of the client
pub name_client: Cow<'static, str>,

/// The latest version from Cargo.toml.
pub cargo_pkg_version: Cow<'static, str>,

/// The full SHA of the latest commit.
pub vergen_git_sha_long: Cow<'static, str>,

/// The 8 character short SHA of the latest commit.
pub vergen_git_sha: Cow<'static, str>,

/// The build timestamp.
pub vergen_build_timestamp: Cow<'static, str>,

/// The target triple.
pub vergen_cargo_target_triple: Cow<'static, str>,

/// The build features.
pub vergen_cargo_features: Cow<'static, str>,

/// The short version information for reth.
pub short_version: Cow<'static, str>,

/// The long version information for reth.
pub long_version: Cow<'static, str>,
/// The build profile name.
pub build_profile_name: Cow<'static, str>,

/// The version information for reth formatted for P2P (devp2p).
///
/// - The latest version from Cargo.toml
/// - The target triple
///
/// # Example
///
/// ```text
/// reth/v{major}.{minor}.{patch}-{sha1}/{target}
/// ```
/// e.g.: `reth/v0.1.0-alpha.1-428a6dc2f/aarch64-apple-darwin`
pub p2p_client_version: Cow<'static, str>,

/// extra data used for payload building
pub extra_data: Cow<'static, str>,
}

/// The default extra data used for payload building.
///
Expand All @@ -81,10 +91,42 @@ pub fn default_extra_data_bytes() -> Bytes {

/// The default client version accessing the database.
pub fn default_client_version() -> ClientVersion {
let meta = version_metadata();
ClientVersion {
version: CARGO_PKG_VERSION.to_string(),
git_sha: VERGEN_GIT_SHA.to_string(),
build_timestamp: VERGEN_BUILD_TIMESTAMP.to_string(),
version: meta.cargo_pkg_version.to_string(),
git_sha: meta.vergen_git_sha.to_string(),
build_timestamp: meta.vergen_build_timestamp.to_string(),
}
}

/// Get a reference to the global version metadata
pub fn version_metadata() -> &'static RethCliVersionConsts {
VERSION_METADATA.get_or_init(default_reth_version_metadata)
}

/// default reth version metadata using compile-time env! macros.
pub fn default_reth_version_metadata() -> RethCliVersionConsts {
RethCliVersionConsts {
name_client: Cow::Borrowed("Reth"),
cargo_pkg_version: Cow::Owned(env!("CARGO_PKG_VERSION").to_string()),
vergen_git_sha_long: Cow::Owned(env!("VERGEN_GIT_SHA").to_string()),
vergen_git_sha: Cow::Owned(env!("VERGEN_GIT_SHA_SHORT").to_string()),
vergen_build_timestamp: Cow::Owned(env!("VERGEN_BUILD_TIMESTAMP").to_string()),
vergen_cargo_target_triple: Cow::Owned(env!("VERGEN_CARGO_TARGET_TRIPLE").to_string()),
vergen_cargo_features: Cow::Owned(env!("VERGEN_CARGO_FEATURES").to_string()),
short_version: Cow::Owned(env!("RETH_SHORT_VERSION").to_string()),
long_version: Cow::Owned(format!(
"{}\n{}\n{}\n{}\n{}",
env!("RETH_LONG_VERSION_0"),
env!("RETH_LONG_VERSION_1"),
env!("RETH_LONG_VERSION_2"),
env!("RETH_LONG_VERSION_3"),
env!("RETH_LONG_VERSION_4"),
)),

build_profile_name: Cow::Owned(env!("RETH_BUILD_PROFILE").to_string()),
p2p_client_version: Cow::Owned(env!("RETH_P2P_CLIENT_VERSION").to_string()),
extra_data: Cow::Owned(default_extra_data()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/cli/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_consensus::noop::NoopConsensus;
use reth_db_api::{tables, transaction::DbTx};
use reth_downloaders::file_client::{ChunkedFileReader, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE};
use reth_node_builder::BlockTy;
use reth_node_core::version::SHORT_VERSION;
use reth_node_core::version::version_metadata;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::OpExecutorProvider;
use reth_optimism_primitives::{bedrock::is_dup_tx, OpPrimitives};
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportOpCommand<C> {
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec, Primitives = OpPrimitives>>(
self,
) -> eyre::Result<()> {
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
info!(target: "reth::cli", "reth {} starting", version_metadata().short_version);

info!(target: "reth::cli",
"Disabled stages requiring state, since cannot execute OVM state changes"
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/cli/src/commands/import_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reth_downloaders::{
};
use reth_execution_types::ExecutionOutcome;
use reth_node_builder::ReceiptTy;
use reth_node_core::version::SHORT_VERSION;
use reth_node_core::version::version_metadata;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_primitives::{bedrock::is_dup_tx, OpPrimitives, OpReceipt};
use reth_primitives_traits::NodePrimitives;
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> ImportReceiptsOpCommand<C> {
pub async fn execute<N: CliNodeTypes<ChainSpec = C::ChainSpec, Primitives = OpPrimitives>>(
self,
) -> eyre::Result<()> {
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
info!(target: "reth::cli", "reth {} starting", version_metadata().short_version);

debug!(target: "reth::cli",
chunk_byte_len=self.chunk_len.unwrap_or(DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE),
Expand Down
Loading