From 14240107cfe469d441ab90aae967ed02d04920ad Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:37:24 -0500 Subject: [PATCH] chore: add docs for why descendant checks are safe --- crates/engine/tree/src/tree/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index c592d0dc102a..8dee278c2741 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -2267,12 +2267,13 @@ where // TODO: switch to calculate state root using `StateRootTask`. - // We attempt to compute state root in parallel if we are currently not persisting anything - // to database. This is safe, because the database state cannot change until we - // finish parallel computation. It is important that nothing is being persisted as - // we are computing in parallel, because we initialize a different database transaction - // per thread and it might end up with a different view of the database. - // let persistence_in_progress = self.persistence_state.in_progress(); + // We only run the parallel state root if we are currently persisting blocks that are all + // ancestors of the one we are executing. If we're committing ancestor blocks, then: any + // trie updates being committed are a subset of the in-memory trie updates collected before + // fetching reverts. So any diff in reverts (pre vs post commit) is already covered by the + // in-memory trie updates we collect in `compute_state_root_parallel`. + // + // See https://github.com/paradigmxyz/reth/issues/12688 for more details let is_descendant_block = self.persistence_state.current_action().map_or(true, |action| { match action { CurrentPersistenceAction::SavingBlocks { blocks } => {