Cover edge case in reduced tree

This commit is contained in:
Paul Hauner 2019-06-17 17:39:33 -07:00
parent c6e24572c7
commit 2b5c70711d
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -186,6 +186,13 @@ where
where
F: Fn(usize) -> Option<u64> + Copy,
{
// It is possible that the given `start_block_root` is not in the reduced tree.
//
// In this case, we add a weightless node at `start_block_root`.
if !self.nodes.contains_key(&start_block_root) {
self.add_weightless_node(start_block_root)?;
};
let _root_weight = self.update_weight(start_block_root, weight_fn)?;
let start_node = self.get_node(start_block_root)?;
@ -389,6 +396,9 @@ where
for &child_hash in &prev_in_tree.children {
let ancestor_hash = self.find_least_common_ancestor(node.block_hash, child_hash)?;
// TODO: handle the case where the new block is a child of an existing node and a
// parent of an existing node.
if ancestor_hash != prev_in_tree.block_hash {
let child = self.get_mut_node(child_hash)?;
let common_ancestor = Node {