From b1f085d0d70b5c1c1f48182304a78c124ea8e2b0 Mon Sep 17 00:00:00 2001 From: Boyu Yang Date: Mon, 6 Nov 2023 10:51:25 +0800 Subject: [PATCH] fix: check mempool when call `eth_getTransactionByHash` --- core/api/src/adapter.rs | 6 +++++- core/api/src/jsonrpc/error.rs | 4 ---- core/api/src/jsonrpc/impl/web3.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/api/src/adapter.rs b/core/api/src/adapter.rs index 2fa385116..0287a27c0 100644 --- a/core/api/src/adapter.rs +++ b/core/api/src/adapter.rs @@ -141,7 +141,11 @@ where ctx: Context, tx_hash: Hash, ) -> ProtocolResult> { - self.storage.get_transaction_by_hash(ctx, &tx_hash).await + if let Some(tx) = self.mempool.get_tx_from_mem(ctx.clone(), &tx_hash) { + Ok(Some(tx)) + } else { + self.storage.get_transaction_by_hash(ctx, &tx_hash).await + } } async fn get_transactions_by_hashes( diff --git a/core/api/src/jsonrpc/error.rs b/core/api/src/jsonrpc/error.rs index 0329d09c8..5237f0a39 100644 --- a/core/api/src/jsonrpc/error.rs +++ b/core/api/src/jsonrpc/error.rs @@ -31,8 +31,6 @@ pub enum RpcError { GasLimitIsZero, #[display(fmt = "Transaction is not signed")] TransactionIsNotSigned, - #[display(fmt = "Cannot get receipt by hash")] - CannotGetReceiptByHash, #[display(fmt = "Cannot get latest block")] CannotGetLatestBlock, #[display(fmt = "Invalid block hash")] @@ -80,7 +78,6 @@ impl RpcError { RpcError::GasLimitIsTooLarge => -40009, RpcError::GasLimitIsZero => -40010, RpcError::TransactionIsNotSigned => -40011, - RpcError::CannotGetReceiptByHash => -40012, RpcError::CannotGetLatestBlock => -40013, RpcError::InvalidBlockHash => -40014, RpcError::InvalidFromBlockNumber(_) => -40015, @@ -118,7 +115,6 @@ impl From for ErrorObjectOwned { RpcError::GasLimitIsTooLarge => ErrorObject::owned(err_code, err, none_data), RpcError::GasLimitIsZero => ErrorObject::owned(err_code, err, none_data), RpcError::TransactionIsNotSigned => ErrorObject::owned(err_code, err, none_data), - RpcError::CannotGetReceiptByHash => ErrorObject::owned(err_code, err, none_data), RpcError::CannotGetLatestBlock => ErrorObject::owned(err_code, err, none_data), RpcError::InvalidBlockHash => ErrorObject::owned(err_code, err, none_data), RpcError::InvalidFromBlockNumber(_) => ErrorObject::owned(err_code, err, none_data), diff --git a/core/api/src/jsonrpc/impl/web3.rs b/core/api/src/jsonrpc/impl/web3.rs index 1d8ecc79a..d2d01f373 100644 --- a/core/api/src/jsonrpc/impl/web3.rs +++ b/core/api/src/jsonrpc/impl/web3.rs @@ -335,7 +335,7 @@ impl Web3RpcServer for Web3RpcImpl { { Ok(Some((stx, receipt).into())) } else { - Err(RpcError::CannotGetReceiptByHash.into()) + Ok(Some(stx.into())) } } else { Ok(None)