consolidate eip4844 pool errors (#4453)

This commit is contained in:
Alessandro Mazza
2023-09-03 18:29:28 +02:00
committed by GitHub
parent e8f2a56f40
commit e4f26e8bf0
3 changed files with 80 additions and 85 deletions

View File

@@ -5,12 +5,12 @@ use jsonrpsee::{
core::Error as RpcError,
types::{error::CALL_EXECUTION_FAILED_CODE, ErrorObject},
};
use reth_primitives::{
abi::decode_revert_reason, Address, BlobTransactionValidationError, Bytes, U256,
};
use reth_primitives::{abi::decode_revert_reason, Address, Bytes, U256};
use reth_revm::tracing::js::JsInspectorError;
use reth_rpc_types::{error::EthRpcErrorCode, BlockError, CallInputError};
use reth_transaction_pool::error::{InvalidPoolTransactionError, PoolError, PoolTransactionError};
use reth_transaction_pool::error::{
Eip4844PoolTransactionError, InvalidPoolTransactionError, PoolError, PoolTransactionError,
};
use revm::primitives::{EVMError, ExecutionResult, Halt, OutOfGasError};
use std::time::Duration;
@@ -472,23 +472,9 @@ pub enum RpcPoolError {
/// Custom pool error
#[error("{0:?}")]
PoolTransactionError(Box<dyn PoolTransactionError>),
/// Unable to find the blob for an EIP4844 transaction
#[error("blob sidecar not found for EIP4844 transaction")]
MissingEip4844Blob,
/// Thrown if an EIP-4844 without any blobs arrives
#[error("blobless blob transaction")]
NoEip4844Blobs,
/// Thrown if an EIP-4844 without any blobs arrives
#[error("too many blobs in transaction: have {have}, permitted {permitted}")]
TooManyEip4844Blobs {
/// Number of blobs the transaction has
have: usize,
/// Number of maximum blobs the transaction can have
permitted: usize,
},
/// Thrown if validating the blob sidecar for the transaction failed.
/// Eip-4844 related error
#[error(transparent)]
InvalidEip4844Blob(BlobTransactionValidationError),
Eip4844(#[from] Eip4844PoolTransactionError),
#[error(transparent)]
Other(Box<dyn std::error::Error + Send + Sync>),
}
@@ -527,19 +513,7 @@ impl From<InvalidPoolTransactionError> for RpcPoolError {
InvalidPoolTransactionError::OversizedData(_, _) => RpcPoolError::OversizedData,
InvalidPoolTransactionError::Underpriced => RpcPoolError::Underpriced,
InvalidPoolTransactionError::Other(err) => RpcPoolError::PoolTransactionError(err),
InvalidPoolTransactionError::MissingEip4844BlobSidecar => {
RpcPoolError::MissingEip4844Blob
}
InvalidPoolTransactionError::NoEip4844Blobs => RpcPoolError::NoEip4844Blobs,
InvalidPoolTransactionError::TooManyEip4844Blobs { have, permitted } => {
RpcPoolError::TooManyEip4844Blobs { have, permitted }
}
InvalidPoolTransactionError::InvalidEip4844Blob(err) => {
RpcPoolError::InvalidEip4844Blob(err)
}
InvalidPoolTransactionError::Eip4844NonceGap => {
RpcPoolError::Invalid(RpcInvalidTransactionError::NonceTooHigh)
}
InvalidPoolTransactionError::Eip4844(err) => RpcPoolError::Eip4844(err),
}
}
}

View File

