From 2a36dc27c4225b95bdde428d6b97b0d8d1bf9ced Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Thu, 4 May 2023 22:25:26 +0300 Subject: [PATCH] chore(provider): seperate error on unwind root mismatch (#2563) --- crates/storage/provider/src/transaction.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/storage/provider/src/transaction.rs b/crates/storage/provider/src/transaction.rs index 93571e5c2e..e74223e619 100644 --- a/crates/storage/provider/src/transaction.rs +++ b/crates/storage/provider/src/transaction.rs @@ -584,7 +584,7 @@ where let (state_root, trie_updates) = StateRoot::incremental_root_with_updates(self.deref_mut(), range.clone())?; if state_root != expected_state_root { - return Err(TransactionError::StateTrieRootMismatch { + return Err(TransactionError::StateRootMismatch { got: state_root, expected: expected_state_root, block_number: *range.end(), @@ -985,7 +985,7 @@ where // but for sake of double verification we will check it again. if new_state_root != parent_state_root { let parent_hash = self.get_block_hash(parent_number)?; - return Err(TransactionError::StateTrieRootMismatch { + return Err(TransactionError::UnwindStateRootMismatch { got: new_state_root, expected: parent_state_root, block_number: parent_number, @@ -1403,8 +1403,8 @@ pub enum TransactionError { #[error(transparent)] TrieError(#[from] StateRootError), /// Root mismatch - #[error("Merkle trie root mismatch on block: #{block_number:?} {block_hash:?}. got: {got:?} expected:{expected:?}")] - StateTrieRootMismatch { + #[error("Merkle trie root mismatch at #{block_number} ({block_hash:?}). Got: {got:?}. Expected: {expected:?}")] + StateRootMismatch { /// Expected root expected: H256, /// Calculated root @@ -1414,6 +1414,18 @@ pub enum TransactionError { /// Block hash block_hash: BlockHash, }, + /// Root mismatch during unwind + #[error("Unwind merkle trie root mismatch at #{block_number} ({block_hash:?}). Got: {got:?}. Expected: {expected:?}")] + UnwindStateRootMismatch { + /// Expected root + expected: H256, + /// Calculated root + got: H256, + /// Target block number + block_number: BlockNumber, + /// Block hash + block_hash: BlockHash, + }, } #[cfg(test)]