Skip to content

Commit

Permalink
blockchain: Fix verifying history setting for the genesis
Browse files Browse the repository at this point in the history
Fix the verifying history setting for a corner case where a DB is
loaded and the block number is still the genesis one (no history yet).
This was provoking that `can_verify_history` to be set as false as the
genesis history root doesn't match the hash of the history store.
  • Loading branch information
jsdanielh committed Aug 9, 2023
1 parent 0b0eb4f commit 186d976
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions blockchain/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,15 @@ impl Blockchain {
// Correctly set flag for verifying the history root.
let history_root = history_store
.get_history_tree_root(Policy::epoch_at(main_chain.head.block_number()), None);
let can_verify_history = history_root
.map(|history_root| &history_root == main_chain.head.history_root())
.unwrap_or(false);
let can_verify_history = if main_chain.head.block_number() == Policy::genesis_block_number()
{
// We always can verify history for the genesis block
true
} else {
history_root
.map(|history_root| &history_root == main_chain.head.history_root())
.unwrap_or(false)
};

// Load macro chain from store.
let macro_chain_info = chain_store
Expand Down

0 comments on commit 186d976

Please sign in to comment.