Skip to content

Commit

Permalink
[qs] tolerate block timestamp being updated asynchronously
Browse files Browse the repository at this point in the history
In previous commit, we move timestamp update to async callback to ensure the consistency between mempool, qs and consensus.
However it introduces the race of timestamp can be updated by sync_to first then async callback and violates the assertion.
  • Loading branch information
Zekun Li authored and zekun000 committed Oct 3, 2024
1 parent 514653c commit 41e82f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
8 changes: 4 additions & 4 deletions consensus/src/quorum_store/batch_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ impl BatchGenerator {
"QS: got clean request from execution, block timestamp {}",
block_timestamp
);
assert!(
self.latest_block_timestamp <= block_timestamp,
"Decreasing block timestamp"
);
// Block timestamp is updated asynchronously, so it may race when it enters state sync.
if self.latest_block_timestamp > block_timestamp {
continue;
}
self.latest_block_timestamp = block_timestamp;

for (author, batch_id) in batches.iter().map(|b| (b.author(), b.batch_id())) {
Expand Down
11 changes: 1 addition & 10 deletions consensus/src/quorum_store/batch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,8 @@ impl BatchStore {

pub fn update_certified_timestamp(&self, certified_time: u64) {
trace!("QS: batch reader updating time {:?}", certified_time);
let prev_time = self
.last_certified_time
self.last_certified_time
.fetch_max(certified_time, Ordering::SeqCst);
// Note: prev_time may be equal to certified_time due to state-sync
// at the epoch boundary.
assert!(
prev_time <= certified_time,
"Decreasing executed block timestamp reported to BatchReader {} {}",
prev_time,
certified_time,
);

let expired_keys = self.clear_expired_payload(certified_time);
if let Err(e) = self.db.delete_batches(expired_keys) {
Expand Down

0 comments on commit 41e82f7

Please sign in to comment.