Skip to content

Send fcU before fully importing block #7745

@michaelsproul

Description

@michaelsproul

The Problem

Presently Lighthouse doesn't send fcU until after fully importing the block, here:

debug!(
?block_root,
%peer_id,
"Gossipsub block processed"
);
self.chain.recompute_head_at_current_slot().await;

The call to the EL happens from within that function, here-ish:

if let Err(e) = chain
.update_execution_engine_forkchoice(
current_slot,
forkchoice_update_params,
OverrideForkchoiceUpdate::Yes,
)
.await

The problem is, even with recent optimisations, these calls are happening after state diff computations and disk writes, which add 1s+ of latency.

Possible Solutions

Background thread for writes

We could add a dedicated background thread for finishing writes of BeaconStates to disk. This would allow import_block to complete sooner, and for the post-processing (like calling fork choice) to begin. This seems like it would be relatively simple to implement.

The added benefit is that we could also de-couple in-memory states from on-disk states, which would benefit the state advance timer as well. See:

Reorder fork choice update within import

Another option is to kick off a fork choice update at the point where we currently update the early attestation cache:

// If the block is recent enough and it was not optimistically imported, check to see if it
// becomes the head block. If so, apply it to the early attester cache. This will allow
// attestations to the block without waiting for the block and state to be inserted to the
// database.

That code is kind of messy and this might be a good opportunity to refactor it and clean it up.

Metadata

Metadata

Assignees

Labels

code-qualityoptimizationSomething to make Lighthouse run more efficiently.tree-statesOngoing state and database overhaul

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions