Fix bug with block production

This commit is contained in:
Paul Hauner
2019-08-30 11:04:15 +10:00
parent 31bbb0f573
commit 3365106340
4 changed files with 35 additions and 24 deletions

View File

@@ -466,6 +466,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
}
if epoch(state.as_ref().slot) != epoch(slot) {
return Err(Error::InvariantViolated(format!(
"Epochs in consistent in proposer lookup: state: {}, requested: {}",
epoch(state.as_ref().slot),
epoch(slot)
)));
}
state
.as_ref()
.get_beacon_proposer_index(slot, RelativeEpoch::Current, &self.spec)
@@ -494,6 +502,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
}
if as_epoch(state.as_ref().slot) != epoch {
return Err(Error::InvariantViolated(format!(
"Epochs in consistent in attestation duties lookup: state: {}, requested: {}",
as_epoch(state.as_ref().slot),
epoch
)));
}
if let Some(attestation_duty) = state
.as_ref()
.get_attestation_duties(validator_index, RelativeEpoch::Current)?
@@ -1123,13 +1139,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
slot: Slot,
) -> Result<(BeaconBlock<T::EthSpec>, BeaconState<T::EthSpec>), BlockProductionError> {
let state = self
.state_at_slot(slot)
.state_at_slot(slot - 1)
.map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;
let slot = self
.slot()
.map_err(|_| BlockProductionError::UnableToReadSlot)?;
self.produce_block_on_state(state.as_ref().clone(), slot, randao_reveal)
}

View File

@@ -37,6 +37,8 @@ pub enum BeaconChainError {
beacon_block_root: Hash256,
},
AttestationValidationError(AttestationValidationError),
/// Returned when an internal check fails, indicating corrupt data.
InvariantViolated(String),
}
easy_from_to!(SlotProcessingError, BeaconChainError);