forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patherror.rs
More file actions
88 lines (78 loc) · 3.04 KB
/
error.rs
File metadata and controls
88 lines (78 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Optimism consensus errors
use alloc::sync::Arc;
use alloy_primitives::B256;
use reth_consensus::ConsensusError;
use reth_primitives_traits::GotExpected;
use reth_storage_errors::provider::ProviderError;
/// Optimism consensus error.
#[derive(Debug, Clone, thiserror::Error)]
pub enum OpConsensusError {
/// Block body has non-empty withdrawals list (l1 withdrawals).
#[error("non-empty block body withdrawals list")]
WithdrawalsNonEmpty,
/// Failed to compute L2 withdrawals storage root.
#[error("compute L2 withdrawals root failed: {_0}")]
L2WithdrawalsRootCalculationFail(#[from] ProviderError),
/// L2 withdrawals root missing in block header.
#[error("L2 withdrawals root missing from block header")]
L2WithdrawalsRootMissing,
/// L2 withdrawals root in block header, doesn't match local storage root of predeploy.
#[error("L2 withdrawals root mismatch, header: {header}, exec_res: {exec_res}")]
L2WithdrawalsRootMismatch {
/// Storage root of pre-deploy in block.
header: B256,
/// Storage root of pre-deploy loaded from local state.
exec_res: B256,
},
/// L1 [`ConsensusError`], that also occurs on L2.
#[error(transparent)]
Eth(ConsensusError),
/// DA footprint gas missing from header
#[error("DA footprint gas missing from header")]
DAFootprintGasMissing,
/// DA footprint gas mismatch
#[error("DA footprint gas mismatch: {0:?}")]
DAFootprintGasDiff(GotExpected<u64>),
}
impl From<OpConsensusError> for ConsensusError {
fn from(error: OpConsensusError) -> Self {
match error {
OpConsensusError::Eth(err) => err,
_ => Self::Custom(Arc::new(error)),
}
}
}
impl From<ConsensusError> for OpConsensusError {
fn from(error: ConsensusError) -> Self {
if let ConsensusError::Custom(ref err) = error &&
let Some(op_err) = err.downcast_ref::<Self>()
{
return op_err.clone()
}
Self::Eth(error)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn consensus_error_from_op_consensus_error() {
let consensus_err = ConsensusError::BaseFeeMissing;
let op_err = OpConsensusError::Eth(consensus_err);
let converted: ConsensusError = op_err.into();
assert!(matches!(converted, ConsensusError::BaseFeeMissing));
let op_specific_err = OpConsensusError::WithdrawalsNonEmpty;
let converted: ConsensusError = op_specific_err.into();
assert!(matches!(converted, ConsensusError::Custom(_)));
}
#[test]
fn op_consensus_error_from_consensus_error() {
let consensus_err = ConsensusError::BaseFeeMissing;
let op_err: OpConsensusError = consensus_err.into();
assert!(matches!(op_err, OpConsensusError::Eth(_)));
let original = OpConsensusError::WithdrawalsNonEmpty;
let as_consensus: ConsensusError = original.into();
let back_to_op: OpConsensusError = as_consensus.into();
assert!(matches!(back_to_op, OpConsensusError::WithdrawalsNonEmpty));
}
}