From 8de9157716de9eaf5fd598c7a1dec7628c85cdd6 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Mon, 28 Jul 2025 09:55:09 -0700 Subject: [PATCH 1/5] fix ssz formatting --- beacon_node/http_api/src/light_client.rs | 23 ++++++++------ beacon_node/http_api/tests/tests.rs | 20 ++++++++++++ common/eth2/src/lib.rs | 26 +++++++++++++++ common/eth2/src/types.rs | 40 ++++++++++++++++++++---- 4 files changed, 93 insertions(+), 16 deletions(-) diff --git a/beacon_node/http_api/src/light_client.rs b/beacon_node/http_api/src/light_client.rs index f9559d738ea..1b97191bdc1 100644 --- a/beacon_node/http_api/src/light_client.rs +++ b/beacon_node/http_api/src/light_client.rs @@ -34,13 +34,15 @@ pub fn get_light_client_updates( match accept_header { Some(api_types::Accept::Ssz) => { let response_chunks = light_client_updates - .iter() - .map(|update| map_light_client_update_to_ssz_chunk::(&chain, update)) - .collect::>(); + .into_iter() + .flat_map(|update| { + map_light_client_update_to_response_chunk::(&chain, update).as_ssz_bytes() + }) + .collect(); Response::builder() .status(200) - .body(response_chunks.as_ssz_bytes()) + .body(response_chunks) .map(|res: Response>| add_ssz_content_type_header(res)) .map_err(|e| { warp_utils::reject::custom_server_error(format!( @@ -146,23 +148,24 @@ pub fn validate_light_client_updates_request( Ok(()) } -fn map_light_client_update_to_ssz_chunk( +fn map_light_client_update_to_response_chunk( chain: &BeaconChain, - light_client_update: &LightClientUpdate, -) -> LightClientUpdateResponseChunk { + light_client_update: LightClientUpdate, +) -> LightClientUpdateResponseChunk { let epoch = light_client_update .attested_header_slot() .epoch(T::EthSpec::slots_per_epoch()); let fork_digest = chain.compute_fork_digest(epoch); - let payload = light_client_update.as_ssz_bytes(); - let response_chunk_len = fork_digest.len() + payload.len(); + let response_chunk_len = fork_digest.len() + light_client_update.ssz_bytes_len(); let response_chunk = LightClientUpdateResponseChunkInner { context: fork_digest, - payload, + payload: light_client_update, }; + println!("response chunk len {:?}", response_chunk_len); + LightClientUpdateResponseChunk { response_chunk_len: response_chunk_len as u64, response_chunk, diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 5ac8cd91864..cceb1566468 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -2213,6 +2213,24 @@ impl ApiTester { self } + pub async fn test_get_beacon_light_client_updates_ssz(self) -> Self { + let current_epoch = self.chain.epoch().unwrap(); + let current_sync_committee_period = current_epoch + .sync_committee_period(&self.chain.spec) + .unwrap(); + + match self + .client + .get_beacon_light_client_updates_ssz::(current_sync_committee_period, 1) + .await + { + Ok(result) => result, + Err(e) => panic!("query failed incorrectly: {e:?}"), + }; + + self + } + pub async fn test_get_beacon_light_client_updates(self) -> Self { let current_epoch = self.chain.epoch().unwrap(); let current_sync_committee_period = current_epoch @@ -7048,6 +7066,8 @@ async fn get_light_client_updates() { ApiTester::new_from_config(config) .await .test_get_beacon_light_client_updates() + .await + .test_get_beacon_light_client_updates_ssz() .await; } diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index a129f9c4fa5..6b0c6824fd8 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -981,6 +981,32 @@ impl BeaconNodeHttpClient { }) } + /// `GET beacon/light_client/updates` + /// + /// Returns `Ok(None)` on a 404 error. + pub async fn get_beacon_light_client_updates_ssz( + &self, + start_period: u64, + count: u64, + ) -> Result>, Error> { + let mut path = self.eth_path(V1)?; + + path.path_segments_mut() + .map_err(|()| Error::InvalidUrl(self.server.clone()))? + .push("beacon") + .push("light_client") + .push("updates"); + + path.query_pairs_mut() + .append_pair("start_period", &start_period.to_string()); + + path.query_pairs_mut() + .append_pair("count", &count.to_string()); + + self.get_bytes_opt_accept_header(path, Accept::Ssz, self.timeouts.get_beacon_blocks_ssz) + .await + } + /// `GET beacon/light_client/bootstrap` /// /// Returns `Ok(None)` on a 404 error. diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 07b5cb50166..1186c318ab6 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -11,6 +11,7 @@ use multiaddr::Multiaddr; use reqwest::header::HeaderMap; use serde::{Deserialize, Deserializer, Serialize}; use serde_utils::quoted_u64::Quoted; +use ssz::Encode; use ssz::{Decode, DecodeError}; use ssz_derive::{Decode, Encode}; use std::fmt::{self, Display}; @@ -823,16 +824,43 @@ pub struct LightClientUpdatesQuery { pub count: u64, } -#[derive(Encode, Decode)] -pub struct LightClientUpdateResponseChunk { +pub struct LightClientUpdateResponseChunk { pub response_chunk_len: u64, - pub response_chunk: LightClientUpdateResponseChunkInner, + pub response_chunk: LightClientUpdateResponseChunkInner, } -#[derive(Encode, Decode)] -pub struct LightClientUpdateResponseChunkInner { +impl Encode for LightClientUpdateResponseChunk { + fn is_ssz_fixed_len() -> bool { + false + } + + fn ssz_bytes_len(&self) -> usize { + 0_u64.ssz_bytes_len() + self.response_chunk.context.len() + + match &self.response_chunk.payload { + LightClientUpdate::Altair(lc) => lc.ssz_bytes_len(), + LightClientUpdate::Capella(lc) => lc.ssz_bytes_len(), + LightClientUpdate::Deneb(lc) => lc.ssz_bytes_len(), + LightClientUpdate::Electra(lc) => lc.ssz_bytes_len(), + LightClientUpdate::Fulu(lc) => lc.ssz_bytes_len(), + } + } + + fn ssz_append(&self, buf: &mut Vec) { + buf.extend_from_slice(&self.response_chunk_len.to_le_bytes()); + buf.extend_from_slice(&self.response_chunk.context); + match &self.response_chunk.payload { + LightClientUpdate::Altair(lc) => lc.ssz_append(buf), + LightClientUpdate::Capella(lc) => lc.ssz_append(buf), + LightClientUpdate::Deneb(lc) => lc.ssz_append(buf), + LightClientUpdate::Electra(lc) => lc.ssz_append(buf), + LightClientUpdate::Fulu(lc) => lc.ssz_append(buf), + }; + } +} + +pub struct LightClientUpdateResponseChunkInner { pub context: [u8; 4], - pub payload: Vec, + pub payload: LightClientUpdate, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)] From 0165b6eb83a88bb449d4dd95212497116773f9fa Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Tue, 29 Jul 2025 11:24:07 -0700 Subject: [PATCH 2/5] fmt --- common/eth2/src/types.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index 1186c318ab6..d86d311b0e1 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -835,7 +835,8 @@ impl Encode for LightClientUpdateResponseChunk { } fn ssz_bytes_len(&self) -> usize { - 0_u64.ssz_bytes_len() + self.response_chunk.context.len() + 0_u64.ssz_bytes_len() + + self.response_chunk.context.len() + match &self.response_chunk.payload { LightClientUpdate::Altair(lc) => lc.ssz_bytes_len(), LightClientUpdate::Capella(lc) => lc.ssz_bytes_len(), From ce33753b77398bb127690fd114d6293e0a77277a Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Tue, 5 Aug 2025 14:30:08 -0700 Subject: [PATCH 3/5] remove print --- beacon_node/http_api/src/light_client.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/beacon_node/http_api/src/light_client.rs b/beacon_node/http_api/src/light_client.rs index 1b97191bdc1..8fd47c52f29 100644 --- a/beacon_node/http_api/src/light_client.rs +++ b/beacon_node/http_api/src/light_client.rs @@ -164,8 +164,6 @@ fn map_light_client_update_to_response_chunk( payload: light_client_update, }; - println!("response chunk len {:?}", response_chunk_len); - LightClientUpdateResponseChunk { response_chunk_len: response_chunk_len as u64, response_chunk, From 67b45a9ea6b15d710e028a184879b1fbf96dbbe6 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Tue, 12 Aug 2025 17:42:28 -0700 Subject: [PATCH 4/5] clean up --- common/eth2/src/lib.rs | 2 +- common/eth2/src/types.rs | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index 6b0c6824fd8..bf0694dcedd 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -1003,7 +1003,7 @@ impl BeaconNodeHttpClient { path.query_pairs_mut() .append_pair("count", &count.to_string()); - self.get_bytes_opt_accept_header(path, Accept::Ssz, self.timeouts.get_beacon_blocks_ssz) + self.get_bytes_opt_accept_header(path, Accept::Ssz, self.timeouts.default) .await } diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index d86d311b0e1..0a60d0bc73a 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -837,25 +837,13 @@ impl Encode for LightClientUpdateResponseChunk { fn ssz_bytes_len(&self) -> usize { 0_u64.ssz_bytes_len() + self.response_chunk.context.len() - + match &self.response_chunk.payload { - LightClientUpdate::Altair(lc) => lc.ssz_bytes_len(), - LightClientUpdate::Capella(lc) => lc.ssz_bytes_len(), - LightClientUpdate::Deneb(lc) => lc.ssz_bytes_len(), - LightClientUpdate::Electra(lc) => lc.ssz_bytes_len(), - LightClientUpdate::Fulu(lc) => lc.ssz_bytes_len(), - } + + self.response_chunk.payload.ssz_bytes_len() } fn ssz_append(&self, buf: &mut Vec) { buf.extend_from_slice(&self.response_chunk_len.to_le_bytes()); buf.extend_from_slice(&self.response_chunk.context); - match &self.response_chunk.payload { - LightClientUpdate::Altair(lc) => lc.ssz_append(buf), - LightClientUpdate::Capella(lc) => lc.ssz_append(buf), - LightClientUpdate::Deneb(lc) => lc.ssz_append(buf), - LightClientUpdate::Electra(lc) => lc.ssz_append(buf), - LightClientUpdate::Fulu(lc) => lc.ssz_append(buf), - }; + self.response_chunk.payload.ssz_append(buf); } } From cd12c14847f0d354c4abd739fb97bcc69ac03d80 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 13 Aug 2025 14:10:56 +1000 Subject: [PATCH 5/5] Yeet env_logger into the sun --- Cargo.lock | 46 +------------------ Cargo.toml | 1 - consensus/state_processing/Cargo.toml | 1 - .../src/per_epoch_processing/tests.rs | 3 -- lcli/Cargo.toml | 1 - lcli/src/main.rs | 18 ++++++-- 6 files changed, 15 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8e4f1bd056..79d332f9ea4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -709,17 +709,6 @@ dependencies = [ "url", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "auto_impl" version = "0.5.0" @@ -2743,19 +2732,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "environment" version = "0.1.2" @@ -4054,15 +4030,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -5058,7 +5025,6 @@ dependencies = [ "clap", "clap_utils", "deposit_contract", - "env_logger 0.9.3", "environment", "eth2", "eth2_network_config", @@ -7491,7 +7457,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ - "env_logger 0.8.4", + "env_logger", "log", "rand 0.8.5", ] @@ -8961,7 +8927,6 @@ dependencies = [ "beacon_chain", "bls", "derivative", - "env_logger 0.9.3", "ethereum_hashing", "ethereum_ssz", "ethereum_ssz_derive", @@ -9262,15 +9227,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "terminal_size" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index 38edb126a03..087cab6f8b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,6 @@ dirs = "3" discv5 = { version = "0.9", features = ["libp2p"] } doppelganger_service = { path = "validator_client/doppelganger_service" } either = "1.9" -env_logger = "0.9" environment = { path = "lighthouse/environment" } eth2 = { path = "common/eth2" } eth2_config = { path = "common/eth2_config" } diff --git a/consensus/state_processing/Cargo.toml b/consensus/state_processing/Cargo.toml index 3acf491f23e..fc55bde9c67 100644 --- a/consensus/state_processing/Cargo.toml +++ b/consensus/state_processing/Cargo.toml @@ -41,5 +41,4 @@ types = { workspace = true } [dev-dependencies] beacon_chain = { workspace = true } -env_logger = { workspace = true } tokio = { workspace = true } diff --git a/consensus/state_processing/src/per_epoch_processing/tests.rs b/consensus/state_processing/src/per_epoch_processing/tests.rs index 6dd3f316c13..f042e8766c6 100644 --- a/consensus/state_processing/src/per_epoch_processing/tests.rs +++ b/consensus/state_processing/src/per_epoch_processing/tests.rs @@ -3,13 +3,10 @@ use crate::per_epoch_processing::process_epoch; use beacon_chain::test_utils::BeaconChainHarness; use beacon_chain::types::{EthSpec, MinimalEthSpec}; use bls::{FixedBytesExtended, Hash256}; -use env_logger::{Builder, Env}; use types::Slot; #[tokio::test] async fn runs_without_error() { - Builder::from_env(Env::default().default_filter_or("error")).init(); - let harness = BeaconChainHarness::builder(MinimalEthSpec) .default_spec() .deterministic_keypairs(8) diff --git a/lcli/Cargo.toml b/lcli/Cargo.toml index a54c10dc680..a95b45089ce 100644 --- a/lcli/Cargo.toml +++ b/lcli/Cargo.toml @@ -20,7 +20,6 @@ bls = { workspace = true } clap = { workspace = true } clap_utils = { workspace = true } deposit_contract = { workspace = true } -env_logger = { workspace = true } environment = { workspace = true } eth2 = { workspace = true } eth2_network_config = { workspace = true } diff --git a/lcli/src/main.rs b/lcli/src/main.rs index fb471914dab..a21dfd4386c 100644 --- a/lcli/src/main.rs +++ b/lcli/src/main.rs @@ -18,12 +18,10 @@ use parse_ssz::run_parse_ssz; use std::path::PathBuf; use std::process; use std::str::FromStr; -use tracing_subscriber::filter::LevelFilter; +use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, util::SubscriberInitExt}; use types::{EthSpec, EthSpecId}; fn main() { - env_logger::init(); - let matches = Command::new("Lighthouse CLI Tool") .version(lighthouse_version::VERSION) .display_order(0) @@ -653,7 +651,7 @@ fn main() { } fn run(env_builder: EnvironmentBuilder, matches: &ArgMatches) -> Result<(), String> { - let (env_builder, _file_logging_layer, _stdout_logging_layer, _sse_logging_layer_opt) = + let (env_builder, file_logging_layer, stdout_logging_layer, _sse_logging_layer_opt) = env_builder .multi_threaded_tokio_runtime() .map_err(|e| format!("should start tokio runtime: {:?}", e))? @@ -682,6 +680,18 @@ fn run(env_builder: EnvironmentBuilder, matches: &ArgMatches) -> .build() .map_err(|e| format!("should build env: {:?}", e))?; + let mut logging_layers = vec![file_logging_layer]; + if let Some(stdout) = stdout_logging_layer { + logging_layers.push(stdout); + } + let logging_result = tracing_subscriber::registry() + .with(logging_layers) + .try_init(); + + if let Err(e) = logging_result { + eprintln!("Failed to initialize logger: {e}"); + } + // Determine testnet-dir path or network name depending on CLI flags. let (testnet_dir, network_name) = if let Some(testnet_dir) = parse_optional::(matches, "testnet-dir")? {