Skip to content

Commit 96d0db9

Browse files
committed
Gossip recently computed light client data (#7023)
Squashed commit of the following: commit 7b861ac Author: Eitan Seri-Levi <[email protected]> Date: Sun Jun 22 17:14:32 2025 +0300 / commit 8ca4ec1 Merge: 08510b9 d509246 Author: Eitan Seri-Levi <[email protected]> Date: Sun Jun 22 16:51:15 2025 +0300 Merge branch 'unstable' of https://github.com/sigp/lighthouse into gossip-light-client-updates commit 08510b9 Merge: e7614a2 54f7bc5 Author: Eitan Seri-Levi <[email protected]> Date: Mon Apr 21 16:36:20 2025 -0700 Merge branch 'release-v7.0.0' into gossip-light-client-updates commit e7614a2 Merge: a2b2eb3 c7acffc Author: Eitan Seri-Levi <[email protected]> Date: Sun Apr 20 10:19:47 2025 -0700 Merge branch 'release-v7.0.0' into gossip-light-client-updates commit a2b2eb3 Merge: d223840 8ce9edc Author: Eitan Seri-Levi <[email protected]> Date: Mon Mar 17 09:25:32 2025 -0600 Merge branch 'release-v7.0.0' into gossip-light-client-updates commit d223840 Merge: 75f00af 522b3cb Author: Eitan Seri-Levi <[email protected]> Date: Sun Feb 23 21:17:25 2025 -0800 Merge branch 'release-v7.0.0' of https://github.com/sigp/lighthouse into gossip-light-client-updates commit 75f00af Author: Eitan Seri-Levi <[email protected]> Date: Sun Feb 23 21:04:07 2025 -0800 fix commit b51196e Author: Eitan Seri-Levi <[email protected]> Date: Sun Feb 23 16:41:27 2025 -0800 fix comments commit f99fef7 Author: Eitan Seri-Levi <[email protected]> Date: Sun Feb 23 16:39:08 2025 -0800 gossip light client data durnig sync committee contributions commit 29b5614 Author: Eitan Seri-Levi <[email protected]> Date: Fri Feb 21 06:53:54 2025 -0800 add logic to gossip light client updates post computation
1 parent 90ce541 commit 96d0db9

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

beacon_node/beacon_chain/src/light_client_server_cache.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ pub struct LightClientServerCache<T: BeaconChainTypes> {
4040
latest_written_current_sync_committee: RwLock<Option<Arc<SyncCommittee<T::EthSpec>>>>,
4141
/// Caches state proofs by block root
4242
prev_block_cache: Mutex<lru::LruCache<Hash256, LightClientCachedData<T::EthSpec>>>,
43+
/// Tracks the latest broadcasted finality update
44+
latest_broadcasted_finality_update: RwLock<Option<LightClientFinalityUpdate<T::EthSpec>>>,
45+
/// Tracks the latest broadcasted optimistic update
46+
latest_broadcasted_optimistic_update: RwLock<Option<LightClientOptimisticUpdate<T::EthSpec>>>,
4347
}
4448

4549
impl<T: BeaconChainTypes> LightClientServerCache<T> {
@@ -49,6 +53,8 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
4953
latest_optimistic_update: None.into(),
5054
latest_light_client_update: None.into(),
5155
latest_written_current_sync_committee: None.into(),
56+
latest_broadcasted_finality_update: None.into(),
57+
latest_broadcasted_optimistic_update: None.into(),
5258
prev_block_cache: lru::LruCache::new(PREV_BLOCK_CACHE_SIZE).into(),
5359
}
5460
}
@@ -334,10 +340,65 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
334340
Ok(new_value)
335341
}
336342

