Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: misc in memory docs #11365

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ impl CanonicalInMemoryState {
}

/// Append new blocks to the in memory state.
///
/// This removes all reorged blocks and appends the new blocks to the tracked chain and connects
/// them to their parent blocks.
fn update_blocks<I>(&self, new_blocks: I, reorged: I)
where
I: IntoIterator<Item = ExecutedBlock>,
Expand Down Expand Up @@ -316,16 +319,18 @@ impl CanonicalInMemoryState {
// clear all numbers
numbers.clear();

// drain all blocks and only keep the ones that are not persisted
// 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().block().number > persisted_height)
.map(|(_, b)| b.block.clone())
.filter(|b| b.block().number > persisted_height)
.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.clone(), parent);
Expand Down Expand Up @@ -410,7 +415,7 @@ impl CanonicalInMemoryState {
self.inner.chain_info_tracker.on_transition_configuration_exchanged();
}

/// Returns the timepstamp of the last transition configuration exchanged,
/// Returns the timestamp of the last transition configuration exchanged,
pub fn last_exchanged_transition_configuration_timestamp(&self) -> Option<Instant> {
self.inner.chain_info_tracker.last_transition_configuration_exchanged_at()
}
Expand Down
Loading