Skip to content

Commit

Permalink
View Service: Don't sync the same block twice (#4578)
Browse files Browse the repository at this point in the history
This should fix an issue wherein a load balanced RPC can cause data
corruption by delivering the same block twice in the stream.

## Issue ticket number and link

This should close #4577.

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > Just a client change

(cherry picked from commit 4245ebc)
  • Loading branch information
cronokirby authored and conorsch committed Jun 20, 2024
1 parent 4a8761f commit 574aa05
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/view/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,17 @@ impl Worker {
}
});

let mut expected_height = start_height;

while let Some(block) = buffered_stream.recv().await {
let block: CompactBlock = block?.try_into()?;

let height = block.height;
if height != expected_height {
tracing::warn!("out of order block detected");
continue;
}
expected_height += 1;

// Lock the SCT only while processing this block.
let mut sct_guard = self.sct.write().await;
Expand Down

0 comments on commit 574aa05

Please sign in to comment.