Skip to content

Commit bc47fd6

Browse files
committed
Avoid putting pre-split states in the state cache
1 parent 5fb55be commit bc47fd6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

beacon_node/store/src/hot_cold_store.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
14771477
// in the cache but not on disk. Instead of relying on the cache we try loading
14781478
// the state summary below and rely on that instead.
14791479
}
1480-
PutStateOutcome::Finalized => {} // Continue to store.
1480+
// Continue to store.
1481+
PutStateOutcome::Finalized | PutStateOutcome::PreFinalizedIgnored => {}
14811482
}
14821483

14831484
// Computing diffs is expensive so we avoid it if we already have this state stored on

beacon_node/store/src/state_cache.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ pub struct StateCache<E: EthSpec> {
4444

4545
#[derive(Debug)]
4646
pub enum PutStateOutcome {
47+
/// State is prior to the cache's finalized state (lower slot) and was not inserted.
48+
PreFinalizedIgnored,
49+
/// State is equal to the cache's finalized state and was not inserted.
4750
Finalized,
51+
/// State was already present in the cache.
4852
Duplicate,
49-
/// Includes deleted states as a result of this insertion
53+
/// State is new to the cache and was inserted.
54+
///
55+
/// Includes deleted states as a result of this insertion.
5056
New(Vec<Hash256>),
5157
}
5258

@@ -136,12 +142,12 @@ impl<E: EthSpec> StateCache<E> {
136142
block_root: Hash256,
137143
state: &BeaconState<E>,
138144
) -> Result<PutStateOutcome, Error> {
139-
if self
140-
.finalized_state
141-
.as_ref()
142-
.is_some_and(|finalized_state| finalized_state.state_root == state_root)
143-
{
144-
return Ok(PutStateOutcome::Finalized);
145+
if let Some(ref finalized_state) = self.finalized_state {
146+
if finalized_state.state_root == state_root {
147+
return Ok(PutStateOutcome::Finalized);
148+
} else if state.slot() <= finalized_state.state.slot() {
149+
return Ok(PutStateOutcome::PreFinalizedIgnored);
150+
}
145151
}
146152

147153
if self.states.peek(&state_root).is_some() {

0 commit comments

Comments
 (0)