reth_primitives_traits/transaction/error.rs
1//! Various error variants that can happen when working with transactions.
2
3use crate::GotExpectedBoxed;
4use alloy_primitives::U256;
5
6/// Represents error variants that can happen when trying to validate a transaction.
7#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
8pub enum InvalidTransactionError {
9 /// The sender does not have enough funds to cover the transaction fees
10 #[error(
11 "sender does not have enough funds ({}) to cover transaction fees: {}", _0.got, _0.expected
12 )]
13 InsufficientFunds(GotExpectedBoxed<U256>),
14 /// The nonce is lower than the account's nonce, or there is a nonce gap present.
15 ///
16 /// This is a consensus error.
17 #[error("transaction nonce is not consistent: next nonce {state}, tx nonce {tx}")]
18 NonceNotConsistent {
19 /// The nonce of the transaction.
20 tx: u64,
21 /// The current state of the nonce in the local chain.
22 state: u64,
23 },
24 /// The transaction is before Spurious Dragon and has a chain ID.
25 #[error("transactions before Spurious Dragon should not have a chain ID")]
26 OldLegacyChainId,
27 /// The chain ID in the transaction does not match the current network configuration.
28 #[error("transaction's chain ID does not match")]
29 ChainIdMismatch,
30 /// The transaction requires EIP-2930 which is not enabled currently.
31 #[error("EIP-2930 transactions are disabled")]
32 Eip2930Disabled,
33 /// The transaction requires EIP-1559 which is not enabled currently.
34 #[error("EIP-1559 transactions are disabled")]
35 Eip1559Disabled,
36 /// The transaction requires EIP-4844 which is not enabled currently.
37 #[error("EIP-4844 transactions are disabled")]
38 Eip4844Disabled,
39 /// The transaction requires EIP-7702 which is not enabled currently.
40 #[error("EIP-7702 transactions are disabled")]
41 Eip7702Disabled,
42 /// Thrown if a transaction is not supported in the current network configuration.
43 #[error("transaction type not supported")]
44 TxTypeNotSupported,
45 /// The calculated gas of the transaction exceeds `u64::MAX`.
46 #[error("gas overflow (maximum of u64)")]
47 GasUintOverflow,
48 /// The transaction is specified to use less gas than required to start the invocation.
49 #[error("intrinsic gas too low")]
50 GasTooLow,
51 /// The transaction gas exceeds the limit
52 #[error("intrinsic gas too high")]
53 GasTooHigh,
54 /// Thrown to ensure no one is able to specify a transaction with a tip higher than the total
55 /// fee cap.
56 #[error("max priority fee per gas higher than max fee per gas")]
57 TipAboveFeeCap,
58 /// Thrown post London if the transaction's fee is less than the base fee of the block.
59 #[error("max fee per gas less than block base fee")]
60 FeeCapTooLow,
61 /// Thrown if the sender of a transaction is a contract.
62 #[error("transaction signer has bytecode set")]
63 SignerAccountHasBytecode,
64 /// Thrown post Osaka if gas limit is too high.
65 #[error("gas limit too high")]
66 GasLimitTooHigh,
67}
68
69impl InvalidTransactionError {
70 /// Returns true if this is [`InvalidTransactionError::NonceNotConsistent`] and the
71 /// transaction's nonce is lower than the state's.
72 pub fn is_nonce_too_low(&self) -> bool {
73 match self {
74 Self::NonceNotConsistent { tx, state } => tx < state,
75 _ => false,
76 }
77 }
78}
79
80/// Represents error variants that can happen when trying to convert a transaction to pooled
81/// transaction.
82#[derive(Debug, Clone, Eq, PartialEq, derive_more::Display, derive_more::Error)]
83pub enum TransactionConversionError {
84 /// This error variant is used when a transaction cannot be converted into a pooled transaction
85 /// because it is not supported for P2P network.
86 #[display("Transaction is not supported for p2p")]
87 UnsupportedForP2P,
88}
89
90/// Represents error variants than can happen when trying to convert a recovered transaction.
91#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)]
92pub enum TryFromRecoveredTransactionError {
93 /// Thrown if the transaction type is unsupported.
94 #[error("Unsupported transaction type: {_0}")]
95 UnsupportedTransactionType(u8),
96 /// This error variant is used when a blob sidecar is missing.
97 #[error("Blob sidecar missing for an EIP-4844 transaction")]
98 BlobSidecarMissing,
99}