From 8124e5ca5a1f6b67a5137bfa25be18285d7b80ee Mon Sep 17 00:00:00 2001 From: JKincorperated <73645805+JKincorperated@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:01:36 +0000 Subject: [PATCH 1/5] Add eip7636 support --- beacon_node/lighthouse_network/src/config.rs | 4 ++++ .../lighthouse_network/src/discovery/enr.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs index 8a93b1185db..c376e7034ea 100644 --- a/beacon_node/lighthouse_network/src/config.rs +++ b/beacon_node/lighthouse_network/src/config.rs @@ -146,6 +146,9 @@ pub struct Config { /// Configuration for the minimum message size for which IDONTWANT messages are send in the mesh. /// Lower the value reduces the optimization effect of the IDONTWANT messages. pub idontwant_message_size_threshold: usize, + + /// Whether to send EIP 7636 information to clients. + pub send_eip_7636_info: bool, } impl Config { @@ -358,6 +361,7 @@ impl Default for Config { invalid_block_storage: None, inbound_rate_limiter_config: None, idontwant_message_size_threshold: DEFAULT_IDONTWANT_MESSAGE_SIZE_THRESHOLD, + send_eip_7636_info: true, } } } diff --git a/beacon_node/lighthouse_network/src/discovery/enr.rs b/beacon_node/lighthouse_network/src/discovery/enr.rs index ce29480ffdb..3e107ac5f4e 100644 --- a/beacon_node/lighthouse_network/src/discovery/enr.rs +++ b/beacon_node/lighthouse_network/src/discovery/enr.rs @@ -8,6 +8,7 @@ use crate::types::{Enr, EnrAttestationBitfield, EnrSyncCommitteeBitfield}; use crate::NetworkConfig; use alloy_rlp::bytes::Bytes; use libp2p::identity::Keypair; +use lighthouse_version::VERSION; use slog::{debug, warn}; use ssz::{Decode, Encode}; use ssz_types::BitVector; @@ -188,6 +189,19 @@ pub fn build_enr( builder.udp6(udp6_port.get()); } + // Add EIP 7636 client information + if config.send_eip_7636_info { + let version = VERSION.split("/").collect::>(); + builder.client_info( + version.first().unwrap_or(&"Lighthouse").to_string(), + version + .get(1) + .unwrap_or(&env!("CARGO_PKG_VERSION")) + .to_string(), + None, + ); + } + // Add QUIC fields to the ENR. // Since QUIC is used as an alternative transport for the libp2p protocols, // the related fields should only be added when both QUIC and libp2p are enabled From 440cb78098adbe4ecbc620aa31b6e52ee97d8f50 Mon Sep 17 00:00:00 2001 From: JKincorperated <73645805+JKincorperated@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:43:49 +0000 Subject: [PATCH 2/5] Add `version()` to the `lighthouse_version` crate and make the `enr.rs` file use it. --- .../lighthouse_network/src/discovery/enr.rs | 19 ++++++------ common/lighthouse_version/src/lib.rs | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/beacon_node/lighthouse_network/src/discovery/enr.rs b/beacon_node/lighthouse_network/src/discovery/enr.rs index 3e107ac5f4e..7e1022d9164 100644 --- a/beacon_node/lighthouse_network/src/discovery/enr.rs +++ b/beacon_node/lighthouse_network/src/discovery/enr.rs @@ -8,7 +8,7 @@ use crate::types::{Enr, EnrAttestationBitfield, EnrSyncCommitteeBitfield}; use crate::NetworkConfig; use alloy_rlp::bytes::Bytes; use libp2p::identity::Keypair; -use lighthouse_version::VERSION; +use lighthouse_version::{version, VERSION}; use slog::{debug, warn}; use ssz::{Decode, Encode}; use ssz_types::BitVector; @@ -191,15 +191,14 @@ pub fn build_enr( // Add EIP 7636 client information if config.send_eip_7636_info { - let version = VERSION.split("/").collect::>(); - builder.client_info( - version.first().unwrap_or(&"Lighthouse").to_string(), - version - .get(1) - .unwrap_or(&env!("CARGO_PKG_VERSION")) - .to_string(), - None, - ); + let name = VERSION + .split("/") + .collect::>() + .first() + .unwrap_or(&"Lighthouse") + .to_string(); + + builder.client_info(name, version().to_string(), None); } // Add QUIC fields to the ENR. diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs index 0751bdadff5..7d466afacbc 100644 --- a/common/lighthouse_version/src/lib.rs +++ b/common/lighthouse_version/src/lib.rs @@ -48,6 +48,25 @@ pub fn version_with_platform() -> String { format!("{}/{}-{}", VERSION, Target::arch(), Target::os()) } +/// Returns semantic versioning information only. +/// +/// ## Example +/// +/// `1.5.1` +pub fn version() -> &'static str { + let mut out = ""; + let mut start = 0; + for (i, c) in VERSION.chars().enumerate() { + if c == '-' { + break; + } else if c == 'v' { + start = i + 1; + } + out = &VERSION[start..i + 1]; + } + out +} + #[cfg(test)] mod test { use super::*; @@ -64,4 +83,14 @@ mod test { VERSION ); } + + #[test] + fn semantic_version_formatting() { + let re = Regex::new(r"^[0-9]+\.[0-9]+\.[0-9]+").unwrap(); + assert!( + re.is_match(version()), + "semantic version doesn't match regex: {}", + version() + ); + } } From 1dff56c64661687eb9ae1bbfca00dc1836c19bd3 Mon Sep 17 00:00:00 2001 From: JKincorperated Date: Mon, 13 Jan 2025 10:51:43 +0000 Subject: [PATCH 3/5] Hardcode version, Add `client_name()`, remove unneeded flag. --- beacon_node/lighthouse_network/src/config.rs | 7 ++----- .../lighthouse_network/src/discovery/enr.rs | 4 ++-- common/lighthouse_version/src/lib.rs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs index c376e7034ea..55c1dbf491d 100644 --- a/beacon_node/lighthouse_network/src/config.rs +++ b/beacon_node/lighthouse_network/src/config.rs @@ -116,7 +116,8 @@ pub struct Config { pub network_load: u8, /// Indicates if the user has set the network to be in private mode. Currently this - /// prevents sending client identifying information over identify. + /// prevents sending client identifying information over identify and prevents + /// EIP-7636 indentifiable information being provided in the ENR. pub private: bool, /// Shutdown beacon node after sync is completed. @@ -146,9 +147,6 @@ pub struct Config { /// Configuration for the minimum message size for which IDONTWANT messages are send in the mesh. /// Lower the value reduces the optimization effect of the IDONTWANT messages. pub idontwant_message_size_threshold: usize, - - /// Whether to send EIP 7636 information to clients. - pub send_eip_7636_info: bool, } impl Config { @@ -361,7 +359,6 @@ impl Default for Config { invalid_block_storage: None, inbound_rate_limiter_config: None, idontwant_message_size_threshold: DEFAULT_IDONTWANT_MESSAGE_SIZE_THRESHOLD, - send_eip_7636_info: true, } } } diff --git a/beacon_node/lighthouse_network/src/discovery/enr.rs b/beacon_node/lighthouse_network/src/discovery/enr.rs index 7e1022d9164..9c3c94c8303 100644 --- a/beacon_node/lighthouse_network/src/discovery/enr.rs +++ b/beacon_node/lighthouse_network/src/discovery/enr.rs @@ -8,7 +8,7 @@ use crate::types::{Enr, EnrAttestationBitfield, EnrSyncCommitteeBitfield}; use crate::NetworkConfig; use alloy_rlp::bytes::Bytes; use libp2p::identity::Keypair; -use lighthouse_version::{version, VERSION}; +use lighthouse_version::{version, client_name}; use slog::{debug, warn}; use ssz::{Decode, Encode}; use ssz_types::BitVector; @@ -190,7 +190,7 @@ pub fn build_enr( } // Add EIP 7636 client information - if config.send_eip_7636_info { + if !config.private { let name = VERSION .split("/") .collect::>() diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs index 7d466afacbc..3efd13790a6 100644 --- a/common/lighthouse_version/src/lib.rs +++ b/common/lighthouse_version/src/lib.rs @@ -54,19 +54,17 @@ pub fn version_with_platform() -> String { /// /// `1.5.1` pub fn version() -> &'static str { - let mut out = ""; - let mut start = 0; - for (i, c) in VERSION.chars().enumerate() { - if c == '-' { - break; - } else if c == 'v' { - start = i + 1; - } - out = &VERSION[start..i + 1]; - } - out + "6.0.1" } +/// Returns the name of the current client running. +/// +/// This will usually be "Lighthouse" +pub fn client_name() -> &'static str { + "Lighthouse" +} + + #[cfg(test)] mod test { use super::*; From 1b0919fcd42d3d49161922d53303a9bf08f5a367 Mon Sep 17 00:00:00 2001 From: JKincorperated Date: Mon, 13 Jan 2025 10:52:17 +0000 Subject: [PATCH 4/5] Make it use the new function. --- beacon_node/lighthouse_network/src/discovery/enr.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/beacon_node/lighthouse_network/src/discovery/enr.rs b/beacon_node/lighthouse_network/src/discovery/enr.rs index 9c3c94c8303..2539e2fb0e9 100644 --- a/beacon_node/lighthouse_network/src/discovery/enr.rs +++ b/beacon_node/lighthouse_network/src/discovery/enr.rs @@ -191,14 +191,7 @@ pub fn build_enr( // Add EIP 7636 client information if !config.private { - let name = VERSION - .split("/") - .collect::>() - .first() - .unwrap_or(&"Lighthouse") - .to_string(); - - builder.client_info(name, version().to_string(), None); + builder.client_info(client_name().to_string(), version().to_string(), None); } // Add QUIC fields to the ENR. From 39493158be5cd1ef0862d26047d5eb22d1e1e113 Mon Sep 17 00:00:00 2001 From: JKincorperated <73645805+JKincorperated@users.noreply.github.com> Date: Wed, 15 Jan 2025 10:59:19 +0000 Subject: [PATCH 5/5] Make cargo fmt zip it --- beacon_node/lighthouse_network/src/discovery/enr.rs | 2 +- common/lighthouse_version/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/beacon_node/lighthouse_network/src/discovery/enr.rs b/beacon_node/lighthouse_network/src/discovery/enr.rs index 2539e2fb0e9..46fbeab2579 100644 --- a/beacon_node/lighthouse_network/src/discovery/enr.rs +++ b/beacon_node/lighthouse_network/src/discovery/enr.rs @@ -8,7 +8,7 @@ use crate::types::{Enr, EnrAttestationBitfield, EnrSyncCommitteeBitfield}; use crate::NetworkConfig; use alloy_rlp::bytes::Bytes; use libp2p::identity::Keypair; -use lighthouse_version::{version, client_name}; +use lighthouse_version::{client_name, version}; use slog::{debug, warn}; use ssz::{Decode, Encode}; use ssz_types::BitVector; diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs index 3efd13790a6..a35b8c42c11 100644 --- a/common/lighthouse_version/src/lib.rs +++ b/common/lighthouse_version/src/lib.rs @@ -64,7 +64,6 @@ pub fn client_name() -> &'static str { "Lighthouse" } - #[cfg(test)] mod test { use super::*;