refactor(provider): deduplicate segment-to-stage mapping in static file manager (#21670)

This commit is contained in:
iPLAY888
2026-02-01 23:09:32 +03:00
committed by GitHub
parent 5528aae8f6
commit af96eeae56
4 changed files with 19 additions and 17 deletions

1
Cargo.lock generated
View File

@@ -10943,6 +10943,7 @@ dependencies = [
"fixed-map",
"insta",
"reth-nippy-jar",
"reth-stages-types",
"serde",
"serde_json",
"strum",

View File

@@ -18,6 +18,7 @@ clap = { workspace = true, features = ["derive"], optional = true }
fixed-map.workspace = true
derive_more.workspace = true
serde = { workspace = true, features = ["alloc", "derive"] }
reth-stages-types.workspace = true
strum = { workspace = true, features = ["derive"] }
[dev-dependencies]
@@ -30,6 +31,7 @@ default = ["std"]
std = [
"alloy-primitives/std",
"derive_more/std",
"reth-stages-types/std",
"serde/std",
"strum/std",
"serde_json/std",

View File

@@ -5,6 +5,7 @@ use core::{
ops::{Range, RangeInclusive},
str::FromStr,
};
use reth_stages_types::StageId;
use serde::{de::Visitor, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
use strum::{EnumIs, EnumString};
@@ -198,6 +199,18 @@ impl StaticFileSegment {
pub const fn is_block_or_change_based(&self) -> bool {
self.is_block_based() || self.is_change_based()
}
/// Maps this segment to the [`StageId`] responsible for it.
pub const fn to_stage_id(&self) -> StageId {
match self {
Self::Headers => StageId::Headers,
Self::Transactions => StageId::Bodies,
Self::Receipts | Self::AccountChangeSets | Self::StorageChangeSets => {
StageId::Execution
}
Self::TransactionSenders => StageId::SenderRecovery,
}
}
}
/// A changeset offset, also with the number of elements in the offset for convenience

View File

@@ -37,7 +37,7 @@ use reth_primitives_traits::{
AlloyBlockHeader as _, BlockBody as _, RecoveredBlock, SealedHeader, SignedTransaction,
StorageEntry,
};
use reth_stages_types::{PipelineTarget, StageId};
use reth_stages_types::PipelineTarget;
use reth_static_file_types::{
find_fixed_range, HighestStaticFiles, SegmentHeader, SegmentRangeInclusive, StaticFileMap,
StaticFileSegment, DEFAULT_BLOCKS_PER_STATIC_FILE,
@@ -1651,14 +1651,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
// If static file entry is ahead of the database entries, then ensure the checkpoint block
// number matches.
let stage_id = match segment {
StaticFileSegment::Headers => StageId::Headers,
StaticFileSegment::Transactions => StageId::Bodies,
StaticFileSegment::Receipts |
StaticFileSegment::AccountChangeSets |
StaticFileSegment::StorageChangeSets => StageId::Execution,
StaticFileSegment::TransactionSenders => StageId::SenderRecovery,
};
let stage_id = segment.to_stage_id();
let checkpoint_block_number =
provider.get_stage_checkpoint(stage_id)?.unwrap_or_default().block_number;
debug!(target: "reth::providers::static_file", ?segment, ?stage_id, checkpoint_block_number, highest_static_file_block, "Retrieved stage checkpoint");
@@ -1790,14 +1783,7 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
let highest_static_file_block = highest_static_file_block.unwrap_or_default();
let stage_id = match segment {
StaticFileSegment::Headers => StageId::Headers,
StaticFileSegment::Transactions => StageId::Bodies,
StaticFileSegment::Receipts |
StaticFileSegment::AccountChangeSets |
StaticFileSegment::StorageChangeSets => StageId::Execution,
StaticFileSegment::TransactionSenders => StageId::SenderRecovery,
};
let stage_id = segment.to_stage_id();
let checkpoint_block_number =
provider.get_stage_checkpoint(stage_id)?.unwrap_or_default().block_number;