From ea979abe43ecc1c1a9c533748547e3862abc3690 Mon Sep 17 00:00:00 2001 From: joshieDo Date: Thu, 27 Jul 2023 17:20:39 +0000 Subject: [PATCH 1/5] clear merkle checkpoint on invalid root --- crates/stages/src/pipeline/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/stages/src/pipeline/mod.rs b/crates/stages/src/pipeline/mod.rs index a108695cfad..eabe71aa5b2 100644 --- a/crates/stages/src/pipeline/mod.rs +++ b/crates/stages/src/pipeline/mod.rs @@ -450,6 +450,18 @@ where "Stage encountered an execution error: {error}" ); + // 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. + 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 an execution error. If the unwind itself fails, we // bail entirely, otherwise we restart the execution loop from the // beginning. From 7ca8bc632be2147be4fd2ec0ca862d44df59c792 Mon Sep 17 00:00:00 2001 From: joshieDo Date: Thu, 27 Jul 2023 23:13:42 +0000 Subject: [PATCH 2/5] place on the correct if branch --- crates/stages/src/pipeline/mod.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/stages/src/pipeline/mod.rs b/crates/stages/src/pipeline/mod.rs index eabe71aa5b2..7f776d7171f 100644 --- a/crates/stages/src/pipeline/mod.rs +++ b/crates/stages/src/pipeline/mod.rs @@ -431,6 +431,18 @@ where "Stage encountered a validation error: {error}" ); + // 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. + 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. @@ -450,18 +462,6 @@ where "Stage encountered an execution error: {error}" ); - // 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. - 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 an execution error. If the unwind itself fails, we // bail entirely, otherwise we restart the execution loop from the // beginning. From a49c84a553e57977b70a4fc181cf84334c28cde8 Mon Sep 17 00:00:00 2001 From: joshieDo Date: Fri, 28 Jul 2023 10:52:37 +0000 Subject: [PATCH 3/5] explicitly drop provider_rw --- crates/stages/src/pipeline/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/stages/src/pipeline/mod.rs b/crates/stages/src/pipeline/mod.rs index 7f776d7171f..909ba1f12ef 100644 --- a/crates/stages/src/pipeline/mod.rs +++ b/crates/stages/src/pipeline/mod.rs @@ -434,6 +434,7 @@ where // 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![])?; From 6b339a31da5d254101d45876a5d74dcd5613278a Mon Sep 17 00:00:00 2001 From: Bjerg Date: Mon, 31 Jul 2023 14:51:30 +0200 Subject: [PATCH 4/5] chore: mark fixme --- crates/stages/src/pipeline/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stages/src/pipeline/mod.rs b/crates/stages/src/pipeline/mod.rs index 909ba1f12ef..237ab826256 100644 --- a/crates/stages/src/pipeline/mod.rs +++ b/crates/stages/src/pipeline/mod.rs @@ -431,7 +431,7 @@ where "Stage encountered a validation error: {error}" ); - // When handling errors, we do not commit the database transaction. This + // 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); From 3e5c7d9be915eba7e83bd3a34531da31842cc299 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Mon, 31 Jul 2023 15:22:29 +0200 Subject: [PATCH 5/5] chore: formatting --- crates/stages/src/pipeline/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/stages/src/pipeline/mod.rs b/crates/stages/src/pipeline/mod.rs index 237ab826256..d15fefacf67 100644 --- a/crates/stages/src/pipeline/mod.rs +++ b/crates/stages/src/pipeline/mod.rs @@ -431,8 +431,8 @@ 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 + // 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)?;