feat: state housekeeping after backfill finished (#9870)

This commit is contained in:
Matthias Seitz
2024-07-29 19:38:20 +02:00
committed by GitHub
parent 0b9e9f46c4
commit 0b91e03ff4
2 changed files with 53 additions and 15 deletions

View File

@ -90,6 +90,19 @@ pub(crate) struct CanonicalInMemoryStateInner {
pub(crate) canon_state_notification_sender: CanonStateNotificationSender,
}
impl CanonicalInMemoryStateInner {
/// Clears all entries in the in memory state.
fn clear(&self) {
let mut blocks = self.in_memory_state.blocks.write();
let mut numbers = self.in_memory_state.numbers.write();
let mut pending = self.in_memory_state.pending.write();
blocks.clear();
numbers.clear();
pending.take();
}
}
/// This type is responsible for providing the blocks, receipts, and state for
/// all canonical blocks not on disk yet and keeps track of the block range that
/// is in memory.
@ -144,6 +157,11 @@ impl CanonicalInMemoryState {
self.state_by_hash(hash).map(|block| block.block().block.header.clone())
}
/// Clears all entries in the in memory state.
pub fn clear_state(&self) {
self.inner.clear()
}
/// Updates the pending block with the given block.
///
/// Note: This assumes that the parent block of the pending block is canonical.