Skip to content

Commit

Permalink
Merge pull request #2032 from subspace/gemini-3f-backport-fix-proving…
Browse files Browse the repository at this point in the history
…-out-of-order-chunks

Gemini 3f backport: Fix proving in case chunks are out of order after sorting by solution distance
  • Loading branch information
nazar-pc authored Oct 1, 2023
2 parents b2ad9ad + 668d13b commit 346bcab
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions crates/subspace-farmer-components/src/proving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,29 +434,22 @@ where
)?
};

let mut s_bucket_records = (0u32..)
.zip(
sector_contents_map
.iter_s_bucket_records(s_bucket)
.expect("S-bucket audit index is guaranteed to be in range; qed"),
)
.take(sector_metadata.pieces_in_sector.into());
let s_bucket_records = sector_contents_map
.iter_s_bucket_records(s_bucket)
.expect("S-bucket audit index is guaranteed to be in range; qed")
.collect::<Vec<_>>();
let winning_chunks = chunk_candidates
.into_iter()
.filter_map(move |chunk_candidate| loop {
let (chunk_offset, (piece_offset, encoded_chunk_used)) = s_bucket_records
.next()
.expect("Chunk candidates are within s-bucket records; qed");

// Not all chunks are within solution range, skip irrelevant chunk offsets until
// desired one is found
if chunk_offset == chunk_candidate.chunk_offset {
return encoded_chunk_used.then_some(WinningChunk {
chunk_offset,
piece_offset,
audit_chunks: chunk_candidate.audit_chunks.into(),
});
}
.filter_map(move |chunk_candidate| {
let (piece_offset, encoded_chunk_used) = s_bucket_records
.get(chunk_candidate.chunk_offset as usize)
.expect("Wouldn't be a candidate if wasn't within s-bucket; qed");

encoded_chunk_used.then_some(WinningChunk {
chunk_offset: chunk_candidate.chunk_offset,
piece_offset: *piece_offset,
audit_chunks: chunk_candidate.audit_chunks.into(),
})
})
.collect::<VecDeque<_>>();

Expand Down

0 comments on commit 346bcab

Please sign in to comment.