Resolve some FIXMEs in the state cache

This commit is contained in:
Michael Sproul
2022-03-18 15:02:44 +11:00
parent 90ddaba1db
commit 648aba0332
2 changed files with 15 additions and 8 deletions

View File

@@ -53,6 +53,11 @@ pub enum Error {
SlotIsBeforeSplit { SlotIsBeforeSplit {
slot: Slot, slot: Slot,
}, },
FinalizedStateDecreasingEpoch,
StateForCacheHasPendingUpdates {
state_root: Hash256,
slot: Slot,
},
} }
pub trait HandleUnavailable<T> { pub trait HandleUnavailable<T> {

View File

@@ -54,8 +54,7 @@ impl<E: EthSpec> StateCache<E> {
.as_ref() .as_ref()
.map_or(false, |finalized_state| epoch < finalized_state.epoch) .map_or(false, |finalized_state| epoch < finalized_state.epoch)
{ {
// FIXME(sproul): panic return Err(Error::FinalizedStateDecreasingEpoch);
panic!("decreasing epoch");
} }
let finalized_slot = epoch.start_slot(E::slots_per_epoch()); let finalized_slot = epoch.start_slot(E::slots_per_epoch());
@@ -97,15 +96,19 @@ impl<E: EthSpec> StateCache<E> {
{ {
return Ok(true); return Ok(true);
} }
if self.states.peek(&state_root).is_some() { if self.states.peek(&state_root).is_some() {
return Ok(true); return Ok(true);
} }
// FIXME(sproul): remove zis // Refuse states with pending mutations: we want cached states to be as small as possible
assert!( // i.e. stored entirely as a binary merkle tree with no updates overlaid.
!state.has_pending_mutations(), if state.has_pending_mutations() {
"what are you doing putting these filthy states in here?" return Err(Error::StateForCacheHasPendingUpdates {
); state_root,
slot: state.slot(),
});
}
// Insert the full state into the cache. // Insert the full state into the cache.
self.states.put(state_root, state.clone()); self.states.put(state_root, state.clone());
@@ -187,7 +190,6 @@ impl BlockMap {
pruned_states pruned_states
} }
// FIXME(sproul): slow, make generic
fn delete(&mut self, state_root_to_delete: &Hash256) { fn delete(&mut self, state_root_to_delete: &Hash256) {
self.blocks.retain(|_, slot_map| { self.blocks.retain(|_, slot_map| {
slot_map slot_map