Updates to block validation

- Rename "parent_hashes" -> "recent_block_hashes"
- Expect block has to be computed prior to function
This commit is contained in:
Paul Hauner 2018-10-23 13:15:08 +02:00
parent 06c20857c8
commit a40b49d586
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
4 changed files with 9 additions and 9 deletions

View File

@ -63,7 +63,7 @@ pub struct AttestationValidationContext<T>
/// The last justified slot as per the client's view of the canonical chain.
pub last_justified_slot: u64,
/// A vec of the hashes of the blocks preceeding the present slot.
pub parent_hashes: Arc<Vec<Hash256>>,
pub recent_block_hashes: Arc<Vec<Hash256>>,
/// The store containing block information.
pub block_store: Arc<BeaconBlockStore<T>>,
/// The store containing validator information.
@ -155,7 +155,7 @@ impl<T> AttestationValidationContext<T>
self.cycle_length,
self.block_slot,
a.slot,
&self.parent_hashes,
&self.recent_block_hashes,
&a.oblique_parent_hashes)?;
/*

View File

@ -80,7 +80,7 @@ pub struct BeaconBlockValidationContext<T>
/// The last finalized slot as per the client's view of the canonical chain.
pub last_finalized_slot: u64,
/// A vec of the hashes of the blocks preceeding the present slot.
pub parent_hashes: Arc<Vec<Hash256>>,
pub recent_block_hashes: Arc<Vec<Hash256>>,
/// A map of slots to a block proposer validation index.
pub proposer_map: Arc<ProposerMap>,
/// A map of (slot, shard_id) to the attestation set of validation indices.
@ -109,7 +109,7 @@ 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, b: &SszBeaconBlock)
pub fn validate_ssz_block(&self, block_hash: &Hash256, b: &SszBeaconBlock)
-> Result<(BeaconBlockStatus, Option<BeaconBlock>), SszBeaconBlockValidationError>
where T: ClientDB + Sized
{
@ -118,7 +118,6 @@ impl<T> BeaconBlockValidationContext<T>
* If this block is already known, return immediately and indicate the the block is
* known. Don't attempt to deserialize the block.
*/
let block_hash = &b.block_hash();
if self.block_store.block_exists(&block_hash)? {
return Ok((BeaconBlockStatus::KnownBlock, None));
}
@ -225,7 +224,7 @@ impl<T> BeaconBlockValidationContext<T>
parent_block_slot,
cycle_length: self.cycle_length,
last_justified_slot: self.last_justified_slot,
parent_hashes: self.parent_hashes.clone(),
recent_block_hashes: self.recent_block_hashes.clone(),
block_store: self.block_store.clone(),
validator_store: self.validator_store.clone(),
attester_map: self.attester_map.clone(),

View File

@ -208,7 +208,7 @@ pub fn setup_attestation_validation_test(shard_id: u16, attester_count: usize)
parent_block_slot,
cycle_length,
last_justified_slot,
parent_hashes: parent_hashes.clone(),
recent_block_hashes: parent_hashes.clone(),
block_store: stores.block.clone(),
validator_store: stores.validator.clone(),
attester_map: Arc::new(attester_map),

View File

@ -225,14 +225,15 @@ pub fn run_block_validation_scenario<F>(
last_justified_slot: params.validation_context_justified_slot,
last_justified_block_hash: params.validation_context_justified_block_hash,
last_finalized_slot: params.validation_context_finalized_slot,
parent_hashes: Arc::new(parent_hashes),
recent_block_hashes: Arc::new(parent_hashes),
proposer_map: Arc::new(proposer_map),
attester_map: Arc::new(attester_map),
block_store: stores.block.clone(),
validator_store: stores.validator.clone(),
pow_store: stores.pow_chain.clone()
};
let validation_status = context.validate_ssz_block(&ssz_block);
let block_hash = Hash256::from(&ssz_block.block_hash()[..]);
let validation_status = context.validate_ssz_block(&block_hash, &ssz_block);
/*
* If validation returned a block, make sure it's the same block we supplied to it.
*