Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ use futures::StreamExt;
use op_alloy_consensus::{transaction::OpTransactionInfo, OpTransaction};
use reth_chain_state::CanonStateSubscriptions;
use reth_optimism_primitives::DepositReceipt;
use reth_primitives_traits::{BlockBody, SignedTransaction};
use reth_primitives_traits::{BlockBody, Recovered, SignedTransaction, WithEncoded};
use reth_rpc_eth_api::{
helpers::{spec::SignersForRpc, EthTransactions, LoadReceipt, LoadTransaction},
try_into_op_tx_info, EthApiTypes as _, FromEthApiError, FromEvmError, RpcConvert, RpcNodeCore,
RpcReceipt, TxInfoMapper,
};
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
use reth_rpc_eth_types::EthApiError;
use reth_storage_api::{errors::ProviderError, ReceiptProvider};
use reth_transaction_pool::{
AddedTransactionOutcome, PoolTransaction, TransactionOrigin, TransactionPool,
AddedTransactionOutcome, PoolPooledTx, PoolTransaction, TransactionOrigin, TransactionPool,
};
use std::{
fmt::{Debug, Formatter},
Expand All @@ -39,11 +39,11 @@ where
self.inner.eth_api.send_raw_transaction_sync_timeout()
}

/// Decodes and recovers the transaction and submits it to the pool.
///
/// Returns the hash of the transaction.
async fn send_raw_transaction(&self, tx: Bytes) -> Result<B256, Self::Error> {
let recovered = recover_raw_transaction(&tx)?;
async fn send_transaction(
&self,
tx: WithEncoded<Recovered<PoolPooledTx<Self::Pool>>>,
) -> Result<B256, Self::Error> {
let (tx, recovered) = tx.split();

// broadcast raw transaction to subscribers if there is any.
self.eth_api().broadcast_raw_transaction(tx.clone());
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ where
/// Handler for: `eth_sendTransaction`
async fn send_transaction(&self, request: RpcTxReq<T::NetworkTypes>) -> RpcResult<B256> {
trace!(target: "rpc::eth", ?request, "Serving eth_sendTransaction");
Ok(EthTransactions::send_transaction(self, request).await?)
Ok(EthTransactions::send_transaction_request(self, request).await?)
}

/// Handler for: `eth_sendRawTransaction`
Expand Down
20 changes: 16 additions & 4 deletions crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ use alloy_rpc_types_eth::{BlockNumberOrTag, TransactionInfo};
use futures::{Future, StreamExt};
use reth_chain_state::CanonStateSubscriptions;
use reth_node_api::BlockBody;
use reth_primitives_traits::{RecoveredBlock, SignedTransaction, TxTy};
use reth_primitives_traits::{Recovered, RecoveredBlock, SignedTransaction, TxTy, WithEncoded};
use reth_rpc_convert::{transaction::RpcConvert, RpcTxReq};
use reth_rpc_eth_types::{
utils::binary_search, EthApiError, EthApiError::TransactionConfirmationTimeout,
utils::{binary_search, recover_raw_transaction},
EthApiError::{self, TransactionConfirmationTimeout},
FillTransactionResult, SignError, TransactionSource,
};
use reth_storage_api::{
BlockNumReader, BlockReaderIdExt, ProviderBlock, ProviderReceipt, ProviderTx, ReceiptProvider,
TransactionsProvider,
};
use reth_transaction_pool::{
AddedTransactionOutcome, PoolTransaction, TransactionOrigin, TransactionPool,
AddedTransactionOutcome, PoolPooledTx, PoolTransaction, TransactionOrigin, TransactionPool,
};
use std::{sync::Arc, time::Duration};

Expand Down Expand Up @@ -76,6 +77,17 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
fn send_raw_transaction(
&self,
tx: Bytes,
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
async move {
let recovered = recover_raw_transaction::<PoolPooledTx<Self::Pool>>(&tx)?;
self.send_transaction(WithEncoded::new(tx, recovered)).await
}
}

/// Submits the transaction to the pool.
fn send_transaction(
&self,
tx: WithEncoded<Recovered<PoolPooledTx<Self::Pool>>>,
) -> impl Future<Output = Result<B256, Self::Error>> + Send;

/// Decodes and recovers the transaction and submits it to the pool.
Expand Down Expand Up @@ -384,7 +396,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {

/// Signs transaction with a matching signer, if any and submits the transaction to the pool.
/// Returns the hash of the signed transaction.
fn send_transaction(
fn send_transaction_request(
&self,
mut request: RpcTxReq<Self::NetworkTypes>,
) -> impl Future<Output = Result<B256, Self::Error>> + Send
Expand Down
20 changes: 10 additions & 10 deletions crates/rpc/rpc/src/eth/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use std::time::Duration;
use crate::EthApi;
use alloy_consensus::BlobTransactionValidationError;
use alloy_eips::{eip7594::BlobTransactionSidecarVariant, BlockId, Typed2718};
use alloy_primitives::{hex, Bytes, B256};
use alloy_primitives::{hex, B256};
use reth_chainspec::{ChainSpecProvider, EthereumHardforks};
use reth_primitives_traits::AlloyBlockHeader;
use reth_primitives_traits::{AlloyBlockHeader, Recovered, WithEncoded};
use reth_rpc_convert::RpcConvert;
use reth_rpc_eth_api::{
helpers::{spec::SignersForRpc, EthTransactions, LoadTransaction},
FromEvmError, RpcNodeCore,
};
use reth_rpc_eth_types::{error::RpcPoolError, utils::recover_raw_transaction, EthApiError};
use reth_rpc_eth_types::{error::RpcPoolError, EthApiError};
use reth_storage_api::BlockReaderIdExt;
use reth_transaction_pool::{
error::Eip4844PoolTransactionError, AddedTransactionOutcome, EthBlobTransactionSidecar,
EthPoolTransaction, PoolTransaction, TransactionPool,
EthPoolTransaction, PoolPooledTx, PoolTransaction, TransactionPool,
};

impl<N, Rpc> EthTransactions for EthApi<N, Rpc>
Expand All @@ -36,12 +36,11 @@ where
self.inner.send_raw_transaction_sync_timeout()
}

/// Decodes and recovers the transaction and submits it to the pool.
///
/// Returns the hash of the transaction.
async fn send_raw_transaction(&self, tx: Bytes) -> Result<B256, Self::Error> {
let recovered = recover_raw_transaction(&tx)?;

async fn send_transaction(
&self,
tx: WithEncoded<Recovered<PoolPooledTx<Self::Pool>>>,
) -> Result<B256, Self::Error> {
let (tx, recovered) = tx.split();
let mut pool_transaction =
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);

Expand Down Expand Up @@ -147,6 +146,7 @@ mod tests {
};
use reth_rpc_eth_api::node::RpcNodeCoreAdapter;
use reth_transaction_pool::test_utils::{testing_pool, TestPool};
use revm_primitives::Bytes;
use std::collections::HashMap;

fn mock_eth_api(
Expand Down