mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
404's on API requests for slots that have been skipped or orphaned (#2272)
## Issue Addressed Resolves #2186 ## Proposed Changes 404 for any block-related information on a slot that was skipped or orphaned Affected endpoints: - `/eth/v1/beacon/blocks/{block_id}` - `/eth/v1/beacon/blocks/{block_id}/root` - `/eth/v1/beacon/blocks/{block_id}/attestations` - `/eth/v1/beacon/headers/{block_id}` ## Additional Info Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -520,14 +520,20 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
}
|
||||
|
||||
/// Returns the block root at the given slot, if any. Only returns roots in the canonical chain.
|
||||
/// Returns `Ok(None)` if the given `Slot` was skipped.
|
||||
///
|
||||
/// ## Errors
|
||||
///
|
||||
/// May return a database error.
|
||||
pub fn block_root_at_slot(&self, slot: Slot) -> Result<Option<Hash256>, Error> {
|
||||
process_results(self.rev_iter_block_roots()?, |mut iter| {
|
||||
iter.find(|(_, this_slot)| *this_slot == slot)
|
||||
.map(|(root, _)| root)
|
||||
let root_opt = iter
|
||||
.find(|(_, this_slot)| *this_slot == slot)
|
||||
.map(|(root, _)| root);
|
||||
if let (Some(root), Some((prev_root, _))) = (root_opt, iter.next()) {
|
||||
return (prev_root != root).then(|| root);
|
||||
}
|
||||
root_opt
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user