Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request paritytech#156 from subspace/fix-block-production-…
Browse files Browse the repository at this point in the history
…stall-on-recommit

Fix block production stall when there are new pieces archived during already active recommitment by not holding unnecessary lock
  • Loading branch information
nazar-pc authored Nov 26, 2021
2 parents db4639f + 96ec358 commit f447bc8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions crates/subspace-farmer/src/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ impl Commitments {
.update_status(salt, CommitmentStatus::InProgress)
.await?;

// Release lock to allow working with other databases, but hold lock for `db_entry.db` such
// that nothing else can modify it
let mut db_guard = db_entry.db.lock().await;
// Release lock to allow working with other databases, but hold lock for `db_entry.db` such
// that nothing else can modify it.
drop(commitment_databases);

let db_path = self.inner.base_directory.join(hex::encode(salt));
Expand All @@ -239,6 +239,8 @@ impl Commitments {
let piece_count = plot.piece_count();
for batch_start in (0..piece_count).step_by(BATCH_SIZE as usize) {
let pieces_to_process = (batch_start + BATCH_SIZE).min(piece_count) - batch_start;
// TODO: Read next batch while creating tags for the previous one for faster
// recommitment.
let pieces = runtime_handle
.block_on(plot.read_pieces(batch_start, pieces_to_process))
.map_err(CommitmentError::Plot)?;
Expand Down Expand Up @@ -293,18 +295,22 @@ impl Commitments {
.collect::<Vec<Salt>>();

for salt in salts {
let commitment_databases = self.inner.commitment_databases.lock().await;
let db_entry = match commitment_databases.databases.peek(&salt).cloned() {
let db_entry = match self
.inner
.commitment_databases
.lock()
.await
.databases
.peek(&salt)
.cloned()
{
Some(db_entry) => db_entry,
None => {
continue;
}
};

// Release lock to allow working with other databases, but hold lock for `db_entry.db` such
// that nothing else can modify it
let db_guard = db_entry.db.lock().await;
drop(commitment_databases);

let db = match db_guard.clone() {
Some(db) => db,
Expand Down

0 comments on commit f447bc8

Please sign in to comment.