Skip to content

Commit

Permalink
fix(collator): avoid 2 parallel shard collations after sync in some c…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
SmaGMan authored and Rexagon committed Dec 11, 2024
1 parent 07e83e6 commit 379672f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions collator/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,8 @@ where
);
}

Self::reset_collation_sync_status(&mut self.collation_sync_state.lock());

// TODO: refactor this logic
// replace last collated block id with last applied
self.blocks_cache
Expand Down Expand Up @@ -1894,6 +1896,20 @@ where
}
}

/// Reset collation status from `WaitForMasterStatus` to `AttemptsInProgress` for every shard.
///
/// Use this method before resuming collation after sync to avoid ambiguous situations.
/// If any shard has collation status `WaitForMasterStatus` and sync was executed,
/// when master collation check was finished first then it will enqueue one more resume for shard,
/// so we will have two parallel collations for shard that will cause panic futher.
fn reset_collation_sync_status(guard: &mut CollationSyncState) {
for (_, collation_state) in guard.states.iter_mut() {
if collation_state.status == CollationStatus::WaitForMasterStatus {
collation_state.status = CollationStatus::AttemptsInProgress;
}
}
}

/// 1. Store collation status for current shard
/// 2. Detect the next step: wait for master status, resume attempts, run master collation
fn detect_next_collation_step(
Expand Down

0 comments on commit 379672f

Please sign in to comment.