Ensure that parent_block.slot < block.slot

This commit is contained in:
Paul Hauner 2018-10-12 20:54:33 +11:00
parent 1f089d423e
commit e8daca4c80
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 26 additions and 0 deletions

View File

@ -53,6 +53,7 @@ pub enum SszBlockValidationError {
UnknownPoWChainRef,
UnknownParentHash,
BadAttestationSsz,
ParentSlotHigherThanBlockSlot,
AttestationValidationError(AttestationValidationError),
AttestationSignatureFailed,
ProposerAttestationHasObliqueHashes,
@ -204,6 +205,15 @@ impl<T> BlockValidationContext<T>
}
};
/*
* The parent block slot must be less than the block slot.
*
* In other words, the parent must come before the child.
*/
if parent_block_slot >= block_slot {
return Err(SszBlockValidationError::ParentSlotHigherThanBlockSlot);
}
/*
* Generate the context in which attestations will be validated.
*/

View File

@ -94,6 +94,22 @@ fn test_block_validation_valid_known_block() {
assert_eq!(status.unwrap(), (BlockStatus::KnownBlock, None));
}
#[test]
fn test_block_validation_parent_slot_too_high() {
let params = get_simple_params();
let mutator = |mut block: Block, attester_map, proposer_map, stores| {
block.slot_number = params.validation_context_justified_slot + 1;
(block, attester_map, proposer_map, stores)
};
let status = run_block_validation_scenario(
&params,
mutator);
assert_eq!(status, Err(SszBlockValidationError::ParentSlotHigherThanBlockSlot));
}
#[test]
fn test_block_validation_invalid_future_slot() {
let params = get_simple_params();