support blocks import to existing db

This commit is contained in:
Svyatoslav Nikolsky 2016-12-08 22:14:32 +03:00
parent a16cc16b88
commit a5e33c7a26
1 changed files with 4 additions and 0 deletions

View File

@ -37,6 +37,10 @@ impl BlocksWriter {
pub fn append_block(&mut self, block: chain::Block) -> Result<(), Error> {
let indexed_block: db::IndexedBlock = block.into();
// do not append block if it is already there
if self.storage.contains_block(db::BlockRef::Hash(indexed_block.hash().clone())) {
return Ok(());
}
// verify && insert only if parent block is already in the storage
if !self.storage.contains_block(db::BlockRef::Hash(indexed_block.header().previous_header_hash.clone())) {
self.orphaned_blocks_pool.insert_orphaned_block(indexed_block.hash().clone(), indexed_block);