chore: move standalone types to types crate (#12483)

This commit is contained in:
Matthias Seitz
2024-11-12 20:40:29 +01:00
committed by GitHub
parent b39957612a
commit 9884167684
4 changed files with 43 additions and 39 deletions

View File

@ -7,14 +7,12 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
mod event;
pub mod segments;
mod static_file_producer;
pub use event::StaticFileProducerEvent;
pub use static_file_producer::{
StaticFileProducer, StaticFileProducerInner, StaticFileProducerResult,
StaticFileProducerWithResult, StaticFileTargets,
StaticFileProducerWithResult,
};
// Re-export for convenience.

View File

@ -10,7 +10,7 @@ use reth_provider::{
};
use reth_prune_types::PruneModes;
use reth_stages_types::StageId;
use reth_static_file_types::HighestStaticFiles;
use reth_static_file_types::{HighestStaticFiles, StaticFileTargets};
use reth_storage_errors::provider::ProviderResult;
use reth_tokio_util::{EventSender, EventStream};
use std::{
@ -66,40 +66,6 @@ pub struct StaticFileProducerInner<Provider> {
event_sender: EventSender<StaticFileProducerEvent>,
}
/// Static File targets, per data segment, measured in [`BlockNumber`].
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct StaticFileTargets {
headers: Option<RangeInclusive<BlockNumber>>,
receipts: Option<RangeInclusive<BlockNumber>>,
transactions: Option<RangeInclusive<BlockNumber>>,
}
impl StaticFileTargets {
/// Returns `true` if any of the targets are [Some].
pub const fn any(&self) -> bool {
self.headers.is_some() || self.receipts.is_some() || self.transactions.is_some()
}
// Returns `true` if all targets are either [`None`] or has beginning of the range equal to the
// highest static_file.
fn is_contiguous_to_highest_static_files(&self, static_files: HighestStaticFiles) -> bool {
[
(self.headers.as_ref(), static_files.headers),
(self.receipts.as_ref(), static_files.receipts),
(self.transactions.as_ref(), static_files.transactions),
]
.iter()
.all(|(target_block_range, highest_static_fileted_block)| {
target_block_range.map_or(true, |target_block_range| {
*target_block_range.start() ==
highest_static_fileted_block.map_or(0, |highest_static_fileted_block| {
highest_static_fileted_block + 1
})
})
})
}
}
impl<Provider> StaticFileProducerInner<Provider> {
fn new(provider: Provider, prune_modes: PruneModes) -> Self {
Self { provider, prune_modes, event_sender: Default::default() }

View File

@ -1,7 +1,7 @@
use crate::StaticFileTargets;
use std::time::Duration;
/// An event emitted by a [`StaticFileProducer`][crate::StaticFileProducer].
/// An event emitted by the static file producer.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum StaticFileProducerEvent {
/// Emitted when static file producer started running.

View File

@ -9,11 +9,14 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
mod compression;
mod event;
mod segment;
use alloy_primitives::BlockNumber;
pub use compression::Compression;
pub use event::StaticFileProducerEvent;
pub use segment::{SegmentConfig, SegmentHeader, SegmentRangeInclusive, StaticFileSegment};
use std::ops::RangeInclusive;
/// Default static file block count.
pub const DEFAULT_BLOCKS_PER_STATIC_FILE: u64 = 500_000;
@ -62,6 +65,43 @@ impl HighestStaticFiles {
}
}
/// Static File targets, per data segment, measured in [`BlockNumber`].
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct StaticFileTargets {
/// Targeted range of headers.
pub headers: Option<RangeInclusive<BlockNumber>>,
/// Targeted range of receipts.
pub receipts: Option<RangeInclusive<BlockNumber>>,
/// Targeted range of transactions.
pub transactions: Option<RangeInclusive<BlockNumber>>,
}
impl StaticFileTargets {
/// Returns `true` if any of the targets are [Some].
pub const fn any(&self) -> bool {
self.headers.is_some() || self.receipts.is_some() || self.transactions.is_some()
}
/// Returns `true` if all targets are either [`None`] or has beginning of the range equal to the
/// highest static file.
pub fn is_contiguous_to_highest_static_files(&self, static_files: HighestStaticFiles) -> bool {
[
(self.headers.as_ref(), static_files.headers),
(self.receipts.as_ref(), static_files.receipts),
(self.transactions.as_ref(), static_files.transactions),
]
.iter()
.all(|(target_block_range, highest_static_fileted_block)| {
target_block_range.map_or(true, |target_block_range| {
*target_block_range.start() ==
highest_static_fileted_block.map_or(0, |highest_static_fileted_block| {
highest_static_fileted_block + 1
})
})
})
}
}
/// Each static file has a fixed number of blocks. This gives out the range where the requested
/// block is positioned. Used for segment filename.
pub const fn find_fixed_range(