mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: convert hash field to OnceLock<TxHash> on TransactionSigned (#12596)
Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
@ -201,7 +201,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
|
||||
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
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ impl<T: Clone + Sync + Send + 'static> Stream for ForkChoiceStream<T> {
|
||||
#[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.
|
||||
|
||||
@ -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) },
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
||||
@ -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)?;
|
||||
|
||||
|
||||
@ -441,7 +441,7 @@ impl ChainBlocks<'_> {
|
||||
/// Returns an iterator over all transaction hashes in the block
|
||||
#[inline]
|
||||
pub fn transaction_hashes(&self) -> impl Iterator<Item = TxHash> + '_ {
|
||||
self.blocks.values().flat_map(|block| block.transactions().map(|tx| tx.hash))
|
||||
self.blocks.values().flat_map(|block| block.transactions().map(|tx| tx.hash()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -84,7 +84,8 @@ where
|
||||
tx_info: TransactionInfo,
|
||||
) -> Result<Self::Transaction, Self::Error> {
|
||||
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;
|
||||
|
||||
|
||||
@ -156,7 +156,7 @@ impl TryFrom<AnyRpcTransaction> for TransactionSigned {
|
||||
_ => return Err(ConversionError::Custom("unknown transaction type".to_string())),
|
||||
};
|
||||
|
||||
Ok(Self { transaction, signature, hash })
|
||||
Ok(Self { transaction, signature, hash: hash.into() })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<TransactionSigned> 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<TxHash>,
|
||||
/// The transaction signature values
|
||||
pub signature: Signature,
|
||||
/// Raw transaction info
|
||||
@ -1106,6 +1110,21 @@ impl AsRef<Self> for TransactionSigned {
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for TransactionSigned {
|
||||
fn hash<H: Hasher>(&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<Self> {
|
||||
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<TransactionSigned<'a>> 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());
|
||||
|
||||
|
||||
@ -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<Self, TransactionSigned> {
|
||||
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<Self, TransactionSigned> {
|
||||
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())
|
||||
|
||||
@ -31,7 +31,8 @@ impl BlobTransaction {
|
||||
tx: TransactionSigned,
|
||||
sidecar: BlobTransactionSidecar,
|
||||
) -> Result<Self, (TransactionSigned, BlobTransactionSidecar)> {
|
||||
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,
|
||||
};
|
||||
|
||||
|
||||
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -628,7 +628,7 @@ pub trait Call: LoadState<Evm: ConfigureEvm<Header = Header>> + SpawnBlocking {
|
||||
cfg.clone(),
|
||||
block_env.clone(),
|
||||
block_txs,
|
||||
tx.hash,
|
||||
tx.hash(),
|
||||
)?;
|
||||
|
||||
let env = EnvWithHandlerCfg::new_with_cfg_env(
|
||||
|
||||
@ -204,7 +204,7 @@ pub trait Trace: LoadState<Evm: ConfigureEvm<Header = Header>> {
|
||||
cfg.clone(),
|
||||
block_env.clone(),
|
||||
block_txs,
|
||||
tx.hash,
|
||||
tx.hash(),
|
||||
)?;
|
||||
|
||||
let env = EnvWithHandlerCfg::new_with_cfg_env(
|
||||
|
||||
@ -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,
|
||||
)
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -41,7 +41,8 @@ where
|
||||
tx_info: TransactionInfo,
|
||||
) -> Result<Self::Transaction, Self::Error> {
|
||||
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) => {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -551,7 +551,7 @@ impl<TX: DbTx + 'static, N: NodeTypes> DatabaseProvider<TX, N> {
|
||||
.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<TX: DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks>> Transaction
|
||||
fn transaction_by_hash(&self, hash: TxHash) -> ProviderResult<Option<TransactionSigned>> {
|
||||
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<TX: DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks>> 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,
|
||||
};
|
||||
|
||||
@ -89,7 +89,7 @@ pub(crate) static TEST_BLOCK: LazyLock<SealedBlock> = LazyLock::new(|| SealedBlo
|
||||
),
|
||||
body: BlockBody {
|
||||
transactions: vec![TransactionSigned {
|
||||
hash: hex!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397").into(),
|
||||
hash: b256!("3541dd1d17e76adeb25dcf2b0a9b60a1669219502e58dcf26a2beafbfb550397").into(),
|
||||
signature: Signature::new(
|
||||
U256::from_str(
|
||||
"51983300959770368863831494747186777928121405155922056726144551509338672451120",
|
||||
|
||||
@ -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()
|
||||
},
|
||||
|
||||
@ -317,7 +317,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))
|
||||
.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<Client, P, St, Tasks>(
|
||||
// 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)
|
||||
|
||||
@ -911,7 +911,7 @@ impl From<PooledTransactionsElementEcRecovered> for MockTransaction {
|
||||
impl From<MockTransaction> 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(),
|
||||
};
|
||||
|
||||
@ -991,9 +991,9 @@ fn import_transactions(&mut self, peer_id: PeerId, transactions: Vec<Transaction
|
||||
};
|
||||
|
||||
// track that the peer knows this transaction
|
||||
peer.transactions.insert(tx.hash);
|
||||
peer.transactions.insert(tx.hash());
|
||||
|
||||
match self.transactions_by_peers.entry(tx.hash) {
|
||||
match self.transactions_by_peers.entry(tx.hash()) {
|
||||
Entry::Occupied(mut entry) => {
|
||||
// transaction was already inserted
|
||||
entry.get_mut().push(peer_id);
|
||||
|
||||
@ -92,16 +92,17 @@ fn txs_provider_example<T: TransactionsProvider>(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<T: ReceiptProvider + TransactionsProvider + HeaderP
|
||||
// Can query receipt by txhash too
|
||||
let tx = provider.transaction_by_id(txid)?.unwrap();
|
||||
let receipt_by_hash =
|
||||
provider.receipt_by_hash(tx.hash)?.ok_or(eyre::eyre!("tx receipt by hash not found"))?;
|
||||
provider.receipt_by_hash(tx.hash())?.ok_or(eyre::eyre!("tx receipt by hash not found"))?;
|
||||
assert_eq!(receipt, receipt_by_hash);
|
||||
|
||||
// Can query all the receipts in a block
|
||||
|
||||
Reference in New Issue
Block a user