diff --git a/lighthouse/db/mod.rs b/lighthouse/db/mod.rs index ab70ede94..e030fc009 100644 --- a/lighthouse/db/mod.rs +++ b/lighthouse/db/mod.rs @@ -4,7 +4,7 @@ extern crate blake2_rfc as blake2; mod disk_db; mod memory_db; mod traits; -mod stores; +pub mod stores; pub use self::disk_db::DiskDB; diff --git a/lighthouse/db/stores/mod.rs b/lighthouse/db/stores/mod.rs index e7281ad14..a7e5c60bb 100644 --- a/lighthouse/db/stores/mod.rs +++ b/lighthouse/db/stores/mod.rs @@ -9,6 +9,7 @@ mod validator_store; pub use self::block_store::BlockStore; pub use self::pow_chain_store::PoWChainStore; +pub use self::validator_store::ValidatorStore; const BLOCKS_DB_COLUMN: &str = "blocks"; const POW_CHAIN_DB_COLUMN: &str = "powchain"; diff --git a/lighthouse/main.rs b/lighthouse/main.rs index 367b71920..257ef1b6b 100644 --- a/lighthouse/main.rs +++ b/lighthouse/main.rs @@ -15,7 +15,7 @@ pub mod config; use std::path::PathBuf; -use slog::Drain; +use slog::{ Drain, Logger }; use clap::{ Arg, App }; use config::LighthouseConfig; use client::Client; diff --git a/lighthouse/state/mod.rs b/lighthouse/state/mod.rs index 737839721..8f8f748d8 100644 --- a/lighthouse/state/mod.rs +++ b/lighthouse/state/mod.rs @@ -4,6 +4,7 @@ extern crate blake2_rfc as blake2; extern crate bytes; extern crate ssz; +use super::Logger; use super::utils; use super::db; diff --git a/lighthouse/state/transition/mod.rs b/lighthouse/state/transition/mod.rs index 518a86db6..2d4592f30 100644 --- a/lighthouse/state/transition/mod.rs +++ b/lighthouse/state/transition/mod.rs @@ -1,8 +1,11 @@ +use super::block; +use super::Logger; use super::utils::types::Hash256; use super::db; mod attestation_parent_hashes; mod shuffling; +mod validate_block; pub use self::attestation_parent_hashes::attestation_parent_hashes; pub use self::shuffling::shuffle; diff --git a/lighthouse/state/transition/validate_block.rs b/lighthouse/state/transition/validate_block.rs index 6ed3a2824..c7c04e10b 100644 --- a/lighthouse/state/transition/validate_block.rs +++ b/lighthouse/state/transition/validate_block.rs @@ -1,55 +1,54 @@ use super::block::SszBlock; use super::Logger; use super::db::{ + ClientDB, + DBError, +}; +use super::db::stores::{ BlockStore, PoWChainStore, + ValidatorStore, }; pub enum BlockStatus { NewBlock, KnownBlock, - UnknownPoWChainRef, } pub enum SszBlockValidationError { SszInvalid, FutureSlot, + UnknownPoWChainRef, + DatabaseError(String), } -macro_rules! valid_if { - ($cond:expr, $val:expr) => { - if ($cond) - return Ok($val); - } - }; +impl From for SszBlockValidationError { + fn from(e: DBError) -> SszBlockValidationError { + SszBlockValidationError::DatabaseError(e.message) + } } -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, +pub fn validate_ssz_block(b: &SszBlock, + expected_slot: u64, + block_store: &BlockStore, + pow_store: &PoWChainStore, + validator_store: &ValidatorStore, log: &Logger) -> Result + where T: Sized + ClientDB { - valid_if!(block_store.block_exists(b.block_hash()), - BlockStatus::KnownBlock); + if block_store.block_exists(&b.block_hash())? { + return Ok(BlockStatus::KnownBlock); + } - invalid_if!(b.slot_number() > expected_slot, - SszBlockValidationError::FutureSlot); + if b.slot_number() > expected_slot { + return Err(SszBlockValidationError::FutureSlot); + } - invalid_if!(pow_store.block_hash_exists(b.pow_chain_ref()) == false, - SszBlockValidationError::UnknownPoWChainRef); + if pow_store.block_hash_exists(b.pow_chain_ref())? == false { + return Err(SszBlockValidationError::UnknownPoWChainRef); + } // Do validation here Ok(BlockStatus::NewBlock)