Add progress to validate_block
This commit is contained in:
parent
af2ba7eebf
commit
bbf640c40d
@ -4,7 +4,7 @@ extern crate blake2_rfc as blake2;
|
|||||||
mod disk_db;
|
mod disk_db;
|
||||||
mod memory_db;
|
mod memory_db;
|
||||||
mod traits;
|
mod traits;
|
||||||
mod stores;
|
pub mod stores;
|
||||||
|
|
||||||
|
|
||||||
pub use self::disk_db::DiskDB;
|
pub use self::disk_db::DiskDB;
|
||||||
|
@ -9,6 +9,7 @@ mod validator_store;
|
|||||||
|
|
||||||
pub use self::block_store::BlockStore;
|
pub use self::block_store::BlockStore;
|
||||||
pub use self::pow_chain_store::PoWChainStore;
|
pub use self::pow_chain_store::PoWChainStore;
|
||||||
|
pub use self::validator_store::ValidatorStore;
|
||||||
|
|
||||||
const BLOCKS_DB_COLUMN: &str = "blocks";
|
const BLOCKS_DB_COLUMN: &str = "blocks";
|
||||||
const POW_CHAIN_DB_COLUMN: &str = "powchain";
|
const POW_CHAIN_DB_COLUMN: &str = "powchain";
|
||||||
|
@ -15,7 +15,7 @@ pub mod config;
|
|||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use slog::Drain;
|
use slog::{ Drain, Logger };
|
||||||
use clap::{ Arg, App };
|
use clap::{ Arg, App };
|
||||||
use config::LighthouseConfig;
|
use config::LighthouseConfig;
|
||||||
use client::Client;
|
use client::Client;
|
||||||
|
@ -4,6 +4,7 @@ extern crate blake2_rfc as blake2;
|
|||||||
extern crate bytes;
|
extern crate bytes;
|
||||||
extern crate ssz;
|
extern crate ssz;
|
||||||
|
|
||||||
|
use super::Logger;
|
||||||
use super::utils;
|
use super::utils;
|
||||||
use super::db;
|
use super::db;
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
use super::block;
|
||||||
|
use super::Logger;
|
||||||
use super::utils::types::Hash256;
|
use super::utils::types::Hash256;
|
||||||
use super::db;
|
use super::db;
|
||||||
|
|
||||||
mod attestation_parent_hashes;
|
mod attestation_parent_hashes;
|
||||||
mod shuffling;
|
mod shuffling;
|
||||||
|
mod validate_block;
|
||||||
|
|
||||||
pub use self::attestation_parent_hashes::attestation_parent_hashes;
|
pub use self::attestation_parent_hashes::attestation_parent_hashes;
|
||||||
pub use self::shuffling::shuffle;
|
pub use self::shuffling::shuffle;
|
||||||
|
@ -1,55 +1,54 @@
|
|||||||
use super::block::SszBlock;
|
use super::block::SszBlock;
|
||||||
use super::Logger;
|
use super::Logger;
|
||||||
use super::db::{
|
use super::db::{
|
||||||
|
ClientDB,
|
||||||
|
DBError,
|
||||||
|
};
|
||||||
|
use super::db::stores::{
|
||||||
BlockStore,
|
BlockStore,
|
||||||
PoWChainStore,
|
PoWChainStore,
|
||||||
|
ValidatorStore,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum BlockStatus {
|
pub enum BlockStatus {
|
||||||
NewBlock,
|
NewBlock,
|
||||||
KnownBlock,
|
KnownBlock,
|
||||||
UnknownPoWChainRef,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SszBlockValidationError {
|
pub enum SszBlockValidationError {
|
||||||
SszInvalid,
|
SszInvalid,
|
||||||
FutureSlot,
|
FutureSlot,
|
||||||
|
UnknownPoWChainRef,
|
||||||
|
DatabaseError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! valid_if {
|
impl From<DBError> for SszBlockValidationError {
|
||||||
($cond:expr, $val:expr) => {
|
fn from(e: DBError) -> SszBlockValidationError {
|
||||||
if ($cond)
|
SszBlockValidationError::DatabaseError(e.message)
|
||||||
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<T>(b: &SszBlock,
|
||||||
|
expected_slot: u64,
|
||||||
|
block_store: &BlockStore<T>,
|
||||||
pub fn validate_ssz_block(b: &SszBlock,
|
pow_store: &PoWChainStore<T>,
|
||||||
expected_slot: &u64,
|
validator_store: &ValidatorStore<T>,
|
||||||
block_store: &BlockStore,
|
|
||||||
pow_store: &PoWChainStore,
|
|
||||||
log: &Logger)
|
log: &Logger)
|
||||||
-> Result<BlockStatus, SszBlockValidationError>
|
-> Result<BlockStatus, SszBlockValidationError>
|
||||||
|
where T: Sized + ClientDB
|
||||||
{
|
{
|
||||||
valid_if!(block_store.block_exists(b.block_hash()),
|
if block_store.block_exists(&b.block_hash())? {
|
||||||
BlockStatus::KnownBlock);
|
return Ok(BlockStatus::KnownBlock);
|
||||||
|
}
|
||||||
|
|
||||||
invalid_if!(b.slot_number() > expected_slot,
|
if b.slot_number() > expected_slot {
|
||||||
SszBlockValidationError::FutureSlot);
|
return Err(SszBlockValidationError::FutureSlot);
|
||||||
|
}
|
||||||
|
|
||||||
invalid_if!(pow_store.block_hash_exists(b.pow_chain_ref()) == false,
|
if pow_store.block_hash_exists(b.pow_chain_ref())? == false {
|
||||||
SszBlockValidationError::UnknownPoWChainRef);
|
return Err(SszBlockValidationError::UnknownPoWChainRef);
|
||||||
|
}
|
||||||
|
|
||||||
// Do validation here
|
// Do validation here
|
||||||
Ok(BlockStatus::NewBlock)
|
Ok(BlockStatus::NewBlock)
|
||||||
|
Loading…
Reference in New Issue
Block a user