diff --git a/Cargo.lock b/Cargo.lock index e9d36c9e4..5795255f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2198,7 +2198,6 @@ dependencies = [ "bytes", "c-kzg", "clap", - "const_format", "discv5", "env_logger 0.9.3", "eth_trie", @@ -2224,7 +2223,6 @@ dependencies = [ "serde_yaml", "sha2 0.10.8", "sha3 0.9.1", - "shadow-rs", "snap", "ssz_types", "superstruct", @@ -7001,7 +6999,9 @@ version = "0.1.0" dependencies = [ "ansi_term", "atty", + "const_format", "directories", + "shadow-rs", "tempfile", "tracing", "tracing-subscriber 0.3.19", diff --git a/ethportal-api/Cargo.toml b/ethportal-api/Cargo.toml index 257f6ec21..b5289acaa 100644 --- a/ethportal-api/Cargo.toml +++ b/ethportal-api/Cargo.toml @@ -2,7 +2,6 @@ name = "ethportal-api" version = "0.4.0" description = "Definitions for various Ethereum Portal Network JSONRPC APIs" -build = "build.rs" authors.workspace = true categories.workspace = true edition.workspace = true @@ -22,7 +21,6 @@ bimap = "0.6.3" bytes.workspace = true c-kzg = "1.0.0" clap.workspace = true -const_format = {version = "0.2.0", features = ["rust_1_64"]} discv5.workspace = true eth_trie.workspace = true ethereum_hashing = "0.7.0" @@ -45,7 +43,6 @@ serde-this-or-that.workspace = true serde_json.workspace = true sha2 = "0.10.1" sha3.workspace = true -shadow-rs = "0.27" ssz_types.workspace = true superstruct = "0.7.0" thiserror.workspace = true @@ -65,6 +62,3 @@ snap.workspace = true test-log.workspace = true tracing.workspace = true tracing-subscriber.workspace = true - -[build-dependencies] -shadow-rs = "0.27" diff --git a/ethportal-api/src/lib.rs b/ethportal-api/src/lib.rs index 6292e7cb8..ceb7f1745 100644 --- a/ethportal-api/src/lib.rs +++ b/ethportal-api/src/lib.rs @@ -17,7 +17,6 @@ mod state; mod test_utils; pub mod types; pub mod utils; -pub mod version; mod web3; pub use beacon::{BeaconNetworkApiClient, BeaconNetworkApiServer}; @@ -48,5 +47,3 @@ pub use types::{ portal::{RawContentKey, RawContentValue}, }; pub use web3::{Web3ApiClient, Web3ApiServer}; - -shadow_rs::shadow!(build_info); diff --git a/ethportal-api/src/types/cli.rs b/ethportal-api/src/types/cli.rs index 37f6cbf71..7c543ae79 100644 --- a/ethportal-api/src/types/cli.rs +++ b/ethportal-api/src/types/cli.rs @@ -9,10 +9,7 @@ use clap::{ }; use url::Url; -use crate::{ - build_info, - types::{bootnodes::Bootnodes, network::Subnetwork}, -}; +use crate::types::{bootnodes::Bootnodes, network::Subnetwork}; pub const DEFAULT_WEB3_IPC_PATH: &str = "/tmp/trin-jsonrpc.ipc"; pub const DEFAULT_WEB3_HTTP_ADDRESS: &str = "http://127.0.0.1:8545/"; @@ -56,22 +53,6 @@ impl FromStr for Web3TransportType { } const APP_NAME: &str = "trin"; -const VERSION: &str = const_format::formatcp!( - "{version}-{hash} {build_os} {rust_version}", - // Remove -alpha.1 versioning if it is present. - // This must be done as it can conflict with eth versioning - version = const_format::str_split!(build_info::PKG_VERSION, '-')[0], - hash = build_info::short_commit(), - build_os = build_info::BUILD_OS, - // the rust version looks like that: - // rustc 1.77.0 (aedd173a2 2024-03-17) - // we remove everything in the brackets and replace spaces with nothing - rust_version = const_format::str_replace!( - const_format::str_split!(build_info::RUST_VERSION, '(')[0], - ' ', - "" - ) -); /// The storage capacity configurtion. #[derive(Debug, Clone, PartialEq, Eq)] @@ -91,7 +72,8 @@ pub enum StorageCapacityConfig { #[command(name = APP_NAME, author = "https://github.com/ethereum/trin/graphs/contributors", about = "Run an eth portal client", - version = VERSION)] + version = "To get the current trin version, please start the client and it will be displayed in the logs.", +)] pub struct TrinConfig { #[arg( default_value = DEFAULT_WEB3_TRANSPORT, diff --git a/ethportal-api/src/version.rs b/ethportal-api/src/version.rs deleted file mode 100644 index a29bae672..000000000 --- a/ethportal-api/src/version.rs +++ /dev/null @@ -1,4 +0,0 @@ -/// Returns the trin version and git revision. -pub const fn get_trin_version() -> &'static str { - crate::build_info::short_commit() -} diff --git a/ethportal-peertest/src/scenarios/basic.rs b/ethportal-peertest/src/scenarios/basic.rs index 27ae75c7e..63e79fda0 100644 --- a/ethportal-peertest/src/scenarios/basic.rs +++ b/ethportal-peertest/src/scenarios/basic.rs @@ -1,13 +1,13 @@ use alloy::primitives::{B256, U256}; use ethportal_api::{ types::{distance::Distance, network::Subnetwork}, - version::get_trin_version, BeaconNetworkApiClient, ContentValue, Discv5ApiClient, HistoryContentKey, HistoryNetworkApiClient, StateNetworkApiClient, Web3ApiClient, }; use jsonrpsee::async_client::Client; use ssz::Encode; use tracing::info; +use trin_utils::version::get_trin_version; use crate::{utils::fixture_header_by_hash, Peertest, PeertestNode}; diff --git a/portalnet/src/discovery.rs b/portalnet/src/discovery.rs index 27904ba16..123d0f3bd 100644 --- a/portalnet/src/discovery.rs +++ b/portalnet/src/discovery.rs @@ -18,13 +18,13 @@ use discv5::{ use ethportal_api::{ types::{discv5::RoutingTableInfo, enr::Enr, network::Subnetwork, portal_wire::NetworkSpec}, utils::bytes::hex_decode, - version::get_trin_version, NodeInfo, }; use lru::LruCache; use parking_lot::RwLock; use tokio::sync::{mpsc, RwLock as TokioRwLock}; use tracing::{debug, info, warn}; +use trin_utils::version::get_trin_short_version_commit; use trin_validation::oracle::HeaderOracle; use utp_rs::{cid::ConnectionPeer, udp::AsyncUdpSocket}; @@ -139,7 +139,7 @@ impl Discovery { .as_secs(); builder.seq(epoch_timestamp); - let trin_version = get_trin_version(); + let trin_version = get_trin_short_version_commit(); // Use "t" as short-hand for "Trin" to save bytes in ENR. let client_info = format!("t {trin_version}"); // Use "c" as short-hand for "client". diff --git a/rpc/src/web3_rpc.rs b/rpc/src/web3_rpc.rs index f8065eaaf..da2490c6f 100644 --- a/rpc/src/web3_rpc.rs +++ b/rpc/src/web3_rpc.rs @@ -1,4 +1,5 @@ -use ethportal_api::{version::get_trin_version, Web3ApiServer}; +use ethportal_api::Web3ApiServer; +use trin_utils::version::get_trin_version; use crate::jsonrpsee::core::{async_trait, RpcResult}; diff --git a/src/lib.rs b/src/lib.rs index 20edd3a2b..e652fa795 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,6 @@ use ethportal_api::types::cli::Web3TransportType; use ethportal_api::{ types::{cli::TrinConfig, network::Subnetwork}, utils::bytes::hex_encode, - version::get_trin_version, }; use portalnet::{ config::PortalnetConfig, @@ -24,6 +23,7 @@ use trin_beacon::initialize_beacon_network; use trin_history::initialize_history_network; use trin_state::initialize_state_network; use trin_storage::PortalStorageConfigFactory; +use trin_utils::version::get_trin_version; use trin_validation::oracle::HeaderOracle; use utp_rs::socket::UtpSocket; diff --git a/trin-utils/Cargo.toml b/trin-utils/Cargo.toml index 5ec5a12ba..6aac2df17 100644 --- a/trin-utils/Cargo.toml +++ b/trin-utils/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "trin-utils" description = "Utils library for Trin." +build = "build.rs" authors.workspace = true categories.workspace = true edition.workspace = true @@ -12,11 +13,16 @@ rust-version.workspace = true version.workspace = true [dependencies] +const_format = {version = "0.2.0", features = ["rust_1_64"]} directories.workspace = true +shadow-rs = "0.27" tempfile.workspace = true tracing.workspace = true tracing-subscriber = { workspace = true, features = ["env-filter"] } +[build-dependencies] +shadow-rs = "0.27" + [target.'cfg(windows)'.dependencies] # The crates for detecting whether the terminal supports colors are OS-specific. ansi_term = "0.12" diff --git a/ethportal-api/build.rs b/trin-utils/build.rs similarity index 100% rename from ethportal-api/build.rs rename to trin-utils/build.rs diff --git a/trin-utils/src/lib.rs b/trin-utils/src/lib.rs index 623e58449..2a0db59ca 100644 --- a/trin-utils/src/lib.rs +++ b/trin-utils/src/lib.rs @@ -4,3 +4,6 @@ pub mod dir; pub mod log; pub mod submodules; +pub mod version; + +shadow_rs::shadow!(build_info); diff --git a/trin-utils/src/version.rs b/trin-utils/src/version.rs new file mode 100644 index 000000000..28c65da1b --- /dev/null +++ b/trin-utils/src/version.rs @@ -0,0 +1,24 @@ +/// Returns the short commit hash +pub const fn get_trin_short_version_commit() -> &'static str { + crate::build_info::short_commit() +} + +/// Returns the full trin version +pub const fn get_trin_version() -> &'static str { + const_format::formatcp!( + "{version}-{hash} {build_os} {rust_version}", + // Remove -alpha.1 versioning if it is present. + // This must be done as it can conflict with eth versioning + version = const_format::str_split!(crate::build_info::PKG_VERSION, '-')[0], + hash = crate::build_info::short_commit(), + build_os = crate::build_info::BUILD_OS, + // the rust version looks like that: + // rustc 1.77.0 (aedd173a2 2024-03-17) + // we remove everything in the brackets and replace spaces with nothing + rust_version = const_format::str_replace!( + const_format::str_split!(crate::build_info::RUST_VERSION, '(')[0], + ' ', + "" + ) + ) +}