feat: rename reth_primitives::RecoveredTx functions to match alloy::Recovered (#13663)

This commit is contained in:
Tuan Tran
2025-01-06 21:27:43 +07:00
committed by GitHub
parent d10af50e45
commit 20d3fa6bbb
27 changed files with 48 additions and 49 deletions

View File

@ -192,7 +192,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let pooled = transaction let pooled = transaction
.clone() .clone()
.into_signed() .into_tx()
.try_into_pooled_eip4844(sidecar.clone()) .try_into_pooled_eip4844(sidecar.clone())
.expect("should not fail to convert blob tx if it is already eip4844"); .expect("should not fail to convert blob tx if it is already eip4844");
let encoded_length = pooled.encode_2718_len(); let encoded_length = pooled.encode_2718_len();

View File

@ -1592,8 +1592,7 @@ mod tests {
body: Vec<RecoveredTx<TransactionSigned>>, body: Vec<RecoveredTx<TransactionSigned>>,
num_of_signer_txs: u64| num_of_signer_txs: u64|
-> SealedBlockWithSenders { -> SealedBlockWithSenders {
let signed_body = let signed_body = body.clone().into_iter().map(|tx| tx.into_tx()).collect::<Vec<_>>();
body.clone().into_iter().map(|tx| tx.into_signed()).collect::<Vec<_>>();
let transactions_root = calculate_transaction_root(&signed_body); let transactions_root = calculate_transaction_root(&signed_body);
let receipts = body let receipts = body
.iter() .iter()

View File

@ -145,7 +145,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
gas_limit: ETHEREUM_BLOCK_GAS_LIMIT, gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
base_fee_per_gas: Some(INITIAL_BASE_FEE), base_fee_per_gas: Some(INITIAL_BASE_FEE),
transactions_root: calculate_transaction_root( transactions_root: calculate_transaction_root(
&transactions.clone().into_iter().map(|tx| tx.into_signed()).collect::<Vec<_>>(), &transactions.clone().into_iter().map(|tx| tx.into_tx()).collect::<Vec<_>>(),
), ),
receipts_root: calculate_receipt_root(&receipts), receipts_root: calculate_receipt_root(&receipts),
beneficiary: Address::random(), beneficiary: Address::random(),
@ -171,7 +171,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
let block = SealedBlock::new( let block = SealedBlock::new(
SealedHeader::seal(header), SealedHeader::seal(header),
BlockBody { BlockBody {
transactions: transactions.into_iter().map(|tx| tx.into_signed()).collect(), transactions: transactions.into_iter().map(|tx| tx.into_tx()).collect(),
ommers: Vec::new(), ommers: Vec::new(),
withdrawals: Some(vec![].into()), withdrawals: Some(vec![].into()),
}, },

View File

@ -285,7 +285,7 @@ where
} }
// Configure the environment for the tx. // Configure the environment for the tx.
*evm.tx_mut() = evm_config.tx_env(tx.as_signed(), tx.signer()); *evm.tx_mut() = evm_config.tx_env(tx.tx(), tx.signer());
let ResultAndState { result, state } = match evm.transact() { let ResultAndState { result, state } = match evm.transact() {
Ok(res) => res, Ok(res) => res,
@ -354,7 +354,7 @@ where
// append sender and transaction to the respective lists // append sender and transaction to the respective lists
executed_senders.push(tx.signer()); executed_senders.push(tx.signer());
executed_txs.push(tx.into_signed()); executed_txs.push(tx.into_tx());
} }
// check if we have a better block // check if we have a better block

View File

@ -64,7 +64,7 @@ pub fn broadcast_ingress_bench(c: &mut Criterion) {
tx.sender(), tx.sender(),
ExtendedAccount::new(0, U256::from(100_000_000)), ExtendedAccount::new(0, U256::from(100_000_000)),
); );
txs.push(Arc::new(tx.transaction().clone().into_signed())); txs.push(Arc::new(tx.transaction().clone().into_tx()));
peer1.send_transactions(peer0_id, txs); peer1.send_transactions(peer0_id, txs);
} }
} }

