feat: use reth-ethereum-primitives (#13830)

This commit is contained in:
Arsenii Kulikov
2025-01-17 04:22:21 +04:00
committed by GitHub
parent 7e972ea23d
commit 8efe441cc0
67 changed files with 941 additions and 3025 deletions

View File

@ -1,10 +1,12 @@
use crate::EthPooledTransaction;
use alloy_consensus::{TxEip1559, TxEip4844, TxLegacy};
use alloy_consensus::{SignableTransaction, TxEip1559, TxEip4844, TxLegacy};
use alloy_eips::{eip1559::MIN_PROTOCOL_BASE_FEE, eip2718::Encodable2718, eip2930::AccessList};
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
use rand::Rng;
use reth_chainspec::MAINNET;
use reth_primitives::{Transaction, TransactionSigned};
use reth_primitives::{
transaction::SignedTransactionIntoRecoveredExt, Transaction, TransactionSigned,
};
use reth_primitives_traits::crypto::secp256k1::sign_message;
/// A generator for transactions for testing purposes.
@ -99,12 +101,12 @@ impl<R: Rng> TransactionGenerator<R> {
/// Generates and returns a pooled EIP-1559 transaction with a random signer.
pub fn gen_eip1559_pooled(&mut self) -> EthPooledTransaction {
self.gen_eip1559().into_ecrecovered().unwrap().try_into().unwrap()
self.gen_eip1559().try_into_ecrecovered().unwrap().try_into().unwrap()
}
/// Generates and returns a pooled EIP-4844 transaction with a random signer.
pub fn gen_eip4844_pooled(&mut self) -> EthPooledTransaction {
let tx = self.gen_eip4844().into_ecrecovered().unwrap();
let tx = self.gen_eip4844().try_into_ecrecovered().unwrap();
let encoded_length = tx.encode_2718_len();
EthPooledTransaction::new(tx, encoded_length)
}

View File

@ -32,7 +32,7 @@ use reth_primitives::{
transaction::{SignedTransactionIntoRecoveredExt, TryFromRecoveredTransactionError},
PooledTransaction, RecoveredTx, Transaction, TransactionSigned, TxType,
};
use reth_primitives_traits::InMemorySize;
use reth_primitives_traits::{InMemorySize, SignedTransaction};
use std::{ops::Range, sync::Arc, time::Instant, vec::IntoIter};
/// A transaction pool implementation using [`MockOrdering`] for transaction ordering.
@ -909,7 +909,7 @@ impl TryFrom<RecoveredTx<TransactionSigned>> for MockTransaction {
fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> {
let sender = tx.signer();
let transaction = tx.into_tx();
let hash = transaction.hash();
let hash = *transaction.tx_hash();
let size = transaction.size();
#[allow(unreachable_patterns)]

View File

@ -7,7 +7,7 @@ use crate::{
};
use alloy_consensus::{
constants::{EIP1559_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID},
BlockHeader, Transaction as _, Typed2718,
BlockHeader, Signed, Transaction as _, Typed2718,
};
use alloy_eips::{
eip2718::Encodable2718,
@ -1249,7 +1249,8 @@ impl From<RecoveredTx<PooledTransaction>> for EthPooledTransaction {
// include the blob sidecar
let (tx, sig, hash) = tx.into_parts();
let (tx, blob) = tx.into_parts();
let tx = TransactionSigned::new(tx.into(), sig, hash);
let tx = Signed::new_unchecked(tx, sig, hash);
let tx = TransactionSigned::from(tx);
let tx = RecoveredTx::new_unchecked(tx, signer);
let mut pooled = Self::new(tx, encoded_length);
pooled.blob_sidecar = EthBlobTransactionSidecar::Present(blob);
@ -1279,9 +1280,8 @@ impl PoolTransaction for EthPooledTransaction {
tx: RecoveredTx<Self::Consensus>,
) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> {
let (tx, signer) = tx.into_parts();
let pooled = tx
.try_into_pooled()
.map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)?;
let pooled =
tx.try_into().map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)?;
Ok(RecoveredTx::new_unchecked(pooled, signer))
}