Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 1 addition & 45 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
21 changes: 11 additions & 10 deletions beacon_node/http_api/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
match accept_header {
Some(api_types::Accept::Ssz) => {
let response_chunks = light_client_updates
.iter()
.map(|update| map_light_client_update_to_ssz_chunk::<T>(&chain, update))
.collect::<Vec<LightClientUpdateResponseChunk>>();
.into_iter()
.flat_map(|update| {
map_light_client_update_to_response_chunk::<T>(&chain, update).as_ssz_bytes()
})
.collect();

Response::builder()
.status(200)
.body(response_chunks.as_ssz_bytes())
.body(response_chunks)
.map(|res: Response<Vec<u8>>| add_ssz_content_type_header(res))
.map_err(|e| {
warp_utils::reject::custom_server_error(format!(
Expand Down Expand Up @@ -146,21 +148,20 @@ pub fn validate_light_client_updates_request<T: BeaconChainTypes>(
Ok(())
}

fn map_light_client_update_to_ssz_chunk<T: BeaconChainTypes>(
fn map_light_client_update_to_response_chunk<T: BeaconChainTypes>(
chain: &BeaconChain<T>,
light_client_update: &LightClientUpdate<T::EthSpec>,
) -> LightClientUpdateResponseChunk {
light_client_update: LightClientUpdate<T::EthSpec>,
) -> LightClientUpdateResponseChunk<T::EthSpec> {
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,
};

LightClientUpdateResponseChunk {
Expand Down
20 changes: 20 additions & 0 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,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::<E>(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
Expand Down Expand Up @@ -7073,6 +7091,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;
}

Expand Down
26 changes: 26 additions & 0 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E: EthSpec>(
&self,
start_period: u64,
count: u64,
) -> Result<Option<Vec<u8>>, 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.default)
.await
}

/// `GET beacon/light_client/bootstrap`
///
/// Returns `Ok(None)` on a 404 error.
Expand Down
29 changes: 23 additions & 6 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -823,16 +824,32 @@ pub struct LightClientUpdatesQuery {
pub count: u64,
}

#[derive(Encode, Decode)]
pub struct LightClientUpdateResponseChunk {
pub struct LightClientUpdateResponseChunk<E: EthSpec> {
pub response_chunk_len: u64,
pub response_chunk: LightClientUpdateResponseChunkInner,
pub response_chunk: LightClientUpdateResponseChunkInner<E>,
}

#[derive(Encode, Decode)]
pub struct LightClientUpdateResponseChunkInner {
impl<E: EthSpec> Encode for LightClientUpdateResponseChunk<E> {
fn is_ssz_fixed_len() -> bool {
false
}

fn ssz_bytes_len(&self) -> usize {
0_u64.ssz_bytes_len()
+ self.response_chunk.context.len()
+ self.response_chunk.payload.ssz_bytes_len()
}

fn ssz_append(&self, buf: &mut Vec<u8>) {
buf.extend_from_slice(&self.response_chunk_len.to_le_bytes());
buf.extend_from_slice(&self.response_chunk.context);
self.response_chunk.payload.ssz_append(buf);
}
}

pub struct LightClientUpdateResponseChunkInner<E: EthSpec> {
pub context: [u8; 4],
pub payload: Vec<u8>,
pub payload: LightClientUpdate<E>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
Expand Down
1 change: 0 additions & 1 deletion consensus/state_processing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ types = { workspace = true }

[dev-dependencies]
beacon_chain = { workspace = true }
env_logger = { workspace = true }
tokio = { workspace = true }
3 changes: 0 additions & 3 deletions consensus/state_processing/src/per_epoch_processing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
18 changes: 14 additions & 4 deletions lcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -653,7 +651,7 @@ fn main() {
}

fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, 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))?
Expand Down Expand Up @@ -682,6 +680,18 @@ fn run<E: EthSpec>(env_builder: EnvironmentBuilder<E>, 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::<PathBuf>(matches, "testnet-dir")? {
Expand Down
Loading