Skip to content

Commit

Permalink
chore: check genesis block during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 31, 2022
1 parent 7502c02 commit a8f9e93
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ where B: BlockchainBackend
difficulty_calculator: Arc::new(difficulty_calculator),
disable_add_block_flag: Arc::new(AtomicBool::new(false)),
};
let genesis_block = Arc::new(blockchain_db.consensus_manager.get_genesis_block());
if is_empty {
info!(target: LOG_TARGET, "Blockchain db is empty. Adding genesis block.");
let genesis_block = Arc::new(blockchain_db.consensus_manager.get_genesis_block());
blockchain_db.insert_block(genesis_block.clone())?;
let mut txn = DbTransaction::new();
let body = &genesis_block.block().body;
Expand All @@ -230,6 +230,16 @@ where B: BlockchainBackend
txn.set_horizon_data(kernel_sum, utxo_sum);
blockchain_db.write(txn)?;
blockchain_db.store_pruning_horizon(config.pruning_horizon)?;
} else {
if blockchain_db.get_chain_metadata()?.pruning_horizon() == 0 {
// Check the genesis block in the DB.
if !blockchain_db.block_exists(genesis_block.accumulated_data().hash.clone())? {
error!(target: LOG_TARGET, "Stored genesis block mismatch with the binary");
return Err(ChainStorageError::CorruptedDatabase(
"Genesis block mismatch.".to_string(),
));
}
}
}
if cleanup_orphans_at_startup {
match blockchain_db.cleanup_all_orphans() {
Expand Down

0 comments on commit a8f9e93

Please sign in to comment.