Skip to content

Commit b9d8ae7

Browse files
committed
Fix nodes_without_children
1 parent ed97b97 commit b9d8ae7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,15 @@ where
900900
pub fn assert_knows_head(&self, head_block_root: Hash256) {
901901
let heads = self.chain.heads().unwrap();
902902
if !heads.iter().any(|head| head.0 == head_block_root) {
903-
panic!("Expected to known head block root {head_block_root:?}, known heads {heads:?}");
903+
let fork_choice = self.chain.canonical_head.fork_choice_read_lock();
904+
if heads.is_empty() {
905+
let nodes = fork_choice.proto_array().core_proto_array().nodes;
906+
panic!("Expected to known head block root {head_block_root:?}, but heads is empty. Nodes: {nodes:#?}");
907+
} else {
908+
panic!(
909+
"Expected to known head block root {head_block_root:?}, known heads {heads:#?}"
910+
);
911+
}
904912
}
905913
}
906914

consensus/proto_array/src/proto_array.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ impl ProtoArray {
10621062
fn nodes_without_children(&self) -> Vec<usize> {
10631063
let mut childs_of = HashMap::<_, Vec<_>>::new();
10641064
for (index, node) in self.nodes.iter().enumerate() {
1065+
// Create entry for this node
1066+
childs_of.entry(index).or_default();
1067+
// Add this node to the parent's child list if any
10651068
if let Some(parent_index) = node.parent {
10661069
childs_of.entry(parent_index).or_default().push(index);
10671070
}

0 commit comments

Comments
 (0)