From a40b49d586115ecdd2a3ed7770b57b86fbb8534f Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 23 Oct 2018 13:15:08 +0200 Subject: [PATCH] Updates to block validation - Rename "parent_hashes" -> "recent_block_hashes" - Expect block has to be computed prior to function --- beacon_chain/validation/src/attestation_validation.rs | 4 ++-- beacon_chain/validation/src/block_validation.rs | 7 +++---- .../validation/tests/attestation_validation/helpers.rs | 2 +- beacon_chain/validation/tests/block_validation/helpers.rs | 5 +++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/beacon_chain/validation/src/attestation_validation.rs b/beacon_chain/validation/src/attestation_validation.rs index 53b45cad8..76bf61b8d 100644 --- a/beacon_chain/validation/src/attestation_validation.rs +++ b/beacon_chain/validation/src/attestation_validation.rs @@ -63,7 +63,7 @@ pub struct AttestationValidationContext /// 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>, + pub recent_block_hashes: Arc>, /// The store containing block information. pub block_store: Arc>, /// The store containing validator information. @@ -155,7 +155,7 @@ impl AttestationValidationContext self.cycle_length, self.block_slot, a.slot, - &self.parent_hashes, + &self.recent_block_hashes, &a.oblique_parent_hashes)?; /* diff --git a/beacon_chain/validation/src/block_validation.rs b/beacon_chain/validation/src/block_validation.rs index 8c2c28b1a..492f5f13a 100644 --- a/beacon_chain/validation/src/block_validation.rs +++ b/beacon_chain/validation/src/block_validation.rs @@ -80,7 +80,7 @@ pub struct BeaconBlockValidationContext /// 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>, + pub recent_block_hashes: Arc>, /// A map of slots to a block proposer validation index. pub proposer_map: Arc, /// A map of (slot, shard_id) to the attestation set of validation indices. @@ -109,7 +109,7 @@ impl BeaconBlockValidationContext /// 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), SszBeaconBlockValidationError> where T: ClientDB + Sized { @@ -118,7 +118,6 @@ impl BeaconBlockValidationContext * 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 BeaconBlockValidationContext 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(), diff --git a/beacon_chain/validation/tests/attestation_validation/helpers.rs b/beacon_chain/validation/tests/attestation_validation/helpers.rs index 0bb0bb77d..eb686b612 100644 --- a/beacon_chain/validation/tests/attestation_validation/helpers.rs +++ b/beacon_chain/validation/tests/attestation_validation/helpers.rs @@ -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), diff --git a/beacon_chain/validation/tests/block_validation/helpers.rs b/beacon_chain/validation/tests/block_validation/helpers.rs index 3e367fa96..7fd0c364a 100644 --- a/beacon_chain/validation/tests/block_validation/helpers.rs +++ b/beacon_chain/validation/tests/block_validation/helpers.rs @@ -225,14 +225,15 @@ pub fn run_block_validation_scenario( 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. *