View File

@ -1538,7 +1538,7 @@ impl<T: SignedTransaction> PropagateTransaction<T> {
{ {
let size = tx.encoded_length(); let size = tx.encoded_length();
let transaction = tx.transaction.clone_into_consensus(); let transaction = tx.transaction.clone_into_consensus();
let transaction = Arc::new(transaction.into_signed()); let transaction = Arc::new(transaction.into_tx());
Self { size, transaction } Self { size, transaction }
} }

View File

@ -80,7 +80,7 @@ async fn test_4844_tx_gossip_penalization() {
} }
let signed_txs: Vec<Arc<TransactionSigned>> = let signed_txs: Vec<Arc<TransactionSigned>> =
txs.iter().map(|tx| Arc::new(tx.transaction().clone().into_signed())).collect(); txs.iter().map(|tx| Arc::new(tx.transaction().clone().into_tx())).collect();
let network_handle = peer0.network(); let network_handle = peer0.network();

View File

@ -58,7 +58,7 @@ impl TryFrom<RecoveredTx<OpTransactionSigned>> for OpPooledTransaction {
type Error = TransactionConversionError; type Error = TransactionConversionError;
fn try_from(value: RecoveredTx<OpTransactionSigned>) -> Result<Self, Self::Error> { fn try_from(value: RecoveredTx<OpTransactionSigned>) -> Result<Self, Self::Error> {
let (tx, signer) = value.to_components(); let (tx, signer) = value.into_parts();
let pooled: RecoveredTx<op_alloy_consensus::OpPooledTransaction> = let pooled: RecoveredTx<op_alloy_consensus::OpPooledTransaction> =
RecoveredTx::from_signed_transaction(tx.try_into()?, signer); RecoveredTx::from_signed_transaction(tx.try_into()?, signer);
Ok(pooled.into()) Ok(pooled.into())
@ -83,7 +83,7 @@ impl PoolTransaction for OpPooledTransaction {
fn try_consensus_into_pooled( fn try_consensus_into_pooled(
tx: RecoveredTx<Self::Consensus>, tx: RecoveredTx<Self::Consensus>,
) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> { ) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> {
let (tx, signer) = tx.to_components(); let (tx, signer) = tx.into_parts();
Ok(RecoveredTx::from_signed_transaction(tx.try_into()?, signer)) Ok(RecoveredTx::from_signed_transaction(tx.try_into()?, signer))
} }

View File

@ -790,7 +790,7 @@ where
)) ))
})?; })?;
*evm.tx_mut() = self.evm_config.tx_env(sequencer_tx.as_signed(), sequencer_tx.signer()); *evm.tx_mut() = self.evm_config.tx_env(sequencer_tx.tx(), sequencer_tx.signer());
let ResultAndState { result, state } = match evm.transact() { let ResultAndState { result, state } = match evm.transact() {
Ok(res) => res, Ok(res) => res,
@ -841,7 +841,7 @@ where
// append sender and transaction to the respective lists // append sender and transaction to the respective lists
info.executed_senders.push(sequencer_tx.signer()); info.executed_senders.push(sequencer_tx.signer());
info.executed_transactions.push(sequencer_tx.into_signed()); info.executed_transactions.push(sequencer_tx.into_tx());
} }
Ok(info) Ok(info)
@ -891,7 +891,7 @@ where
} }
// Configure the environment for the tx. // Configure the environment for the tx.
*evm.tx_mut() = self.evm_config.tx_env(tx.as_signed(), tx.signer()); *evm.tx_mut() = self.evm_config.tx_env(tx.tx(), tx.signer());
let ResultAndState { result, state } = match evm.transact() { let ResultAndState { result, state } = match evm.transact() {
Ok(res) => res, Ok(res) => res,
@ -954,7 +954,7 @@ where
// append sender and transaction to the respective lists // append sender and transaction to the respective lists
info.executed_senders.push(tx.signer()); info.executed_senders.push(tx.signer());
info.executed_transactions.push(tx.into_signed()); info.executed_transactions.push(tx.into_tx());
} }
Ok(None) Ok(None)

