Fix issue with last_justified_block_hash

Previously we were just checking it exists in the DB. This is incorrect
because the last_justified_block_hash _must_ be in the chain referenced
by the block.

I.e., it's not OK for a block to reference a justified block in another
chain.
This commit is contained in:
Paul Hauner
2018-10-09 12:14:59 +11:00
parent f13a4fffea
commit cf9f8c1e85
5 changed files with 20 additions and 25 deletions

View File

@@ -3,10 +3,7 @@ use std::sync::Arc;
use super::db::{
MemoryDB,
};
use super::db::stores::{
BlockStore,
ValidatorStore,
};
use super::db::stores::ValidatorStore;
use super::types::{
AttestationRecord,
AttesterMap,
@@ -30,18 +27,15 @@ use super::hashing::{
pub struct TestStore {
pub db: Arc<MemoryDB>,
pub block: Arc<BlockStore<MemoryDB>>,
pub validator: Arc<ValidatorStore<MemoryDB>>,
}
impl TestStore {
pub fn new() -> Self {
let db = Arc::new(MemoryDB::open());
let block = Arc::new(BlockStore::new(db.clone()));
let validator = Arc::new(ValidatorStore::new(db.clone()));
Self {
db,
block,
validator,
}
}
@@ -141,8 +135,6 @@ pub fn setup_attestation_validation_test(shard_id: u16, attester_count: usize)
let justified_block_hash = Hash256::from("justified_block".as_bytes());
let shard_block_hash = Hash256::from("shard_block".as_bytes());
stores.block.put_serialized_block(&justified_block_hash.as_ref(), &[42]).unwrap();
let attestation_slot = block_slot - 1;
let mut keypairs = vec![];
@@ -167,8 +159,8 @@ pub fn setup_attestation_validation_test(shard_id: u16, attester_count: usize)
block_slot,
cycle_length,
last_justified_slot,
last_justified_block_hash: justified_block_hash,
parent_hashes: parent_hashes.clone(),
block_store: stores.block.clone(),
validator_store: stores.validator.clone(),
attester_map: Arc::new(attester_map),
};

View File

@@ -41,6 +41,7 @@ pub struct BlockTestParams {
pub parent_proposer_index: usize,
pub validation_context_slot: u64,
pub validation_context_justified_slot: u64,
pub validation_context_justified_block_hash: Hash256,
pub validation_context_finalized_slot: u64,
}
@@ -93,7 +94,6 @@ pub fn setup_block_validation_scenario(params: &BlockTestParams)
let shard_block_hash = Hash256::from("shard_block_hash".as_bytes());
stores.pow_chain.put_block_hash(pow_chain_ref.as_ref()).unwrap();
stores.block.put_serialized_block(justified_block_hash.as_ref(), &vec![42]).unwrap();
/*
* Generate a minimum viable parent block and store it in the database.
@@ -205,6 +205,7 @@ pub fn run_block_validation_scenario<F>(
present_slot: params.validation_context_slot,
cycle_length: params.cycle_length,
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),
proposer_map: Arc::new(proposer_map),

View File

@@ -34,6 +34,7 @@ fn get_simple_params() -> BlockTestParams {
let validation_context_slot = block_slot;
let validation_context_justified_slot = attestations_justified_slot;
let validation_context_justified_block_hash = Hash256::from("justified_hash".as_bytes());
let validation_context_finalized_slot = 0;
BlockTestParams {
@@ -47,6 +48,7 @@ fn get_simple_params() -> BlockTestParams {
attestations_justified_slot,
validation_context_slot,
validation_context_justified_slot,
validation_context_justified_block_hash,
validation_context_finalized_slot,
}
}