mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Fix bug with num_nodes/num_chunks
This commit is contained in:
@@ -316,7 +316,7 @@ impl TreeHashCache {
|
||||
old_flags,
|
||||
old_overlay.height(),
|
||||
new_overlay.height(),
|
||||
new_overlay.total_chunks(),
|
||||
new_overlay.num_chunks(),
|
||||
)
|
||||
.ok_or_else(|| Error::UnableToShrinkMerkleTree)?
|
||||
};
|
||||
|
||||
@@ -42,6 +42,10 @@ impl BTreeOverlay {
|
||||
self.num_leaf_nodes() - self.lengths.len()
|
||||
}
|
||||
|
||||
/// Returns the number of nodes in the tree.
|
||||
///
|
||||
/// Note: this is distinct from `num_chunks`, which returns the total number of chunks in
|
||||
/// this tree.
|
||||
pub fn num_nodes(&self) -> usize {
|
||||
2 * self.num_leaf_nodes() - 1
|
||||
}
|
||||
@@ -71,7 +75,11 @@ impl BTreeOverlay {
|
||||
self.first_node()..self.next_node()
|
||||
}
|
||||
|
||||
pub fn total_chunks(&self) -> usize {
|
||||
/// Returns the number of chunks inside this tree (including subtrees).
|
||||
///
|
||||
/// Note: this is distinct from `num_nodes` which returns the number of nodes in the binary
|
||||
/// tree.
|
||||
pub fn num_chunks(&self) -> usize {
|
||||
self.next_node() - self.first_node()
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ where
|
||||
let mut lengths = vec![];
|
||||
|
||||
for item in self {
|
||||
lengths.push(BTreeOverlay::new(item, 0, depth)?.num_nodes())
|
||||
lengths.push(BTreeOverlay::new(item, 0, depth)?.num_chunks())
|
||||
}
|
||||
|
||||
// Disallow zero-length as an empty list still has one all-padding node.
|
||||
@@ -177,8 +177,6 @@ where
|
||||
|
||||
cache.update_internal_nodes(&new_overlay)?;
|
||||
|
||||
dbg!(&new_overlay);
|
||||
|
||||
// Mix in length.
|
||||
let root_node = new_overlay.root();
|
||||
if cache.changed(root_node)? {
|
||||
|
||||
Reference in New Issue
Block a user