Skip to content

Commit

Permalink
plural
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Dec 16, 2024
1 parent bbb4447 commit 46f7d85
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/static-file/types/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum StaticFileSegment {
#[strum(serialize = "receipts")]
/// Static File segment responsible for the `Receipts` table.
Receipts,
#[strum(serialize = "block_meta")]
#[strum(serialize = "bmeta")]
/// Static File segment responsible for the `BlockBodyIndices`, `BlockOmmers`,
/// `BlockWithdrawals` tables.
BlockMeta,
Expand Down
12 changes: 6 additions & 6 deletions crates/storage/db/src/static_file/masks.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
add_static_file_mask,
static_file::mask::{ColumnSelectorOne, ColumnSelectorTwo},
BlockBodyIndices, BlockOmmers, BlockWithdrawals, HeaderTerminalDifficulties,
BlockBodyIndices, BlockWithdrawals, HeaderTerminalDifficulties,
};
use alloy_primitives::BlockHash;
use reth_db_api::table::Table;
use reth_db_api::{models::StoredBlockOmmers, table::Table};

// HEADER MASKS
add_static_file_mask! {
Expand Down Expand Up @@ -46,13 +46,13 @@ add_static_file_mask! {
// BLOCK_META MASKS
add_static_file_mask! {
#[doc = "Mask for a `StoredBlockBodyIndices` from BlockMeta static file segment"]
BodyIndiceMask, <BlockBodyIndices as Table>::Value, 0b001
BodyIndicesMask, <BlockBodyIndices as Table>::Value, 0b001
}
add_static_file_mask! {
#[doc = "Mask for a `StoredBlockWithdrawals` from BlockMeta static file segment"]
OmmerMask<H>, H, 0b010
#[doc = "Mask for a `StoredBlockOmmers` from BlockMeta static file segment"]
OmmersMask<H>, StoredBlockOmmers<H>, 0b010
}
add_static_file_mask! {
#[doc = "Mask for a `StoredBlockWithdrawals` from BlockMeta static file segment"]
WithdrawalMask, <BlockWithdrawals as Table>::Value, 0b100
WithdrawalsMask, <BlockWithdrawals as Table>::Value, 0b100
}
18 changes: 8 additions & 10 deletions crates/storage/provider/src/providers/static_file/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ use reth_chainspec::ChainInfo;
use reth_db::{
models::StoredBlockBodyIndices,
static_file::{
BlockHashMask, BodyIndiceMask, HeaderMask, HeaderWithHashMask, OmmerMask, ReceiptMask,
StaticFileCursor, TDWithHashMask, TotalDifficultyMask, TransactionMask, WithdrawalMask,
BlockHashMask, BodyIndicesMask, HeaderMask, HeaderWithHashMask, OmmersMask, ReceiptMask,
StaticFileCursor, TDWithHashMask, TotalDifficultyMask, TransactionMask, WithdrawalsMask,
},
table::{Decompress, Value},
};
use reth_node_types::{FullNodePrimitives, NodePrimitives};
use reth_primitives::{transaction::recover_signers, SealedHeader, TransactionMeta};
use reth_primitives_traits::SignedTransaction;
use reth_storage_api::{
BlockBodyIndicesProvider, BlockReader, OmmersProvider, WithdrawalsProvider,
};
use reth_storage_api::{BlockBodyIndicesProvider, OmmersProvider, WithdrawalsProvider};
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use std::{
fmt::Debug,
Expand Down Expand Up @@ -366,9 +364,9 @@ impl<N: NodePrimitives> WithdrawalsProvider for StaticFileJarProvider<'_, N> {
_: u64,
) -> ProviderResult<Option<Withdrawals>> {
if let Some(num) = id.as_number() {
return Ok(self.cursor()?.get_one::<WithdrawalMask>(num.into())?.map(|s| s.withdrawals))
return Ok(self.cursor()?.get_one::<WithdrawalsMask>(num.into())?.map(|s| s.withdrawals))
}
// Only accepts block number quries
// Only accepts block number queries
Err(ProviderError::UnsupportedProvider)
}

Expand All @@ -383,16 +381,16 @@ impl<N: FullNodePrimitives<BlockHeader: Value>> OmmersProvider for StaticFileJar
if let Some(num) = id.as_number() {
return Ok(self
.cursor()?
.get_one::<OmmerMask<Self::Header>>(num.into())?
.get_one::<OmmersMask<Self::Header>>(num.into())?
.map(|s| s.ommers))
}
// Only accepts block number quries
// Only accepts block number queries
Err(ProviderError::UnsupportedProvider)
}
}

