Skip to content

Commit a44f435

Browse files
authored
fix(levm): propagate database errors (#2639)
**Motivation** <!-- Why does this pull request exist? What are its goals? --> - We were just propagating Internal errors but we also want to propagate DatabaseErrors. Before this we were just reverting the transaction and that is wrong. **Description** <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #issue_number
1 parent 6ed8a1f commit a44f435

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

crates/vm/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ impl From<RevmError<ExecutionDBError>> for EvmError {
118118

119119
impl From<VMError> for EvmError {
120120
fn from(value: VMError) -> Self {
121-
if value.is_internal() {
122-
// We don't categorize our internal errors yet, so we label them as "Custom"
121+
if value.should_propagate() {
123122
EvmError::Custom(value.to_string())
124123
} else {
125124
// If an error is not internal it means it is a transaction validation error.

crates/vm/levm/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ pub enum VMError {
2424
InvalidContractPrefix,
2525
#[error("Very Large Number")]
2626
VeryLargeNumber,
27-
#[error("Fatal Error")]
28-
FatalError,
2927
#[error("Invalid Transaction")]
3028
InvalidTransaction,
3129
#[error("Revert Opcode")]
@@ -77,8 +75,10 @@ pub enum VMError {
7775
}
7876

7977
impl VMError {
80-
pub fn is_internal(&self) -> bool {
81-
matches!(self, VMError::Internal(_))
78+
/// These errors are unexpected and indicate critical issues.
79+
/// They should not cause a transaction to revert silently but instead fail loudly, propagating the error.
80+
pub fn should_propagate(&self) -> bool {
81+
matches!(self, VMError::Internal(_)) || matches!(self, VMError::DatabaseError(_))
8282
}
8383
}
8484

crates/vm/levm/src/execution_handlers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a> VM<'a> {
2828
logs: std::mem::take(&mut current_call_frame.logs),
2929
}),
3030
Err(error) => {
31-
if error.is_internal() {
31+
if error.should_propagate() {
3232
return Err(error);
3333
}
3434

@@ -233,7 +233,7 @@ impl<'a> VM<'a> {
233233
.backups
234234
.pop()
235235
.ok_or(VMError::Internal(InternalError::CouldNotPopCallframe))?;
236-
if error.is_internal() {
236+
if error.should_propagate() {
237237
return Err(error);
238238
}
239239

0 commit comments

Comments
 (0)