Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
return Ok(None);
}

// Fast-path for the split slot (which usually corresponds to the finalized slot).
let split = self.store.get_split_info();
if request_slot == split.slot {
return Ok(Some(split.state_root));
}

// Try an optimized path of reading the root directly from the head state.
let fast_lookup: Option<Hash256> = self.with_head(|head| {
if head.beacon_block.slot() <= request_slot {
Expand Down
4 changes: 4 additions & 0 deletions beacon_node/beacon_chain/tests/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3155,6 +3155,10 @@ async fn weak_subjectivity_sync_test(
.get_state(&state_root, Some(slot), CACHE_STATE_IN_TESTS)
.unwrap()
.unwrap();
assert_eq!(
state_root,
beacon_chain.state_root_at_slot(slot).unwrap().unwrap()
);
assert_eq!(state.slot(), slot);
assert_eq!(state.canonical_root().unwrap(), state_root);
}
Expand Down
Loading