Skip to content

fix: use hashed_keys for extracting storage logs from db#4606

Open
sanekmelnikov wants to merge 3 commits intomainfrom
alm-recovery-patch
Open

fix: use hashed_keys for extracting storage logs from db#4606
sanekmelnikov wants to merge 3 commits intomainfrom
alm-recovery-patch

Conversation

@sanekmelnikov
Copy link
Collaborator

@sanekmelnikov sanekmelnikov commented Jan 9, 2026

What ❔

When recovering lost storage logs using compressed state diffs from L1, only the hashed_key is available. As a result, the backfilled postgres data in storage_logs won't have the address and key fields.

The current logic causes tree recovery to fail here, as the query expects these fields to be present.
(Note that tree_writes field in l1_batches isn't available in this case as well - it can't be recovered because it is decoded using address and key)

This PR replaces get_touched_slots_for_executed_l1_batch with get_touched_slots_for_l1_batch to use hashed_key instead.
To ensure the order of writes is preserved, we sort values by leaf_index.

Why ❔

To enable L1 recovery

Is this a breaking change?

  • Yes
  • No

Checklist

  • 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 zkstack dev fmt and zkstack dev lint.

perekopskiy
perekopskiy previously approved these changes Jan 12, 2026
Copy link
Contributor

@perekopskiy perekopskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment on lines +829 to +832
if let Some(&(initial_write_batch_for_key, leaf_index)) =
l1_batches_for_initial_writes.get(&hashed_key)
{
if initial_write_batch_for_key <= l1_batch_number {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd assert! that these 2 ifs are entered for each protective read

@sanekmelnikov sanekmelnikov marked this pull request as ready for review January 13, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants