Skip to content

Commit

Permalink
chore: unify more tx signed fns (paradigmxyz#12883)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 26, 2024
1 parent 6bba5e6 commit ebf837e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
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 @@ -2186,7 +2186,7 @@ mod tests {
.await;

assert!(!pool.is_empty());
assert!(pool.get(signed_tx.hash_ref()).is_some());
assert!(pool.get(signed_tx.tx_hash()).is_some());
handle.terminate().await;
}

Expand Down
16 changes: 3 additions & 13 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ impl PartialEq for TransactionSigned {
fn eq(&self, other: &Self) -> bool {
self.signature == other.signature &&
self.transaction == other.transaction &&
self.hash_ref() == other.hash_ref()
self.tx_hash() == other.tx_hash()
}
}

Expand All @@ -1054,24 +1054,14 @@ impl TransactionSigned {
Self { hash: Default::default(), signature, transaction }
}

/// Transaction signature.
pub const fn signature(&self) -> &Signature {
&self.signature
}

/// Transaction
pub const fn transaction(&self) -> &Transaction {
&self.transaction
}

/// Transaction hash. Used to identify transaction.
pub fn hash(&self) -> TxHash {
*self.hash_ref()
}

/// Reference to transaction hash. Used to identify transaction.
pub fn hash_ref(&self) -> &TxHash {
self.hash.get_or_init(|| self.recalculate_hash())
*self.tx_hash()
}

/// Recovers a list of signers from a transaction list iterator.
Expand Down Expand Up @@ -1237,7 +1227,7 @@ impl SignedTransaction for TransactionSigned {
type Type = TxType;

fn tx_hash(&self) -> &TxHash {
self.hash_ref()
self.hash.get_or_init(|| self.recalculate_hash())
}

fn signature(&self) -> &Signature {
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mod tests {
};
use alloy_eips::eip2718::Decodable2718;
use alloy_primitives::{hex, Address, PrimitiveSignature as Signature, B256, U256};
use reth_primitives_traits::SignedTransaction;
use std::str::FromStr;

#[test]
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/maintain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use reth_primitives::{
PooledTransactionsElementEcRecovered, SealedHeader, TransactionSigned,
TransactionSignedEcRecovered,
};
use reth_primitives_traits::SignedTransaction;
use reth_storage_api::{errors::provider::ProviderError, BlockReaderIdExt, StateProviderFactory};
use reth_tasks::TaskSpawner;
use std::{
Expand Down Expand Up @@ -317,7 +318,7 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
// find all transactions that were mined in the old chain but not in the new chain
let pruned_old_transactions = old_blocks
.transactions_ecrecovered()
.filter(|tx| !new_mined_transactions.contains(tx.hash_ref()))
.filter(|tx| !new_mined_transactions.contains(tx.tx_hash()))
.filter_map(|tx| {
if tx.is_eip4844() {
// reorged blobs no longer include the blob, which is necessary for
Expand Down
3 changes: 2 additions & 1 deletion crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use reth_primitives::{
PooledTransactionsElementEcRecovered, SealedBlock, Transaction, TransactionSigned,
TransactionSignedEcRecovered,
};
use reth_primitives_traits::SignedTransaction;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -1244,7 +1245,7 @@ impl PoolTransaction for EthPooledTransaction {

/// Returns hash of the transaction.
fn hash(&self) -> &TxHash {
self.transaction.hash_ref()
self.transaction.tx_hash()
}

/// Returns the Sender of the transaction.
Expand Down

0 comments on commit ebf837e

Please sign in to comment.