Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(provider): rename to get_in_memory_or_storage_by_block_range_while #11421

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ impl<N: ProviderNodeTypes> BlockchainProvider2<N> {
(start, end)
}

/// Fetches a range of data from both in-memory state and storage while a predicate is met.
/// Fetches a range of data from both in-memory state and persistent storage while a predicate
/// is met.
///
/// Creates a snapshot of the in-memory chain state and database provider to prevent
/// inconsistencies. Splits the range into in-memory and storage sections, prioritizing
Expand All @@ -132,7 +133,7 @@ impl<N: ProviderNodeTypes> BlockchainProvider2<N> {
/// user to retrieve the required items from the database using [`RangeInclusive`].
/// * `map_block_state_item` function (`G`) provides each block of the range in the in-memory
/// state, allowing for selection or filtering for the desired data.
fn fetch_db_mem_range_while<T, F, G, P>(
fn get_in_memory_or_storage_by_block_range_while<T, F, G, P>(
&self,
range: impl RangeBounds<BlockNumber>,
fetch_db_range: F,
Expand Down Expand Up @@ -252,7 +253,8 @@ impl<N: ProviderNodeTypes> BlockchainProvider2<N> {
S: FnOnce(DatabaseProviderRO<N::DB, N::ChainSpec>) -> ProviderResult<Option<R>>,
M: Fn(usize, TxNumber, Arc<BlockState>) -> ProviderResult<Option<R>>,
{
// Order of instantiation matters. More information on: `fetch_db_mem_range_while`.
// Order of instantiation matters. More information on:
// `get_in_memory_or_storage_by_block_range_while`.
let in_mem_chain = self.canonical_in_memory_state.canonical_chain().collect::<Vec<_>>();
let provider = self.database.provider()?;

Expand Down Expand Up @@ -426,7 +428,7 @@ impl<N: ProviderNodeTypes> HeaderProvider for BlockchainProvider2<N> {
}

fn headers_range(&self, range: impl RangeBounds<BlockNumber>) -> ProviderResult<Vec<Header>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
range,
|db_provider, range, _| db_provider.headers_range(range),
|block_state, _| Some(block_state.block().block().header.header().clone()),
Expand All @@ -446,7 +448,7 @@ impl<N: ProviderNodeTypes> HeaderProvider for BlockchainProvider2<N> {
&self,
range: impl RangeBounds<BlockNumber>,
) -> ProviderResult<Vec<SealedHeader>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
range,
|db_provider, range, _| db_provider.sealed_headers_range(range),
|block_state, _| Some(block_state.block().block().header.clone()),
Expand All @@ -459,7 +461,7 @@ impl<N: ProviderNodeTypes> HeaderProvider for BlockchainProvider2<N> {
range: impl RangeBounds<BlockNumber>,
predicate: impl FnMut(&SealedHeader) -> bool,
) -> ProviderResult<Vec<SealedHeader>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
range,
|db_provider, range, predicate| db_provider.sealed_headers_while(range, predicate),
|block_state, predicate| {
Expand All @@ -484,7 +486,7 @@ impl<N: ProviderNodeTypes> BlockHashReader for BlockchainProvider2<N> {
start: BlockNumber,
end: BlockNumber,
) -> ProviderResult<Vec<B256>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
start..end,
|db_provider, inclusive_range, _| {
db_provider
Expand Down Expand Up @@ -654,7 +656,7 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
}

fn block_range(&self, range: RangeInclusive<BlockNumber>) -> ProviderResult<Vec<Block>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
range,
|db_provider, range, _| db_provider.block_range(range),
|block_state, _| Some(block_state.block().block().clone().unseal()),
Expand All @@ -666,7 +668,7 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
&self,
range: RangeInclusive<BlockNumber>,
) -> ProviderResult<Vec<BlockWithSenders>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
range,
|db_provider, range, _| db_provider.block_with_senders_range(range),
|block_state, _| Some(block_state.block_with_senders()),
Expand All @@ -678,7 +680,7 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
&self,
range: RangeInclusive<BlockNumber>,
) -> ProviderResult<Vec<SealedBlockWithSenders>> {
self.fetch_db_mem_range_while(
self.get_in_memory_or_storage_by_block_range_while(
range,
|db_provider, range, _| db_provider.sealed_block_with_senders_range(range),
|block_state, _| Some(block_state.sealed_block_with_senders()),
Expand Down
Loading