Skip to content

Commit

Permalink
bugfix: broken trin versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Dec 17, 2024
1 parent 8e2dd0d commit 4738f4e
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions ethportal-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -65,6 +62,3 @@ snap.workspace = true
test-log.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

[build-dependencies]
shadow-rs = "0.27"
3 changes: 0 additions & 3 deletions ethportal-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -48,5 +47,3 @@ pub use types::{
portal::{RawContentKey, RawContentValue},
};
pub use web3::{Web3ApiClient, Web3ApiServer};

shadow_rs::shadow!(build_info);
24 changes: 3 additions & 21 deletions ethportal-api/src/types/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down Expand Up @@ -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)]
Expand All @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions ethportal-api/src/version.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ethportal-peertest/src/scenarios/basic.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
4 changes: 2 additions & 2 deletions portalnet/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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".
Expand Down
3 changes: 2 additions & 1 deletion rpc/src/web3_rpc.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions trin-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions trin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
pub mod dir;
pub mod log;
pub mod submodules;
pub mod version;

shadow_rs::shadow!(build_info);
24 changes: 24 additions & 0 deletions trin-utils/src/version.rs
Original file line number Diff line number Diff line change
@@ -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],
' ',
""
)
)
}

0 comments on commit 4738f4e

Please sign in to comment.