From e2d45eafaeff79ac6ade130d7b1651471e5fe19c Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 4 Oct 2018 15:43:17 +1000 Subject: [PATCH] Separate parent block checking and proposer checking --- .../validation/src/block_validation.rs | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/beacon_chain/validation/src/block_validation.rs b/beacon_chain/validation/src/block_validation.rs index c256d656c..459320f8c 100644 --- a/beacon_chain/validation/src/block_validation.rs +++ b/beacon_chain/validation/src/block_validation.rs @@ -181,6 +181,23 @@ impl BlockValidationContext return Err(SszBlockValidationError::ProposerAttestationHasObliqueHashes); } + /* + * Read the parent hash from the block we are validating then attempt to load + * that parent block ssz from the database. + * + * If that parent doesn't exist in the database or is invalid, reject the block. + * + * Also, read the slot from the parent block for later use. + */ + let parent_hash = b.parent_hash(); + let parent_slot = match self.block_store.get_serialized_block(&parent_hash)? { + None => return Err(SszBlockValidationError::UnknownParentHash), + Some(ssz) => { + let parent_block = SszBlock::from_slice(&ssz[..])?; + parent_block.slot_number() + } + }; + /* * Generate the context in which attestations will be validated. */ @@ -201,28 +218,16 @@ impl BlockValidationContext .validate_attestation(&first_attestation)?; /* - * Read the parent hash from the block we are validating then attempt to load - * the parent block ssz from the database. If that parent doesn't exist in - * the database, reject the block. + * Attempt to read load the parent block proposer from the proposer map. Return with an + * error if it fails. * - * If the parent does exist in the database, read the slot of that parent. Then, - * determine the proposer of that slot (the parent slot) by looking it up - * in the proposer map. - * - * If that proposer (the proposer of the parent block) was not present in the first (0'th) + * 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_hash = b.parent_hash(); - match self.block_store.get_serialized_block(&parent_hash)? { - None => return Err(SszBlockValidationError::UnknownParentHash), - Some(ssz) => { - let parent_block = SszBlock::from_slice(&ssz[..])?; - let proposer = self.proposer_map.get(&parent_block.slot_number()) - .ok_or(SszBlockValidationError::BadProposerMap)?; - if !attestation_voters.contains(&proposer) { - return Err(SszBlockValidationError::NoProposerSignature); - } - } + let parent_block_proposer = self.proposer_map.get(&parent_slot) + .ok_or(SszBlockValidationError::BadProposerMap)?; + if !attestation_voters.contains(&parent_block_proposer) { + return Err(SszBlockValidationError::NoProposerSignature); } /*