fix(tree): remove_blocks fixes, return hash and number in persistence task (#10678)

This commit is contained in:
Dan Cline
2024-09-05 12:35:16 -04:00
committed by GitHub
parent e8128a3c85
commit 60bc403f08
4 changed files with 246 additions and 117 deletions

View File

@ -288,11 +288,24 @@ impl CanonicalInMemoryState {
///
/// This will update the links between blocks and remove all blocks that are [..
/// `persisted_height`].
pub fn remove_persisted_blocks(&self, persisted_height: u64) {
pub fn remove_persisted_blocks(&self, persisted_num_hash: BlockNumHash) {
// if the persisted hash is not in the canonical in memory state, do nothing, because it
// means canonical blocks were not actually persisted.
//
// This can happen if the persistence task takes a long time, while a reorg is happening.
{
if self.inner.in_memory_state.blocks.read().get(&persisted_num_hash.hash).is_none() {
// do nothing
return
}
}
{
let mut blocks = self.inner.in_memory_state.blocks.write();
let mut numbers = self.inner.in_memory_state.numbers.write();
let BlockNumHash { number: persisted_height, hash: _ } = persisted_num_hash;
// clear all numbers
numbers.clear();