Skip to content

Commit

Permalink
order bmeta segment
Browse files Browse the repository at this point in the history
put on bottom
  • Loading branch information
joshieDo committed Dec 19, 2024
1 parent 46f7d85 commit e9e1c33
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crates/static-file/types/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl StaticFileSegment {
Self::Headers => "headers",
Self::Transactions => "transactions",
Self::Receipts => "receipts",
Self::BlockMeta => "blockmeta",
Self::BlockMeta => "bmeta",
}
}

Expand Down
51 changes: 28 additions & 23 deletions crates/storage/provider/src/providers/static_file/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,13 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
highest_tx,
highest_block,
)?,
StaticFileSegment::BlockMeta => {
self.ensure_invariants::<_, tables::BlockBodyIndices>(
StaticFileSegment::BlockMeta => self
.ensure_invariants::<_, tables::BlockBodyIndices>(
provider,
segment,
highest_tx,
highest_block,
)?
}
highest_block,
)?,
} {
update_unwind_target(unwind);
}
Expand Down Expand Up @@ -838,35 +837,39 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
where
Provider: DBProvider + BlockReader + StageCheckpointReader,
{
let highest_static_file_entry = highest_static_file_entry.unwrap_or_default();
let highest_static_file_block = highest_static_file_block.unwrap_or_default();
let mut db_cursor = provider.tx_ref().cursor_read::<T>()?;

if let Some((db_first_entry, _)) = db_cursor.first()? {
// If there is a gap between the entry found in static file and
// database, then we have most likely lost static file data and need to unwind so we can
// load it again
if !(db_first_entry <= highest_static_file_entry ||
highest_static_file_entry + 1 == db_first_entry)
if let (Some(highest_entry), Some(highest_block)) =
(highest_static_file_entry, highest_static_file_block)
{
info!(
target: "reth::providers::static_file",
?db_first_entry,
?highest_static_file_entry,
unwind_target = highest_static_file_block,
?segment,
"Setting unwind target."
);
return Ok(Some(highest_static_file_block))
// If there is a gap between the entry found in static file and
// database, then we have most likely lost static file data and need to unwind so we
// can load it again
if !(db_first_entry <= highest_entry || highest_entry + 1 == db_first_entry) {
info!(
target: "reth::providers::static_file",
?db_first_entry,
?highest_entry,
unwind_target = highest_block,
?segment,
"Setting unwind target."
);
return Ok(Some(highest_block))
}
}

if let Some((db_last_entry, _)) = db_cursor.last()? {
if db_last_entry > highest_static_file_entry {
if highest_static_file_entry
.is_none_or(|highest_entry| db_last_entry > highest_entry)
{
return Ok(None)
}
}
}

let highest_static_file_entry = highest_static_file_entry.unwrap_or_default();
let highest_static_file_block = highest_static_file_block.unwrap_or_default();

// If static file entry is ahead of the database entries, then ensure the checkpoint block
// number matches.
let checkpoint_block_number = provider
Expand Down Expand Up @@ -906,6 +909,8 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
// TODO(joshie): is_block_meta
writer.prune_headers(highest_static_file_block - checkpoint_block_number)?;
} else if let Some(block) = provider.block_body_indices(checkpoint_block_number)? {
// todo joshie: is querying block_body_indices a potential issue once bbi is moved
// to sf as well
let number = highest_static_file_entry - block.last_tx_num();
if segment.is_receipts() {
writer.prune_receipts(number, checkpoint_block_number)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<N: NodePrimitives> StaticFileWriters<N> {
}

pub(crate) fn commit(&self) -> ProviderResult<()> {
for writer_lock in [&self.headers, &self.transactions, &self.receipts] {
for writer_lock in [&self.headers, &self.block_meta, &self.transactions, &self.receipts] {
let mut writer = writer_lock.write();
if let Some(writer) = writer.as_mut() {
writer.commit()?;
Expand Down

0 comments on commit e9e1c33

Please sign in to comment.