Faster head block lookup for attn verification #7010
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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