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

fix(external-node): Check txs at insert time instead of read time #555

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions core/lib/zksync_core/src/sync_layer/batch_status_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,10 @@ impl BatchStatusUpdater {
.unwrap()
.number;

// We don't want to change the internal state until we actually persist the changes.
let mut last_committed_l1_batch = self.last_committed_l1_batch;
let mut last_proven_l1_batch = self.last_proven_l1_batch;
let mut last_executed_l1_batch = self.last_executed_l1_batch;

assert!(
last_executed_l1_batch <= last_proven_l1_batch,
"Incorrect local state: executed batch must be proven"
);
assert!(
last_proven_l1_batch <= last_committed_l1_batch,
"Incorrect local state: proven batch must be committed"
);
assert!(
last_committed_l1_batch <= last_sealed_batch,
"Incorrect local state: unkonwn batch marked as committed"
);

let mut batch = last_executed_l1_batch.next();
// In this loop we try to progress on the batch statuses, utilizing the same request to the node to potentially
// update all three statuses (e.g. if the node is still syncing), but also skipping the gaps in the statuses
Expand Down Expand Up @@ -289,7 +275,16 @@ impl BatchStatusUpdater {
/// tables to be ever accessed by the `eth_sender` module.
async fn apply_status_changes(&mut self, changes: StatusChanges) {
let total_latency = EN_METRICS.batch_status_updater_loop_iteration.start();
let mut storage = self.pool.access_storage_tagged("sync_layer").await.unwrap();
let mut connection = self.pool.access_storage_tagged("sync_layer").await.unwrap();

let mut transaction = connection.start_transaction().await.unwrap();

let last_sealed_batch = transaction
.blocks_dal()
.get_newest_l1_batch_header()
.await
.unwrap()
.number;

for change in changes.commit.into_iter() {
tracing::info!(
Expand All @@ -298,7 +293,13 @@ impl BatchStatusUpdater {
change.l1_tx_hash,
change.happened_at
);
storage

assert!(
change.number <= last_sealed_batch,
"Incorrect update state: unknown batch marked as committed"
);

transaction
.eth_sender_dal()
.insert_bogus_confirmed_eth_tx(
change.number,
Expand All @@ -317,7 +318,13 @@ impl BatchStatusUpdater {
change.l1_tx_hash,
change.happened_at
);
storage

assert!(
change.number <= self.last_committed_l1_batch,
"Incorrect update state: proven batch must be committed"
);

transaction
.eth_sender_dal()
.insert_bogus_confirmed_eth_tx(
change.number,
Expand All @@ -337,7 +344,12 @@ impl BatchStatusUpdater {
change.happened_at
);

storage
assert!(
change.number <= self.last_proven_l1_batch,
"Incorrect update state: executed batch must be proven"
);

transaction
.eth_sender_dal()
.insert_bogus_confirmed_eth_tx(
change.number,
Expand All @@ -350,6 +362,8 @@ impl BatchStatusUpdater {
self.last_executed_l1_batch = change.number;
}

transaction.commit().await.unwrap();

total_latency.observe();
}
}
Loading