View File

@ -89,7 +89,7 @@ where
) -> Result<Self::Transaction, Self::Error> { ) -> Result<Self::Transaction, Self::Error> {
let from = tx.signer(); let from = tx.signer();
let hash = *tx.tx_hash(); let hash = *tx.tx_hash();
let OpTransactionSigned { transaction, signature, .. } = tx.into_signed(); let OpTransactionSigned { transaction, signature, .. } = tx.into_tx();
let mut deposit_receipt_version = None; let mut deposit_receipt_version = None;
let mut deposit_nonce = None; let mut deposit_nonce = None;

View File

@ -99,12 +99,12 @@ where
fn next(&mut self, ctx: ()) -> Option<RecoveredTx<Self::Transaction>> { fn next(&mut self, ctx: ()) -> Option<RecoveredTx<Self::Transaction>> {
while let Some(tx) = self.before.next(ctx) { while let Some(tx) = self.before.next(ctx) {
if let Some(before_max_gas) = self.before_max_gas { if let Some(before_max_gas) = self.before_max_gas {
if self.before_gas + tx.as_signed().gas_limit() <= before_max_gas { if self.before_gas + tx.tx().gas_limit() <= before_max_gas {
self.before_gas += tx.as_signed().gas_limit(); self.before_gas += tx.tx().gas_limit();
return Some(tx); return Some(tx);
} }
self.before.mark_invalid(tx.signer(), tx.as_signed().nonce()); self.before.mark_invalid(tx.signer(), tx.tx().nonce());
self.after.mark_invalid(tx.signer(), tx.as_signed().nonce()); self.after.mark_invalid(tx.signer(), tx.tx().nonce());
} else { } else {
return Some(tx); return Some(tx);
} }
@ -112,11 +112,11 @@ where
while let Some(tx) = self.after.next(ctx) { while let Some(tx) = self.after.next(ctx) {
if let Some(after_max_gas) = self.after_max_gas { if let Some(after_max_gas) = self.after_max_gas {
if self.after_gas + tx.as_signed().gas_limit() <= after_max_gas { if self.after_gas + tx.tx().gas_limit() <= after_max_gas {
self.after_gas += tx.as_signed().gas_limit(); self.after_gas += tx.tx().gas_limit();
return Some(tx); return Some(tx);
} }
self.after.mark_invalid(tx.signer(), tx.as_signed().nonce()); self.after.mark_invalid(tx.signer(), tx.tx().nonce());
} else { } else {
return Some(tx); return Some(tx);
} }

View File

@ -1546,17 +1546,17 @@ impl<T> RecoveredTx<T> {
} }
/// Returns a reference to [`TransactionSigned`] /// Returns a reference to [`TransactionSigned`]
pub const fn as_signed(&self) -> &T { pub const fn tx(&self) -> &T {
&self.signed_transaction &self.signed_transaction
} }
/// Transform back to [`TransactionSigned`] /// Transform back to [`TransactionSigned`]
pub fn into_signed(self) -> T { pub fn into_tx(self) -> T {
self.signed_transaction self.signed_transaction
} }
/// Dissolve Self to its component /// Dissolve Self to its component
pub fn to_components(self) -> (T, Address) { pub fn into_parts(self) -> (T, Address) {
(self.signed_transaction, self.signer) (self.signed_transaction, self.signer)
} }

View File

@ -12,7 +12,7 @@ pub type PooledTransactionsElementEcRecovered<T = PooledTransaction> = Recovered
impl PooledTransactionsElementEcRecovered { impl PooledTransactionsElementEcRecovered {
/// Transform back to [`RecoveredTx`] /// Transform back to [`RecoveredTx`]
pub fn into_ecrecovered_transaction(self) -> RecoveredTx<TransactionSigned> { pub fn into_ecrecovered_transaction(self) -> RecoveredTx<TransactionSigned> {
let (tx, signer) = self.to_components(); let (tx, signer) = self.into_parts();
RecoveredTx::from_signed_transaction(tx.into(), signer) RecoveredTx::from_signed_transaction(tx.into(), signer)
} }

View File

@ -682,7 +682,7 @@ pub trait Call:
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg, cfg_env_with_handler_cfg,
block_env, block_env,
RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()), RpcNodeCore::evm_config(&this).tx_env(tx.tx(), tx.signer()),
); );
let (res, _) = this.transact(&mut db, env)?; let (res, _) = this.transact(&mut db, env)?;

View File

@ -341,7 +341,7 @@ pub trait LoadPendingBlock:
let env = Env::boxed( let env = Env::boxed(
cfg.cfg_env.clone(), cfg.cfg_env.clone(),
block_env.clone(), block_env.clone(),
Self::evm_config(self).tx_env(tx.as_signed(), tx.signer()), Self::evm_config(self).tx_env(tx.tx(), tx.signer()),
); );
let mut evm = revm::Evm::builder().with_env(env).with_db(&mut db).build(); let mut evm = revm::Evm::builder().with_env(env).with_db(&mut db).build();
@ -393,7 +393,7 @@ pub trait LoadPendingBlock:
cumulative_gas_used += gas_used; cumulative_gas_used += gas_used;
// append transaction to the list of executed transactions // append transaction to the list of executed transactions
let (tx, sender) = tx.to_components(); let (tx, sender) = tx.into_parts();
executed_txs.push(tx); executed_txs.push(tx);
senders.push(sender); senders.push(sender);
results.push(result); results.push(result);

View File

@ -226,7 +226,7 @@ pub trait Trace:
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg, cfg_env_with_handler_cfg,
block_env, block_env,
RpcNodeCore::evm_config(&this).tx_env(tx.as_signed(), tx.signer()), RpcNodeCore::evm_config(&this).tx_env(tx.tx(), tx.signer()),
); );
let (res, _) = let (res, _) =
this.inspect(StateCacheDbRefMutWrapper(&mut db), env, &mut inspector)?; this.inspect(StateCacheDbRefMutWrapper(&mut db), env, &mut inspector)?;

View File

@ -68,5 +68,5 @@ pub fn transaction_to_call_request<T: alloy_consensus::Transaction>(
tx: RecoveredTx<T>, tx: RecoveredTx<T>,
) -> TransactionRequest { ) -> TransactionRequest {
let from = tx.signer(); let from = tx.signer();
TransactionRequest::from_transaction_with_sender(tx.into_signed(), from) TransactionRequest::from_transaction_with_sender(tx.into_tx(), from)
} }

View File

@ -273,7 +273,7 @@ where
env: Env::boxed( env: Env::boxed(
cfg_env_with_handler_cfg.cfg_env.clone(), cfg_env_with_handler_cfg.cfg_env.clone(),
block_env, block_env,
this.eth_api().evm_config().tx_env(tx.as_signed(), tx.signer()), this.eth_api().evm_config().tx_env(tx.tx(), tx.signer()),
), ),
handler_cfg: cfg_env_with_handler_cfg.handler_cfg, handler_cfg: cfg_env_with_handler_cfg.handler_cfg,
}; };

