Skip to content

Commit

Permalink
fix(en): Delete old txs by (init_addr, nonce) (#1942)
Browse files Browse the repository at this point in the history
## What ❔

Delete txs not only by hash but also by (init_addr, nonce) before
inserting them

## Why ❔

Fix bug

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
perekopskiy authored May 15, 2024
1 parent cf80184 commit fa5f4a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion core/lib/dal/src/transactions_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,29 @@ impl TransactionsDal<'_, '_> {
"#,
&tx_hashes as &[&[u8]],
)
.instrument("mark_txs_as_executed_in_l2_block#remove_old_txs")
.instrument("mark_txs_as_executed_in_l2_block#remove_old_txs_with_hashes")
.execute(&mut transaction)
.await?;
for tx in transactions {
let Some(nonce) = tx.transaction.nonce() else {
// Nonce is missing for L1 and upgrade txs, they can be skipped in this loop.
continue;
};
let initiator = tx.transaction.initiator_account();
sqlx::query!(
r#"
DELETE FROM transactions
WHERE
initiator_address = $1
AND nonce = $2
"#,
initiator.as_bytes(),
nonce.0 as i32,
)
.instrument("mark_txs_as_executed_in_l2_block#remove_old_txs_with_addr_and_nonce")
.execute(&mut transaction)
.await?;
}

// Different transaction types have different sets of fields to insert so we handle them separately.
transaction
Expand Down

0 comments on commit fa5f4a7

Please sign in to comment.