From bc56e65d5dd93d17c00e12e9f2c05e0a924e24b5 Mon Sep 17 00:00:00 2001 From: coderofstuff <114628839+coderofstuff@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:28:14 -0600 Subject: [PATCH] Various fixes - Keep using old root to minimize proof size. Old root is calculated using the temporary gd stores - fix the off-by-one in block_at_depth and chain_up_to_depth - revert the temp fix to sync with the off-by-one --- consensus/src/processes/pruning_proof/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/consensus/src/processes/pruning_proof/mod.rs b/consensus/src/processes/pruning_proof/mod.rs index e0ca2a1e85..34ae371dbf 100644 --- a/consensus/src/processes/pruning_proof/mod.rs +++ b/consensus/src/processes/pruning_proof/mod.rs @@ -868,8 +868,7 @@ impl PruningProofManager { } if current_header.direct_parents().is_empty() // Stop at genesis - // Need to ensure this does the same 2M+1 depth that block_at_depth does - || (pp_header.header.blue_score > current_header.blue_score + required_level_0_depth + || (pp_header.header.blue_score >= current_header.blue_score + required_level_0_depth && intersected_with_required_block_chain) { break current_header; @@ -916,9 +915,8 @@ impl PruningProofManager { true, ); - // Need to ensure this does the same 2M+1 depth that block_at_depth does if has_required_block - && (root == self.genesis_hash || ghostdag_store.get_blue_score(selected_tip).unwrap() > required_level_depth) + && (root == self.genesis_hash || ghostdag_store.get_blue_score(selected_tip).unwrap() >= required_level_depth) { break Ok((ghostdag_store, selected_tip, root)); } @@ -1016,7 +1014,8 @@ impl PruningProofManager { let mut headers = Vec::with_capacity(2 * self.pruning_proof_m as usize); let mut queue = BinaryHeap::>::new(); let mut visited = BlockHashSet::new(); - queue.push(Reverse(SortableBlock::new(root, self.headers_store.get_header(root).unwrap().blue_work))); + // Still use "old_root" to make sure we use the minimum amount of records for the proof + queue.push(Reverse(SortableBlock::new(old_root, self.headers_store.get_header(old_root).unwrap().blue_work))); while let Some(current) = queue.pop() { let current = current.0.hash; if !visited.insert(current) { @@ -1158,7 +1157,7 @@ impl PruningProofManager { let mut current_gd = high_gd; let mut current = high; let mut res = vec![current]; - while current_gd.blue_score + depth >= high_gd.blue_score { + while current_gd.blue_score + depth > high_gd.blue_score { if current_gd.selected_parent.is_origin() { break; } @@ -1186,7 +1185,7 @@ impl PruningProofManager { .map_err(|err| PruningProofManagerInternalError::BlockAtDepth(format!("high: {high}, depth: {depth}, {err}")))?; let mut current_gd = high_gd; let mut current = high; - while current_gd.blue_score + depth >= high_gd.blue_score { + while current_gd.blue_score + depth > high_gd.blue_score { if current_gd.selected_parent.is_origin() { break; }