Skip to content
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
39 changes: 24 additions & 15 deletions crates/optimism/trie/src/db/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,33 @@ impl MdbxProofsStorage {
return Ok(keys);
}

// Prune mode: remove tombstones and write state to block 0 (not append)
let (to_delete, to_append): (Vec<_>, Vec<_>) =
pairs.into_iter().partition(|(_, vv)| vv.value.0.is_none());

for (k, vv) in to_append {
// Dupsort upsert doesn't replace - manually delete old block 0 entry first
let val = cur.seek_by_key_subkey(k.clone(), 0)?;
if val.is_some() && val.unwrap().block_number == 0 {
cur.delete_current()?;
// Drop current cursor to start clean for Phase 1
drop(cur);
Comment on lines +172 to +173
Copy link
Member

Choose a reason for hiding this comment

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

nice


// Phase 1: Batch Delete (Sequential)
// Remove all existing state at Block 0 for these keys.
Comment on lines +175 to +176
Copy link
Member

Choose a reason for hiding this comment

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

thank you for the numbered steps in these code comments, improves readability

{
let mut del_cur = tx.cursor_dup_write::<T>()?;
for (k, _) in &pairs {
// Seek to (Key, Block 0)
if let Some(vv) = del_cur.seek_by_key_subkey(k.clone(), 0)? &&
vv.block_number == 0
{
del_cur.delete_current()?;
}
}
cur.upsert(k, &vv)?;
}

// Delete tombstones after updates to avoid overwrites
self.delete_dup_sorted::<T, _, V>(
tx,
to_delete.into_iter().map(|(k, _)| (k, block_number)),
)?;
// Phase 2: Batch Write (Sequential)
// Write new values (skipping tombstones).
{
let mut write_cur = tx.cursor_dup_write::<T>()?;
for (k, vv) in pairs {
if vv.value.0.is_some() {
write_cur.upsert(k, &vv)?;
}
}
}

Ok(keys)
}
Expand Down
Loading