Skip to content

Commit

Permalink
fix(dal): correct tx_index_in_l1_batch in `get_vm_events_for_l1_bat…
Browse files Browse the repository at this point in the history
…ch` (#1463)

## What ❔

Fix calculation for `tx_index_in_l1_batch` in
`get_vm_events_for_l1_batch` method.

## 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`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
perekopskiy committed Mar 20, 2024
1 parent 103a56b commit 8bf37ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.

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

12 changes: 8 additions & 4 deletions core/lib/dal/src/events_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ impl EventsDal<'_, '_> {
else {
return Ok(None);
};
let mut tx_index_in_l1_batch = -1;
let events = sqlx::query!(
r#"
SELECT
Expand All @@ -351,7 +352,8 @@ impl EventsDal<'_, '_> {
topic2,
topic3,
topic4,
value
value,
event_index_in_tx
FROM
events
WHERE
Expand All @@ -368,8 +370,7 @@ impl EventsDal<'_, '_> {
.fetch_all(self.storage)
.await?
.into_iter()
.enumerate()
.map(|(index_in_l1_batch, row)| {
.map(|row| {
let indexed_topics = vec![row.topic1, row.topic2, row.topic3, row.topic4]
.into_iter()
.filter_map(|topic| {
Expand All @@ -380,8 +381,11 @@ impl EventsDal<'_, '_> {
}
})
.collect();
if row.event_index_in_tx == 0 {
tx_index_in_l1_batch += 1;
}
VmEvent {
location: (l1_batch_number, index_in_l1_batch as u32),
location: (l1_batch_number, tx_index_in_l1_batch as u32),
address: Address::from_slice(&row.address),
indexed_topics,
value: row.value,
Expand Down

0 comments on commit 8bf37ac

Please sign in to comment.