fix: remove redundant check in bodies stage (#12569)

This commit is contained in:
Arsenii Kulikov
2024-11-15 16:35:35 +04:00
committed by GitHub
parent efa350d28d
commit 56826cbdbb
6 changed files with 11 additions and 39 deletions

View File

@ -1,5 +1,5 @@
use crate::PipelineEvent; use crate::PipelineEvent;
use alloy_primitives::{BlockNumber, TxNumber}; use alloy_primitives::TxNumber;
use reth_consensus::ConsensusError; use reth_consensus::ConsensusError;
use reth_errors::{BlockExecutionError, DatabaseError, RethError}; use reth_errors::{BlockExecutionError, DatabaseError, RethError};
use reth_network_p2p::error::DownloadError; use reth_network_p2p::error::DownloadError;
@ -112,16 +112,6 @@ pub enum StageError {
/// Expected static file transaction number. /// Expected static file transaction number.
static_file: TxNumber, 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. /// The prune checkpoint for the given segment is missing.
#[error("missing prune checkpoint for {0}")] #[error("missing prune checkpoint for {0}")]
MissingPruneCheckpoint(PruneSegment), MissingPruneCheckpoint(PruneSegment),
@ -156,7 +146,6 @@ impl StageError {
Self::MissingDownloadBuffer | Self::MissingDownloadBuffer |
Self::MissingSyncGap | Self::MissingSyncGap |
Self::ChannelClosed | Self::ChannelClosed |
Self::InconsistentBlockNumber { .. } |
Self::InconsistentTxNumber { .. } | Self::InconsistentTxNumber { .. } |
Self::Internal(_) | Self::Internal(_) |
Self::Fatal(_) Self::Fatal(_)

View File

@ -176,17 +176,7 @@ where
// Increment block on static file header. // Increment block on static file header.
if block_number > 0 { if block_number > 0 {
let appended_block_number = static_file_producer.increment_block(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,
})
}
} }
match response { match response {

View File

@ -46,9 +46,7 @@ impl<Provider: StaticFileProviderFactory + DBProvider> Segment<Provider> for Hea
debug_assert_eq!(header_block, header_td_block); debug_assert_eq!(header_block, header_td_block);
debug_assert_eq!(header_td_block, canonical_header_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)?;
static_file_writer.append_header(&header, header_td.0, &canonical_header)?;
debug_assert_eq!(_static_file_block, header_block);
} }
Ok(()) Ok(())

View File

@ -30,8 +30,7 @@ impl<Provider: StaticFileProviderFactory + DBProvider + BlockReader> Segment<Pro
static_file_provider.get_writer(*block_range.start(), StaticFileSegment::Receipts)?; static_file_provider.get_writer(*block_range.start(), StaticFileSegment::Receipts)?;
for block in block_range { for block in block_range {
let _static_file_block = static_file_writer.increment_block(block)?; static_file_writer.increment_block(block)?;
debug_assert_eq!(_static_file_block, block);
let block_body_indices = provider let block_body_indices = provider
.block_body_indices(block)? .block_body_indices(block)?

View File

@ -32,8 +32,7 @@ impl<Provider: StaticFileProviderFactory + DBProvider + BlockReader> Segment<Pro
.get_writer(*block_range.start(), StaticFileSegment::Transactions)?; .get_writer(*block_range.start(), StaticFileSegment::Transactions)?;
for block in block_range { for block in block_range {
let _static_file_block = static_file_writer.increment_block(block)?; static_file_writer.increment_block(block)?;
debug_assert_eq!(_static_file_block, block);
let block_body_indices = provider let block_body_indices = provider
.block_body_indices(block)? .block_body_indices(block)?

View File

@ -320,10 +320,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
/// and create the next one if we are past the end range. /// and create the next one if we are past the end range.
/// ///
/// Returns the current [`BlockNumber`] as seen in the static file. /// Returns the current [`BlockNumber`] as seen in the static file.
pub fn increment_block( pub fn increment_block(&mut self, expected_block_number: BlockNumber) -> ProviderResult<()> {
&mut self,
expected_block_number: BlockNumber,
) -> ProviderResult<BlockNumber> {
let segment = self.writer.user_header().segment(); let segment = self.writer.user_header().segment();
self.check_next_block_number(expected_block_number)?; self.check_next_block_number(expected_block_number)?;
@ -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 { if let Some(metrics) = &self.metrics {
metrics.record_segment_operation( metrics.record_segment_operation(
segment, segment,
@ -359,7 +356,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
); );
} }
Ok(block) Ok(())
} }
/// Verifies if the incoming block number matches the next expected block number /// Verifies if the incoming block number matches the next expected block number
@ -524,13 +521,13 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
header: &Header, header: &Header,
total_difficulty: U256, total_difficulty: U256,
hash: &BlockHash, hash: &BlockHash,
) -> ProviderResult<BlockNumber> { ) -> ProviderResult<()> {
let start = Instant::now(); let start = Instant::now();
self.ensure_no_queued_prune()?; self.ensure_no_queued_prune()?;
debug_assert!(self.writer.user_header().segment() == StaticFileSegment::Headers); 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(header)?;
self.append_column(CompactU256::from(total_difficulty))?; self.append_column(CompactU256::from(total_difficulty))?;
@ -544,7 +541,7 @@ impl<N: NodePrimitives> StaticFileProviderRW<N> {
); );
} }
Ok(block_number) Ok(())
} }
/// Appends transaction to static file. /// Appends transaction to static file.