@@ -114,30 +114,10 @@ impl PoolError {
}
}
/// Represents errors that can happen when validating transactions for the pool
///
/// See [TransactionValidator](crate::TransactionValidator).
/// Represents all errors that can happen when validating transactions for the pool for EIP-4844
/// transactions
#[derive(Debug, thiserror::Error)]
pub enum InvalidPoolTransactionError {
/// Hard consensus errors
#[error(transparent)]
Consensus(#[from] InvalidTransactionError),
/// Thrown when a new transaction is added to the pool, but then immediately discarded to
/// respect the size limits of the pool.
#[error("Transaction's gas limit {0} exceeds block's gas limit {1}.")]
ExceedsGasLimit(u64, u64),
/// Thrown when a new transaction is added to the pool, but then immediately discarded to
/// respect the max_init_code_size.
#[error("Transaction's size {0} exceeds max_init_code_size {1}.")]
ExceedsMaxInitCodeSize(usize, usize),
/// Thrown if the input data of a transaction is greater
/// than some meaningful limit a user might use. This is not a consensus error
/// making the transaction invalid, rather a DOS protection.
#[error("Input data too large")]
OversizedData(usize, usize),
/// Thrown if the transaction's fee is below the minimum fee
#[error("transaction underpriced")]
Underpriced,
pub enum Eip4844PoolTransactionError {
/// Thrown if we're unable to find the blob for a transaction that was previously extracted
#[error("blob sidecar not found for EIP4844 transaction")]
MissingEip4844BlobSidecar,
@@ -163,6 +143,35 @@ pub enum InvalidPoolTransactionError {
/// would introduce gap in the nonce sequence.
#[error("Nonce too high.")]
Eip4844NonceGap,
}
/// Represents errors that can happen when validating transactions for the pool
///
/// See [TransactionValidator](crate::TransactionValidator).
#[derive(Debug, thiserror::Error)]
pub enum InvalidPoolTransactionError {
/// Hard consensus errors
#[error(transparent)]
Consensus(#[from] InvalidTransactionError),
/// Thrown when a new transaction is added to the pool, but then immediately discarded to
/// respect the size limits of the pool.
#[error("Transaction's gas limit {0} exceeds block's gas limit {1}.")]
ExceedsGasLimit(u64, u64),
/// Thrown when a new transaction is added to the pool, but then immediately discarded to
/// respect the max_init_code_size.
#[error("Transaction's size {0} exceeds max_init_code_size {1}.")]
ExceedsMaxInitCodeSize(usize, usize),
/// Thrown if the input data of a transaction is greater
/// than some meaningful limit a user might use. This is not a consensus error
/// making the transaction invalid, rather a DOS protection.
#[error("Input data too large")]
OversizedData(usize, usize),
/// Thrown if the transaction's fee is below the minimum fee
#[error("transaction underpriced")]
Underpriced,
/// Eip-4844 related errors
#[error(transparent)]
Eip4844(#[from] Eip4844PoolTransactionError),
/// Any other error that occurred while inserting/validating that is transaction specific
#[error("{0:?}")]
Other(Box<dyn PoolTransactionError>),
@@ -220,27 +229,31 @@ impl InvalidPoolTransactionError {
false
}
InvalidPoolTransactionError::Other(err) => err.is_bad_transaction(),
InvalidPoolTransactionError::MissingEip4844BlobSidecar => {
// this is only reachable when blob transactions are reinjected and we're unable to
// find the previously extracted blob
false
}
InvalidPoolTransactionError::InvalidEip4844Blob(_) => {
// This is only reachable when the blob is invalid
true
}
InvalidPoolTransactionError::Eip4844NonceGap => {
// it is possible that the pool sees `nonce n` before `nonce n-1` and this is only
// thrown for valid(good) blob transactions
false
}
InvalidPoolTransactionError::NoEip4844Blobs => {
// this is a malformed transaction and should not be sent over the network
true
}
InvalidPoolTransactionError::TooManyEip4844Blobs { .. } => {
// this is a malformed transaction and should not be sent over the network
true
InvalidPoolTransactionError::Eip4844(eip4844_err) => {
match eip4844_err {
Eip4844PoolTransactionError::MissingEip4844BlobSidecar => {
// this is only reachable when blob transactions are reinjected and we're
// unable to find the previously extracted blob
false
}
Eip4844PoolTransactionError::InvalidEip4844Blob(_) => {
// This is only reachable when the blob is invalid
true
}
Eip4844PoolTransactionError::Eip4844NonceGap => {
// it is possible that the pool sees `nonce n` before `nonce n-1` and this
// is only thrown for valid(good) blob transactions
false
}
Eip4844PoolTransactionError::NoEip4844Blobs => {
// this is a malformed transaction and should not be sent over the network
true
}
Eip4844PoolTransactionError::TooManyEip4844Blobs { .. } => {
// this is a malformed transaction and should not be sent over the network
true
}
}
}
}
}

View File

@@ -2,7 +2,7 @@
use crate::{
blobstore::BlobStore,
error::InvalidPoolTransactionError,
error::{Eip4844PoolTransactionError, InvalidPoolTransactionError},
traits::TransactionOrigin,
validate::{ValidTransaction, ValidationTask, MAX_INIT_CODE_SIZE, TX_MAX_SIZE},
EthBlobTransactionSidecar, EthPoolTransaction, TransactionValidationOutcome,
@@ -217,7 +217,9 @@ where
// no blobs
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::NoEip4844Blobs,
InvalidPoolTransactionError::Eip4844(
Eip4844PoolTransactionError::NoEip4844Blobs,
),
)
}
@@ -225,10 +227,12 @@ where
// too many blobs
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::TooManyEip4844Blobs {
have: blob_count,
permitted: MAX_BLOBS_PER_BLOCK,
},
InvalidPoolTransactionError::Eip4844(
Eip4844PoolTransactionError::TooManyEip4844Blobs {
have: blob_count,
permitted: MAX_BLOBS_PER_BLOCK,
},
),
)
}
@@ -247,7 +251,9 @@ where
} else {
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::MissingEip4844BlobSidecar,
InvalidPoolTransactionError::Eip4844(
Eip4844PoolTransactionError::MissingEip4844BlobSidecar,
),
)
}
}
@@ -257,7 +263,9 @@ where
if let Err(err) = eip4844.validate_blob(&blob, &self.kzg_settings) {
return TransactionValidationOutcome::Invalid(
transaction,
InvalidPoolTransactionError::InvalidEip4844Blob(err),
InvalidPoolTransactionError::Eip4844(
Eip4844PoolTransactionError::InvalidEip4844Blob(err),
),
)
}
// store the extracted blob