Fast path for /eth/v1/beacon/blocks/head/root (#8729)

Closes:

- https://github.com/sigp/lighthouse/issues/8667


  Use the `early_attester_cache` to serve the head block root (if present). This should be faster than waiting for the head to finish importing.


Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
Michael Sproul
2026-02-02 17:41:43 +11:00
committed by GitHub
parent 3ecf964385
commit 940fa81a5b
2 changed files with 30 additions and 1 deletions

View File

@@ -254,4 +254,12 @@ impl<E: EthSpec> EarlyAttesterCache<E> {
.filter(|item| item.beacon_block_root == block_root)
.map(|item| item.proto_block.clone())
}
/// Fetch the slot and block root of the current head block.
pub fn get_head_block_root(&self) -> Option<(Slot, Hash256)> {
self.item
.read()
.as_ref()
.map(|item| (item.block.slot(), item.beacon_block_root))
}
}