Skip to content

Commit

Permalink
Fix logic err when caching last chunk each block
Browse files Browse the repository at this point in the history
  • Loading branch information
j-berman committed Sep 29, 2024
1 parent 04d820e commit ca100ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/fcmp_pp/tree_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ static void cache_last_chunk(const std::unique_ptr<C> &curve,
CHECK_AND_ASSERT_THROW_MES(!layer_ext.hashes.empty(), "unexpected empty layer ext");

const ChildChunkIdx end_child_chunk_idx = layer_ext.start_idx + layer_ext.hashes.size();
const ChildChunkIdx start_child_chunk_idx = std::max(layer_ext.start_idx,
end_child_chunk_idx - (end_child_chunk_idx % parent_width));

const ChildChunkIdx offset = end_child_chunk_idx % parent_width;
const ChildChunkIdx end_offset = offset ? offset : parent_width;
CHECK_AND_ASSERT_THROW_MES(end_child_chunk_idx >= end_offset, "high end_offset");

const ChildChunkIdx start_child_chunk_idx = std::max(layer_ext.start_idx, end_child_chunk_idx - end_offset);

MDEBUG("Caching start_child_chunk_idx " << start_child_chunk_idx << " to end_child_chunk_idx " << end_child_chunk_idx
<< " (layer start idx " << layer_ext.start_idx << ")");
<< " (layer start idx " << layer_ext.start_idx << " , parent_width " << parent_width << " , end_offset " << end_offset << ")");

// TODO: this code is duplicated above
for (ChildChunkIdx child_chunk_idx = start_child_chunk_idx; child_chunk_idx < end_child_chunk_idx; ++child_chunk_idx)
Expand Down Expand Up @@ -582,4 +586,4 @@ template CurveTrees<Helios, Selene>::LastHashes TreeSync<Helios, Selene>::get_la
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
}//namespace curve_trees
}//namespace fcmp_pp
}//namespace fcmp_pp
2 changes: 1 addition & 1 deletion src/fcmp_pp/tree_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@ class TreeSync
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
}//namespace curve_trees
}//namespace fcmp_pp
}//namespace fcmp_pp

0 comments on commit ca100ec

Please sign in to comment.