Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commitment-generator): events_queue shadow mode #1138

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

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

63 changes: 62 additions & 1 deletion core/lib/dal/src/events_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use zksync_types::{
event::L1_MESSENGER_BYTECODE_PUBLICATION_EVENT_SIGNATURE,
l2_to_l1_log::{L2ToL1Log, UserL2ToL1Log},
tx::IncludedTxLocation,
L1BatchNumber, MiniblockNumber, VmEvent, H256,
Address, L1BatchNumber, MiniblockNumber, VmEvent, H256,
};

use crate::{
instrument::InstrumentExt,
models::storage_event::{StorageL2ToL1Log, StorageWeb3Log},
SqlxError, StorageProcessor,
};
Expand Down Expand Up @@ -327,6 +328,66 @@ impl EventsDal<'_, '_> {

Ok(result)
}

pub async fn get_vm_events_for_l1_batch(
&mut self,
l1_batch_number: L1BatchNumber,
) -> Result<Option<Vec<VmEvent>>, SqlxError> {
let Some((from_miniblock, to_miniblock)) = self
.storage
.blocks_dal()
.get_miniblock_range_of_l1_batch(l1_batch_number)
.await?
else {
return Ok(None);
};
let events = sqlx::query!(
r#"
SELECT
address,
topic1,
topic2,
topic3,
topic4,
value
FROM
events
WHERE
miniblock_number BETWEEN $1 AND $2
ORDER BY
miniblock_number ASC,
event_index_in_block ASC
"#,
i64::from(from_miniblock.0),
i64::from(to_miniblock.0),
)
.instrument("get_vm_events_for_l1_batch")
.report_latency()
.fetch_all(self.storage)
.await?
.into_iter()
.enumerate()
.map(|(index_in_l1_batch, row)| {
let indexed_topics = vec![row.topic1, row.topic2, row.topic3, row.topic4]
.into_iter()
.filter_map(|topic| {
if !topic.is_empty() {
Some(H256::from_slice(&topic))
} else {
None
}
})
.collect();
VmEvent {
location: (l1_batch_number, index_in_l1_batch as u32),
address: Address::from_slice(&row.address),
indexed_topics,
value: row.value,
}
})
.collect();
Ok(Some(events))
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions core/lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ thiserror = "1.0"
num_enum = "0.6"
hex = "0.4"
prost = "0.12.1"
itertools = "0.10.3"

# Crypto stuff
secp256k1 = { version = "0.27", features = ["recovery", "global-context"] }
Expand Down