impl<N: NodePrimitives> BlockBodyIndicesProvider for StaticFileJarProvider<'_, N> {
fn block_body_indices(&self, num: u64) -> ProviderResult<Option<StoredBlockBodyIndices>> {
self.cursor()?.get_one::<BodyIndiceMask>(num.into())
self.cursor()?.get_one::<BodyIndicesMask>(num.into())
}
}
15 changes: 10 additions & 5 deletions crates/storage/provider/src/providers/static_file/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,12 @@ impl<N: NodePrimitives> StaticFileProvider<N> {
highest_block,
)?,
StaticFileSegment::BlockMeta => {
todo!(); // TODO(joshie)
self.ensure_invariants::<_, tables::BlockBodyIndices>(
provider,
segment,
highest_tx,
highest_block,
)?
}
} {
update_unwind_target(unwind);
Expand Down Expand Up @@ -1671,12 +1676,12 @@ impl<N: NodePrimitives> WithdrawalsProvider for StaticFileProvider<N> {
fn withdrawals_by_block(
&self,
id: BlockHashOrNumber,
_: u64,
timestamp: u64,
) -> ProviderResult<Option<Withdrawals>> {
if let Some(num) = id.as_number() {
return self
.get_segment_provider_from_block(StaticFileSegment::BlockMeta, num, None)
.and_then(|provider| provider.withdrawals_by_block(num))
.and_then(|provider| provider.withdrawals_by_block(id, timestamp))
.or_else(|err| {
if let ProviderError::MissingStaticFileBlock(_, _) = err {
Ok(None)
Expand All @@ -1685,7 +1690,7 @@ impl<N: NodePrimitives> WithdrawalsProvider for StaticFileProvider<N> {
}
})
}
// Only accepts block number quries
// Only accepts block number queries
Err(ProviderError::UnsupportedProvider)
}

Expand All @@ -1709,7 +1714,7 @@ impl<N: FullNodePrimitives<BlockHeader: Value>> OmmersProvider for StaticFilePro
}
})
}
// Only accepts block number quries
// Only accepts block number queries
Err(ProviderError::UnsupportedProvider)
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/storage/provider/src/providers/static_file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub(crate) struct StaticFileWriters<N> {
headers: RwLock<Option<StaticFileProviderRW<N>>>,
transactions: RwLock<Option<StaticFileProviderRW<N>>>,
receipts: RwLock<Option<StaticFileProviderRW<N>>>,
block_meta: RwLock<Option<StaticFileProviderRW<N>>>,
}

impl<N> Default for StaticFileWriters<N> {
Expand All @@ -41,6 +42,7 @@ impl<N> Default for StaticFileWriters<N> {
headers: Default::default(),
transactions: Default::default(),
receipts: Default::default(),
block_meta: Default::default(),
}
}
}
Expand All @@ -55,7 +57,7 @@ impl<N: NodePrimitives> StaticFileWriters<N> {
StaticFileSegment::Headers => self.headers.write(),
StaticFileSegment::Transactions => self.transactions.write(),
StaticFileSegment::Receipts => self.receipts.write(),
StaticFileSegment::BlockMeta => todo!(), // TODO(joshie),
StaticFileSegment::BlockMeta => self.block_meta.write(),
};

if write_guard.is_none() {
Expand Down

0 comments on commit 46f7d85

Please sign in to comment.