feat: add thorough error message to state root error (#7607)

This commit is contained in:
Dan Cline
2024-04-24 16:23:45 -04:00
committed by GitHub
parent 659059c67f
commit 76a3d8278a
5 changed files with 79 additions and 3 deletions

View File

@@ -243,6 +243,36 @@ impl InsertBlockErrorKind {
matches!(self, InsertBlockErrorKind::Consensus(_))
}
/// Returns true if this error is a state root error
pub fn is_state_root_error(&self) -> bool {
// we need to get the state root errors inside of the different variant branches
match self {
InsertBlockErrorKind::Execution(err) => {
matches!(
err,
BlockExecutionError::Validation(BlockValidationError::StateRoot { .. })
)
}
InsertBlockErrorKind::Canonical(err) => {
matches!(
err,
CanonicalError::Validation(BlockValidationError::StateRoot { .. }) |
CanonicalError::Provider(
ProviderError::StateRootMismatch(_) |
ProviderError::UnwindStateRootMismatch(_)
)
)
}
InsertBlockErrorKind::Provider(err) => {
matches!(
err,
ProviderError::StateRootMismatch(_) | ProviderError::UnwindStateRootMismatch(_)
)
}
_ => false,
}
}
/// Returns true if the error is caused by an invalid block
///
/// This is intended to be used to determine if the block should be marked as invalid.

View File

@@ -153,4 +153,9 @@ impl BlockExecutionError {
pub fn is_fatal(&self) -> bool {
matches!(self, Self::CanonicalCommit { .. } | Self::CanonicalRevert { .. })
}
/// Returns `true` if the error is a state root error.
pub fn is_state_root_error(&self) -> bool {
matches!(self, Self::Validation(BlockValidationError::StateRoot(_)))
}
}