chore: remove PooledTransactionsElement alias (#13384)

This commit is contained in:
Matthias Seitz
2024-12-13 15:48:56 +01:00
committed by GitHub
parent 197f274b31
commit b67e5a262c
19 changed files with 93 additions and 113 deletions

View File

@ -43,15 +43,13 @@ pub use reth_primitives_traits::{
};
pub use static_file::StaticFileSegment;
pub use alloy_consensus::{transaction::PooledTransaction, ReceiptWithBloom};
pub use transaction::{
util::secp256k1::{public_key_to_address, recover_signer_unchecked, sign_message},
InvalidTransactionError, PooledTransactionsElement, PooledTransactionsElementEcRecovered,
RecoveredTx, Transaction, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered,
TxType,
InvalidTransactionError, PooledTransactionsElementEcRecovered, RecoveredTx, Transaction,
TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, TxType,
};
pub use alloy_consensus::ReceiptWithBloom;
// Re-exports
pub use reth_ethereum_forks::*;

View File

@ -1,10 +1,11 @@
//! Transaction types.
use alloc::vec::Vec;
pub use alloy_consensus::transaction::PooledTransaction;
use alloy_consensus::{
transaction::{PooledTransaction, RlpEcdsaTx},
SignableTransaction, Signed, Transaction as _, TxEip1559, TxEip2930, TxEip4844,
TxEip4844Variant, TxEip4844WithSidecar, TxEip7702, TxLegacy, Typed2718, TypedTransaction,
transaction::RlpEcdsaTx, SignableTransaction, Signed, Transaction as _, TxEip1559, TxEip2930,
TxEip4844, TxEip4844Variant, TxEip4844WithSidecar, TxEip7702, TxLegacy, Typed2718,
TypedTransaction,
};
use alloy_eips::{
eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718},
@ -27,7 +28,7 @@ use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock};
use op_alloy_consensus::DepositTransaction;
#[cfg(feature = "optimism")]
use op_alloy_consensus::TxDeposit;
pub use pooled::{PooledTransactionsElement, PooledTransactionsElementEcRecovered};
pub use pooled::PooledTransactionsElementEcRecovered;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
pub use reth_primitives_traits::{
transaction::error::{
@ -853,25 +854,25 @@ impl TransactionSigned {
&self.transaction
}
/// Tries to convert a [`TransactionSigned`] into a [`PooledTransactionsElement`].
/// Tries to convert a [`TransactionSigned`] into a [`PooledTransaction`].
///
/// This function used as a helper to convert from a decoded p2p broadcast message to
/// [`PooledTransactionsElement`]. Since EIP4844 variants are disallowed to be broadcasted on
/// [`PooledTransaction`]. Since EIP4844 variants are disallowed to be broadcasted on
/// p2p, return an err if `tx` is [`Transaction::Eip4844`].
pub fn try_into_pooled(self) -> Result<PooledTransactionsElement, Self> {
pub fn try_into_pooled(self) -> Result<PooledTransaction, Self> {
let hash = self.hash();
match self {
Self { transaction: Transaction::Legacy(tx), signature, .. } => {
Ok(PooledTransactionsElement::Legacy(Signed::new_unchecked(tx, signature, hash)))
Ok(PooledTransaction::Legacy(Signed::new_unchecked(tx, signature, hash)))
}
Self { transaction: Transaction::Eip2930(tx), signature, .. } => {
Ok(PooledTransactionsElement::Eip2930(Signed::new_unchecked(tx, signature, hash)))
Ok(PooledTransaction::Eip2930(Signed::new_unchecked(tx, signature, hash)))
}
Self { transaction: Transaction::Eip1559(tx), signature, .. } => {
Ok(PooledTransactionsElement::Eip1559(Signed::new_unchecked(tx, signature, hash)))
Ok(PooledTransaction::Eip1559(Signed::new_unchecked(tx, signature, hash)))
}
Self { transaction: Transaction::Eip7702(tx), signature, .. } => {
Ok(PooledTransactionsElement::Eip7702(Signed::new_unchecked(tx, signature, hash)))
Ok(PooledTransaction::Eip7702(Signed::new_unchecked(tx, signature, hash)))
}
// Not supported because missing blob sidecar
tx @ Self { transaction: Transaction::Eip4844(_), .. } => Err(tx),
@ -889,13 +890,13 @@ impl TransactionSigned {
pub fn try_into_pooled_eip4844(
self,
sidecar: BlobTransactionSidecar,
) -> Result<PooledTransactionsElement, Self> {
) -> Result<PooledTransaction, Self> {
let hash = self.hash();
Ok(match self {
// If the transaction is an EIP-4844 transaction...
Self { transaction: Transaction::Eip4844(tx), signature, .. } => {
// Construct a pooled eip488 tx with the provided sidecar.
PooledTransactionsElement::Eip4844(Signed::new_unchecked(
PooledTransaction::Eip4844(Signed::new_unchecked(
TxEip4844WithSidecar { tx, sidecar },
signature,
hash,
@ -1251,7 +1252,7 @@ impl Decodable for TransactionSigned {
/// This cannot be used for decoding EIP-4844 transactions in p2p `PooledTransactions`, since
/// the EIP-4844 variant of [`TransactionSigned`] does not include the blob sidecar.
///
/// For a method suitable for decoding pooled transactions, see [`PooledTransactionsElement`].
/// For a method suitable for decoding pooled transactions, see [`PooledTransaction`].
///
/// CAUTION: Due to a quirk in [`Header::decode`], this method will succeed even if a typed
/// transaction is encoded in this format, and does not start with a RLP header:

View File

@ -2,14 +2,12 @@
//! response to `GetPooledTransactions`.
use crate::RecoveredTx;
use alloy_consensus::transaction::PooledTransaction;
use alloy_eips::eip4844::BlobTransactionSidecar;
use reth_primitives_traits::transaction::error::TransactionConversionError;
/// Tmp alias for the transaction type.
pub type PooledTransactionsElement = alloy_consensus::transaction::PooledTransaction;
/// A signed pooled transaction with recovered signer.
pub type PooledTransactionsElementEcRecovered<T = PooledTransactionsElement> = RecoveredTx<T>;
pub type PooledTransactionsElementEcRecovered<T = PooledTransaction> = RecoveredTx<T>;
impl PooledTransactionsElementEcRecovered {
/// Transform back to [`RecoveredTx`]
@ -39,7 +37,7 @@ impl TryFrom<RecoveredTx> for PooledTransactionsElementEcRecovered {
type Error = TransactionConversionError;
fn try_from(tx: RecoveredTx) -> Result<Self, Self::Error> {
match PooledTransactionsElement::try_from(tx.signed_transaction) {
match PooledTransaction::try_from(tx.signed_transaction) {
Ok(pooled_transaction) => {
Ok(Self::from_signed_transaction(pooled_transaction, tx.signer))
}
@ -78,7 +76,7 @@ mod tests {
for hex_data in &input_too_short {
let input_rlp = &mut &hex_data[..];
let res = PooledTransactionsElement::decode(input_rlp);
let res = PooledTransaction::decode(input_rlp);
assert!(
res.is_err(),
@ -88,7 +86,7 @@ mod tests {
// this is a legacy tx so we can attempt the same test with decode_enveloped
let input_rlp = &mut &hex_data[..];
let res = PooledTransactionsElement::decode_2718(input_rlp);
let res = PooledTransaction::decode_2718(input_rlp);
assert!(
res.is_err(),
@ -104,7 +102,7 @@ mod tests {
let data = hex!("02f903d382426882ba09832dc6c0848674742682ed9694714b6a4ea9b94a8a7d9fd362ed72630688c8898c80b90364492d24749189822d8512430d3f3ff7a2ede675ac08265c08e2c56ff6fdaa66dae1cdbe4a5d1d7809f3e99272d067364e597542ac0c369d69e22a6399c3e9bee5da4b07e3f3fdc34c32c3d88aa2268785f3e3f8086df0934b10ef92cfffc2e7f3d90f5e83302e31382e302d64657600000000000000000000000000000000000000000000569e75fc77c1a856f6daaf9e69d8a9566ca34aa47f9133711ce065a571af0cfd000000000000000000000000e1e210594771824dad216568b91c9cb4ceed361c00000000000000000000000000000000000000000000000000000000000546e00000000000000000000000000000000000000000000000000000000000e4e1c00000000000000000000000000000000000000000000000000000000065d6750c00000000000000000000000000000000000000000000000000000000000f288000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cf600000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000000f1628e56fa6d8c50e5b984a58c0df14de31c7b857ce7ba499945b99252976a93d06dcda6776fc42167fbe71cb59f978f5ef5b12577a90b132d14d9c6efa528076f0161d7bf03643cfc5490ec5084f4a041db7f06c50bd97efa08907ba79ddcac8b890f24d12d8db31abbaaf18985d54f400449ee0559a4452afe53de5853ce090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000064ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000c080a01428023fc54a27544abc421d5d017b9a7c5936ad501cbdecd0d9d12d04c1a033a0753104bbf1c87634d6ff3f0ffa0982710612306003eb022363b57994bdef445a"
);
let res = PooledTransactionsElement::decode_2718(&mut &data[..]).unwrap();
let res = PooledTransaction::decode_2718(&mut &data[..]).unwrap();
assert_eq!(res.to(), Some(address!("714b6a4ea9b94a8a7d9fd362ed72630688c8898c")));
}
@ -123,7 +121,7 @@ mod tests {
let data = &hex!("d30b02808083c5cdeb8783c5acfd9e407c565656")[..];
let input_rlp = &mut &data[..];
let res = PooledTransactionsElement::decode(input_rlp);
let res = PooledTransaction::decode(input_rlp);
assert_matches!(res, Ok(_tx));
assert!(input_rlp.is_empty());
@ -135,7 +133,7 @@ mod tests {
assert!(input_rlp.is_empty());
// we can also decode_enveloped
let res = PooledTransactionsElement::decode_2718(&mut &data[..]);
let res = PooledTransaction::decode_2718(&mut &data[..]);
assert_matches!(res, Ok(_tx));
}
}