Begin basics of block validation
This commit is contained in:
parent
d4e6f12ded
commit
51c842c236
@ -2,6 +2,7 @@ pub struct ChainConfig {
|
|||||||
pub cycle_length: u8,
|
pub cycle_length: u8,
|
||||||
pub shard_count: u16,
|
pub shard_count: u16,
|
||||||
pub min_committee_size: u64,
|
pub min_committee_size: u64,
|
||||||
|
pub genesis_time: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChainConfig {
|
impl ChainConfig {
|
||||||
@ -10,6 +11,7 @@ impl ChainConfig {
|
|||||||
cycle_length: 8,
|
cycle_length: 8,
|
||||||
shard_count: 1024,
|
shard_count: 1024,
|
||||||
min_committee_size: 128,
|
min_committee_size: 128,
|
||||||
|
genesis_time: 1537488655, // arbitrary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ extern crate bytes;
|
|||||||
extern crate ssz;
|
extern crate ssz;
|
||||||
|
|
||||||
use super::utils;
|
use super::utils;
|
||||||
|
use super::db;
|
||||||
|
|
||||||
pub mod active_state;
|
pub mod active_state;
|
||||||
pub mod attestation_record;
|
pub mod attestation_record;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::super::utils::types::Hash256;
|
use super::utils::types::Hash256;
|
||||||
|
use super::db;
|
||||||
|
|
||||||
mod attestation_parent_hashes;
|
mod attestation_parent_hashes;
|
||||||
mod shuffling;
|
mod shuffling;
|
||||||
|
56
lighthouse/state/transition/validate_block.rs
Normal file
56
lighthouse/state/transition/validate_block.rs
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user