diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index adb2c83b1..aa89b4112 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -201,7 +201,7 @@ impl> Command { let encoded_length = pooled.encode_2718_len(); // insert the blob into the store - blob_store.insert(transaction.hash, sidecar)?; + blob_store.insert(transaction.hash(), sidecar)?; encoded_length } diff --git a/crates/chain-state/src/notifications.rs b/crates/chain-state/src/notifications.rs index 865f2bd65..03d740d3d 100644 --- a/crates/chain-state/src/notifications.rs +++ b/crates/chain-state/src/notifications.rs @@ -196,7 +196,7 @@ impl Stream for ForkChoiceStream { #[cfg(test)] mod tests { use super::*; - use alloy_primitives::B256; + use alloy_primitives::{b256, B256}; use reth_execution_types::ExecutionOutcome; use reth_primitives::{Receipt, Receipts, TransactionSigned, TxType}; @@ -332,7 +332,11 @@ mod tests { block_receipts[0].0, BlockReceipts { block: block1.num_hash(), - tx_receipts: vec![(B256::default(), receipt1)] + tx_receipts: vec![( + // Transaction hash of a Transaction::default() + b256!("20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"), + receipt1 + )] } ); @@ -403,7 +407,11 @@ mod tests { block_receipts[0].0, BlockReceipts { block: old_block1.num_hash(), - tx_receipts: vec![(B256::default(), old_receipt)] + tx_receipts: vec![( + // Transaction hash of a Transaction::default() + b256!("20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"), + old_receipt + )] } ); // Confirm this is from the reverted segment. @@ -415,7 +423,11 @@ mod tests { block_receipts[1].0, BlockReceipts { block: new_block1.num_hash(), - tx_receipts: vec![(B256::default(), new_receipt)] + tx_receipts: vec![( + // Transaction hash of a Transaction::default() + b256!("20b5378c6fe992c118b557d2f8e8bbe0b7567f6fe5483a8f0f1c51e93a9d91ab"), + new_receipt + )] } ); // Confirm this is from the committed segment. diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index ec69bbd00..fd80fa9e1 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -339,7 +339,7 @@ where // Treat error as fatal Err(error) => { return Err(RethError::Execution(BlockExecutionError::Validation( - BlockValidationError::EVM { hash: tx.hash, error: Box::new(error) }, + BlockValidationError::EVM { hash: tx.hash(), error: Box::new(error) }, ))) } }; diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 80f6786c4..ac6427caf 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -399,7 +399,7 @@ where // grab the blob sidecars from the executed txs blob_sidecars = pool .get_all_blobs_exact( - executed_txs.iter().filter(|tx| tx.is_eip4844()).map(|tx| tx.hash).collect(), + executed_txs.iter().filter(|tx| tx.is_eip4844()).map(|tx| tx.hash()).collect(), ) .map_err(PayloadBuilderError::other)?; diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 2c672884d..200a37423 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -441,7 +441,7 @@ impl ChainBlocks<'_> { /// Returns an iterator over all transaction hashes in the block #[inline] pub fn transaction_hashes(&self) -> impl Iterator + '_ { - self.blocks.values().flat_map(|block| block.transactions().map(|tx| tx.hash)) + self.blocks.values().flat_map(|block| block.transactions().map(|tx| tx.hash())) } } diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 20525325e..1c93ae549 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -2178,7 +2178,7 @@ mod tests { .await; assert!(!pool.is_empty()); - assert!(pool.get(&signed_tx.hash).is_some()); + assert!(pool.get(signed_tx.hash_ref()).is_some()); handle.terminate().await; } diff --git a/crates/net/network/tests/it/txgossip.rs b/crates/net/network/tests/it/txgossip.rs index 2e2ee4a03..98624c4c6 100644 --- a/crates/net/network/tests/it/txgossip.rs +++ b/crates/net/network/tests/it/txgossip.rs @@ -95,7 +95,7 @@ async fn test_4844_tx_gossip_penalization() { let peer0_reputation_after = peer1.peer_handle().peer_by_id(*peer0.peer_id()).await.unwrap().reputation(); assert_ne!(peer0_reputation_before, peer0_reputation_after); - assert_eq!(received, txs[1].transaction().hash); + assert_eq!(received, txs[1].transaction().hash()); // this will return an [`Empty`] error because blob txs are disallowed to be broadcasted assert!(peer1_tx_listener.try_recv().is_err()); diff --git a/crates/optimism/rpc/src/eth/block.rs b/crates/optimism/rpc/src/eth/block.rs index 6678fbe5d..22d26e824 100644 --- a/crates/optimism/rpc/src/eth/block.rs +++ b/crates/optimism/rpc/src/eth/block.rs @@ -48,7 +48,7 @@ where .enumerate() .map(|(idx, (ref tx, receipt))| -> Result<_, _> { let meta = TransactionMeta { - tx_hash: tx.hash, + tx_hash: tx.hash(), index: idx as u64, block_hash, block_number, diff --git a/crates/optimism/rpc/src/eth/transaction.rs b/crates/optimism/rpc/src/eth/transaction.rs index 11e338172..dad151c41 100644 --- a/crates/optimism/rpc/src/eth/transaction.rs +++ b/crates/optimism/rpc/src/eth/transaction.rs @@ -84,7 +84,8 @@ where tx_info: TransactionInfo, ) -> Result { let from = tx.signer(); - let TransactionSigned { transaction, signature, hash } = tx.into_signed(); + let hash = tx.hash(); + let TransactionSigned { transaction, signature, .. } = tx.into_signed(); let mut deposit_receipt_version = None; let mut deposit_nonce = None; diff --git a/crates/primitives/src/alloy_compat.rs b/crates/primitives/src/alloy_compat.rs index 462b27f9c..a72c83996 100644 --- a/crates/primitives/src/alloy_compat.rs +++ b/crates/primitives/src/alloy_compat.rs @@ -156,7 +156,7 @@ impl TryFrom for TransactionSigned { _ => return Err(ConversionError::Custom("unknown transaction type".to_string())), }; - Ok(Self { transaction, signature, hash }) + Ok(Self { transaction, signature, hash: hash.into() }) } } diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index ea436a92c..5900abb42 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -14,11 +14,14 @@ use alloy_primitives::{ keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256, }; use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header}; -use core::mem; +use core::{ + hash::{Hash, Hasher}, + mem, +}; use derive_more::{AsRef, Deref}; use once_cell as _; #[cfg(not(feature = "std"))] -use once_cell::sync::Lazy as LazyLock; +use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock}; #[cfg(feature = "optimism")] use op_alloy_consensus::DepositTransaction; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; @@ -26,7 +29,7 @@ use reth_primitives_traits::InMemorySize; use serde::{Deserialize, Serialize}; use signature::decode_with_eip155_chain_id; #[cfg(feature = "std")] -use std::sync::LazyLock; +use std::sync::{LazyLock, OnceLock}; pub use error::{ InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError, @@ -1078,10 +1081,11 @@ impl From for TransactionSignedNoHash { /// Signed transaction. #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(rlp))] -#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Serialize, Deserialize)] +#[derive(Debug, Clone, Eq, AsRef, Deref, Serialize, Deserialize)] pub struct TransactionSigned { /// Transaction hash - pub hash: TxHash, + #[serde(skip)] + pub hash: OnceLock, /// The transaction signature values pub signature: Signature, /// Raw transaction info @@ -1106,6 +1110,21 @@ impl AsRef for TransactionSigned { } } +impl Hash for TransactionSigned { + fn hash(&self, state: &mut H) { + self.signature.hash(state); + self.transaction.hash(state); + } +} + +impl PartialEq for TransactionSigned { + fn eq(&self, other: &Self) -> bool { + self.signature == other.signature && + self.transaction == other.transaction && + self.hash_ref() == other.hash_ref() + } +} + // === impl TransactionSigned === impl TransactionSigned { @@ -1120,13 +1139,13 @@ impl TransactionSigned { } /// Transaction hash. Used to identify transaction. - pub const fn hash(&self) -> TxHash { - self.hash + pub fn hash(&self) -> TxHash { + *self.hash_ref() } /// Reference to transaction hash. Used to identify transaction. - pub const fn hash_ref(&self) -> &TxHash { - &self.hash + pub fn hash_ref(&self) -> &TxHash { + self.hash.get_or_init(|| self.recalculate_hash()) } /// Recover signer from signature and hash. @@ -1259,9 +1278,7 @@ impl TransactionSigned { /// /// This will also calculate the transaction hash using its encoding. pub fn from_transaction_and_signature(transaction: Transaction, signature: Signature) -> Self { - let mut initial_tx = Self { transaction, hash: Default::default(), signature }; - initial_tx.hash = initial_tx.recalculate_hash(); - initial_tx + Self { transaction, signature, hash: Default::default() } } /// Decodes legacy transaction from the data buffer into a tuple. @@ -1321,7 +1338,8 @@ impl TransactionSigned { // so decoding methods do not need to manually advance the buffer pub fn decode_rlp_legacy_transaction(data: &mut &[u8]) -> alloy_rlp::Result { let (transaction, hash, signature) = Self::decode_rlp_legacy_transaction_tuple(data)?; - let signed = Self { transaction: Transaction::Legacy(transaction), hash, signature }; + let signed = + Self { transaction: Transaction::Legacy(transaction), hash: hash.into(), signature }; Ok(signed) } } @@ -1330,7 +1348,7 @@ impl SignedTransaction for TransactionSigned { type Transaction = Transaction; fn tx_hash(&self) -> &TxHash { - &self.hash + self.hash_ref() } fn transaction(&self) -> &Self::Transaction { @@ -1608,19 +1626,19 @@ impl Decodable2718 for TransactionSigned { TxType::Legacy => Err(Eip2718Error::UnexpectedType(0)), TxType::Eip2930 => { let (tx, signature, hash) = TxEip2930::rlp_decode_signed(buf)?.into_parts(); - Ok(Self { transaction: Transaction::Eip2930(tx), signature, hash }) + Ok(Self { transaction: Transaction::Eip2930(tx), signature, hash: hash.into() }) } TxType::Eip1559 => { let (tx, signature, hash) = TxEip1559::rlp_decode_signed(buf)?.into_parts(); - Ok(Self { transaction: Transaction::Eip1559(tx), signature, hash }) + Ok(Self { transaction: Transaction::Eip1559(tx), signature, hash: hash.into() }) } TxType::Eip7702 => { let (tx, signature, hash) = TxEip7702::rlp_decode_signed(buf)?.into_parts(); - Ok(Self { transaction: Transaction::Eip7702(tx), signature, hash }) + Ok(Self { transaction: Transaction::Eip7702(tx), signature, hash: hash.into() }) } TxType::Eip4844 => { let (tx, signature, hash) = TxEip4844::rlp_decode_signed(buf)?.into_parts(); - Ok(Self { transaction: Transaction::Eip4844(tx), signature, hash }) + Ok(Self { transaction: Transaction::Eip4844(tx), signature, hash: hash.into() }) } #[cfg(feature = "optimism")] TxType::Deposit => Ok(Self::from_transaction_and_signature( @@ -1661,7 +1679,6 @@ impl<'a> arbitrary::Arbitrary<'a> for TransactionSigned { #[cfg(feature = "optimism")] let signature = if transaction.is_deposit() { TxDeposit::signature() } else { signature }; - Ok(Self::from_transaction_and_signature(transaction, signature)) } } @@ -1900,7 +1917,7 @@ pub mod serde_bincode_compat { impl<'a> From<&'a super::TransactionSigned> for TransactionSigned<'a> { fn from(value: &'a super::TransactionSigned) -> Self { Self { - hash: value.hash, + hash: value.hash(), signature: value.signature, transaction: Transaction::from(&value.transaction), } @@ -1910,7 +1927,7 @@ pub mod serde_bincode_compat { impl<'a> From> for super::TransactionSigned { fn from(value: TransactionSigned<'a>) -> Self { Self { - hash: value.hash, + hash: value.hash.into(), signature: value.signature, transaction: value.transaction.into(), } @@ -2203,7 +2220,7 @@ mod tests { ) { let expected = TransactionSigned::from_transaction_and_signature(transaction, signature); if let Some(hash) = hash { - assert_eq!(hash, expected.hash); + assert_eq!(hash, expected.hash()); } assert_eq!(bytes.len(), expected.length()); diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index 86cd40a8f..05ad4afa8 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -69,17 +69,18 @@ impl PooledTransactionsElement { /// [`PooledTransactionsElement`]. Since [`BlobTransaction`] is disallowed to be broadcasted on /// p2p, return an err if `tx` is [`Transaction::Eip4844`]. pub fn try_from_broadcast(tx: TransactionSigned) -> Result { + let hash = tx.hash(); match tx { - TransactionSigned { transaction: Transaction::Legacy(tx), signature, hash } => { + TransactionSigned { transaction: Transaction::Legacy(tx), signature, .. } => { Ok(Self::Legacy { transaction: tx, signature, hash }) } - TransactionSigned { transaction: Transaction::Eip2930(tx), signature, hash } => { + TransactionSigned { transaction: Transaction::Eip2930(tx), signature, .. } => { Ok(Self::Eip2930 { transaction: tx, signature, hash }) } - TransactionSigned { transaction: Transaction::Eip1559(tx), signature, hash } => { + TransactionSigned { transaction: Transaction::Eip1559(tx), signature, .. } => { Ok(Self::Eip1559 { transaction: tx, signature, hash }) } - TransactionSigned { transaction: Transaction::Eip7702(tx), signature, hash } => { + TransactionSigned { transaction: Transaction::Eip7702(tx), signature, .. } => { Ok(Self::Eip7702 { transaction: tx, signature, hash }) } // Not supported because missing blob sidecar @@ -99,9 +100,10 @@ impl PooledTransactionsElement { tx: TransactionSigned, sidecar: BlobTransactionSidecar, ) -> Result { + let hash = tx.hash(); Ok(match tx { // If the transaction is an EIP-4844 transaction... - TransactionSigned { transaction: Transaction::Eip4844(tx), signature, hash } => { + TransactionSigned { transaction: Transaction::Eip4844(tx), signature, .. } => { // Construct a `PooledTransactionsElement::BlobTransaction` with provided sidecar. Self::BlobTransaction(BlobTransaction { signature, @@ -187,23 +189,25 @@ impl PooledTransactionsElement { /// Returns the inner [`TransactionSigned`]. pub fn into_transaction(self) -> TransactionSigned { match self { - Self::Legacy { transaction, signature, hash } => { - TransactionSigned { transaction: Transaction::Legacy(transaction), signature, hash } - } + Self::Legacy { transaction, signature, hash } => TransactionSigned { + transaction: Transaction::Legacy(transaction), + signature, + hash: hash.into(), + }, Self::Eip2930 { transaction, signature, hash } => TransactionSigned { transaction: Transaction::Eip2930(transaction), signature, - hash, + hash: hash.into(), }, Self::Eip1559 { transaction, signature, hash } => TransactionSigned { transaction: Transaction::Eip1559(transaction), signature, - hash, + hash: hash.into(), }, Self::Eip7702 { transaction, signature, hash } => TransactionSigned { transaction: Transaction::Eip7702(transaction), signature, - hash, + hash: hash.into(), }, Self::BlobTransaction(blob_tx) => blob_tx.into_parts().0, } @@ -460,7 +464,7 @@ impl Decodable2718 for PooledTransactionsElement { } tx_type => { let typed_tx = TransactionSigned::typed_decode(tx_type, buf)?; - + let hash = typed_tx.hash(); match typed_tx.transaction { Transaction::Legacy(_) => Err(RlpError::Custom( "legacy transactions should not be a result of typed decoding", @@ -473,17 +477,17 @@ impl Decodable2718 for PooledTransactionsElement { Transaction::Eip2930(tx) => Ok(Self::Eip2930 { transaction: tx, signature: typed_tx.signature, - hash: typed_tx.hash, + hash }), Transaction::Eip1559(tx) => Ok(Self::Eip1559 { transaction: tx, signature: typed_tx.signature, - hash: typed_tx.hash, + hash }), Transaction::Eip7702(tx) => Ok(Self::Eip7702 { transaction: tx, signature: typed_tx.signature, - hash: typed_tx.hash, + hash }), #[cfg(feature = "optimism")] Transaction::Deposit(_) => Err(RlpError::Custom("Optimism deposit transaction cannot be decoded to PooledTransactionsElement").into()) diff --git a/crates/primitives/src/transaction/sidecar.rs b/crates/primitives/src/transaction/sidecar.rs index 48a02f4e7..ec8c9b7f0 100644 --- a/crates/primitives/src/transaction/sidecar.rs +++ b/crates/primitives/src/transaction/sidecar.rs @@ -31,7 +31,8 @@ impl BlobTransaction { tx: TransactionSigned, sidecar: BlobTransactionSidecar, ) -> Result { - let TransactionSigned { transaction, signature, hash } = tx; + let hash = tx.hash(); + let TransactionSigned { transaction, signature, .. } = tx; match transaction { Transaction::Eip4844(transaction) => Ok(Self { hash, @@ -39,7 +40,7 @@ impl BlobTransaction { signature, }), transaction => { - let tx = TransactionSigned { transaction, signature, hash }; + let tx = TransactionSigned { transaction, signature, hash: hash.into() }; Err((tx, sidecar)) } } @@ -61,7 +62,7 @@ impl BlobTransaction { pub fn into_parts(self) -> (TransactionSigned, BlobTransactionSidecar) { let transaction = TransactionSigned { transaction: Transaction::Eip4844(self.transaction.tx), - hash: self.hash, + hash: self.hash.into(), signature: self.signature, }; diff --git a/crates/primitives/src/transaction/variant.rs b/crates/primitives/src/transaction/variant.rs index 888c83946..dd47df9a8 100644 --- a/crates/primitives/src/transaction/variant.rs +++ b/crates/primitives/src/transaction/variant.rs @@ -36,8 +36,8 @@ impl TransactionSignedVariant { pub fn hash(&self) -> B256 { match self { Self::SignedNoHash(tx) => tx.hash(), - Self::Signed(tx) => tx.hash, - Self::SignedEcRecovered(tx) => tx.hash, + Self::Signed(tx) => tx.hash(), + Self::SignedEcRecovered(tx) => tx.hash(), } } diff --git a/crates/prune/prune/src/segments/user/transaction_lookup.rs b/crates/prune/prune/src/segments/user/transaction_lookup.rs index 2df8cccf3..ada401930 100644 --- a/crates/prune/prune/src/segments/user/transaction_lookup.rs +++ b/crates/prune/prune/src/segments/user/transaction_lookup.rs @@ -142,7 +142,7 @@ mod tests { for block in &blocks { tx_hash_numbers.reserve_exact(block.body.transactions.len()); for transaction in &block.body.transactions { - tx_hash_numbers.push((transaction.hash, tx_hash_numbers.len() as u64)); + tx_hash_numbers.push((transaction.hash(), tx_hash_numbers.len() as u64)); } } let tx_hash_numbers_len = tx_hash_numbers.len(); diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index 1eade554f..d7e74c37b 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -628,7 +628,7 @@ pub trait Call: LoadState> + SpawnBlocking { cfg.clone(), block_env.clone(), block_txs, - tx.hash, + tx.hash(), )?; let env = EnvWithHandlerCfg::new_with_cfg_env( diff --git a/crates/rpc/rpc-eth-api/src/helpers/trace.rs b/crates/rpc/rpc-eth-api/src/helpers/trace.rs index 104042d17..a1e6084da 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/trace.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/trace.rs @@ -204,7 +204,7 @@ pub trait Trace: LoadState> { cfg.clone(), block_env.clone(), block_txs, - tx.hash, + tx.hash(), )?; let env = EnvWithHandlerCfg::new_with_cfg_env( diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 78040b48c..dd6bf9bbc 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -107,7 +107,7 @@ where let mut transactions = block.transactions_with_sender().enumerate().peekable(); let mut inspector = None; while let Some((index, (signer, tx))) = transactions.next() { - let tx_hash = tx.hash; + let tx_hash = tx.hash(); let env = EnvWithHandlerCfg { env: Env::boxed( @@ -255,7 +255,7 @@ where cfg.clone(), block_env.clone(), block_txs, - tx.hash, + tx.hash(), )?; let env = EnvWithHandlerCfg { @@ -274,7 +274,7 @@ where Some(TransactionContext { block_hash: Some(block_hash), tx_index: Some(index), - tx_hash: Some(tx.hash), + tx_hash: Some(tx.hash()), }), &mut None, ) diff --git a/crates/rpc/rpc/src/eth/helpers/block.rs b/crates/rpc/rpc/src/eth/helpers/block.rs index fd3b9db9d..bc1e93447 100644 --- a/crates/rpc/rpc/src/eth/helpers/block.rs +++ b/crates/rpc/rpc/src/eth/helpers/block.rs @@ -42,7 +42,7 @@ where .enumerate() .map(|(idx, (tx, receipt))| { let meta = TransactionMeta { - tx_hash: tx.hash, + tx_hash: tx.hash(), index: idx as u64, block_hash, block_number, diff --git a/crates/rpc/rpc/src/eth/helpers/types.rs b/crates/rpc/rpc/src/eth/helpers/types.rs index 8f135a910..157213b54 100644 --- a/crates/rpc/rpc/src/eth/helpers/types.rs +++ b/crates/rpc/rpc/src/eth/helpers/types.rs @@ -41,7 +41,8 @@ where tx_info: TransactionInfo, ) -> Result { let from = tx.signer(); - let TransactionSigned { transaction, signature, hash } = tx.into_signed(); + let hash = tx.hash(); + let TransactionSigned { transaction, signature, .. } = tx.into_signed(); let inner: TxEnvelope = match transaction { reth_primitives::Transaction::Legacy(tx) => { diff --git a/crates/stages/stages/src/stages/tx_lookup.rs b/crates/stages/stages/src/stages/tx_lookup.rs index 3fdcbd0da..5208cc936 100644 --- a/crates/stages/stages/src/stages/tx_lookup.rs +++ b/crates/stages/stages/src/stages/tx_lookup.rs @@ -383,7 +383,7 @@ mod tests { for block in &blocks[..=max_processed_block] { for transaction in &block.body.transactions { if block.number > max_pruned_block { - tx_hash_numbers.push((transaction.hash, tx_hash_number)); + tx_hash_numbers.push((transaction.hash(), tx_hash_number)); } tx_hash_number += 1; } diff --git a/crates/storage/provider/src/providers/database/mod.rs b/crates/storage/provider/src/providers/database/mod.rs index 354eb10c1..7d94fb98a 100644 --- a/crates/storage/provider/src/providers/database/mod.rs +++ b/crates/storage/provider/src/providers/database/mod.rs @@ -725,7 +725,10 @@ mod tests { provider.transaction_sender(0), Ok(Some(sender)) if sender == block.body.transactions[0].recover_signer().unwrap() ); - assert_matches!(provider.transaction_id(block.body.transactions[0].hash), Ok(Some(0))); + assert_matches!( + provider.transaction_id(block.body.transactions[0].hash()), + Ok(Some(0)) + ); } { @@ -743,7 +746,7 @@ mod tests { Ok(_) ); assert_matches!(provider.transaction_sender(0), Ok(None)); - assert_matches!(provider.transaction_id(block.body.transactions[0].hash), Ok(None)); + assert_matches!(provider.transaction_id(block.body.transactions[0].hash()), Ok(None)); } } diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 8c390b06c..d35e0a971 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -551,7 +551,7 @@ impl DatabaseProvider { .map(|tx| match transaction_kind { TransactionVariant::NoHash => TransactionSigned { // Caller explicitly asked for no hash, so we don't calculate it - hash: B256::ZERO, + hash: Default::default(), signature: tx.signature, transaction: tx.transaction, }, @@ -1500,7 +1500,7 @@ impl> Transaction fn transaction_by_hash(&self, hash: TxHash) -> ProviderResult> { if let Some(id) = self.transaction_id(hash)? { Ok(self.transaction_by_id_no_hash(id)?.map(|tx| TransactionSigned { - hash, + hash: hash.into(), signature: tx.signature, transaction: tx.transaction, })) @@ -1518,7 +1518,7 @@ impl> Transaction if let Some(transaction_id) = self.transaction_id(tx_hash)? { if let Some(tx) = self.transaction_by_id_no_hash(transaction_id)? { let transaction = TransactionSigned { - hash: tx_hash, + hash: tx_hash.into(), signature: tx.signature, transaction: tx.transaction, }; diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index 3259eee2b..2b8dc0f85 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -89,7 +89,7 @@ pub(crate) static TEST_BLOCK: LazyLock = LazyLock::new(|| SealedBlo ), body: BlockBody { transactions: vec![TransactionSigned { - hash: hex!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397").into(), + hash: b256!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397").into(), signature: Signature::new( U256::from_str( "51983300959770368863831494747186777928121405155922056726144551509338672451120", diff --git a/crates/transaction-pool/src/blobstore/tracker.rs b/crates/transaction-pool/src/blobstore/tracker.rs index 63d6e30ee..d58abe9b4 100644 --- a/crates/transaction-pool/src/blobstore/tracker.rs +++ b/crates/transaction-pool/src/blobstore/tracker.rs @@ -43,7 +43,7 @@ impl BlobStoreCanonTracker { .body .transactions() .filter(|tx| tx.transaction.is_eip4844()) - .map(|tx| tx.hash); + .map(|tx| tx.hash()); (*num, iter) }); self.add_blocks(blob_txs); @@ -128,18 +128,18 @@ mod tests { body: BlockBody { transactions: vec![ TransactionSigned { - hash: tx1_hash, + hash: tx1_hash.into(), transaction: Transaction::Eip4844(Default::default()), ..Default::default() }, TransactionSigned { - hash: tx2_hash, + hash: tx2_hash.into(), transaction: Transaction::Eip4844(Default::default()), ..Default::default() }, // Another transaction that is not EIP-4844 TransactionSigned { - hash: B256::random(), + hash: B256::random().into(), transaction: Transaction::Eip7702(Default::default()), ..Default::default() }, @@ -161,12 +161,12 @@ mod tests { body: BlockBody { transactions: vec![ TransactionSigned { - hash: tx3_hash, + hash: tx3_hash.into(), transaction: Transaction::Eip1559(Default::default()), ..Default::default() }, TransactionSigned { - hash: tx2_hash, + hash: tx2_hash.into(), transaction: Transaction::Eip2930(Default::default()), ..Default::default() }, diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 271c63a38..47e70e914 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -317,7 +317,7 @@ pub async fn maintain_transaction_pool( // 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)) + .filter(|tx| !new_mined_transactions.contains(tx.hash_ref())) .filter_map(|tx| { if tx.is_eip4844() { // reorged blobs no longer include the blob, which is necessary for @@ -325,7 +325,7 @@ pub async fn maintain_transaction_pool( // been validated previously, we still need the blob in order to // accurately set the transaction's // encoded-length which is propagated over the network. - pool.get_blob(tx.hash) + pool.get_blob(TransactionSigned::hash(&tx)) .ok() .flatten() .map(Arc::unwrap_or_clone) diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index 344781b1f..009543642 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -911,7 +911,7 @@ impl From for MockTransaction { impl From for TransactionSignedEcRecovered { fn from(tx: MockTransaction) -> Self { let signed_tx = TransactionSigned { - hash: *tx.hash(), + hash: (*tx.hash()).into(), signature: Signature::test_signature(), transaction: tx.clone().into(), }; diff --git a/docs/crates/network.md b/docs/crates/network.md index a6ac24305..be2c7cb3b 100644 --- a/docs/crates/network.md +++ b/docs/crates/network.md @@ -991,9 +991,9 @@ fn import_transactions(&mut self, peer_id: PeerId, transactions: Vec { // transaction was already inserted entry.get_mut().push(peer_id); diff --git a/examples/db-access/src/main.rs b/examples/db-access/src/main.rs index 0f7d1a269..f3b7fdf58 100644 --- a/examples/db-access/src/main.rs +++ b/examples/db-access/src/main.rs @@ -92,16 +92,17 @@ fn txs_provider_example(provider: T) -> eyre::Result<() // Can query the tx by hash let tx_by_hash = - provider.transaction_by_hash(tx.hash)?.ok_or(eyre::eyre!("txhash not found"))?; + provider.transaction_by_hash(tx.hash())?.ok_or(eyre::eyre!("txhash not found"))?; assert_eq!(tx, tx_by_hash); // Can query the tx by hash with info about the block it was included in - let (tx, meta) = - provider.transaction_by_hash_with_meta(tx.hash)?.ok_or(eyre::eyre!("txhash not found"))?; - assert_eq!(tx.hash, meta.tx_hash); + let (tx, meta) = provider + .transaction_by_hash_with_meta(tx.hash())? + .ok_or(eyre::eyre!("txhash not found"))?; + assert_eq!(tx.hash(), meta.tx_hash); // Can reverse lookup the key too - let id = provider.transaction_id(tx.hash)?.ok_or(eyre::eyre!("txhash not found"))?; + let id = provider.transaction_id(tx.hash())?.ok_or(eyre::eyre!("txhash not found"))?; assert_eq!(id, txid); // Can find the block of a transaction given its key @@ -171,7 +172,7 @@ fn receipts_provider_example