Return a specific error for frozen attn states (#2384)

## Issue Addressed

NA

## Proposed Changes

Return a very specific error when at attestation reads shuffling from a frozen `BeaconState`. Previously, this was returning `MissingBeaconState` which indicates a much more serious issue.

## Additional Info

Since `get_inconsistent_state_for_attestation_verification_only` is only called once in `BeaconChain::with_committee_cache`, it is quite easy to reason about the impact of this change.
This commit is contained in:
Paul Hauner 2021-06-01 06:59:43 +00:00
parent ba9c4c5eea
commit bf4e02e2cc

View File

@ -106,6 +106,11 @@ pub enum HotColdDBError {
IterationError { IterationError {
unexpected_key: BytesKey, unexpected_key: BytesKey,
}, },
AttestationStateIsFinalized {
split_slot: Slot,
request_slot: Option<Slot>,
state_root: Hash256,
},
} }
impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> { impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
@ -345,8 +350,15 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
) -> Result<Option<BeaconState<E>>, Error> { ) -> Result<Option<BeaconState<E>>, Error> {
metrics::inc_counter(&metrics::BEACON_STATE_GET_COUNT); metrics::inc_counter(&metrics::BEACON_STATE_GET_COUNT);
if slot.map_or(false, |slot| slot < self.get_split_slot()) { let split_slot = self.get_split_slot();
Ok(None)
if slot.map_or(false, |slot| slot < split_slot) {
Err(HotColdDBError::AttestationStateIsFinalized {
split_slot,
request_slot: slot,
state_root: *state_root,
}
.into())
} else { } else {
self.load_hot_state(state_root, BlockReplay::InconsistentStateRoots) self.load_hot_state(state_root, BlockReplay::InconsistentStateRoots)
} }