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(snapshots): write Receipt to snapshots during ExecutionStage #6103

Merged
merged 152 commits into from
Jan 29, 2024

Conversation

joshieDo
Copy link
Collaborator

@joshieDo joshieDo commented Jan 17, 2024

attention: it only writes to static files if there's no pruning/configuration enabled for receipts (includes --full which only includes deposit contract receipts). Meaning: it keeps them on database

on top of #5733

// `maybe_snapshotter` already prunes receipts if it detects that there are more
// elements in the static files than expected.
if let Some(stage_checkpoint) = stage_checkpoint.as_mut() {
for block_number in range {
Copy link
Member

Choose a reason for hiding this comment

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

this is to "unwind" the stage progress?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added more context, lmk if it makes sense

}
reverse_walker.delete_current()?;
None => {
Copy link
Member

Choose a reason for hiding this comment

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

i'd like if we could either make maybe_snapshotter more verbose in its naming, split it out into two separate functions, or add some more comments here. it is a bit hard to follow what exactly goes on since maybe_snapshotter (as a name) doesn't say much, but seems to do a lot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed the name and added context, lmk if it makes sense

Base automatically changed from joshie/tx-snap-sync to feat/static-files January 26, 2024 12:47
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.

few nits

Comment on lines 127 to 128
// for receipts.
let snapshotter = try_prepare_snapshotter(&self.prune_modes, provider, start_block)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function is standalone for testing reasons?

then this makes sense, though I'd also add a fn try_prepare_snapshotter(&self if possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i guess this was doing too much and not very clear

  • check if snapshotter is to be used. - put it outside of the function
  • consistency check of the static file data (eg. do i have more receipts than database expects? then unwind static files)

added more docs that hopefully clarify

if let Some(stage_checkpoint) = stage_checkpoint.as_mut() {
stage_checkpoint.progress.processed -= receipt.cumulative_gas_used;
if let Some(stage_checkpoint) = stage_checkpoint.as_mut() {
stage_checkpoint.progress.processed -= receipt.cumulative_gas_used;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does this -=?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because this is part of the unwind and we need to set the total gas progress back .

it already existed beforehand, this is my understanding

///
/// `omit_changed_check` should be set to true of bundle has some of it data
/// detached, This would make some original values not known.
pub fn write_to_db<TX: DbTxMut + DbTx>(
pub fn write_to_storage<TX: DbTxMut + DbTx>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer a where clause instead

let (_, body_indices) =
bodies_cursor.seek_exact(block_number)?.unwrap_or_else(|| {
let mut body_indices = |block_number: BlockNumber| {
Ok::<_,DatabaseError>(bodies_cursor.seek_exact(block_number)?.unwrap_or_else(|| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this large Ok looks very strange
can you do this in two steps?

crates/storage/provider/src/providers/snapshot/manager.rs Outdated Show resolved Hide resolved
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.

lgtm

crates/stages/src/stages/execution.rs Outdated Show resolved Hide resolved
@@ -264,6 +264,13 @@ impl SnapshotProvider {
index.insert(tx_end, current_block_range.clone());
})
.or_insert_with(|| BTreeMap::from([(tx_end, current_block_range)]));
} else if let Some(1) = tx_index.get(&segment).map(|index| index.len()) {
// Only happens if we unwind all the txs/receipts from the first static file.
// Should only happen in test scenarios.
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, isn't it possible that we have index of length one during the normal node operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i may be missing something, but i think highly unlikely...

Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
@joshieDo joshieDo merged commit 17d94cf into feat/static-files Jan 29, 2024
24 checks passed
@joshieDo joshieDo deleted the joshie/receipts-snap-sync branch January 29, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-static-files Related to static files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants