Skip to content
Snippets Groups Projects
Commit 40cd5b16 authored by Éloïs's avatar Éloïs
Browse files

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

parent 0130e0cb
No related branches found
No related tags found
1 merge request!206[fix] bc-dal: fork tree must be resistant to light data corruption
......@@ -265,11 +265,11 @@ 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);
if let Some(Some(ref node)) = self.nodes.get(node_id.0) {
branch.push(node.data);
if let Some(parent_id) = node.parent {
let mut parent = self.get_ref_node(parent_id);
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)
......@@ -279,15 +279,19 @@ impl ForkTree {
branch.push(parent.data);
if let Some(parent_id) = parent.parent {
parent = self.get_ref_node(parent_id);
parent = self.get_ref_node(parent_id).clone();
} else {
break;
}
}
}
}
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment