move mempool checks outside transaction check function

This commit is contained in:
Sergio Chouhy 2025-07-16 08:43:05 -03:00
parent 1ef7be0af6
commit b1724ec235
2 changed files with 11 additions and 9 deletions

View File

@ -247,7 +247,6 @@ impl SignedTransaction {
) -> SignedTransaction { ) -> SignedTransaction {
let hash = body.hash(); let hash = body.hash();
let signature: Signature = private_key.sign(&hash); let signature: Signature = private_key.sign(&hash);
// TODO: Implement actual signature over `hash`
let public_key = VerifyingKey::from(&private_key); let public_key = VerifyingKey::from(&private_key);
Self { Self {
body, body,

View File

@ -78,6 +78,7 @@ impl SequencerCore {
let tx = tx let tx = tx
.into_authenticated() .into_authenticated()
.map_err(|_| TransactionMalformationErrorKind::InvalidSignature)?; .map_err(|_| TransactionMalformationErrorKind::InvalidSignature)?;
let TransactionBody { let TransactionBody {
tx_kind, tx_kind,
ref execution_input, ref execution_input,
@ -87,13 +88,8 @@ impl SequencerCore {
.. ..
} = tx.body(); } = tx.body();
let mempool_size = self.mempool.len();
let tx_hash = *tx.hash(); 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(); let curr_sequencer_roots = self.get_tree_roots();
if tx_roots != curr_sequencer_roots { if tx_roots != curr_sequencer_roots {
@ -178,12 +174,19 @@ impl SequencerCore {
pub fn push_tx_into_mempool_pre_check( pub fn push_tx_into_mempool_pre_check(
&mut self, &mut self,
item: SignedTransaction, signed_tx: SignedTransaction,
tx_roots: [[u8; 32]; 2], tx_roots: [[u8; 32]; 2],
) -> Result<(), TransactionMalformationErrorKind> { ) -> 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(()) Ok(())
} }