From b49f38ca4b2d3274018085d5a71d37bc4c0e0ba2 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Thu, 10 Jul 2025 14:35:41 -0300 Subject: [PATCH] avoid computing hash multiple times in transaction_pre_check --- sequencer_core/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 9946504..f2890ed 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -82,11 +82,12 @@ impl SequencerCore { ref nullifier_created_hashes, .. } = tx; + let tx_hash = tx.hash(); let mempool_size = self.mempool.len(); if mempool_size >= self.sequencer_config.max_num_tx_in_block { - return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: tx.hash() }); + return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: tx_hash }); } let curr_sequencer_roots = self.get_tree_roots(); @@ -94,7 +95,7 @@ impl SequencerCore { if tx_roots != curr_sequencer_roots { return Err( TransactionMalformationErrorKind::ChainStateFurtherThanTransactionState { - tx: tx.hash(), + tx: tx_hash, }, ); } @@ -108,7 +109,7 @@ impl SequencerCore { //Public transactions can not make private operations. return Err( TransactionMalformationErrorKind::PublicTransactionChangedPrivateData { - tx: tx.hash(), + tx: tx_hash, }, ); } @@ -120,7 +121,7 @@ impl SequencerCore { //between public and private state. return Err( TransactionMalformationErrorKind::PrivateTransactionChangedPublicData { - tx: tx.hash(), + tx: tx_hash, }, ); } @@ -129,7 +130,7 @@ impl SequencerCore { }; //Tree checks - let tx_tree_check = self.store.pub_tx_store.get_tx(tx.hash()).is_some(); + let tx_tree_check = self.store.pub_tx_store.get_tx(tx_hash).is_some(); let nullifier_tree_check = nullifier_created_hashes .iter() .map(|nullifier_hash| {