fix: ensure backfill and persistence dont happen at the same time (#9895)

Co-authored-by: Federico Gimenez <fgimenez@users.noreply.github.com>
This commit is contained in:
Matthias Seitz
2024-07-30 13:14:41 +02:00
committed by GitHub
parent 3a088a9ec7
commit f72eab2997

View File

@@ -713,6 +713,14 @@ where
BackfillSyncState::Idle,
"backfill action should only be emitted when backfill is idle"
);
if self.persistence_state.in_progress() {
// backfill sync and persisting data are mutually exclusive, so we can't start
// backfill while we're still persisting
debug!(target: "engine", "skipping backfill file while persistence task is active");
return
}
self.backfill_sync_state = BackfillSyncState::Pending;
debug!(target: "engine", "emitting backfill action event");
}
@@ -724,8 +732,14 @@ where
}
/// Returns true if the canonical chain length minus the last persisted
/// block is greater than or equal to the persistence threshold.
/// block is greater than or equal to the persistence threshold and
/// backfill is not running.
fn should_persist(&self) -> bool {
if !self.backfill_sync_state.is_idle() {
// can't persist if backfill is running
return false
}
let min_block = self.persistence_state.last_persisted_block_number;
self.state.tree_state.max_block_number().saturating_sub(min_block) >=
self.config.persistence_threshold()