mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
Add untested minimum viable block processing
This commit is contained in:
@@ -2,49 +2,17 @@ extern crate rayon;
|
||||
|
||||
use self::rayon::prelude::*;
|
||||
|
||||
use std::sync::{
|
||||
Arc,
|
||||
RwLock,
|
||||
};
|
||||
use super::attestation_validation::{
|
||||
AttestationValidationContext,
|
||||
AttestationValidationError,
|
||||
};
|
||||
use super::types::{
|
||||
AttestationRecord,
|
||||
AttesterMap,
|
||||
BeaconBlock,
|
||||
ProposerMap,
|
||||
};
|
||||
use super::attestation_validation::{AttestationValidationContext, AttestationValidationError};
|
||||
use super::db::stores::{BeaconBlockStore, PoWChainStore, ValidatorStore};
|
||||
use super::db::{ClientDB, DBError};
|
||||
use super::ssz::{Decodable, DecodeError};
|
||||
use super::ssz_helpers::attestation_ssz_splitter::{
|
||||
split_one_attestation,
|
||||
split_all_attestations,
|
||||
AttestationSplitError,
|
||||
};
|
||||
use super::ssz_helpers::ssz_beacon_block::{
|
||||
SszBeaconBlock,
|
||||
SszBeaconBlockError,
|
||||
};
|
||||
use super::db::{
|
||||
ClientDB,
|
||||
DBError,
|
||||
};
|
||||
use super::db::stores::{
|
||||
BeaconBlockStore,
|
||||
PoWChainStore,
|
||||
ValidatorStore,
|
||||
};
|
||||
use super::ssz::{
|
||||
Decodable,
|
||||
DecodeError,
|
||||
split_all_attestations, split_one_attestation, AttestationSplitError,
|
||||
};
|
||||
use super::ssz_helpers::ssz_beacon_block::{SszBeaconBlock, SszBeaconBlockError};
|
||||
use super::types::Hash256;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BeaconBlockStatus {
|
||||
NewBlock,
|
||||
KnownBlock,
|
||||
}
|
||||
use super::types::{AttestationRecord, AttesterMap, BeaconBlock, ProposerMap};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum SszBeaconBlockValidationError {
|
||||
@@ -67,7 +35,8 @@ pub enum SszBeaconBlockValidationError {
|
||||
|
||||
/// The context against which a block should be validated.
|
||||
pub struct BeaconBlockValidationContext<T>
|
||||
where T: ClientDB + Sized
|
||||
where
|
||||
T: ClientDB + Sized,
|
||||
{
|
||||
/// The slot as determined by the system time.
|
||||
pub present_slot: u64,
|
||||
@@ -94,7 +63,8 @@ pub struct BeaconBlockValidationContext<T>
|
||||
}
|
||||
|
||||
impl<T> BeaconBlockValidationContext<T>
|
||||
where T: ClientDB
|
||||
where
|
||||
T: ClientDB,
|
||||
{
|
||||
/// Validate some SszBeaconBlock against a block validation context. An SszBeaconBlock varies from a BeaconBlock in
|
||||
/// that is a read-only structure that reads directly from encoded SSZ.
|
||||
@@ -109,19 +79,13 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
/// Note: this function does not implement randao_reveal checking as it is not in the
|
||||
/// specification.
|
||||
#[allow(dead_code)]
|
||||
pub fn validate_ssz_block(&self, block_hash: &Hash256, b: &SszBeaconBlock)
|
||||
-> Result<(BeaconBlockStatus, Option<BeaconBlock>), SszBeaconBlockValidationError>
|
||||
where T: ClientDB + Sized
|
||||
pub fn validate_ssz_block(
|
||||
&self,
|
||||
b: &SszBeaconBlock,
|
||||
) -> Result<BeaconBlock, SszBeaconBlockValidationError>
|
||||
where
|
||||
T: ClientDB + Sized,
|
||||
{
|
||||
|
||||
/*
|
||||
* If this block is already known, return immediately and indicate the the block is
|
||||
* known. Don't attempt to deserialize the block.
|
||||
*/
|
||||
if self.block_store.block_exists(&block_hash)? {
|
||||
return Ok((BeaconBlockStatus::KnownBlock, None));
|
||||
}
|
||||
|
||||
/*
|
||||
* If the block slot corresponds to a slot in the future, return immediately with an error.
|
||||
*
|
||||
@@ -173,11 +137,8 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
* The first attestation must be validated separately as it must contain a signature of the
|
||||
* proposer of the previous block (this is checked later in this function).
|
||||
*/
|
||||
let (first_attestation_ssz, next_index) = split_one_attestation(
|
||||
&attestations_ssz,
|
||||
0)?;
|
||||
let (first_attestation, _) = AttestationRecord::ssz_decode(
|
||||
&first_attestation_ssz, 0)?;
|
||||
let (first_attestation_ssz, next_index) = split_one_attestation(&attestations_ssz, 0)?;
|
||||
let (first_attestation, _) = AttestationRecord::ssz_decode(&first_attestation_ssz, 0)?;
|
||||
|
||||
/*
|
||||
* The first attestation may not have oblique hashes.
|
||||
@@ -197,7 +158,8 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
*
|
||||
* Also, read the slot from the parent block for later use.
|
||||
*/
|
||||
let parent_hash = b.parent_hash()
|
||||
let parent_hash = b
|
||||
.parent_hash()
|
||||
.ok_or(SszBeaconBlockValidationError::BadAncestorHashesSsz)?;
|
||||
let parent_block_slot = match self.block_store.get_serialized_block(&parent_hash)? {
|
||||
None => return Err(SszBeaconBlockValidationError::UnknownParentHash),
|
||||
@@ -233,8 +195,8 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
/*
|
||||
* Validate this first attestation.
|
||||
*/
|
||||
let attestation_voters = attestation_validation_context
|
||||
.validate_attestation(&first_attestation)?;
|
||||
let attestation_voters =
|
||||
attestation_validation_context.validate_attestation(&first_attestation)?;
|
||||
|
||||
/*
|
||||
* Attempt to read load the parent block proposer from the proposer map. Return with an
|
||||
@@ -243,7 +205,9 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
* If the signature of proposer for the parent slot was not present in the first (0'th)
|
||||
* attestation of this block, reject the block.
|
||||
*/
|
||||
let parent_block_proposer = self.proposer_map.get(&parent_block_slot)
|
||||
let parent_block_proposer = self
|
||||
.proposer_map
|
||||
.get(&parent_block_slot)
|
||||
.ok_or(SszBeaconBlockValidationError::BadProposerMap)?;
|
||||
if !attestation_voters.contains(&parent_block_proposer) {
|
||||
return Err(SszBeaconBlockValidationError::NoProposerSignature);
|
||||
@@ -253,8 +217,7 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
* Split the remaining attestations into a vector of slices, each containing
|
||||
* a single serialized attestation record.
|
||||
*/
|
||||
let other_attestations = split_all_attestations(attestations_ssz,
|
||||
next_index)?;
|
||||
let other_attestations = split_all_attestations(attestations_ssz, next_index)?;
|
||||
|
||||
/*
|
||||
* Verify each other AttestationRecord.
|
||||
@@ -278,7 +241,7 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
*/
|
||||
match failure.read() {
|
||||
Ok(ref option) if option.is_none() => (),
|
||||
_ => return None
|
||||
_ => return None,
|
||||
}
|
||||
/*
|
||||
* If there has not been a failure yet, attempt to serialize and validate the
|
||||
@@ -317,22 +280,18 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
/*
|
||||
* Attestation validation succeded.
|
||||
*/
|
||||
Ok(_) => Some(attestation)
|
||||
Ok(_) => Some(attestation),
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
}).collect();
|
||||
|
||||
match failure.into_inner() {
|
||||
Err(_) => return Err(SszBeaconBlockValidationError::RwLockPoisoned),
|
||||
Ok(failure) => {
|
||||
match failure {
|
||||
Some(error) => return Err(error),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
}
|
||||
Ok(failure) => match failure {
|
||||
Some(error) => return Err(error),
|
||||
_ => (),
|
||||
},
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -360,7 +319,7 @@ impl<T> BeaconBlockValidationContext<T>
|
||||
attestations: deserialized_attestations,
|
||||
specials,
|
||||
};
|
||||
Ok((BeaconBlockStatus::NewBlock, Some(block)))
|
||||
Ok(block)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,8 +332,7 @@ impl From<DBError> for SszBeaconBlockValidationError {
|
||||
impl From<AttestationSplitError> for SszBeaconBlockValidationError {
|
||||
fn from(e: AttestationSplitError) -> Self {
|
||||
match e {
|
||||
AttestationSplitError::TooShort =>
|
||||
SszBeaconBlockValidationError::BadAttestationSsz
|
||||
AttestationSplitError::TooShort => SszBeaconBlockValidationError::BadAttestationSsz,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -382,10 +340,12 @@ impl From<AttestationSplitError> for SszBeaconBlockValidationError {
|
||||
impl From<SszBeaconBlockError> for SszBeaconBlockValidationError {
|
||||
fn from(e: SszBeaconBlockError) -> Self {
|
||||
match e {
|
||||
SszBeaconBlockError::TooShort =>
|
||||
SszBeaconBlockValidationError::DBError("Bad parent block in db.".to_string()),
|
||||
SszBeaconBlockError::TooLong =>
|
||||
SszBeaconBlockValidationError::DBError("Bad parent block in db.".to_string()),
|
||||
SszBeaconBlockError::TooShort => {
|
||||
SszBeaconBlockValidationError::DBError("Bad parent block in db.".to_string())
|
||||
}
|
||||
SszBeaconBlockError::TooLong => {
|
||||
SszBeaconBlockValidationError::DBError("Bad parent block in db.".to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,10 +353,8 @@ impl From<SszBeaconBlockError> for SszBeaconBlockValidationError {
|
||||
impl From<DecodeError> for SszBeaconBlockValidationError {
|
||||
fn from(e: DecodeError) -> Self {
|
||||
match e {
|
||||
DecodeError::TooShort =>
|
||||
SszBeaconBlockValidationError::BadAttestationSsz,
|
||||
DecodeError::TooLong =>
|
||||
SszBeaconBlockValidationError::BadAttestationSsz,
|
||||
DecodeError::TooShort => SszBeaconBlockValidationError::BadAttestationSsz,
|
||||
DecodeError::TooLong => SszBeaconBlockValidationError::BadAttestationSsz,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::attestation_validation::helpers::{
|
||||
generate_attestation,
|
||||
insert_justified_block_hash,
|
||||
};
|
||||
use super::bls::{
|
||||
Keypair,
|
||||
};
|
||||
use super::db::{
|
||||
MemoryDB,
|
||||
};
|
||||
use super::db::stores::{
|
||||
BeaconBlockStore,
|
||||
PoWChainStore,
|
||||
ValidatorStore,
|
||||
};
|
||||
use super::types::{
|
||||
AttestationRecord,
|
||||
AttesterMap,
|
||||
BeaconBlock,
|
||||
Hash256,
|
||||
ProposerMap,
|
||||
};
|
||||
use super::attestation_validation::helpers::{generate_attestation, insert_justified_block_hash};
|
||||
use super::bls::Keypair;
|
||||
use super::db::stores::{BeaconBlockStore, PoWChainStore, ValidatorStore};
|
||||
use super::db::MemoryDB;
|
||||
use super::ssz::SszStream;
|
||||
use super::ssz_helpers::ssz_beacon_block::SszBeaconBlock;
|
||||
use super::types::{AttestationRecord, AttesterMap, BeaconBlock, Hash256, ProposerMap};
|
||||
use super::validation::block_validation::{
|
||||
BeaconBlockValidationContext,
|
||||
SszBeaconBlockValidationError,
|
||||
BeaconBlockStatus,
|
||||
};
|
||||
use super::ssz::{
|
||||
SszStream,
|
||||
BeaconBlockValidationContext, SszBeaconBlockValidationError,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -74,9 +53,15 @@ type ParentHashes = Vec<Hash256>;
|
||||
|
||||
/// Setup for a block validation function, without actually executing the
|
||||
/// block validation function.
|
||||
pub fn setup_block_validation_scenario(params: &BeaconBlockTestParams)
|
||||
-> (BeaconBlock, ParentHashes, AttesterMap, ProposerMap, TestStore)
|
||||
{
|
||||
pub fn setup_block_validation_scenario(
|
||||
params: &BeaconBlockTestParams,
|
||||
) -> (
|
||||
BeaconBlock,
|
||||
ParentHashes,
|
||||
AttesterMap,
|
||||
ProposerMap,
|
||||
TestStore,
|
||||
) {
|
||||
let stores = TestStore::new();
|
||||
|
||||
let cycle_length = params.cycle_length;
|
||||
@@ -100,7 +85,10 @@ pub fn setup_block_validation_scenario(params: &BeaconBlockTestParams)
|
||||
/*
|
||||
* Store a valid PoW chain ref
|
||||
*/
|
||||
stores.pow_chain.put_block_hash(pow_chain_ref.as_ref()).unwrap();
|
||||
stores
|
||||
.pow_chain
|
||||
.put_block_hash(pow_chain_ref.as_ref())
|
||||
.unwrap();
|
||||
|
||||
/*
|
||||
* Generate a minimum viable parent block and store it in the database.
|
||||
@@ -110,7 +98,10 @@ pub fn setup_block_validation_scenario(params: &BeaconBlockTestParams)
|
||||
parent_block.slot = block_slot - 1;
|
||||
parent_block.attestations.push(parent_attestation);
|
||||
let parent_block_ssz = serialize_block(&parent_block);
|
||||
stores.block.put_serialized_block(parent_hash.as_ref(), &parent_block_ssz).unwrap();
|
||||
stores
|
||||
.block
|
||||
.put_serialized_block(parent_hash.as_ref(), &parent_block_ssz)
|
||||
.unwrap();
|
||||
|
||||
let proposer_map = {
|
||||
let mut proposer_map = ProposerMap::new();
|
||||
@@ -132,24 +123,28 @@ pub fn setup_block_validation_scenario(params: &BeaconBlockTestParams)
|
||||
&mut parent_hashes,
|
||||
&justified_block_hash,
|
||||
block_slot,
|
||||
attestation_slot);
|
||||
attestation_slot,
|
||||
);
|
||||
/*
|
||||
* For each shard in this slot, generate an attestation.
|
||||
*/
|
||||
for shard in 0..shards_per_slot {
|
||||
let mut signing_keys = vec![];
|
||||
let mut attesters = vec![];
|
||||
/*
|
||||
* Generate a random keypair for each validator and clone it into the
|
||||
* list of keypairs. Store it in the database.
|
||||
*/
|
||||
let mut signing_keys = vec![];
|
||||
let mut attesters = vec![];
|
||||
/*
|
||||
* Generate a random keypair for each validator and clone it into the
|
||||
* list of keypairs. Store it in the database.
|
||||
*/
|
||||
for _ in 0..validators_per_shard {
|
||||
let keypair = Keypair::random();
|
||||
keypairs.push(keypair.clone());
|
||||
stores.validator.put_public_key_by_index(i, &keypair.pk).unwrap();
|
||||
signing_keys.push(Some(keypair.sk.clone()));
|
||||
attesters.push(i);
|
||||
i += 1;
|
||||
let keypair = Keypair::random();
|
||||
keypairs.push(keypair.clone());
|
||||
stores
|
||||
.validator
|
||||
.put_public_key_by_index(i, &keypair.pk)
|
||||
.unwrap();
|
||||
signing_keys.push(Some(keypair.sk.clone()));
|
||||
attesters.push(i);
|
||||
i += 1;
|
||||
}
|
||||
attester_map.insert((attestation_slot, shard), attesters);
|
||||
|
||||
@@ -163,7 +158,8 @@ pub fn setup_block_validation_scenario(params: &BeaconBlockTestParams)
|
||||
cycle_length,
|
||||
&parent_hashes,
|
||||
&signing_keys[..],
|
||||
&stores.block);
|
||||
&stores.block,
|
||||
);
|
||||
attestations.push(attestation);
|
||||
}
|
||||
(attester_map, attestations, keypairs)
|
||||
@@ -180,11 +176,7 @@ pub fn setup_block_validation_scenario(params: &BeaconBlockTestParams)
|
||||
specials: vec![],
|
||||
};
|
||||
|
||||
(block,
|
||||
parent_hashes,
|
||||
attester_map,
|
||||
proposer_map,
|
||||
stores)
|
||||
(block, parent_hashes, attester_map, proposer_map, stores)
|
||||
}
|
||||
|
||||
/// Helper function to take some BeaconBlock and SSZ serialize it.
|
||||
@@ -199,25 +191,20 @@ pub fn serialize_block(b: &BeaconBlock) -> Vec<u8> {
|
||||
/// Returns the Result returned from the block validation function.
|
||||
pub fn run_block_validation_scenario<F>(
|
||||
params: &BeaconBlockTestParams,
|
||||
mutator_func: F)
|
||||
-> Result<(BeaconBlockStatus, Option<BeaconBlock>), SszBeaconBlockValidationError>
|
||||
where F: FnOnce(BeaconBlock, AttesterMap, ProposerMap, TestStore)
|
||||
-> (BeaconBlock, AttesterMap, ProposerMap, TestStore)
|
||||
mutator_func: F,
|
||||
) -> Result<BeaconBlock, SszBeaconBlockValidationError>
|
||||
where
|
||||
F: FnOnce(BeaconBlock, AttesterMap, ProposerMap, TestStore)
|
||||
-> (BeaconBlock, AttesterMap, ProposerMap, TestStore),
|
||||
{
|
||||
let (block,
|
||||
parent_hashes,
|
||||
attester_map,
|
||||
proposer_map,
|
||||
stores) = setup_block_validation_scenario(¶ms);
|
||||
let (block, parent_hashes, attester_map, proposer_map, stores) =
|
||||
setup_block_validation_scenario(¶ms);
|
||||
|
||||
let (block,
|
||||
attester_map,
|
||||
proposer_map,
|
||||
stores) = mutator_func(block, attester_map, proposer_map, stores);
|
||||
let (block, attester_map, proposer_map, stores) =
|
||||
mutator_func(block, attester_map, proposer_map, stores);
|
||||
|
||||
let ssz_bytes = serialize_block(&block);
|
||||
let ssz_block = SszBeaconBlock::from_slice(&ssz_bytes[..])
|
||||
.unwrap();
|
||||
let ssz_block = SszBeaconBlock::from_slice(&ssz_bytes[..]).unwrap();
|
||||
|
||||
let context = BeaconBlockValidationContext {
|
||||
present_slot: params.validation_context_slot,
|
||||
@@ -230,17 +217,17 @@ pub fn run_block_validation_scenario<F>(
|
||||
attester_map: Arc::new(attester_map),
|
||||
block_store: stores.block.clone(),
|
||||
validator_store: stores.validator.clone(),
|
||||
pow_store: stores.pow_chain.clone()
|
||||
pow_store: stores.pow_chain.clone(),
|
||||
};
|
||||
let block_hash = Hash256::from(&ssz_block.block_hash()[..]);
|
||||
let validation_status = context.validate_ssz_block(&block_hash, &ssz_block);
|
||||
let validation_result = context.validate_ssz_block(&ssz_block);
|
||||
/*
|
||||
* If validation returned a block, make sure it's the same block we supplied to it.
|
||||
*
|
||||
* I.e., there were no errors during the serialization -> deserialization process.
|
||||
*/
|
||||
if let Ok((_, Some(returned_block))) = &validation_status {
|
||||
if let Ok(returned_block) = &validation_result {
|
||||
assert_eq!(*returned_block, block);
|
||||
};
|
||||
validation_status
|
||||
validation_result
|
||||
}
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
use super::bls::{
|
||||
AggregateSignature,
|
||||
};
|
||||
use super::bls::AggregateSignature;
|
||||
use super::hashing::canonical_hash;
|
||||
use super::helpers::{
|
||||
BeaconBlockTestParams,
|
||||
TestStore,
|
||||
run_block_validation_scenario,
|
||||
serialize_block,
|
||||
};
|
||||
use super::types::{
|
||||
BeaconBlock,
|
||||
Hash256,
|
||||
ProposerMap,
|
||||
run_block_validation_scenario, serialize_block, BeaconBlockTestParams, TestStore,
|
||||
};
|
||||
use super::ssz_helpers::ssz_beacon_block::SszBeaconBlock;
|
||||
use super::validation::block_validation::{
|
||||
SszBeaconBlockValidationError,
|
||||
BeaconBlockStatus,
|
||||
};
|
||||
use super::validation::attestation_validation::{
|
||||
AttestationValidationError,
|
||||
};
|
||||
use super::hashing::canonical_hash;
|
||||
use super::types::{BeaconBlock, Hash256, ProposerMap};
|
||||
use super::validation::attestation_validation::AttestationValidationError;
|
||||
use super::validation::block_validation::SszBeaconBlockValidationError;
|
||||
|
||||
fn get_simple_params() -> BeaconBlockTestParams {
|
||||
let validators_per_shard: usize = 5;
|
||||
@@ -66,11 +52,9 @@ fn test_block_validation_valid() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status.unwrap().0, BeaconBlockStatus::NewBlock);
|
||||
assert!(status.is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -83,15 +67,21 @@ fn test_block_validation_valid_known_block() {
|
||||
*/
|
||||
let block_ssz = serialize_block(&block);
|
||||
let block_hash = canonical_hash(&block_ssz);
|
||||
stores.block.put_serialized_block(&block_hash, &block_ssz).unwrap();
|
||||
stores
|
||||
.block
|
||||
.put_serialized_block(&block_hash, &block_ssz)
|
||||
.unwrap();
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status.unwrap(), (BeaconBlockStatus::KnownBlock, None));
|
||||
/*
|
||||
* This function does _not_ check if a block is already known.
|
||||
*
|
||||
* Known blocks will appear as valid blocks.
|
||||
*/
|
||||
assert!(status.is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -103,11 +93,12 @@ fn test_block_validation_parent_slot_too_high() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::ParentSlotHigherThanBlockSlot));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::ParentSlotHigherThanBlockSlot)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -119,9 +110,7 @@ fn test_block_validation_invalid_future_slot() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::FutureSlot));
|
||||
}
|
||||
@@ -131,8 +120,8 @@ fn test_block_validation_invalid_slot_already_finalized() {
|
||||
let mut params = get_simple_params();
|
||||
|
||||
params.validation_context_finalized_slot = params.block_slot;
|
||||
params.validation_context_justified_slot = params.validation_context_finalized_slot +
|
||||
u64::from(params.cycle_length);
|
||||
params.validation_context_justified_slot =
|
||||
params.validation_context_finalized_slot + u64::from(params.cycle_length);
|
||||
|
||||
let mutator = |block, attester_map, proposer_map, stores| {
|
||||
/*
|
||||
@@ -141,11 +130,12 @@ fn test_block_validation_invalid_slot_already_finalized() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::SlotAlreadyFinalized));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::SlotAlreadyFinalized)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -157,11 +147,12 @@ fn test_block_validation_invalid_unknown_pow_hash() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::UnknownPoWChainRef));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::UnknownPoWChainRef)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -173,11 +164,12 @@ fn test_block_validation_invalid_unknown_parent_hash() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::UnknownParentHash));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::UnknownParentHash)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -192,36 +184,44 @@ fn test_block_validation_invalid_1st_attestation_signature() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::AttestationValidationError(
|
||||
AttestationValidationError::BadAggregateSignature)));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::AttestationValidationError(
|
||||
AttestationValidationError::BadAggregateSignature
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_validation_invalid_no_parent_proposer_signature() {
|
||||
let params = get_simple_params();
|
||||
|
||||
let mutator = |block: BeaconBlock, attester_map, mut proposer_map: ProposerMap, stores: TestStore| {
|
||||
/*
|
||||
* Set the proposer for this slot to be a validator that does not exist.
|
||||
*/
|
||||
let ssz = {
|
||||
let parent_hash = block.parent_hash().unwrap().as_ref();
|
||||
stores.block.get_serialized_block(parent_hash).unwrap().unwrap()
|
||||
let mutator =
|
||||
|block: BeaconBlock, attester_map, mut proposer_map: ProposerMap, stores: TestStore| {
|
||||
/*
|
||||
* Set the proposer for this slot to be a validator that does not exist.
|
||||
*/
|
||||
let ssz = {
|
||||
let parent_hash = block.parent_hash().unwrap().as_ref();
|
||||
stores
|
||||
.block
|
||||
.get_serialized_block(parent_hash)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
};
|
||||
let parent_block_slot = SszBeaconBlock::from_slice(&ssz[..]).unwrap().slot();
|
||||
proposer_map.insert(parent_block_slot, params.total_validators + 1);
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
let parent_block_slot = SszBeaconBlock::from_slice(&ssz[..]).unwrap().slot();
|
||||
proposer_map.insert(parent_block_slot, params.total_validators + 1);
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::NoProposerSignature));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::NoProposerSignature)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -236,9 +236,7 @@ fn test_block_validation_invalid_bad_proposer_map() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::BadProposerMap));
|
||||
}
|
||||
@@ -255,10 +253,12 @@ fn test_block_validation_invalid_2nd_attestation_signature() {
|
||||
(block, attester_map, proposer_map, stores)
|
||||
};
|
||||
|
||||
let status = run_block_validation_scenario(
|
||||
¶ms,
|
||||
mutator);
|
||||
let status = run_block_validation_scenario(¶ms, mutator);
|
||||
|
||||
assert_eq!(status, Err(SszBeaconBlockValidationError::AttestationValidationError(
|
||||
AttestationValidationError::BadAggregateSignature)));
|
||||
assert_eq!(
|
||||
status,
|
||||
Err(SszBeaconBlockValidationError::AttestationValidationError(
|
||||
AttestationValidationError::BadAggregateSignature
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user