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

Faster head block lookup for attn verification #7010

Draft
wants to merge 2 commits into
base: unstable
Choose a base branch
from

Conversation

paulhauner
Copy link
Member

@paulhauner paulhauner commented Feb 19, 2025

Issue Addressed

NA

Proposed Changes

Reduce attestation process by several ms (approx 6ms in my experiments) by avoiding fork_choice.get_block when an attestation points to the canonical head.

When reading blocks from fork choice, we presently check to ensure the block is a known, valid descendant of (or equal to) the finalised checkpoint
with is_finalized_checkpoint_or_descendant. This involves some iterations through ancestors and can get somewhat expensive.

In this PR, I make the assumption that if the attestation head block is either:

  • our canonical head, or,
  • in our early attester cache

then it's safe to assume that the block is known, valid and descends from the finalised checkpoint. This negates the need to query fork_choice.get_block entirely.

This optimisation works for the "happy path" without adding additional cost to the "sad path". I.e., when the network is happy we expect all attestations to point to our head block, so we make consistent gainz. Conversely, when the network is sad and voting for another block, this optimisation won't help but it also won't hurt.

Additional Info

NA

TODO

  • Graphs to prove this is worthwhile.

@paulhauner paulhauner added work-in-progress PR is a work-in-progress optimization Something to make Lighthouse run more efficiently. labels Feb 19, 2025
@paulhauner paulhauner changed the base branch from stable to unstable February 19, 2025 02:25
@dapplion
Copy link
Collaborator

A related idea we discussed with @michaelsproul is to run a pruning routine with the finalized checkpoint advances such that the proto array only contains nodes that are descendants of finalized. Then those checks are no longer necessary.

@paulhauner
Copy link
Member Author

paulhauner commented Feb 19, 2025

A related idea we discussed with @michaelsproul is to run a pruning routine with the finalized checkpoint advances such that the proto array only contains nodes that are descendants of finalized. Then those checks are no longer necessary.

That makes sense, it would likely help other code paths too. I'd still expect that the change in this PR is useful (perhaps to a minor degree) as it reduces lock contention for fork_choice.

With the pruning routine, I wonder how we'd do that such that:

  1. It's 100% reliable that all nodes are finalised descendants, and,
  2. We don't add that pruning time onto the fork choice "insert block" path, which is important for attestation performance.

To satisfy (1) I would expect to run the pruning whenever we add a finality-inducing block to fork choice, however I think that would impact (2). Perhaps the impact is not too bad?

@dapplion
Copy link
Collaborator

That makes sense, it would likely help other code paths too. I'd still expect that the change in this PR is useful (perhaps to a minor degree) as it reduces lock contention for fork_choice.

Right

It's 100% reliable that all nodes are finalised descendants, and,

What type of challenges do you anticipate there?

We don't add that pruning time onto the fork choice "insert block" path, which is important for attestation performance.

That's the biggest issue yes. On a timely finalizing network we just need to iterate 96 nodes, maybe it's not too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Something to make Lighthouse run more efficiently. work-in-progress PR is a work-in-progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants