From c2a8a6ea6822fde3894401134a7d33e9389bc214 Mon Sep 17 00:00:00 2001 From: Piotr Heilman Date: Mon, 25 Nov 2024 09:13:40 +0100 Subject: [PATCH] Fix off chain startup. --- src/identity/processor.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/identity/processor.rs b/src/identity/processor.rs index b86b8202..55123429 100644 --- a/src/identity/processor.rs +++ b/src/identity/processor.rs @@ -566,7 +566,27 @@ impl IdentityProcessor for OffChainIdentityProcessor { } async fn tree_init_correction(&self, _initial_root_hash: &Hash) -> anyhow::Result<()> { - // For off chain mode we don't correct tree at all + // it's enough to run with read committed here + // since in the worst case another instance of the sequencer + // will try to do the same thing but with a later root + // in such a case the state will be corrected later in the program + let mut tx = self + .database + .begin_tx(IsolationLevel::ReadCommitted) + .await?; + + let root_hash = tx + .get_latest_root_by_status(ProcessedStatus::Processed) + .await?; + + if let Some(root_hash) = root_hash { + // This deletion is required as when tree is being initialized we do not read batches. + // Just restarting from last processed tree. + tx.delete_batches_after_root(&root_hash).await?; // TODO: We probably shouldn't do this in HA + } + + tx.commit().await?; + Ok(()) }