in merkledb/src/merkledb_debug.rs [80:117]
fn check_reachability_invariant(&self) -> bool {
let mut id_exists: HashSet<MerkleNodeId> = HashSet::new();
for i in 0..self.get_sequence_number() {
// there is no requirement that IDs be sequential just monotonic
if self.find_node_by_id(i as MerkleNodeId).is_some() {
id_exists.insert(i);
}
}
let mut ret = true;
for i in 0..self.get_sequence_number() {
if let Some(node) = self.find_node_by_id(i as MerkleNodeId) {
let mut chlensum: usize = 0;
for (ch, len) in node.children().iter() {
if !id_exists.contains(ch) {
eprintln!("Child {ch:?} of Node {node:?} does not exist");
ret = false;
}
chlensum += len;
}
if !node.children().is_empty() && node.len() != chlensum {
eprintln!("Sum of children length do not sum to node length. {node:?}");
}
if let Some(attr) = self.node_attributes(i as MerkleNodeId) {
let cas_parent = attr.cas_parent();
let file_parent = attr.file_parent();
if cas_parent != 0 && !id_exists.contains(&cas_parent) {
eprintln!("CAS Parent in attribute {attr:?} of Node {node:?} does not exist");
ret = false;
}
if file_parent != 0 && !id_exists.contains(&file_parent) {
eprintln!("FILE Parent in attribute {attr:?} of Node {node:?} does not exist");
ret = false;
}
}
}
}
ret
}