Skip to content
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

Persist light client updates #5545

Open
wants to merge 16 commits into
base: unstable
Choose a base branch
from

Conversation

eserilev
Copy link
Collaborator

@eserilev eserilev commented Apr 9, 2024

Issue Addressed

Partially #3651

Proposed Changes

This PR aims to persist light client updates. Once persisted, this will allow lighthouse nodes to serve them over RPC.

@eserilev eserilev added light-client work-in-progress PR is a work-in-progress labels Apr 9, 2024
.ok_or(BeaconChainError::DBInconsistent(format!(
"Attested state not available {:?}",
attested_block.state_root()
)))?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not acceptable w.r.t performance. You should extend the use of cached_parts such that you never have to get states from the store in the happy path. The function to generate updates in LightClientUpdate::new should not be used.

See this document for an implementation suggestion https://hackmd.io/@dapplion/BkxPbc6eQT

@eserilev eserilev added the ready-for-review The code is ready for review label May 27, 2024
@eserilev eserilev marked this pull request as ready for review May 27, 2024 18:03
@jimmygchen jimmygchen removed the work-in-progress PR is a work-in-progress label May 28, 2024
Copy link
Collaborator

@dapplion dapplion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! Two points:

We should run the specs tests for the is_better_update function, see here https://github.com/ethereum/consensus-specs/blob/dev/tests/formats/light_client/update_ranking.md

The function under which updates are computed only gets triggered for recent blocks. See

// Do not trigger light_client server update producer for old blocks, to extra work
// during sync.
if self.config.enable_light_client_server
&& block_delay_total < self.slot_clock.slot_duration() * 32
{

Now that the LC server computes recent updates AND full updates, the latter should include historical updates. Therefore we should be producing updates during forward range sync. Also for backfill sync, but that's a feature for another PR :)

@@ -152,6 +197,84 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
Ok(())
}

pub fn store_light_client_update(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can inline this function above

let should_persist_light_client_update = if let Some(prev_light_client_update) = prev_light_client_update {
    is_better_light_client_update(
        &prev_light_client_update,
        &new_light_client_update,
        chain_spec,
    )?
} else {
    true
} 

@@ -140,6 +151,40 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
signature_slot,
chain_spec,
)?);

let new_light_client_update = LightClientUpdate::new(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should not condition creating new LightClientUpdate on having a non-zero finalized_block_root. If the chain does not finalize for a full sync committee period we still need to produce them. Your is_better_light_client_update implementation covers the case of finalized vs non-finalized updates and will prioritize the finalized ones.

LightClientUpdate should be produced anytime we may be able to produce a better update

// Implements spec prioritization rules:
// Full nodes SHOULD provide the best derivable LightClientUpdate for each sync committee period
// ref: https://github.com/ethereum/consensus-specs/blob/113c58f9bf9c08867f6f5f633c4d98e0364d612a/specs/altair/light-client/full-node.md#create_light_client_update
fn is_better_light_client_update<E: EthSpec>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this implementation to the LightClientUpdate type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
light-client ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants