diff --git a/lighthouse/state/chain_config.rs b/lighthouse/state/chain_config.rs index 3d285e7a7..857c2f862 100644 --- a/lighthouse/state/chain_config.rs +++ b/lighthouse/state/chain_config.rs @@ -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 } } } diff --git a/lighthouse/state/mod.rs b/lighthouse/state/mod.rs index baa7597d3..737839721 100644 --- a/lighthouse/state/mod.rs +++ b/lighthouse/state/mod.rs @@ -5,6 +5,7 @@ extern crate bytes; extern crate ssz; use super::utils; +use super::db; pub mod active_state; pub mod attestation_record; diff --git a/lighthouse/state/transition/mod.rs b/lighthouse/state/transition/mod.rs index dd8967e65..518a86db6 100644 --- a/lighthouse/state/transition/mod.rs +++ b/lighthouse/state/transition/mod.rs @@ -1,4 +1,5 @@ -use super::super::utils::types::Hash256; +use super::utils::types::Hash256; +use super::db; mod attestation_parent_hashes; mod shuffling; diff --git a/lighthouse/state/transition/validate_block.rs b/lighthouse/state/transition/validate_block.rs new file mode 100644 index 000000000..6ed3a2824 --- /dev/null +++ b/lighthouse/state/transition/validate_block.rs @@ -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 +{ + 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) +}