Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
coderofstuff committed Jul 10, 2024
1 parent 4f6ad73 commit bc56e65
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions consensus/src/processes/pruning_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -1016,7 +1014,8 @@ impl PruningProofManager {
let mut headers = Vec::with_capacity(2 * self.pruning_proof_m as usize);
let mut queue = BinaryHeap::<Reverse<SortableBlock>>::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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bc56e65

Please sign in to comment.