Skip to content

feat(l1): properly format client version #2564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0a51c91
Add more information to client version
Mechanix97 Apr 23, 2025
dad8631
Use const variables
Mechanix97 Apr 24, 2025
6bd21d5
Use vergen to get more envs vars
Mechanix97 Apr 24, 2025
e732be8
remove unnecesary dependencies
Mechanix97 Apr 24, 2025
00221ea
Add develop tag hardcoded
Mechanix97 Apr 24, 2025
e4ea587
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 24, 2025
72719f4
Refactor to ethrex_constart, added to hello_message
Mechanix97 Apr 24, 2025
8bfbac9
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 24, 2025
76c4be9
Merge remote-tracking branch 'Origin/main' into feat/properly-format-…
Mechanix97 Apr 24, 2025
3d7fbc2
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 24, 2025
8d2a846
Added function to abstract the client information
Mechanix97 Apr 24, 2025
7ff8460
Add rpc admin
Mechanix97 Apr 24, 2025
61fe0f0
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 24, 2025
b5c83ad
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 25, 2025
82d5b27
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 25, 2025
37a244f
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 28, 2025
5d40b89
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 28, 2025
307a37e
feat use client_info as argument
Mechanix97 Apr 28, 2025
7870d5d
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 28, 2025
36362a3
Merge branch 'feat/properly-format-client-version' of github.com:lamb…
Mechanix97 Apr 28, 2025
4209edb
Fix tests
Mechanix97 Apr 28, 2025
043809b
Fix client version RPC
Mechanix97 Apr 28, 2025
f3beab3
Fix tests
Mechanix97 Apr 28, 2025
545abc8
Fix RPC test
Mechanix97 Apr 28, 2025
fd3c16d
add admin client_info
Mechanix97 Apr 28, 2025
2a9a2e5
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 28, 2025
2fce0fa
Fix clippy
Mechanix97 Apr 28, 2025
ac77a8b
Merge branch 'feat/properly-format-client-version' of github.com:lamb…
Mechanix97 Apr 28, 2025
6998ffd
add version command
Mechanix97 Apr 28, 2025
545283b
nit get_client_version
Mechanix97 Apr 28, 2025
0d40ea1
replace client_version
Mechanix97 Apr 28, 2025
9127a09
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 29, 2025
e4cc096
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 29, 2025
4d6cb67
fix merge
Mechanix97 Apr 29, 2025
3c0ed5f
Merge branch 'feat/properly-format-client-version' of github.com:lamb…
Mechanix97 Apr 29, 2025
ba76106
Fix merge2
Mechanix97 Apr 29, 2025
9bf2727
Fix merge2
Mechanix97 Apr 29, 2025
01b0076
Merge branch 'feat/properly-format-client-version' of github.com:lamb…
Mechanix97 Apr 29, 2025
48c1e09
cargo fmt
Mechanix97 Apr 29, 2025
e534575
chenge vergen import
Mechanix97 Apr 30, 2025
51a7dbd
nit new line
Mechanix97 Apr 30, 2025
76d7ab5
Remove Web3 mod
Mechanix97 Apr 30, 2025
26edb2c
Add comment to build
Mechanix97 Apr 30, 2025
c2b1ca2
Merge branch 'main' into feat/properly-format-client-version
Mechanix97 Apr 30, 2025
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
58 changes: 57 additions & 1 deletion Cargo.lock

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

6 changes: 5 additions & 1 deletion cmd/ethrex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "ethrex"
version = "0.1.0"
edition = "2021"
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -21,7 +22,7 @@ hex.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
k256.workspace = true
clap = { version = "4.3", features = ["derive", "env"] }
clap = { version = "4.3", features = ["derive", "env", "string"] }
clap_complete = "4.5.17"
eyre = "0.6.12"
directories = "5.0.1"
Expand Down Expand Up @@ -83,3 +84,6 @@ criterion = { version = "0.5.1", features = ["html_reports"] }
path = "../../bench/criterion_benchmark.rs"
name = "criterion_benchmark"
harness = false

[build-dependencies]
vergen = { version = "9.0.0", features = ["rustc"] }
14 changes: 14 additions & 0 deletions cmd/ethrex/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::error::Error;
use vergen::{Emitter, RustcBuilder};

// This build code is needed to add some env vars in order to construct the node client version
// VERGEN_RUSTC_COMMIT_HASH to get the commit hash
// VERGEN_RUSTC_HOST_TRIPLE to get the build OS
// VERGEN_RUSTC_SEMVER to get the rustc version

