feat: support blobs in eth_sendRawTransaction (#4495)

This commit is contained in:
Dan Cline
2023-09-06 08:48:15 -04:00
committed by GitHub
parent 6299c26b56
commit 422d930914
6 changed files with 32 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
//! Decoding tests for [`PooledTransactions`]
use reth_eth_wire::PooledTransactions;
use reth_primitives::{hex, PooledTransactionsElement};
use reth_primitives::{hex, Bytes, PooledTransactionsElement};
use reth_rlp::Decodable;
use std::{fs, path::PathBuf};
@ -21,3 +21,13 @@ fn decode_blob_transaction_data() {
let hex_data = hex::decode(data.trim()).unwrap();
let _txs = PooledTransactionsElement::decode(&mut &hex_data[..]).unwrap();
}
#[test]
fn decode_blob_rpc_transaction() {
// test data pulled from hive test that sends blob transactions
let network_data_path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("testdata/rpc_blob_transaction");
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
let hex_data = Bytes::from(hex::decode(data.trim()).unwrap());
let _txs = PooledTransactionsElement::decode_enveloped(hex_data).unwrap();
}

View File

@ -394,7 +394,7 @@ impl PooledTransactionsElementEcRecovered {
self.transaction
}
/// Transform back to [`PooledTransactionsElement`]
/// Transform back to [`TransactionSignedEcRecovered`]
pub fn into_ecrecovered_transaction(self) -> TransactionSignedEcRecovered {
let (tx, signer) = self.into_components();
tx.into_ecrecovered_transaction(signer)
@ -414,3 +414,11 @@ impl PooledTransactionsElementEcRecovered {
Self { transaction, signer }
}
}
impl From<TransactionSignedEcRecovered> for PooledTransactionsElementEcRecovered {
fn from(tx: TransactionSignedEcRecovered) -> Self {
let signer = tx.signer;
let transaction = tx.signed_transaction.into();
Self { transaction, signer }
}
}

View File

@ -14,7 +14,7 @@ use crate::{
use async_trait::async_trait;
use reth_network_api::NetworkInfo;
use reth_primitives::{
Address, BlockId, BlockNumberOrTag, Bytes, FromRecoveredTransaction, Header,
Address, BlockId, BlockNumberOrTag, Bytes, FromRecoveredPooledTransaction, Header,
IntoRecoveredTransaction, Receipt, SealedBlock,
TransactionKind::{Call, Create},
TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, H256, U128, U256, U64,
@ -504,7 +504,7 @@ where
let recovered =
signed_tx.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)?;
let pool_transaction = <Pool::Transaction>::from_recovered_transaction(recovered);
let pool_transaction = <Pool::Transaction>::from_recovered_transaction(recovered.into());
// submit the transaction to the pool with a `Local` origin
let hash = self.pool().add_transaction(TransactionOrigin::Local, pool_transaction).await?;

View File

@ -1,18 +1,20 @@
//! Commonly used code snippets
use crate::eth::error::{EthApiError, EthResult};
use reth_primitives::{Bytes, TransactionSigned, TransactionSignedEcRecovered};
use reth_primitives::{Bytes, PooledTransactionsElement, PooledTransactionsElementEcRecovered};
/// Recovers a [TransactionSignedEcRecovered] from an enveloped encoded byte stream.
/// Recovers a [PooledTransactionsElementEcRecovered] from an enveloped encoded byte stream.
///
/// See [TransactionSigned::decode_enveloped]
pub(crate) fn recover_raw_transaction(data: Bytes) -> EthResult<TransactionSignedEcRecovered> {
/// See [PooledTransactionsElement::decode_enveloped]
pub(crate) fn recover_raw_transaction(
data: Bytes,
) -> EthResult<PooledTransactionsElementEcRecovered> {
if data.is_empty() {
return Err(EthApiError::EmptyRawTransactionData)
}
let transaction = TransactionSigned::decode_enveloped(data)
let transaction = PooledTransactionsElement::decode_enveloped(data)
.map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
transaction.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)
transaction.try_into_ecrecovered().or(Err(EthApiError::InvalidTransactionSignature))
}

View File

@ -110,7 +110,7 @@ where
.eth_api
.evm_env_at(block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)))
.await?;
let tx = tx_env_with_recovered(&tx);
let tx = tx_env_with_recovered(&tx.into_ecrecovered_transaction());
let env = Env { cfg, block, tx };
let config = tracing_config(&trace_types);