Fix bug with num_nodes/num_chunks
This commit is contained in:
parent
a84a063c25
commit
e19abee7f9
@ -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)? {
|
||||
|
@ -215,9 +215,9 @@ fn test_list_of_struct_with_vec() {
|
||||
|
||||
let modified = vec![
|
||||
vec![a.clone(), c.clone()],
|
||||
// vec![a.clone(), b.clone(), c.clone(), d.clone()],
|
||||
// vec![b.clone(), a.clone(), c.clone(), d.clone()],
|
||||
// vec![],
|
||||
vec![a.clone(), b.clone(), c.clone(), d.clone()],
|
||||
vec![b.clone(), a.clone(), c.clone(), d.clone()],
|
||||
vec![],
|
||||
];
|
||||
|
||||
test_routine(original, modified);
|
||||
|
Loading…
Reference in New Issue
Block a user