feat: use network tx for Pool::Pooled (#13159)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Arsenii Kulikov
2024-12-05 22:50:43 +04:00
committed by GitHub
parent 4fe5c2a577
commit 8226fa0cac
17 changed files with 148 additions and 138 deletions

View File

@ -344,7 +344,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
async move {
let recovered = recover_raw_transaction(tx)?;
let pool_transaction =
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered.into());
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
// submit the transaction to the pool with a `Local` origin
let hash = self

View File

@ -1,21 +1,21 @@
//! Commonly used code snippets
use alloy_eips::eip2718::Decodable2718;
use alloy_primitives::Bytes;
use reth_primitives::{PooledTransactionsElement, PooledTransactionsElementEcRecovered};
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, RecoveredTx};
use reth_primitives_traits::SignedTransaction;
use std::future::Future;
use super::{EthApiError, EthResult};
/// Recovers a [`PooledTransactionsElementEcRecovered`] from an enveloped encoded byte stream.
/// Recovers a [`SignedTransaction`] from an enveloped encoded byte stream.
///
/// See [`Decodable2718::decode_2718`]
pub fn recover_raw_transaction(data: Bytes) -> EthResult<PooledTransactionsElementEcRecovered> {
/// See [`alloy_eips::eip2718::Decodable2718::decode_2718`]
pub fn recover_raw_transaction<T: SignedTransaction>(data: Bytes) -> EthResult<RecoveredTx<T>> {
if data.is_empty() {
return Err(EthApiError::EmptyRawTransactionData)
}
let transaction = PooledTransactionsElement::decode_2718(&mut data.as_ref())
let transaction = T::decode_2718(&mut data.as_ref())
.map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))

View File

@ -79,7 +79,7 @@ where
let transactions = txs
.into_iter()
.map(recover_raw_transaction)
.map(recover_raw_transaction::<PooledTransactionsElement>)
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|tx| tx.to_components())

View File

@ -10,7 +10,7 @@ use alloy_rpc_types_mev::{
use jsonrpsee::core::RpcResult;
use reth_chainspec::EthChainSpec;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::TransactionSigned;
use reth_primitives::{PooledTransactionsElement, TransactionSigned};
use reth_provider::{ChainSpecProvider, HeaderProvider};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::MevSimApiServer;
@ -171,7 +171,8 @@ where
match &body[idx] {
BundleItem::Tx { tx, can_revert } => {
let recovered_tx =
recover_raw_transaction(tx.clone()).map_err(EthApiError::from)?;
recover_raw_transaction::<PooledTransactionsElement>(tx.clone())
.map_err(EthApiError::from)?;
let (tx, signer) = recovered_tx.to_components();
let tx = tx.into_transaction();

View File

@ -19,6 +19,7 @@ use reth_consensus_common::calc::{
base_block_reward, base_block_reward_pre_merge, block_reward, ommer_reward,
};
use reth_evm::ConfigureEvmEnv;
use reth_primitives::PooledTransactionsElement;
use reth_provider::{BlockReader, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::TraceApiServer;
@ -115,7 +116,8 @@ where
trace_types: HashSet<TraceType>,
block_id: Option<BlockId>,
) -> Result<TraceResults, Eth::Error> {
let tx = recover_raw_transaction(tx)?.into_ecrecovered_transaction();
let tx = recover_raw_transaction::<PooledTransactionsElement>(tx)?
.into_ecrecovered_transaction();
let (cfg, block, at) = self.eth_api().evm_env_at(block_id.unwrap_or_default()).await?;