View File

@ -44,7 +44,7 @@ where
) -> Result<Self::Transaction, Self::Error> { ) -> Result<Self::Transaction, Self::Error> {
let from = tx.signer(); let from = tx.signer();
let hash = tx.hash(); let hash = tx.hash();
let TransactionSigned { transaction, signature, .. } = tx.into_signed(); let TransactionSigned { transaction, signature, .. } = tx.into_tx();
let inner: TxEnvelope = match transaction { let inner: TxEnvelope = match transaction {
reth_primitives::Transaction::Legacy(tx) => { reth_primitives::Transaction::Legacy(tx) => {

View File

@ -172,7 +172,7 @@ where
match &body[idx] { match &body[idx] {
BundleItem::Tx { tx, can_revert } => { BundleItem::Tx { tx, can_revert } => {
let recovered_tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)?; let recovered_tx = recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(tx)?;
let (tx, signer) = recovered_tx.to_components(); let (tx, signer) = recovered_tx.into_parts();
let tx: PoolConsensusTx<Eth::Pool> = let tx: PoolConsensusTx<Eth::Pool> =
<Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus(tx); <Eth::Pool as TransactionPool>::Transaction::pooled_into_consensus(tx);

View File

@ -121,7 +121,7 @@ where
let env = EnvWithHandlerCfg::new_with_cfg_env( let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg, cfg_env_with_handler_cfg,
block_env, block_env,
self.eth_api().evm_config().tx_env(tx.as_signed(), tx.signer()), self.eth_api().evm_config().tx_env(tx.tx(), tx.signer()),
); );
let config = TracingInspectorConfig::from_parity_config(&trace_types); let config = TracingInspectorConfig::from_parity_config(&trace_types);

View File

@ -103,7 +103,7 @@ where
) { ) {
let entry = inspect.entry(tx.sender()).or_default(); let entry = inspect.entry(tx.sender()).or_default();
let tx = tx.clone_into_consensus(); let tx = tx.clone_into_consensus();
entry.insert(tx.nonce().to_string(), tx.into_signed().into()); entry.insert(tx.nonce().to_string(), tx.into_tx().into());
} }
let AllPoolTransactions { pending, queued } = self.pool.all_transactions(); let AllPoolTransactions { pending, queued } = self.pool.all_transactions();

View File

@ -600,7 +600,7 @@ where
let local_transactions = local_transactions let local_transactions = local_transactions
.into_iter() .into_iter()
.map(|tx| tx.transaction.clone_into_consensus().into_signed()) .map(|tx| tx.transaction.clone_into_consensus().into_tx())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let num_txs = local_transactions.len(); let num_txs = local_transactions.len();

View File

@ -357,7 +357,7 @@ where
}; };
size += encoded_len; size += encoded_len;
elements.push(pooled.into_signed()); elements.push(pooled.into_tx());
if limit.exceeds(size) { if limit.exceeds(size) {
break break

View File

@ -685,7 +685,7 @@ impl PoolTransaction for MockTransaction {
fn try_consensus_into_pooled( fn try_consensus_into_pooled(
tx: RecoveredTx<Self::Consensus>, tx: RecoveredTx<Self::Consensus>,
) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> { ) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> {
let (tx, signer) = tx.to_components(); let (tx, signer) = tx.into_parts();
Self::Pooled::try_from(tx) Self::Pooled::try_from(tx)
.map(|tx| tx.with_signer(signer)) .map(|tx| tx.with_signer(signer))
.map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing) .map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)
@ -871,7 +871,7 @@ impl EthPoolTransaction for MockTransaction {
self, self,
sidecar: Arc<BlobTransactionSidecar>, sidecar: Arc<BlobTransactionSidecar>,
) -> Option<RecoveredTx<Self::Pooled>> { ) -> Option<RecoveredTx<Self::Pooled>> {
let (tx, signer) = self.into_consensus().to_components(); let (tx, signer) = self.into_consensus().into_parts();
tx.try_into_pooled_eip4844(Arc::unwrap_or_clone(sidecar)) tx.try_into_pooled_eip4844(Arc::unwrap_or_clone(sidecar))
.map(|tx| tx.with_signer(signer)) .map(|tx| tx.with_signer(signer))
.ok() .ok()
@ -881,7 +881,7 @@ impl EthPoolTransaction for MockTransaction {
tx: RecoveredTx<Self::Consensus>, tx: RecoveredTx<Self::Consensus>,
sidecar: BlobTransactionSidecar, sidecar: BlobTransactionSidecar,
) -> Option<Self> { ) -> Option<Self> {
let (tx, signer) = tx.to_components(); let (tx, signer) = tx.into_parts();
tx.try_into_pooled_eip4844(sidecar) tx.try_into_pooled_eip4844(sidecar)
.map(|tx| tx.with_signer(signer)) .map(|tx| tx.with_signer(signer))
.ok() .ok()
@ -909,7 +909,7 @@ impl TryFrom<RecoveredTx<TransactionSigned>> for MockTransaction {
fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> { fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> {
let sender = tx.signer(); let sender = tx.signer();
let transaction = tx.into_signed(); let transaction = tx.into_tx();
let hash = transaction.hash(); let hash = transaction.hash();
let size = transaction.size(); let size = transaction.size();

View File

@ -1245,7 +1245,7 @@ impl<T: SignedTransaction> EthPooledTransaction<T> {
impl From<PooledTransactionsElementEcRecovered> for EthPooledTransaction { impl From<PooledTransactionsElementEcRecovered> for EthPooledTransaction {
fn from(tx: PooledTransactionsElementEcRecovered) -> Self { fn from(tx: PooledTransactionsElementEcRecovered) -> Self {
let encoded_length = tx.encode_2718_len(); let encoded_length = tx.encode_2718_len();
let (tx, signer) = tx.to_components(); let (tx, signer) = tx.into_parts();
match tx { match tx {
PooledTransaction::Eip4844(tx) => { PooledTransaction::Eip4844(tx) => {
// include the blob sidecar // include the blob sidecar
@ -1280,7 +1280,7 @@ impl PoolTransaction for EthPooledTransaction {
fn try_consensus_into_pooled( fn try_consensus_into_pooled(
tx: RecoveredTx<Self::Consensus>, tx: RecoveredTx<Self::Consensus>,
) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> { ) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> {
let (tx, signer) = tx.to_components(); let (tx, signer) = tx.into_parts();
let pooled = tx let pooled = tx
.try_into_pooled() .try_into_pooled()
.map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)?; .map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)?;
@ -1427,7 +1427,7 @@ impl EthPoolTransaction for EthPooledTransaction {
tx: RecoveredTx<Self::Consensus>, tx: RecoveredTx<Self::Consensus>,
sidecar: BlobTransactionSidecar, sidecar: BlobTransactionSidecar,
) -> Option<Self> { ) -> Option<Self> {
let (tx, signer) = tx.to_components(); let (tx, signer) = tx.into_parts();
tx.try_into_pooled_eip4844(sidecar) tx.try_into_pooled_eip4844(sidecar)
.ok() .ok()
.map(|tx| tx.with_signer(signer)) .map(|tx| tx.with_signer(signer))

View File

@ -909,7 +909,7 @@ fn on_new_transactions(&mut self, hashes: impl IntoIterator<Item = TxHash>) {
.get_all(hashes) .get_all(hashes)
.into_iter() .into_iter()
.map(|tx| { .map(|tx| {
(*tx.hash(), Arc::new(tx.transaction.to_recovered_transaction().into_signed())) (*tx.hash(), Arc::new(tx.transaction.to_recovered_transaction().into_tx()))
}) })
.collect(), .collect(),
); );
@ -1098,7 +1098,7 @@ fn on_get_pooled_transactions(
.pool .pool
.get_all(request.0) .get_all(request.0)
.into_iter() .into_iter()
.map(|tx| tx.transaction.to_recovered_transaction().into_signed()) .map(|tx| tx.transaction.to_recovered_transaction().into_tx())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// we sent a response at which point we assume that the peer is aware of the transaction // we sent a response at which point we assume that the peer is aware of the transaction