Skip to content

Commit

Permalink
Add all mismatches in chronological order to MismatchedChecksum error
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhelsing committed Dec 7, 2023
1 parent 02e95b4 commit 79db831
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub enum GgrsError {
/// [`SyncTestSession`]: crate::SyncTestSession
MismatchedChecksum {
/// The frame at which the mismatch occurred.
frame: Frame,
current_frame: Frame,
/// The frames with mismatched checksums (one or more)
mismatched_frames: Vec<Frame>,
},
/// The Session is not synchronized yet. Please start the session and wait a few ms to let the clients synchronize.
NotSynchronized,
Expand All @@ -47,11 +49,14 @@ impl Display for GgrsError {
"The session is not yet synchronized with all remote sessions."
)
}
GgrsError::MismatchedChecksum { frame } => {
GgrsError::MismatchedChecksum {
current_frame,
mismatched_frames,
} => {
write!(
f,
"Detected checksum mismatch during rollback on frame {}.",
frame
"Detected checksum mismatch during rollback on frame {}, mismatched frames: {:?}",
current_frame, mismatched_frames
)
}
GgrsError::SpectatorTooFarBehind => {
Expand Down
15 changes: 9 additions & 6 deletions src/sessions/sync_test_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ impl<T: Config> SyncTestSession<T> {
if self.check_distance > 0 && current_frame > self.check_distance as i32 {
// compare checksums of older frames to our checksum history (where only the first version of any checksum is recorded)
let oldest_frame_to_check = current_frame - self.check_distance as Frame;
for frame_to_check in oldest_frame_to_check..=current_frame {
if !self.checksums_consistent(frame_to_check) {
return Err(GgrsError::MismatchedChecksum {
frame: frame_to_check,
});
}
let mismatched_frames: Vec<_> = (oldest_frame_to_check..=current_frame)
.filter(|frame_to_check| !self.checksums_consistent(*frame_to_check))
.collect();

if !mismatched_frames.is_empty() {
return Err(GgrsError::MismatchedChecksum {
current_frame,
mismatched_frames,
});
}

// simulate rollbacks according to the check_distance
Expand Down

0 comments on commit 79db831

Please sign in to comment.