From 547d25b6466af9c949fe7aabc0bb3dba96d6c5ab Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:14:51 -0400 Subject: [PATCH] chore(tree): log and diff header root difference in witness hook (#11184) --- .../engine/invalid-block-hooks/src/witness.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/engine/invalid-block-hooks/src/witness.rs b/crates/engine/invalid-block-hooks/src/witness.rs index 7a9c6e0f96..4b15213191 100644 --- a/crates/engine/invalid-block-hooks/src/witness.rs +++ b/crates/engine/invalid-block-hooks/src/witness.rs @@ -230,19 +230,27 @@ where // Calculate the state root and trie updates after re-execution. They should match // the original ones. - let (state_root, trie_output) = state_provider.state_root_with_updates(hashed_state)?; - if let Some(trie_updates) = trie_updates { - if state_root != trie_updates.1 { + let (re_executed_root, trie_output) = + state_provider.state_root_with_updates(hashed_state)?; + if let Some((original_updates, original_root)) = trie_updates { + if re_executed_root != original_root { let filename = format!("{}_{}.state_root.diff", block.number, block.hash()); - let diff_path = self.save_diff(filename, &state_root, &trie_updates.1)?; - warn!(target: "engine::invalid_block_hooks::witness", diff_path = %diff_path.display(), "State root mismatch after re-execution"); + let diff_path = self.save_diff(filename, &re_executed_root, &original_root)?; + warn!(target: "engine::invalid_block_hooks::witness", ?original_root, ?re_executed_root, diff_path = %diff_path.display(), "State root mismatch after re-execution"); } - if &trie_output != trie_updates.0 { + // If the re-executed state root does not match the _header_ state root, also log that. + if re_executed_root != block.state_root { + let filename = format!("{}_{}.header_state_root.diff", block.number, block.hash()); + let diff_path = self.save_diff(filename, &re_executed_root, &block.state_root)?; + warn!(target: "engine::invalid_block_hooks::witness", header_state_root=?block.state_root, ?re_executed_root, diff_path = %diff_path.display(), "Re-executed state root does not match block state root"); + } + + if &trie_output != original_updates { // Trie updates are too big to diff, so we just save the original and re-executed let original_path = self.save_file( format!("{}_{}.trie_updates.original.json", block.number, block.hash()), - trie_updates.0, + original_updates, )?; let re_executed_path = self.save_file( format!("{}_{}.trie_updates.re_executed.json", block.number, block.hash()),