Begin basics of block validation

This commit is contained in:
Paul Hauner 2018-09-21 11:14:28 +10:00
parent d4e6f12ded
commit 51c842c236
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
4 changed files with 61 additions and 1 deletions

View File

@ -2,6 +2,7 @@ pub struct ChainConfig {
pub cycle_length: u8,
pub shard_count: u16,
pub min_committee_size: u64,
pub genesis_time: u64,
}
impl ChainConfig {
@ -10,6 +11,7 @@ impl ChainConfig {
cycle_length: 8,
shard_count: 1024,
min_committee_size: 128,
genesis_time: 1537488655, // arbitrary
}
}
}

View File

@ -5,6 +5,7 @@ extern crate bytes;
extern crate ssz;
use super::utils;
use super::db;
pub mod active_state;
pub mod attestation_record;

View File

@ -1,4 +1,5 @@
use super::super::utils::types::Hash256;
use super::utils::types::Hash256;
use super::db;
mod attestation_parent_hashes;
mod shuffling;

View File

@ -0,0 +1,56 @@
use super::block::SszBlock;
use super::Logger;
use super::db::{
BlockStore,
PoWChainStore,
};
pub enum BlockStatus {
NewBlock,
KnownBlock,
UnknownPoWChainRef,
}
pub enum SszBlockValidationError {
SszInvalid,
FutureSlot,
}
macro_rules! valid_if {
($cond:expr, $val:expr) => {
if ($cond)
return Ok($val);
}
};
}
macro_rules! invalid_if {
($cond:expr, $val:expr) => {
if ($cond)
return Err($val);
}
};
}
fn slot_from_time()
pub fn validate_ssz_block(b: &SszBlock,
expected_slot: &u64,
block_store: &BlockStore,
pow_store: &PoWChainStore,
log: &Logger)
-> Result<BlockStatus, SszBlockValidationError>
{
valid_if!(block_store.block_exists(b.block_hash()),
BlockStatus::KnownBlock);
invalid_if!(b.slot_number() > expected_slot,
SszBlockValidationError::FutureSlot);
invalid_if!(pow_store.block_hash_exists(b.pow_chain_ref()) == false,
SszBlockValidationError::UnknownPoWChainRef);
// Do validation here
Ok(BlockStatus::NewBlock)
}