Skip to content

Commit

Permalink
fix: remove redundant check in bodies stage (#12569)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Nov 15, 2024
1 parent efa350d commit 56826cb
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 39 deletions.
13 changes: 1 addition & 12 deletions crates/stages/api/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::PipelineEvent;
use alloy_primitives::{BlockNumber, TxNumber};
use alloy_primitives::TxNumber;
use reth_consensus::ConsensusError;
use reth_errors::{BlockExecutionError, DatabaseError, RethError};
use reth_network_p2p::error::DownloadError;
Expand Down Expand Up @@ -112,16 +112,6 @@ pub enum StageError {
/// Expected static file transaction number.
static_file: TxNumber,
},
/// Unrecoverable inconsistency error related to a block number in a static file segment.
#[error("inconsistent block number for {segment}. db: {database}, static_file: {static_file}")]
InconsistentBlockNumber {
/// Static File segment where this error was encountered.
segment: StaticFileSegment,
/// Expected database block number.
database: BlockNumber,
/// Expected static file block number.
static_file: BlockNumber,
},
/// The prune checkpoint for the given segment is missing.
#[error("missing prune checkpoint for {0}")]
MissingPruneCheckpoint(PruneSegment),
Expand Down Expand Up @@ -156,7 +146,6 @@ impl StageError {
Self::MissingDownloadBuffer |
Self::MissingSyncGap |
Self::ChannelClosed |
Self::InconsistentBlockNumber { .. } |
Self::InconsistentTxNumber { .. } |
Self::Internal(_) |
Self::Fatal(_)
Expand Down
12 changes: 1 addition & 11 deletions crates/stages/stages/src/stages/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,7 @@ where

// Increment block on static file header.
if block_number > 0 {
let appended_block_number = static_file_producer.increment_block(block_number)?;

if appended_block_number != block_number {
// This scenario indicates a critical error in the logic of adding new
// items. It should be treated as an `expect()` failure.
return Err(StageError::InconsistentBlockNumber {
segment: StaticFileSegment::Transactions,
database: block_number,
static_file: appended_block_number,
})
}
static_file_producer.increment_block(block_number)?;
}

match response {
Expand Down
4 changes: 1 addition & 3 deletions crates/static-file/static-file/src/segments/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ impl<Provider: StaticFileProviderFactory + DBProvider> Segment<Provider> for Hea
debug_assert_eq!(header_block, header_td_block);
debug_assert_eq!(header_td_block, canonical_header_block);

let _static_file_block =
static_file_writer.append_header(&header, header_td.0, &canonical_header)?;
debug_assert_eq!(_static_file_block, header_block);
static_file_writer.append_header(&header, header_td.0, &canonical_header)?;
}

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions crates/static-file/static-file/src/segments/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ impl<Provider: StaticFileProviderFactory + DBProvider + BlockReader> Segment<Pro
static_file_provider.get_writer(*block_range.start(), StaticFileSegment::Receipts)?;

for block in block_range {
let _static_file_block = static_file_writer.increment_block(block)?;
debug_assert_eq!(_static_file_block, block);
static_file_writer.increment_block(block)?;

let block_body_indices = provider
.block_body_indices(block)?
Expand Down
3 changes: 1 addition & 2 deletions crates/static-file/static-file/src/segments/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl<Provider: StaticFileProviderFactory + DBProvider + BlockReader> Segment<Pro
.get_writer(*block_range.start(), StaticFileSegment::Transactions)?;

for block in block_range {
let _static_file_block = static_file_writer.increment_block(block)?;
debug_assert_eq!(_static_file_block, block);
static_file_writer.increment_block(block)?;

let block_body_indices = provider
.block_body_indices(block)?
Expand Down
15 changes: 6 additions & 9 deletions crates/storage/provider/src/providers/static_file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
/// and create the next one if we are past the end range.
///
/// Returns the current [`BlockNumber`] as seen in the static file.
pub fn increment_block(
&mut self,
expected_block_number: BlockNumber,
) -> ProviderResult<BlockNumber> {
pub fn increment_block(&mut self, expected_block_number: BlockNumber) -> ProviderResult<()> {
let segment = self.writer.user_header().segment();

self.check_next_block_number(expected_block_number)?;
Expand All @@ -350,7 +347,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
}
}

let block = self.writer.user_header_mut().increment_block();
self.writer.user_header_mut().increment_block();
if let Some(metrics) = &self.metrics {
metrics.record_segment_operation(
segment,
Expand All @@ -359,7 +356,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
);
}

Ok(block)
Ok(())
}

/// Verifies if the incoming block number matches the next expected block number
Expand Down Expand Up @@ -524,13 +521,13 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
header: &Header,
total_difficulty: U256,
hash: &BlockHash,
) -> ProviderResult<BlockNumber> {
) -> ProviderResult<()> {
let start = Instant::now();
self.ensure_no_queued_prune()?;

debug_assert!(self.writer.user_header().segment() == StaticFileSegment::Headers);

let block_number = self.increment_block(header.number)?;
self.increment_block(header.number)?;

self.append_column(header)?;
self.append_column(CompactU256::from(total_difficulty))?;
Expand All @@ -544,7 +541,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
);
}

Ok(block_number)
Ok(())
}

/// Appends transaction to static file.
Expand Down

0 comments on commit 56826cb

Please sign in to comment.