From 518784205f2a9a9593240b6694d855bcadbc2a9e Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 14 Jun 2023 20:09:27 +0200 Subject: [PATCH] refactor: convert closure into function (#3144) --- crates/stages/src/stages/tx_lookup.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/stages/src/stages/tx_lookup.rs b/crates/stages/src/stages/tx_lookup.rs index 11757dc40d..6b92d51c42 100644 --- a/crates/stages/src/stages/tx_lookup.rs +++ b/crates/stages/src/stages/tx_lookup.rs @@ -79,16 +79,6 @@ impl Stage for TransactionLookupStage { let chunk: Vec<_> = chunk.collect(); transaction_count += chunk.len(); - // closure that will calculate the TxHash - let calculate_hash = - |entry: Result<(TxNumber, TransactionSignedNoHash), reth_db::DatabaseError>, - rlp_buf: &mut Vec| - -> Result<(H256, u64), Box> { - let (tx_id, tx) = entry.map_err(|e| Box::new(e.into()))?; - tx.transaction.encode_with_signature(&tx.signature, rlp_buf, false); - Ok((H256(keccak256(rlp_buf)), tx_id)) - }; - // Spawn the task onto the global rayon pool // This task will send the results through the channel after it has calculated the hash. rayon::spawn(move || { @@ -179,6 +169,17 @@ impl Stage for TransactionLookupStage { } } +/// Calculates the hash of the given transaction +#[inline] +fn calculate_hash( + entry: Result<(TxNumber, TransactionSignedNoHash), DatabaseError>, + rlp_buf: &mut Vec, +) -> Result<(H256, TxNumber), Box> { + let (tx_id, tx) = entry.map_err(|e| Box::new(e.into()))?; + tx.transaction.encode_with_signature(&tx.signature, rlp_buf, false); + Ok((H256(keccak256(rlp_buf)), tx_id)) +} + fn stage_checkpoint( provider: &DatabaseProviderRW<'_, &DB>, ) -> Result {