Add progress to validate_block

This commit is contained in:
Paul Hauner 2018-09-22 11:13:55 +10:00
parent af2ba7eebf
commit bbf640c40d
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
6 changed files with 33 additions and 29 deletions

View File

@ -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;

View File

@ -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";

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<DBError> 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<T>(b: &SszBlock,
expected_slot: u64,
block_store: &BlockStore<T>,
pow_store: &PoWChainStore<T>,
validator_store: &ValidatorStore<T>,
log: &Logger)
-> Result<BlockStatus, SszBlockValidationError>
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)