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(storage): fallback lookups for pruned history #4121

Merged
merged 18 commits into from
Aug 9, 2023

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Aug 8, 2023

Changes

Missed cursor jump to delete the original shard

We did a jump to the previous shard

if let Some(prev_value) = cursor
.prev()?
and if it wasn't found for the same key, we needed to first jump back to the original shard, and only then delete current entry:
// Jump back to the original last shard.
cursor.next()?;
// Delete shard.
cursor.delete_current()?;

HistoryInfo lookups with pruned history

History shard exists

Two problems:

  1. There was a missing check
    chunk.select(rank) as u64 != self.block_number &&
    that is required even with unpruned history. rank == 0 can mean not only that the target block is less then the first block in the shard, but also that the first block in shard is equal to the target block, in which case we need to look it up in the changeset.
  2. If the target block is not found in any shard and the history is pruned, it doesn't always mean that it's the first write ever. So we need to fallback to the changeset lookup because the key may have been actually written:
    if lowest_available_block_number.is_some() {
    // The key may have been written, but due to pruning we may not have changesets
    // and history, so we need to make a changeset lookup.
    Ok(HistoryInfo::InChangeset(chunk.select(rank) as u64))
    } else {
    // The key is written to, but only after our block.
    Ok(HistoryInfo::NotYetWritten)
    }

History shard does not exist

If the target block is not found in any shard and the history is pruned, it doesn't always mean that it's the first write ever. So we need to fallback to the plain state lookup because the key may have been actually written:

} else if lowest_available_block_number.is_some() {
// The key may have been written, but due to pruning we may not have changesets and
// history, so we need to make a plain state lookup.
Ok(HistoryInfo::MaybeInPlainState)
} else {

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #4121 (4ceff49) into main (fd7e28e) will decrease coverage by 0.02%.
Report is 1 commits behind head on main.
The diff coverage is 94.87%.

Impacted file tree graph

Files Changed Coverage Δ
crates/prune/src/pruner.rs 82.70% <0.00%> (-0.14%) ⬇️
...storage/provider/src/providers/state/historical.rs 87.14% <97.36%> (+0.10%) ⬆️

... and 14 files with indirect coverage changes

Flag Coverage Δ
integration-tests 16.85% <0.00%> (+<0.01%) ⬆️
unit-tests 64.09% <94.87%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 25.94% <ø> (+0.54%) ⬆️
blockchain tree 82.83% <ø> (ø)
pipeline 90.07% <ø> (ø)
storage (db) 74.75% <97.36%> (+0.02%) ⬆️
trie 94.71% <ø> (ø)
txpool 48.23% <ø> (-0.03%) ⬇️
networking 77.69% <ø> (-0.14%) ⬇️
rpc 58.68% <ø> (+<0.01%) ⬆️
consensus 63.76% <ø> (ø)
revm 32.26% <ø> (ø)
payload builder 6.57% <ø> (ø)
primitives 87.88% <ø> (-0.03%) ⬇️

@shekhirin shekhirin force-pushed the alexey/historical-state-maybe-plainstate branch from 9121bed to 65296d0 Compare August 8, 2023 14:56
@shekhirin shekhirin force-pushed the alexey/historical-state-maybe-plainstate branch from c9ef7bb to 4f20ae4 Compare August 8, 2023 16:45
@shekhirin shekhirin changed the title fix(storage): lookup in plain state for pruned node fix(storage): fallback history lookups for pruned node Aug 8, 2023
@shekhirin shekhirin changed the title fix(storage): fallback history lookups for pruned node fix(storage): fallback lookups for pruned history Aug 8, 2023
@shekhirin shekhirin force-pushed the alexey/historical-state-maybe-plainstate branch from 78b7427 to 47f00e5 Compare August 8, 2023 18:59
@shekhirin shekhirin marked this pull request as ready for review August 9, 2023 06:57
@shekhirin shekhirin requested review from mattsse, rkrasiuk and joshieDo and removed request for rakita and gakonst August 9, 2023 06:57
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

nice find!

Base automatically changed from alexey/historical-state-prune to main August 9, 2023 18:24
@shekhirin shekhirin added this pull request to the merge queue Aug 9, 2023
Merged via the queue into main with commit 7426a01 Aug 9, 2023
24 checks passed
@shekhirin shekhirin deleted the alexey/historical-state-maybe-plainstate branch August 9, 2023 21:14
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.

3 participants