From f72eab2997b8a49a15fdb5f3e68d3346c8394968 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 30 Jul 2024 13:14:41 +0200 Subject: [PATCH] fix: ensure backfill and persistence dont happen at the same time (#9895) Co-authored-by: Federico Gimenez --- crates/engine/tree/src/tree/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 113a9c1822..6fc4ef6f27 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -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()