343+
/// Checks if we've already broadcasted the latest finality update.
344+
/// If we haven't, update the `latest_broadcasted_finality_update` cache
345+
/// and return the latest finality update for broadcasting, else return `None`.
346+
pub fn should_broadcast_latest_finality_update(
347+
&self,
348+
) -> Option<LightClientFinalityUpdate<T::EthSpec>> {
349+
if let Some(latest_finality_update) = self.get_latest_finality_update() {
350+
let latest_broadcasted_finality_update =
351+
self.latest_broadcasted_finality_update.read().clone();
352+
match latest_broadcasted_finality_update {
353+
Some(latest_broadcasted_finality_update) => {
354+
if latest_broadcasted_finality_update != latest_finality_update {
355+
*self.latest_broadcasted_finality_update.write() =
356+
Some(latest_finality_update.clone());
357+
return Some(latest_finality_update);
358+
}
359+
}
360+
None => {
361+
*self.latest_broadcasted_finality_update.write() =
362+
Some(latest_finality_update.clone());
363+
return Some(latest_finality_update);
364+
}
365+
}
366+
}
367+
368+
None
369+
}
370+
337371
pub fn get_latest_finality_update(&self) -> Option<LightClientFinalityUpdate<T::EthSpec>> {
338372
self.latest_finality_update.read().clone()
339373
}
340374

375+
/// Checks if we've already broadcasted the latest optimistic update.
376+
/// If we haven't, update the `latest_broadcasted_optimistic_update` cache
377+
/// and return the latest optimistic update for broadcasting, else return `None`.
378+
pub fn should_broadcast_latest_optimistic_update(
379+
&self,
380+
) -> Option<LightClientOptimisticUpdate<T::EthSpec>> {
381+
if let Some(latest_optimistic_update) = self.get_latest_optimistic_update() {
382+
let latest_broadcasted_optimistic_update = self.latest_optimistic_update.read().clone();
383+
match latest_broadcasted_optimistic_update {
384+
Some(latest_broadcasted_optimistic_update) => {
385+
if latest_broadcasted_optimistic_update != latest_optimistic_update {
386+
*self.latest_broadcasted_optimistic_update.write() =
387+
Some(latest_optimistic_update.clone());
388+
return Some(latest_optimistic_update);
389+
}
390+
}
391+
None => {
392+
*self.latest_broadcasted_optimistic_update.write() =
393+
Some(latest_optimistic_update.clone());
394+
return Some(latest_optimistic_update);
395+
}
396+
}
397+
}
398+
399+
None
400+
}
401+
341402
pub fn get_latest_optimistic_update(&self) -> Option<LightClientOptimisticUpdate<T::EthSpec>> {
342403
self.latest_optimistic_update.read().clone()
343404
}

beacon_node/http_api/src/sync_committees.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,38 @@ pub fn process_signed_contribution_and_proofs<T: BeaconChainTypes>(
320320

321321
let seen_timestamp = timestamp_now();
322322

323+
if let Some(latest_optimistic_update) = chain
324+
.light_client_server_cache
325+
.should_broadcast_latest_optimistic_update()
326+
{
327+
let _ = publish_pubsub_message(
328+
&network_tx,
329+
PubsubMessage::LightClientOptimisticUpdate(Box::new(latest_optimistic_update)),
330+
)
331+
.inspect_err(|e| {
332+
error!(
333+
error = ?e,
334+
"Unable to broadcast latest light client optimistic update"
335+
);
336+
});
337+
};
338+
339+
if let Some(latest_finality_update) = chain
340+
.light_client_server_cache
341+
.should_broadcast_latest_finality_update()
342+
{
343+
let _ = publish_pubsub_message(
344+
&network_tx,
345+
PubsubMessage::LightClientFinalityUpdate(Box::new(latest_finality_update)),
346+
)
347+
.inspect_err(|e| {
348+
error!(
349+
error = ?e,
350+
"Unable to broadcast latest light client finality update"
351+
);
352+
});
353+
};
354+
323355
// Verify contributions & broadcast to the network.
324356
for (index, contribution) in signed_contribution_and_proofs.into_iter().enumerate() {
325357
let aggregator_index = contribution.message.aggregator_index;

beacon_node/store/src/hot_cold_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ pub fn get_ancestor_state_root<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStor
35383538
.get_cold_state_root(target_slot)
35393539
.map_err(Box::new)
35403540
.map_err(StateSummaryIteratorError::LoadStateRootError)?
3541-
.ok_or_else(|| StateSummaryIteratorError::MissingStateRoot {
3541+
.ok_or(StateSummaryIteratorError::MissingStateRoot {
35423542
target_slot,
35433543
state_upper_limit,
35443544
});

0 commit comments

Comments
 (0)