From 8303e51554df0b5671b63eb54fca71d8c8b23f0a Mon Sep 17 00:00:00 2001 From: Chirag Baghasingh <76247491+chirag-bgh@users.noreply.github.com> Date: Sat, 4 Feb 2023 14:18:15 +0530 Subject: [PATCH] feat: format PoorError to mirror Geth's TxPool Error messages (#1156) Co-authored-by: Matthias Seitz --- crates/rpc/rpc/src/eth/error.rs | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/crates/rpc/rpc/src/eth/error.rs b/crates/rpc/rpc/src/eth/error.rs index fd83ba484..7d81ee2fc 100644 --- a/crates/rpc/rpc/src/eth/error.rs +++ b/crates/rpc/rpc/src/eth/error.rs @@ -18,19 +18,47 @@ pub(crate) enum EthApiError { #[error("Invalid transaction signature")] InvalidTransactionSignature, #[error(transparent)] - PoolError(GethCompatPoolError), + PoolError(GethTxPoolError), } impl_to_rpc_result!(EthApiError); -/// A helper error type that ensures error messages are compatible with `geth` -// TODO: replace thiserror with custom convert +/// A helper error type that mirrors `geth` Txpool's error messages #[derive(Debug, thiserror::Error)] -#[error(transparent)] -pub(crate) struct GethCompatPoolError(PoolError); +pub(crate) enum GethTxPoolError { + #[error("already known")] + AlreadyKnown, + #[error("invalid sender")] + InvalidSender, + #[error("transaction underpriced")] + Underpriced, + #[error("txpool is full")] + TxPoolOverflow, + #[error("replacement transaction underpriced")] + ReplaceUnderpriced, + #[error("exceeds block gas limit")] + GasLimit, + #[error("negative value")] + NegativeValue, + #[error("oversized data")] + OversizedData, +} + +impl From for GethTxPoolError { + fn from(err: PoolError) -> GethTxPoolError { + match err { + PoolError::ReplacementUnderpriced(_) => GethTxPoolError::ReplaceUnderpriced, + PoolError::ProtocolFeeCapTooLow(_, _) => GethTxPoolError::Underpriced, + PoolError::SpammerExceededCapacity(_, _) => GethTxPoolError::TxPoolOverflow, + PoolError::DiscardedOnInsert(_) => GethTxPoolError::TxPoolOverflow, + PoolError::TxExceedsGasLimit(_, _, _) => GethTxPoolError::GasLimit, + PoolError::TxExceedsMaxInitCodeSize(_, _, _) => GethTxPoolError::OversizedData, + } + } +} impl From for EthApiError { fn from(err: PoolError) -> Self { - EthApiError::PoolError(GethCompatPoolError(err)) + EthApiError::PoolError(GethTxPoolError::from(err)) } }