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: clarify block order #11279

Merged
merged 1 commit into from
Sep 27, 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
15 changes: 10 additions & 5 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ impl CanonicalInMemoryState {
MemoryOverlayStateProvider::new(historical, in_memory)
}

/// Returns an iterator over all canonical blocks in the in-memory state, from newest to oldest.
/// Returns an iterator over all canonical blocks in the in-memory state, from newest to oldest
/// (highest to lowest).
pub fn canonical_chain(&self) -> impl Iterator<Item = Arc<BlockState>> {
let pending = self.inner.in_memory_state.pending.borrow().clone();
let head = self.inner.in_memory_state.head_state();
Expand Down Expand Up @@ -666,8 +667,12 @@ impl BlockState {
.unwrap_or_default()
}

/// Returns a vector of parent `BlockStates`.
/// The block state order in the output vector is newest to oldest.
/// Returns a vector of __parent__ `BlockStates`.
///
/// The block state order in the output vector is newest to oldest (highest to lowest):
/// `[5,4,3,2,1]`
///
/// Note: This does not include self.
pub fn parent_state_chain(&self) -> Vec<&Self> {
let mut parents = Vec::new();
let mut current = self.parent.as_deref();
Expand All @@ -681,8 +686,8 @@ impl BlockState {
}

/// Returns a vector of `BlockStates` representing the entire in memory chain.
/// The block state order in the output vector is newest to oldest, including
/// self as the first element.
/// The block state order in the output vector is newest to oldest (highest to lowest),
/// including self as the first element.
pub fn chain(&self) -> Vec<&Self> {
let mut chain = vec![self];
self.append_parent_chain(&mut chain);
Expand Down
Loading