diff --git a/eth2/lmd_ghost/src/reduced_tree.rs b/eth2/lmd_ghost/src/reduced_tree.rs index c48fd11d0..a0fc2d96e 100644 --- a/eth2/lmd_ghost/src/reduced_tree.rs +++ b/eth2/lmd_ghost/src/reduced_tree.rs @@ -186,6 +186,13 @@ where where F: Fn(usize) -> Option + 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 {