Skip to content

Commit

Permalink
Fix empty l2 block having one tx (#992)
Browse files Browse the repository at this point in the history
* Skip apply tx if 0 txs found

* Lint

* Assign vars in place

* Fix test

---------

Co-authored-by: yaziciahmet <yaziciahmetcleargmail.com>
  • Loading branch information
yaziciahmet authored Aug 15, 2024
1 parent 12bb40f commit fe4cadd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/citrea/tests/e2e/sequencer_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async fn transaction_failing_on_l1_is_removed_from_mempool() -> Result<(), anyho

assert_eq!(block.transactions.len(), 0);
assert!(tx_from_mempool.is_none());
assert_eq!(soft_confirmation.txs.unwrap().len(), 1); // TODO: if we can also remove the tx from soft confirmation, that'd be very efficient
assert_eq!(soft_confirmation.txs.unwrap().len(), 0);

wait_for_l2_block(&full_node_test_client, block.header.number.unwrap(), None).await;

Expand Down
29 changes: 18 additions & 11 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,25 @@ where
&mut signed_batch,
) {
(Ok(()), mut batch_workspace) => {
let evm_txs_count = txs_to_run.len();
let call_txs = CallMessage { txs: txs_to_run };
let raw_message =
<Runtime<C, Da::Spec> as EncodeCall<citrea_evm::Evm<C>>>::encode_call(call_txs);
let signed_blob = self.make_blob(raw_message, &mut batch_workspace)?;
let txs = vec![signed_blob.clone()];
let mut txs = vec![];
let mut tx_receipts = vec![];

let (batch_workspace, tx_receipts) = self.stf.apply_soft_confirmation_txs(
self.fork_manager.active_fork(),
txs.clone(),
batch_workspace,
);
let evm_txs_count = txs_to_run.len();
if evm_txs_count > 0 {
let call_txs = CallMessage { txs: txs_to_run };
let raw_message =
<Runtime<C, Da::Spec> as EncodeCall<citrea_evm::Evm<C>>>::encode_call(
call_txs,
);
let signed_blob = self.make_blob(raw_message, &mut batch_workspace)?;
txs.push(signed_blob);

(batch_workspace, tx_receipts) = self.stf.apply_soft_confirmation_txs(
self.fork_manager.active_fork(),
txs.clone(),
batch_workspace,
);
}

// create the unsigned batch with the txs then sign th sc
let unsigned_batch = UnsignedSoftConfirmationBatch::new(
Expand Down

0 comments on commit fe4cadd

Please sign in to comment.