Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(primitives): rename RecoveredTx functions to match alloy::… #13669

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {

let pooled = transaction
.clone()
.into_signed()
.into_tx()
.try_into_pooled_eip4844(sidecar.clone())
.expect("should not fail to convert blob tx if it is already eip4844");
let encoded_length = pooled.encode_2718_len();
Expand Down
3 changes: 1 addition & 2 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,7 @@ mod tests {
body: Vec<RecoveredTx<TransactionSigned>>,
num_of_signer_txs: u64|
-> SealedBlockWithSenders {
let signed_body =
body.clone().into_iter().map(|tx| tx.into_signed()).collect::<Vec<_>>();
let signed_body = body.clone().into_iter().map(|tx| tx.into_tx()).collect::<Vec<_>>();
let transactions_root = calculate_transaction_root(&signed_body);
let receipts = body
.iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/chain-state/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
base_fee_per_gas: Some(INITIAL_BASE_FEE),
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),
beneficiary: Address::random(),
Expand All @@ -171,7 +171,7 @@ impl<N: NodePrimitives> TestBlockBuilder<N> {
let block = SealedBlock::new(
SealedHeader::seal(header),
BlockBody {
transactions: transactions.into_iter().map(|tx| tx.into_signed()).collect(),
transactions: transactions.into_iter().map(|tx| tx.into_tx()).collect(),
ommers: Vec::new(),
withdrawals: Some(vec![].into()),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ where
}

// 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() {
Ok(res) => res,
Expand Down Expand Up @@ -354,7 +354,7 @@ where

// append sender and transaction to the respective lists
executed_senders.push(tx.signer());
executed_txs.push(tx.into_signed());
executed_txs.push(tx.into_tx());
}

// check if we have a better block
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/benches/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn broadcast_ingress_bench(c: &mut Criterion) {
tx.sender(),
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ impl<T: SignedTransaction> PropagateTransaction<T> {
{
let size = tx.encoded_length();
let transaction = tx.transaction.clone_into_consensus();
let transaction = Arc::new(transaction.into_signed());
let transaction = Arc::new(transaction.into_tx());
Self { size, transaction }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/tests/it/txgossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn test_4844_tx_gossip_penalization() {
}

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();

Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ impl TryFrom<RecoveredTx<OpTransactionSigned>> for OpPooledTransaction {
type Error = TransactionConversionError;

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> =
RecoveredTx::from_signed_transaction(tx.try_into()?, signer);
RecoveredTx::new_unchecked(tx.try_into()?, signer);
Ok(pooled.into())
}
}
Expand All @@ -83,8 +83,8 @@ impl PoolTransaction for OpPooledTransaction {
fn try_consensus_into_pooled(
tx: RecoveredTx<Self::Consensus>,
) -> Result<RecoveredTx<Self::Pooled>, Self::TryFromConsensusError> {
let (tx, signer) = tx.to_components();
Ok(RecoveredTx::from_signed_transaction(tx.try_into()?, signer))
let (tx, signer) = tx.into_parts();
Ok(RecoveredTx::new_unchecked(tx.try_into()?, signer))
}

fn hash(&self) -> &TxHash {
Expand Down Expand Up @@ -459,7 +459,7 @@ mod tests {
});
let signature = Signature::test_signature();
let signed_tx = OpTransactionSigned::new_unhashed(deposit_tx, signature);
let signed_recovered = RecoveredTx::from_signed_transaction(signed_tx, signer);
let signed_recovered = RecoveredTx::new_unchecked(signed_tx, signer);
let len = signed_recovered.encode_2718_len();
let pooled_tx = OpPooledTransaction::new(signed_recovered, len);
let outcome = validator.validate_one(origin, pooled_tx);
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/node/tests/it/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl OpPayloadTransactions for CustomTxPriority {
..Default::default()
};
let signature = sender.sign_transaction_sync(&mut end_of_block_tx).unwrap();
let end_of_block_tx = RecoveredTx::from_signed_transaction(
let end_of_block_tx = RecoveredTx::new_unchecked(
OpTransactionSigned::new_unhashed(
OpTypedTransaction::Eip1559(end_of_block_tx),
signature,
Expand Down
8 changes: 4 additions & 4 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Ok(res) => res,
Expand Down Expand Up @@ -841,7 +841,7 @@ where

// append sender and transaction to the respective lists
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)
Expand Down Expand Up @@ -891,7 +891,7 @@ where
}

// 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() {
Ok(res) => res,
Expand Down Expand Up @@ -954,7 +954,7 @@ where

// append sender and transaction to the respective lists
info.executed_senders.push(tx.signer());
info.executed_transactions.push(tx.into_signed());
info.executed_transactions.push(tx.into_tx());
}

Ok(None)
Expand Down
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 @@ -89,7 +89,7 @@ where
) -> Result<Self::Transaction, Self::Error> {
let from = tx.signer();
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_nonce = None;

Expand Down
14 changes: 7 additions & 7 deletions crates/payload/util/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,24 @@ where
fn next(&mut self, ctx: ()) -> Option<RecoveredTx<Self::Transaction>> {
while let Some(tx) = self.before.next(ctx) {
if let Some(before_max_gas) = self.before_max_gas {
if self.before_gas + tx.as_signed().gas_limit() <= before_max_gas {
self.before_gas += tx.as_signed().gas_limit();
if self.before_gas + tx.tx().gas_limit() <= before_max_gas {
self.before_gas += tx.tx().gas_limit();
return Some(tx);
}
self.before.mark_invalid(tx.signer(), tx.as_signed().nonce());
self.after.mark_invalid(tx.signer(), tx.as_signed().nonce());
self.before.mark_invalid(tx.signer(), tx.tx().nonce());
self.after.mark_invalid(tx.signer(), tx.tx().nonce());
} else {
return Some(tx);
}
}

while let Some(tx) = self.after.next(ctx) {
if let Some(after_max_gas) = self.after_max_gas {
if self.after_gas + tx.as_signed().gas_limit() <= after_max_gas {
self.after_gas += tx.as_signed().gas_limit();
if self.after_gas + tx.tx().gas_limit() <= after_max_gas {
self.after_gas += tx.tx().gas_limit();
return Some(tx);
}
self.after.mark_invalid(tx.signer(), tx.as_signed().nonce());
self.after.mark_invalid(tx.signer(), tx.tx().nonce());
} else {
return Some(tx);
}
Expand Down
35 changes: 18 additions & 17 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use alloy_eips::{
use alloy_primitives::{
keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256,
};
use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header};
use alloy_rlp::{Decodable, Encodable, Header};
use core::hash::{Hash, Hasher};
use derive_more::{AsRef, Deref};
use once_cell as _;
Expand Down Expand Up @@ -912,15 +912,15 @@ impl TransactionSigned {
/// Returns the [`RecoveredTx`] transaction with the given sender.
#[inline]
pub const fn with_signer(self, signer: Address) -> RecoveredTx<Self> {
RecoveredTx::from_signed_transaction(self, signer)
RecoveredTx::new_unchecked(self, signer)
}

/// Consumes the type, recover signer and return [`RecoveredTx`]
///
/// Returns `None` if the transaction's signature is invalid, see also [`Self::recover_signer`].
pub fn into_ecrecovered(self) -> Option<RecoveredTx<Self>> {
let signer = self.recover_signer()?;
Some(RecoveredTx { signed_transaction: self, signer })
Some(RecoveredTx::new_unchecked(self, signer))
}

/// Consumes the type, recover signer and return [`RecoveredTx`] _without
Expand All @@ -930,7 +930,7 @@ impl TransactionSigned {
/// [`Self::recover_signer_unchecked`].
pub fn into_ecrecovered_unchecked(self) -> Option<RecoveredTx<Self>> {
let signer = self.recover_signer_unchecked()?;
Some(RecoveredTx { signed_transaction: self, signer })
Some(RecoveredTx::new_unchecked(self, signer))
}

/// Tries to recover signer and return [`RecoveredTx`]. _without ensuring that
Expand All @@ -941,7 +941,7 @@ impl TransactionSigned {
pub fn try_into_ecrecovered_unchecked(self) -> Result<RecoveredTx<Self>, Self> {
match self.recover_signer_unchecked() {
None => Err(self),
Some(signer) => Ok(RecoveredTx { signed_transaction: self, signer }),
Some(signer) => Ok(RecoveredTx::new_unchecked(self, signer)),
}
}

Expand Down Expand Up @@ -1184,13 +1184,13 @@ impl alloy_consensus::Transaction for TransactionSigned {

impl From<RecoveredTx<Self>> for TransactionSigned {
fn from(recovered: RecoveredTx<Self>) -> Self {
recovered.signed_transaction
recovered.into_tx()
}
}

impl From<RecoveredTx<PooledTransaction>> for TransactionSigned {
fn from(recovered: RecoveredTx<PooledTransaction>) -> Self {
recovered.signed_transaction.into()
recovered.into_tx().into()
}
}

Expand Down Expand Up @@ -1523,6 +1523,7 @@ pub type TransactionSignedEcRecovered<T = TransactionSigned> = RecoveredTx<T>;

/// Signed transaction with recovered signer.
#[derive(Debug, Clone, PartialEq, Hash, Eq, AsRef, Deref)]
#[non_exhaustive]
pub struct RecoveredTx<T = TransactionSigned> {
/// Signer of the transaction
signer: Address,
Expand All @@ -1546,30 +1547,30 @@ impl<T> RecoveredTx<T> {
}

/// Returns a reference to [`TransactionSigned`]
pub const fn as_signed(&self) -> &T {
pub const fn tx(&self) -> &T {
&self.signed_transaction
}

/// Transform back to [`TransactionSigned`]
pub fn into_signed(self) -> T {
pub fn into_tx(self) -> T {
self.signed_transaction
}

/// Dissolve Self to its component
pub fn to_components(self) -> (T, Address) {
pub fn into_parts(self) -> (T, Address) {
(self.signed_transaction, self.signer)
}

/// Create [`RecoveredTx`] from [`TransactionSigned`] and [`Address`] of the
/// signer.
#[inline]
pub const fn from_signed_transaction(signed_transaction: T, signer: Address) -> Self {
pub const fn new_unchecked(signed_transaction: T, signer: Address) -> Self {
Self { signed_transaction, signer }
}

/// Applies the given closure to the inner transactions.
pub fn map_transaction<Tx>(self, f: impl FnOnce(T) -> Tx) -> RecoveredTx<Tx> {
RecoveredTx::from_signed_transaction(f(self.signed_transaction), self.signer)
RecoveredTx::new_unchecked(f(self.signed_transaction), self.signer)
}
}

Expand All @@ -1592,7 +1593,7 @@ impl<T: SignedTransaction> Decodable for RecoveredTx<T> {
let signer = signed_transaction
.recover_signer()
.ok_or(RlpError::Custom("Unable to recover decoded transaction signer."))?;
Ok(Self { signer, signed_transaction })
Ok(Self::new_unchecked(signed_transaction, signer))
}
}

Expand All @@ -1619,7 +1620,7 @@ pub trait SignedTransactionIntoRecoveredExt: SignedTransaction {
/// Tries to recover signer and return [`RecoveredTx`] by cloning the type.
fn try_ecrecovered(&self) -> Option<RecoveredTx<Self>> {
let signer = self.recover_signer()?;
Some(RecoveredTx { signed_transaction: self.clone(), signer })
Some(RecoveredTx::new_unchecked(self.clone(), signer))
}

/// Tries to recover signer and return [`RecoveredTx`].
Expand All @@ -1629,7 +1630,7 @@ pub trait SignedTransactionIntoRecoveredExt: SignedTransaction {
fn try_into_ecrecovered(self) -> Result<RecoveredTx<Self>, Self> {
match self.recover_signer() {
None => Err(self),
Some(signer) => Ok(RecoveredTx { signed_transaction: self, signer }),
Some(signer) => Ok(RecoveredTx::new_unchecked(self, signer)),
}
}

Expand All @@ -1639,12 +1640,12 @@ pub trait SignedTransactionIntoRecoveredExt: SignedTransaction {
/// Returns `None` if the transaction's signature is invalid.
fn into_ecrecovered_unchecked(self) -> Option<RecoveredTx<Self>> {
let signer = self.recover_signer_unchecked()?;
Some(RecoveredTx::from_signed_transaction(self, signer))
Some(RecoveredTx::new_unchecked(self, signer))
}

/// Returns the [`RecoveredTx`] transaction with the given sender.
fn with_signer(self, signer: Address) -> RecoveredTx<Self> {
RecoveredTx::from_signed_transaction(self, signer)
RecoveredTx::new_unchecked(self, signer)
}
}

Expand Down
17 changes: 8 additions & 9 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub type PooledTransactionsElementEcRecovered<T = PooledTransaction> = Recovered
impl PooledTransactionsElementEcRecovered {
/// Transform back to [`RecoveredTx`]
pub fn into_ecrecovered_transaction(self) -> RecoveredTx<TransactionSigned> {
let (tx, signer) = self.to_components();
RecoveredTx::from_signed_transaction(tx.into(), signer)
let (tx, signer) = self.into_parts();
RecoveredTx::new_unchecked(tx.into(), signer)
}

/// Converts from an EIP-4844 [`RecoveredTx`] to a
Expand All @@ -24,11 +24,11 @@ impl PooledTransactionsElementEcRecovered {
tx: RecoveredTx<TransactionSigned>,
sidecar: BlobTransactionSidecar,
) -> Result<Self, RecoveredTx<TransactionSigned>> {
let RecoveredTx { signer, signed_transaction } = tx;
let (signed_transaction, signer) = tx.into_parts();
let transaction = signed_transaction
.try_into_pooled_eip4844(sidecar)
.map_err(|tx| RecoveredTx { signer, signed_transaction: tx })?;
Ok(Self::from_signed_transaction(transaction, signer))
.map_err(|tx| RecoveredTx::new_unchecked(tx, signer))?;
Ok(Self::new_unchecked(transaction, signer))
}
}

Expand All @@ -37,10 +37,9 @@ impl TryFrom<RecoveredTx<TransactionSigned>> for PooledTransactionsElementEcReco
type Error = TransactionConversionError;

fn try_from(tx: RecoveredTx<TransactionSigned>) -> Result<Self, Self::Error> {
match PooledTransaction::try_from(tx.signed_transaction) {
Ok(pooled_transaction) => {
Ok(Self::from_signed_transaction(pooled_transaction, tx.signer))
}
let (signed_transaction, signer) = tx.into_parts();
match PooledTransaction::try_from(signed_transaction) {
Ok(pooled_transaction) => Ok(Self::new_unchecked(pooled_transaction, signer)),
Err(_) => Err(TransactionConversionError::UnsupportedForP2P),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub trait Call:
let env = EnvWithHandlerCfg::new_with_cfg_env(
cfg_env_with_handler_cfg,
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)?;
Expand Down
Loading
Loading