@@ -2,6 +2,7 @@ use std::sync::Arc;
22
33use miden_protocol:: Word ;
44use miden_protocol:: block:: { BlockHeader , BlockNumber } ;
5+ use miden_protocol:: transaction:: TransactionHeader ;
56use pretty_assertions:: assert_eq;
67use serial_test:: serial;
78
@@ -114,6 +115,9 @@ fn failed_batch_transactions_are_requeued() {
114115 reference. select_batch ( ) . unwrap ( ) ;
115116 reference. add_transaction ( txs[ 1 ] . clone ( ) ) . unwrap ( ) ;
116117 reference. add_transaction ( txs[ 2 ] . clone ( ) ) . unwrap ( ) ;
118+ reference
119+ . transactions
120+ . increment_failure_count ( failed_batch. txs ( ) . iter ( ) . map ( |tx| tx. id ( ) ) ) ;
117121
118122 assert_eq ! ( uut, reference) ;
119123}
@@ -185,11 +189,9 @@ fn cannot_have_multiple_inflight_blocks() {
185189// BLOCK FAILED TESTS
186190// ================================================================================================
187191
188- /// A failed block should have all of its transactions reverted.
189192#[ test]
190- fn block_failure_reverts_its_transactions ( ) {
191- // We will revert everything so the reference should be the empty mempool.
192- let ( mut uut, reference) = Mempool :: for_tests ( ) ;
193+ fn block_failure_increments_tx_failures ( ) {
194+ let ( mut uut, mut reference) = Mempool :: for_tests ( ) ;
193195
194196 let reverted_txs = MockProvenTxBuilder :: sequential ( ) ;
195197
@@ -200,20 +202,51 @@ fn block_failure_reverts_its_transactions() {
200202 ] ) ) ) ;
201203
202204 // Block 1 will contain just the first batch.
203- let ( number, _batches ) = uut. select_block ( ) ;
205+ let ( number, block ) = uut. select_block ( ) ;
204206
205207 // Create another dependent batch.
206208 uut. add_transaction ( reverted_txs[ 1 ] . clone ( ) ) . unwrap ( ) ;
207209 uut. select_batch ( ) ;
208210 // Create another dependent transaction.
209211 uut. add_transaction ( reverted_txs[ 2 ] . clone ( ) ) . unwrap ( ) ;
210212
211- // Fail the block which should result in everything reverting.
212213 uut. rollback_block ( number) ;
213214
215+ // Reference should contain all transactions, no batches, with tx failure from just that block.
216+ reference. add_transaction ( reverted_txs[ 0 ] . clone ( ) ) . unwrap ( ) ;
217+ reference. add_transaction ( reverted_txs[ 1 ] . clone ( ) ) . unwrap ( ) ;
218+ reference. add_transaction ( reverted_txs[ 2 ] . clone ( ) ) . unwrap ( ) ;
219+
220+ reference. transactions . increment_failure_count (
221+ block
222+ . iter ( )
223+ . flat_map ( |batch| batch. transactions ( ) . as_slice ( ) . iter ( ) . map ( TransactionHeader :: id) ) ,
224+ ) ;
225+
214226 assert_eq ! ( uut, reference) ;
215227}
216228
229+ #[ test]
230+ fn transactions_exceeding_failure_limit_are_removed ( ) {
231+ let ( mut uut, _) = Mempool :: for_tests ( ) ;
232+
233+ let failing_tx = MockProvenTxBuilder :: with_account_index ( 0 ) . build ( ) ;
234+ let failing_tx = Arc :: new ( AuthenticatedTransaction :: from_inner ( failing_tx) ) ;
235+ let tx_id = failing_tx. id ( ) ;
236+
237+ uut. add_transaction ( failing_tx) . unwrap ( ) ;
238+
239+ for _ in 0 ..3 {
240+ let reverted = uut. transactions . increment_failure_count ( std:: iter:: once ( tx_id) ) ;
241+ assert ! ( reverted. is_empty( ) ) ;
242+ assert_eq ! ( uut. unbatched_transactions_count( ) , 1 ) ;
243+ }
244+
245+ let reverted = uut. transactions . increment_failure_count ( std:: iter:: once ( tx_id) ) ;
246+ assert ! ( reverted. contains( & tx_id) ) ;
247+ assert_eq ! ( uut. unbatched_transactions_count( ) , 0 ) ;
248+ }
249+
217250/// We've decided that transactions from a rolled back batch should be requeued.
218251///
219252/// This test checks this at a basic level by ensuring that rolling back a batch is the same as
@@ -244,6 +277,9 @@ fn transactions_from_reverted_batches_are_requeued() {
244277 reference. add_transaction ( tx_set_a[ 1 ] . clone ( ) ) . unwrap ( ) ;
245278 reference. add_transaction ( tx_set_b[ 2 ] . clone ( ) ) . unwrap ( ) ;
246279 reference. add_transaction ( tx_set_a[ 2 ] . clone ( ) ) . unwrap ( ) ;
280+ reference
281+ . transactions
282+ . increment_failure_count ( [ tx_set_a[ 1 ] . id ( ) , tx_set_b[ 1 ] . id ( ) ] . into_iter ( ) ) ;
247283
248284 assert_eq ! ( uut, reference) ;
249285}
@@ -339,6 +375,9 @@ fn pass_through_txs_with_note_dependencies() {
339375 uut. rollback_batch ( batch_a. id ( ) ) ;
340376 reference. add_transaction ( tx_pass_through_a) . unwrap ( ) ;
341377 reference. add_transaction ( tx_pass_through_b) . unwrap ( ) ;
378+ reference
379+ . transactions
380+ . increment_failure_count ( batch_a. txs ( ) . iter ( ) . map ( |tx| tx. id ( ) ) ) ;
342381
343382 assert_eq ! ( uut, reference) ;
344383}
0 commit comments