Skip to content

Conversation

@michaelsproul
Copy link
Member

Issue Addressed

Attempt to address performance issues caused by importing the same block multiple times.

Proposed Changes

  • Check fork choice "after" obtaining the fork choice write lock in BeaconChain::import_block. We actually use an upgradable read lock, but this is semantically equivalent (the upgradable read has the advantage of not excluding regular reads).

The hope is that this change has several benefits:

  1. By preventing duplicate block imports we save time repeating work inside import_block that is unnecessary, e.g. writing the state to disk. Although the store itself now takes some measures to avoid re-writing diffs, it is even better if we avoid a disk write entirely.
  2. By returning DuplicateFullyImported, we reduce some duplicated work downstream. E.g. if multiple threads importing columns trigger import_block, now only one of them will get a notification of the block import completing successfully, and only this one will run recompute_head. This should help avoid a situation where multiple beacon processor workers are consumed by threads blocking on the recompute_head_lock. However, a similar block-fest is still possible with the upgradable fork choice lock (a large number of threads can be blocked waiting for the first thread to complete block import).

Additional Info

Longer term this will likely be obsoleted by @ethDreamer's block status tracker.

@michaelsproul michaelsproul added optimization Something to make Lighthouse run more efficiently. fulu Required for the upcoming Fulu hard fork labels Sep 16, 2025
@jimmygchen jimmygchen added the ready-for-merge This PR is ready to merge. label Sep 16, 2025
@mergify mergify bot merged commit f04d5ec into unstable Sep 16, 2025
37 checks passed
@mergify mergify bot deleted the duplicate-block-check branch September 16, 2025 04:10
jtraglia pushed a commit to jtraglia/lighthouse that referenced this pull request Sep 16, 2025
Attempt to address performance issues caused by importing the same block multiple times.


  - Check fork choice "after" obtaining the fork choice write lock in `BeaconChain::import_block`. We actually use an upgradable read lock, but this is semantically equivalent (the upgradable read has the advantage of not excluding regular reads).

The hope is that this change has several benefits:

1. By preventing duplicate block imports we save time repeating work inside `import_block` that is unnecessary, e.g. writing the state to disk. Although the store itself now takes some measures to avoid re-writing diffs, it is even better if we avoid a disk write entirely.
2. By returning `DuplicateFullyImported`, we reduce some duplicated work downstream. E.g. if multiple threads importing columns trigger `import_block`, now only _one_ of them will get a notification of the block import completing successfully, and only this one will run `recompute_head`. This should help avoid a situation where multiple beacon processor workers are consumed by threads blocking on the `recompute_head_lock`. However, a similar block-fest is still possible with the upgradable fork choice lock (a large number of threads can be blocked waiting for the first thread to complete block import).


Co-Authored-By: Michael Sproul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fulu Required for the upcoming Fulu hard fork optimization Something to make Lighthouse run more efficiently. ready-for-merge This PR is ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants