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: only write receipts once on PersistenceService::save_blocks #9976

Merged
merged 1 commit into from
Aug 1, 2024
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
37 changes: 15 additions & 22 deletions crates/engine/tree/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,24 @@ impl<DB: Database> PersistenceService<DB> {
// NOTE: checked non-empty above
let first_block = blocks.first().unwrap().block();
let last_block = blocks.last().unwrap().block().clone();

// use the storage writer to write receipts
let current_block = first_block.number;
debug!(target: "tree::persistence", len=blocks.len(), ?current_block, "Writing execution data to static files");

let receipts_writer =
static_file_provider.get_writer(first_block.number, StaticFileSegment::Receipts)?;

{
let mut storage_writer = StorageWriter::new(Some(provider_rw), Some(receipts_writer));
let receipts_iter = blocks.iter().map(|block| {
let receipts = block.execution_outcome().receipts().receipt_vec.clone();
debug_assert!(receipts.len() == 1);
receipts.first().unwrap().clone()
});
storage_writer.append_receipts_from_blocks(current_block, receipts_iter)?;
}

debug!(target: "tree::persistence", block_count = %blocks.len(), "Writing blocks to database");
let first_number = first_block.number;

let last_block_number = last_block.number;

// Only write receipts to static files if there is no receipt pruning configured.
let mut storage_writer = if provider_rw.prune_modes_ref().has_receipts_pruning() {
StorageWriter::new(Some(provider_rw), None)
} else {
StorageWriter::new(
Some(provider_rw),
Some(
static_file_provider
.get_writer(first_block.number, StaticFileSegment::Receipts)?,
),
)
};
Comment on lines +135 to +145
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

once this save_blocks gets moved to StorageWriter, this will get abstracted away


debug!(target: "tree::persistence", block_count = %blocks.len(), "Writing blocks and execution data to storage");

// TODO: remove all the clones and do performant / batched writes for each type of object
// instead of a loop over all blocks,
// meaning:
Expand All @@ -169,8 +164,6 @@ impl<DB: Database> PersistenceService<DB> {
// Write state and changesets to the database.
// Must be written after blocks because of the receipt lookup.
let execution_outcome = block.execution_outcome().clone();
// TODO: do we provide a static file producer here?
let mut storage_writer = StorageWriter::new(Some(provider_rw), None);
storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::No)?;

// insert hashes and intermediate merkle nodes
Expand Down
Loading