Skip to content

Commit

Permalink
chore: use slice arg for tx decoding (paradigmxyz#13181)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and lean-apple committed Dec 11, 2024
1 parent 2479ec6 commit e009b41
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
///
/// Returns the hash of the transaction.
async fn send_raw_transaction(&self, tx: Bytes) -> Result<B256, Self::Error> {
let recovered = recover_raw_transaction(tx.clone())?;
let recovered = recover_raw_transaction(&tx)?;
let pool_transaction = <Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);

// On optimism, transactions are forwarded directly to the sequencer to be included in
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
tx: Bytes,
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
async move {
let recovered = recover_raw_transaction(tx)?;
let recovered = recover_raw_transaction(&tx)?;
let pool_transaction =
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);

Expand Down
13 changes: 7 additions & 6 deletions crates/rpc/rpc-eth-types/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
//! Commonly used code snippets
use alloy_primitives::Bytes;
use super::{EthApiError, EthResult};
use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, RecoveredTx};
use reth_primitives_traits::SignedTransaction;
use std::future::Future;

use super::{EthApiError, EthResult};

/// Recovers a [`SignedTransaction`] from an enveloped encoded byte stream.
///
/// This is a helper function that returns the appropriate RPC-specific error if the input data is
/// malformed.
///
/// See [`alloy_eips::eip2718::Decodable2718::decode_2718`]
pub fn recover_raw_transaction<T: SignedTransaction>(data: Bytes) -> EthResult<RecoveredTx<T>> {
pub fn recover_raw_transaction<T: SignedTransaction>(mut data: &[u8]) -> EthResult<RecoveredTx<T>> {
if data.is_empty() {
return Err(EthApiError::EmptyRawTransactionData)
}

let transaction = T::decode_2718(&mut data.as_ref())
.map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
let transaction =
T::decode_2718(&mut data).map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;

transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ where

let transactions = txs
.into_iter()
.map(recover_raw_transaction::<PoolPooledTx<Eth::Pool>>)
.map(|tx| recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|tx| tx.to_components())
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc/rpc/src/eth/sim_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,8 @@ where
while idx < body.len() {
match &body[idx] {
BundleItem::Tx { tx, can_revert } => {
let recovered_tx =
recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx.clone())
.map_err(EthApiError::from)?;
let recovered_tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)
.map_err(EthApiError::from)?;
let (tx, signer) = recovered_tx.to_components();
let tx: PoolConsensusTx<Eth::Pool> =
<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus(tx);
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ where
trace_types: HashSet<TraceType>,
block_id: Option<BlockId>,
) -> Result<TraceResults, Eth::Error> {
let tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)?
let tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx)?
.map_transaction(<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus);

let (cfg, block, at) = self.eth_api().evm_env_at(block_id.unwrap_or_default()).await?;
Expand Down

0 comments on commit e009b41

Please sign in to comment.