Commit 40cd5b16 authored by Éloïs's avatar Éloïs

[fix] bc-dal: fork tree must be resistant to light data corruption

parent 0130e0cb
Pipeline #6711 passed with stages
in 16 minutes and 32 seconds
......@@ -265,29 +265,33 @@ impl ForkTree {
/// Get fork branch
pub fn get_fork_branch(&self, node_id: TreeNodeId) -> Vec<Blockstamp> {
let mut branch = Vec::with_capacity(self.max_depth);
let node = self.get_ref_node(node_id);
branch.push(node.data);
if let Some(parent_id) = node.parent {
let mut parent = self.get_ref_node(parent_id);
while !self.main_branch.contains_key(&parent.data.id)
|| self
.get_main_branch_block_hash(parent.data.id)
.expect("safe unwrap")
!= parent.data.hash
{
branch.push(parent.data);
if let Some(parent_id) = parent.parent {
parent = self.get_ref_node(parent_id);
} else {
break;
if let Some(Some(ref node)) = self.nodes.get(node_id.0) {
branch.push(node.data);
if let Some(parent_id) = node.parent {
if let Some(Some(mut parent)) = self.nodes.get(parent_id.0).cloned() {
while !self.main_branch.contains_key(&parent.data.id)
|| self
.get_main_branch_block_hash(parent.data.id)
.expect("safe unwrap")
!= parent.data.hash
{
branch.push(parent.data);
if let Some(parent_id) = parent.parent {
parent = self.get_ref_node(parent_id).clone();
} else {
break;
}
}
}
}
}
branch.reverse();
branch
branch.reverse();
branch
} else {
vec![]
}
}
/// Modify the main branch (function to call after a successful roolback)
pub fn change_main_branch(
......@@ -417,6 +421,7 @@ impl ForkTree {
// Remove root node
self.nodes[root_node_id.0] = None;
self.sheets.remove(&root_node_id);
self.root = Some(root_node_main_child_id);
}
......
......@@ -178,8 +178,17 @@ pub fn dbex_fork_tree(profile_path: PathBuf, _csv: bool) {
.read(|fork_tree| fork_tree.clone())
.expect("Fail to read fork tree DB !");
// Print all sheets
println!("-----------------------------------");
println!("sheets={:?}", fork_tree.get_sheets());
println!("-----------------------------------");
// Print all fork branches
for (tree_node_id, blockstamp) in fork_tree.get_sheets() {
debug!(
"fork_tree.get_fork_branch({:?}, {})",
tree_node_id, blockstamp
);
let branch = fork_tree.get_fork_branch(tree_node_id);
if !branch.is_empty() {
println!("Fork branch #{}:", blockstamp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment