Skip to content

Commit

Permalink
fix: delete orphans if they exist (#4868)
Browse files Browse the repository at this point in the history
Description
---
Orphans should be deleted from the orphan database if they exist. 

Motivation and Context
---
If the block is added to the main chain, it should not exist in the orphan database as well. It will also remove the orphan tips if it removes the block from the pool. 

How Has This Been Tested?
---
Unit test and manually running

fixes: #4867
  • Loading branch information
SWvheerden committed Oct 31, 2022
1 parent 09eda1b commit 6ff1c02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base_layer/core/src/base_node/sync/block_sync/synchronizer.rs
Expand Up @@ -307,6 +307,7 @@ impl<B: BlockchainBackend + 'static> BlockSynchronizer<B> {
if let Err(err) = self
.db
.write_transaction()
.delete_orphan(header_hash)
.insert_bad_block(header_hash, current_height)
.commit()
.await
Expand All @@ -333,6 +334,7 @@ impl<B: BlockchainBackend + 'static> BlockSynchronizer<B> {
let timer = Instant::now();
self.db
.write_transaction()
.delete_orphan(header_hash)
.insert_block_body(block.clone())
.set_best_block(
block.height(),
Expand Down
5 changes: 5 additions & 0 deletions base_layer/core/src/chain_storage/async_db.rs
Expand Up @@ -387,6 +387,11 @@ impl<'a, B: BlockchainBackend + 'static> AsyncDbTransaction<'a, B> {
self
}

pub fn delete_orphan(&mut self, hash: HashOutput) -> &mut Self {
self.transaction.delete_orphan(hash);
self
}

pub fn insert_bad_block(&mut self, hash: HashOutput, height: u64) -> &mut Self {
self.transaction.insert_bad_block(hash, height);
self
Expand Down

0 comments on commit 6ff1c02

Please sign in to comment.