fn main() -> Result<(), Box<dyn Error>> {
let rustc = RustcBuilder::all_rustc()?;

Emitter::default().add_instructions(&rustc)?.emit()?;
Ok(())
}
6 changes: 2 additions & 4 deletions cmd/ethrex/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ use tracing::{info, warn, Level};

use crate::{
initializers::{init_blockchain, init_store},
utils::{self, set_datadir},
utils::{self, get_client_version, set_datadir},
DEFAULT_DATADIR,
};

#[cfg(any(feature = "l2", feature = "based"))]
use crate::l2;

pub const VERSION_STRING: &str = env!("CARGO_PKG_VERSION");

#[allow(clippy::upper_case_acronyms)]
#[derive(ClapParser)]
#[command(name="ethrex", author = "Lambdaclass", version=VERSION_STRING, about, about = "ethrex Execution client")]
#[command(name="ethrex", author = "Lambdaclass", version=get_client_version(), about, about = "ethrex Execution client")]
pub struct CLI {
#[command(flatten)]
pub opts: Options,
Expand Down
7 changes: 6 additions & 1 deletion cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
cli::Options,
networks,
utils::{parse_socket_addr, read_genesis_file, read_jwtsecret_file, read_known_peers},
utils::{
get_client_version, parse_socket_addr, read_genesis_file, read_jwtsecret_file,
read_known_peers,
},
};
use ethrex_blockchain::Blockchain;
use ethrex_p2p::{
Expand Down Expand Up @@ -157,6 +160,7 @@ pub async fn init_rpc_api(
local_p2p_node,
local_node_record,
syncer,
get_client_version(),
#[cfg(feature = "based")]
get_gateway_http_client(&l2_opts.based_opts),
#[cfg(feature = "based")]
Expand Down Expand Up @@ -229,6 +233,7 @@ pub async fn init_network(
peer_table.clone(),
store,
blockchain,
get_client_version(),
)
.await
.expect("Network starts");
Expand Down
11 changes: 11 additions & 0 deletions cmd/ethrex/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,14 @@ pub fn parse_hex(s: &str) -> eyre::Result<Bytes, FromHexError> {
None => hex::decode(s).map(Into::into),
}
}

pub fn get_client_version() -> String {
format!(
"{}/v{}-develop-{}/{}/rustc-v{}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
&env!("VERGEN_RUSTC_COMMIT_HASH")[0..6],
env!("VERGEN_RUSTC_HOST_TRIPLE"),
env!("VERGEN_RUSTC_SEMVER")
)
}
1 change: 1 addition & 0 deletions crates/networking/p2p/discv4/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ pub(super) mod tests {
storage,
blockchain,
broadcast,
client_version: "ethrex/test".to_string(),
};

let discv4 = Discv4Server::try_new(ctx.clone()).await?;
Expand Down
4 changes: 4 additions & 0 deletions crates/networking/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ pub struct P2PContext {
pub(crate) broadcast: RLPxConnBroadcastSender,
pub local_node: Node,
pub enr_seq: u64,
pub client_version: String,
}

#[allow(clippy::too_many_arguments)]
pub async fn start_network(
local_node: Node,
tracker: TaskTracker,
Expand All @@ -62,6 +64,7 @@ pub async fn start_network(
peer_table: Arc<Mutex<KademliaTable>>,
storage: Store,
blockchain: Arc<Blockchain>,
client_version: String,
) -> Result<(), NetworkError> {
let (channel_broadcast_send_end, _) = tokio::sync::broadcast::channel::<(
tokio::task::Id,
Expand All @@ -80,6 +83,7 @@ pub async fn start_network(
storage,
blockchain,
broadcast: channel_broadcast_send_end,
client_version,
};
let discovery = Discv4Server::try_new(context.clone())
.await
Expand Down
5 changes: 5 additions & 0 deletions crates/networking/p2p/rlpx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub(crate) struct RLPxConnection<S> {
next_periodic_ping: Instant,
next_tx_broadcast: Instant,
broadcasted_txs: HashSet<H256>,
client_version: String,
/// Send end of the channel used to broadcast messages
/// to other connected peers, is ok to have it here,
/// since internally it's an Arc.
Expand All @@ -96,13 +97,15 @@ pub(crate) struct RLPxConnection<S> {
}

impl<S: AsyncWrite + AsyncRead + std::marker::Unpin> RLPxConnection<S> {
#[allow(clippy::too_many_arguments)]
pub fn new(
signer: SigningKey,
node: Node,
stream: S,
codec: RLPxCodec,
storage: Store,
blockchain: Arc<Blockchain>,
client_version: String,
connection_broadcast: RLPxConnBroadcastSender,
) -> Self {
Self {
Expand All @@ -117,6 +120,7 @@ impl<S: AsyncWrite + AsyncRead + std::marker::Unpin> RLPxConnection<S> {
next_periodic_ping: Instant::now() + PERIODIC_TASKS_CHECK_INTERVAL,
next_tx_broadcast: Instant::now() + PERIODIC_TX_BROADCAST_INTERVAL,
broadcasted_txs: HashSet::new(),
client_version,
connection_broadcast_send: connection_broadcast,
}
}
Expand Down Expand Up @@ -245,6 +249,7 @@ impl<S: AsyncWrite + AsyncRead + std::marker::Unpin> RLPxConnection<S> {
let hello_msg = Message::Hello(p2p::HelloMessage::new(
SUPPORTED_CAPABILITIES.to_vec(),
PublicKey::from(self.signer.verifying_key()),
self.client_version.clone(),
));

self.send(hello_msg).await?;
Expand Down
2 changes: 2 additions & 0 deletions crates/networking/p2p/rlpx/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ where
codec,
context.storage,
context.blockchain,
context.client_version,
context.broadcast,
))
}
Expand Down Expand Up @@ -86,6 +87,7 @@ where
codec,
context.storage,
context.blockchain,
context.client_version,
context.broadcast,
))
}
Expand Down
10 changes: 6 additions & 4 deletions crates/networking/p2p/rlpx/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ impl RLPDecode for Capability {
pub(crate) struct HelloMessage {
pub(crate) capabilities: Vec<(Capability, u8)>,
pub(crate) node_id: PublicKey,
pub(crate) client_id: String,
}

impl HelloMessage {
pub fn new(capabilities: Vec<(Capability, u8)>, node_id: PublicKey) -> Self {
pub fn new(capabilities: Vec<(Capability, u8)>, node_id: PublicKey, client_id: String) -> Self {
Self {
capabilities,
node_id,
client_id,
}
}
}
Expand All @@ -66,7 +68,7 @@ impl RLPxMessage for HelloMessage {
fn encode(&self, mut buf: &mut dyn BufMut) -> Result<(), RLPEncodeError> {
Encoder::new(&mut buf)
.encode_field(&5_u8) // protocolVersion
.encode_field(&"Ethrex/0.1.0") // clientId
.encode_field(&self.client_id) // clientId
.encode_field(&self.capabilities) // capabilities
.encode_field(&0u8) // listenPort (ignored)
.encode_field(&pubkey2id(&self.node_id)) // nodeKey
Expand All @@ -81,8 +83,7 @@ impl RLPxMessage for HelloMessage {

assert_eq!(protocol_version, 5, "only protocol version 5 is supported");

let (_client_id, decoder): (String, _) = decoder.decode_field("clientId")?;
// TODO: store client id for debugging purposes
let (client_id, decoder): (String, _) = decoder.decode_field("clientId")?;

// [[cap1, capVersion1], [cap2, capVersion2], ...]
let (capabilities, decoder): (Vec<(Capability, u8)>, _) =
Expand All @@ -99,6 +100,7 @@ impl RLPxMessage for HelloMessage {
Ok(Self::new(
capabilities,
id2pubkey(node_id).ok_or(RLPDecodeError::MalformedData)?,
client_id,
))
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/networking/rpc/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn node_info(
storage: Store,
local_node: Node,
local_node_record: NodeRecord,
client_version: String,
) -> Result<Value, RpcErr> {
let enode_url = local_node.enode_url();
let enr_url = match local_node_record.enr_url() {
Expand All @@ -52,7 +53,7 @@ pub fn node_info(
enode: enode_url,
enr: enr_url,
id: hex::encode(Keccak256::digest(local_node.node_id.as_bytes())),
name: "ethrex/0.1.0/rust1.82".to_string(),
name: client_version,
ip: local_node.ip.to_string(),
ports: Ports {
discovery: local_node.udp_port,
Expand Down
1 change: 0 additions & 1 deletion crates/networking/rpc/eth/gas_price.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::eth::fee_calculator::estimate_gas_tip;

use crate::rpc::{RpcApiContext, RpcHandler};
use crate::utils::RpcErr;
use serde_json::Value;
Expand Down
1 change: 1 addition & 0 deletions crates/networking/rpc/eth/max_priority_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mod tests {
local_node_record: example_local_node_record(),
active_filters: Default::default(),
syncer: Arc::new(SyncManager::dummy()),
client_version: "ethrex/test".to_string(),
#[cfg(feature = "based")]
gateway_eth_client: EthClient::new(""),
#[cfg(feature = "based")]
Expand Down
1 change: 0 additions & 1 deletion crates/networking/rpc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod eth;
pub mod l2;
mod net;
mod rpc;
mod web3;

pub mod clients;
pub mod types;
Expand Down
Loading