From 0b913e22656cf55cafac1f7372b1d87a44c4e950 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:31:43 +0100 Subject: [PATCH] fix(pipeline): clear `MerkleStage` checkpoints on invalid root (#3973) Co-authored-by: Bjerg Co-authored-by: Oliver Nordbjerg --- crates/stages/src/pipeline/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/stages/src/pipeline/mod.rs b/crates/stages/src/pipeline/mod.rs index a108695cfa..d15fefacf6 100644 --- a/crates/stages/src/pipeline/mod.rs +++ b/crates/stages/src/pipeline/mod.rs @@ -431,6 +431,19 @@ where "Stage encountered a validation error: {error}" ); + // FIXME: When handling errors, we do not commit the database transaction. + // This leads to the Merkle stage not clearing its + // checkpoint, and restarting from an invalid place. + drop(provider_rw); + provider_rw = factory.provider_rw().map_err(PipelineError::Interface)?; + provider_rw + .save_stage_checkpoint_progress(StageId::MerkleExecute, vec![])?; + provider_rw.save_stage_checkpoint( + StageId::MerkleExecute, + prev_checkpoint.unwrap_or_default(), + )?; + provider_rw.commit()?; + // We unwind because of a validation error. If the unwind itself fails, // we bail entirely, otherwise we restart the execution loop from the // beginning.