From 65c7c1c4f9db388f7f1ad0f6084ceb845e67c646 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:49:33 +0100 Subject: [PATCH] chore: use `transaction_by_id_no_hash` to avoid hash computation (#3718) --- crates/stages/src/stages/sender_recovery.rs | 10 ++++++++-- .../provider/src/providers/database/provider.rs | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/stages/src/stages/sender_recovery.rs b/crates/stages/src/stages/sender_recovery.rs index 482ed1eb4..e6294b3a8 100644 --- a/crates/stages/src/stages/sender_recovery.rs +++ b/crates/stages/src/stages/sender_recovery.rs @@ -453,8 +453,14 @@ mod tests { while let Some((_, body)) = body_cursor.next()? { for tx_id in body.tx_num_range() { - let transaction: TransactionSigned = - provider.transaction_by_id(tx_id)?.expect("no transaction entry"); + let transaction: TransactionSigned = provider + .transaction_by_id_no_hash(tx_id)? + .map(|tx| TransactionSigned { + hash: Default::default(), // we don't require the hash + signature: tx.signature, + transaction: tx.transaction, + }) + .expect("no transaction entry"); let signer = transaction.recover_signer().expect("failed to recover signer"); assert_eq!(Some(signer), provider.transaction_sender(tx_id)?) diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 28a00f45e..2d494c40e 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -935,12 +935,16 @@ impl<'this, TX: DbTx<'this>> TransactionsProvider for DatabaseProvider<'this, TX } fn transaction_by_id_no_hash(&self, id: TxNumber) -> Result> { - Ok(self.tx.get::(id)?.map(Into::into)) + Ok(self.tx.get::(id)?) } fn transaction_by_hash(&self, hash: TxHash) -> Result> { if let Some(id) = self.transaction_id(hash)? { - Ok(self.transaction_by_id(id)?) + Ok(self.transaction_by_id_no_hash(id)?.map(|tx| TransactionSigned { + hash, + signature: tx.signature, + transaction: tx.transaction, + })) } else { Ok(None) } @@ -953,7 +957,12 @@ impl<'this, TX: DbTx<'this>> TransactionsProvider for DatabaseProvider<'this, TX ) -> Result> { let mut transaction_cursor = self.tx.cursor_read::()?; if let Some(transaction_id) = self.transaction_id(tx_hash)? { - if let Some(transaction) = self.transaction_by_id(transaction_id)? { + if let Some(tx) = self.transaction_by_id_no_hash(transaction_id)? { + let transaction = TransactionSigned { + hash: tx_hash, + signature: tx.signature, + transaction: tx.transaction, + }; if let Some(block_number) = transaction_cursor.seek(transaction_id).map(|b| b.map(|(_, bn)| bn))? {