Skip to content

Commit

Permalink
Merge pull request #2031 from subspace/fix-proving-out-of-order-chunks
Browse files Browse the repository at this point in the history
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 07ec9c3 + a3f6d75 commit 8341203
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 8341203

Please sign in to comment.