Skip to content
Snippets Groups Projects
Commit 55e5e692 authored by Wei Tang's avatar Wei Tang
Browse files

Calculate spec block hash

parent 10d6dcc1
No related merge requests found
use primitives::H256;
use runtime_primitives;
use header::Header;
use extrinsic::Extrinsic;
use spec::SpecHeader;
pub type Block = runtime_primitives::generic::Block<Header, Extrinsic>;
pub trait BlockExt {
fn spec_hash(&self) -> H256;
}
impl BlockExt for Block {
fn spec_hash(&self) -> H256 {
let extrinsic = &self.extrinsics[0];
let header = &self.header;
let spec_header = SpecHeader {
parent_hash: header.parent_hash,
slot_number: extrinsic.slot_number,
randao_reveal: extrinsic.randao_reveal,
attestations: extrinsic.attestations.clone(),
pow_chain_ref: extrinsic.pow_chain_ref,
active_state_root: header.active_state_root,
crystallized_state_root: header.crystallized_state_root,
};
spec_header.spec_hash()
}
}
......@@ -26,7 +26,7 @@ pub struct SpecHeader {
}
impl SpecHeader {
pub fn hash(&self) -> H256 {
pub fn spec_hash(&self) -> H256 {
let encoded = ssz::Encode::encode(self);
let mut blake2 = Blake2b::new_keyed(&[], 64);
blake2.input(&encoded);
......
......@@ -33,7 +33,7 @@ pub fn execute_block(block: Block) {
let attestations = &extrinsic.attestations;
let mut active_state = Active::get();
let crystallized_state = Crystallized::get();
let mut crystallized_state = Crystallized::get();
validation::validate_block_pre_processing_conditions();
active_state.update_recent_block_hashes(parent_slot, slot, parent_hash);
......@@ -46,6 +46,13 @@ pub fn execute_block(block: Block) {
attestations
);
validation::process_cycle_transitions::<BlockHashesBySlot, BlockVoteCache>(
slot,
parent_hash,
&mut crystallized_state,
&mut active_state
);
ParentSlot::put(&slot);
// TODO: Update ParentHash
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment