From b1724ec235465e9f685b8efe7baae8b6f53ebd22 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Wed, 16 Jul 2025 08:43:05 -0300 Subject: [PATCH] move mempool checks outside transaction check function --- common/src/transaction.rs | 1 - sequencer_core/src/lib.rs | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/common/src/transaction.rs b/common/src/transaction.rs index ee832c7..d02ed41 100644 --- a/common/src/transaction.rs +++ b/common/src/transaction.rs @@ -247,7 +247,6 @@ impl SignedTransaction { ) -> SignedTransaction { let hash = body.hash(); let signature: Signature = private_key.sign(&hash); - // TODO: Implement actual signature over `hash` let public_key = VerifyingKey::from(&private_key); Self { body, diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index f812ea0..188394d 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -78,6 +78,7 @@ impl SequencerCore { let tx = tx .into_authenticated() .map_err(|_| TransactionMalformationErrorKind::InvalidSignature)?; + let TransactionBody { tx_kind, ref execution_input, @@ -87,13 +88,8 @@ impl SequencerCore { .. } = tx.body(); - let mempool_size = self.mempool.len(); let tx_hash = *tx.hash(); - if mempool_size >= self.sequencer_config.max_num_tx_in_block { - return Err(TransactionMalformationErrorKind::MempoolFullForRound { tx: tx_hash }); - } - let curr_sequencer_roots = self.get_tree_roots(); if tx_roots != curr_sequencer_roots { @@ -178,12 +174,19 @@ impl SequencerCore { pub fn push_tx_into_mempool_pre_check( &mut self, - item: SignedTransaction, + signed_tx: SignedTransaction, tx_roots: [[u8; 32]; 2], ) -> Result<(), TransactionMalformationErrorKind> { - let item = self.transaction_pre_check(item, tx_roots)?; + let mempool_size = self.mempool.len(); + if mempool_size >= self.sequencer_config.max_num_tx_in_block { + return Err(TransactionMalformationErrorKind::MempoolFullForRound { + tx: signed_tx.body.hash(), + }); + } - self.mempool.push_item(item.into()); + let authenticated_tx = self.transaction_pre_check(signed_tx, tx_roots)?; + + self.mempool.push_item(authenticated_tx.into()); Ok(()) }