You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
might be wrong but in_memory file is it not better to remove block below persisted height than to clear then re-insert in the for loop
numbers.retain(|&block_num, _| block_num > persisted_height);
// drain all blocks and only keep the ones that are not persisted (below the persisted
// height)
let mut old_blocks = blocks
.drain()
.filter(|(_, b)| b.block_ref().block().number > persisted_height)
.map(|(_, b)| b.block.clone())
.collect::<Vec<_>>();
// sort the blocks by number so we can insert them back in natural order (low -> high)
old_blocks.sort_unstable_by_key(|block| block.block().number);
// re-insert the blocks in natural order and connect them to their parent blocks
for block in old_blocks {
let parent = blocks.get(&block.block().parent_hash).cloned();
let block_state = BlockState::with_parent(block, parent);
let hash = block_state.hash();
// append new blocks
blocks.insert(hash, Arc::new(block_state));
}
Additional context
No response
The text was updated successfully, but these errors were encountered:
Describe the feature
might be wrong but
in_memory file
is it not better to remove block below persisted height than to clear then re-insert in the for loopAdditional context
No response
The text was updated successfully, but these errors were encountered: